Add simple time period list and detail view

shows time period display name
This commit is contained in:
Jolien Trog 2025-10-10 16:36:33 +02:00
parent f2833c195c
commit e7d758d520
5 changed files with 96 additions and 21 deletions

View file

@ -1,6 +1,37 @@
// Controller für details zu einer Timeperiod
<!--/
indexAction
<?php
Detail; zeigt Display Name oben im Header, Name und Ranges im Content
/-->
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Controllers;
use Icinga\Module\Icingadb\Widget\Detail\TimePeriodDetailsTable;
use ipl\Stdlib\Filter;
use Icinga\Module\Icingadb\Model\Timeperiod;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemTable\TimePeriodsTable;
use ipl\Web\Compat\CompatController;
class TimeperiodController extends Controller
{
public function indexAction(): void
{
$this->addTitleTab('Time Period');
$timePeriodId = $this->params->getRequired('id');
$timePeriod = Timeperiod::on($this->getDb())
->filter(Filter::equal('id', $timePeriodId))
->first();
// $query = Timeperiod::on($db);
$this->addContent(new TimePeriodDetailsTable($timePeriod));
}
}
// Controller für details zu einer Timeperiod
//indexAction
//
//Detail; zeigt Display Name oben im Header, Name und Ranges im Content

View file

@ -1,28 +1,21 @@
// Controller für alle Timeperiods zeigt Liste
<!--/
indexAction
Liste; zeigt erst mal nur Display Name
/-->
<?php
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Controllers;
use Icinga\Application\Icinga;
use Icinga\Module\Icingadb\Model\Timeperiod;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemTable\TimePeriodsTable;
use Icinga\Web\Controller;
use ipl\Web\Compat\CompatController;
class TimeperiodsController extends CompatController
class TimeperiodsController extends Controller
{
public function indexAction(): void
{
$this->addTitleTab('Time Periods');
$db = $this->getDb();
$query = Timeperiod::on($db);
@ -30,6 +23,10 @@ class TimeperiodsController extends CompatController
$this->addContent(new TimePeriodsTable($query));
}
}
// Controller für alle Timeperiods zeigt Liste
//indexAction
//Liste; zeigt erst mal nur Display Name

View file

@ -553,6 +553,12 @@ namespace Icinga\Module\Icingadb {
'description' => $this->translate('List history'),
'icon' => 'history'
]);
$section->add(N_('Time Periods'), [
'url' => 'icingadb/timeperiods',
'priority' => 130,
'description' => $this->translate('List time periods'),
'icon' => 'clock'
]);
}
$this->provideConfigTab('database', [

View file

@ -0,0 +1,38 @@
<?php
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Widget\Detail;
use ipl\Html\Table;
use ipl\Orm\Model;
/**
*
*/
class TimePeriodDetailsTable extends Table
{
protected $defaultAttributes = ['class' => 'common-table'];
protected Model $timePeriod;
public function __construct(Model $timePeriod)
{
$this->timePeriod = $timePeriod;
}
protected function assemble(): void
{
$this->getHeader()->addHtml(self::row([
$this->timePeriod->display_name,
], null, 'th'));
$tbody = $this->getBody();
$tbody->addHtml(self::row([
$this->timePeriod->display_name,
$this->timePeriod->name,
]));
}
}

View file

@ -8,6 +8,7 @@ use Icinga\Module\Icingadb\Common\DetailActions;
use Icinga\Module\Icingadb\Common\Links;
use ipl\Html\Html;
use ipl\Html\Table;
use ipl\Orm\Query;
use ipl\Web\Url;
use ipl\Web\Widget\ItemTable;
use ipl\Web\Widget\Link;
@ -16,22 +17,24 @@ class TimePeriodsTable extends Table
{
protected $defaultAttributes = ['class' => 'common-table'];
protected Query $timeperiods;
protected Query $timePeriods;
public function __construct($timeperiods)
public function __construct($timePeriods)
{
$this->timeperiods = $timeperiods;
$this->timePeriods = $timePeriods;
}
protected function assemble()
{
$tbody = $this->getBody();
foreach ($this->timeperiods as $timeperiod) {
$displayName = new Link($timeperiod->display_name, Url::fromPath('timeperiods/details', ['id' =>$timeperiod->id]));
foreach ($this->timePeriods as $timePeriod) {
$displayName = new Link($timePeriod->display_name, Url::fromPath('icingadb/timeperiod/index', ['id' =>$timePeriod->id]));
$displayName = Html::tag('strong')->add($displayName->setBaseTarget('_next'));
$r = Table::row([
$displayName
// hier muss noch rage rein!
]);
$tbody->addHtml($r);