From db4bcc2b64ededbe946c208a390de9b535c8143a Mon Sep 17 00:00:00 2001 From: Jolien Trog Date: Thu, 16 Oct 2025 14:10:42 +0200 Subject: [PATCH] Add ranges view for time period detail --- .../controllers/TimeperiodController.php | 20 +++---- .../controllers/TimeperiodsController.php | 8 --- .../Widget/Detail/TimePeriodDetail.php | 58 +++++++++++++++++++ .../Widget/Detail/TimePeriodDetailsTable.php | 38 ------------ .../Widget/ItemTable/TimePeriodsTable.php | 13 ++++- 5 files changed, 76 insertions(+), 61 deletions(-) create mode 100644 library/Icingadb/Widget/Detail/TimePeriodDetail.php delete mode 100644 library/Icingadb/Widget/Detail/TimePeriodDetailsTable.php diff --git a/application/controllers/TimeperiodController.php b/application/controllers/TimeperiodController.php index 3a925348..a727bce5 100644 --- a/application/controllers/TimeperiodController.php +++ b/application/controllers/TimeperiodController.php @@ -4,12 +4,13 @@ namespace Icinga\Module\Icingadb\Controllers; -use Icinga\Module\Icingadb\Widget\Detail\TimePeriodDetailsTable; +use Icinga\Exception\NotFoundError; +use Icinga\Module\Icingadb\Model\TimeperiodRange; +use Icinga\Module\Icingadb\Widget\Detail\TimePeriodDetail; 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 { @@ -22,16 +23,11 @@ class TimeperiodController extends Controller ->filter(Filter::equal('id', $timePeriodId)) ->first(); -// $query = Timeperiod::on($db); + $ranges = TimeperiodRange::on($this->getDb()) + ->filter(Filter::equal('timeperiod_id', $timePeriodId)); - $this->addContent(new TimePeriodDetailsTable($timePeriod)); + + $this->addContent(new TimePeriodDetail($timePeriod, $ranges)); } } - - -// Controller für details zu einer Timeperiod - -//indexAction -// -//Detail; zeigt Display Name oben im Header, Name und Ranges im Content diff --git a/application/controllers/TimeperiodsController.php b/application/controllers/TimeperiodsController.php index f1acded2..1da9a5b2 100644 --- a/application/controllers/TimeperiodsController.php +++ b/application/controllers/TimeperiodsController.php @@ -15,18 +15,10 @@ class TimeperiodsController extends Controller { $this->addTitleTab('Time Periods'); - $db = $this->getDb(); $query = Timeperiod::on($db); $this->addContent(new TimePeriodsTable($query)); - - } } - -// Controller für alle Timeperiods zeigt Liste - -//indexAction -//Liste; zeigt erst mal nur Display Name diff --git a/library/Icingadb/Widget/Detail/TimePeriodDetail.php b/library/Icingadb/Widget/Detail/TimePeriodDetail.php new file mode 100644 index 00000000..9b242df4 --- /dev/null +++ b/library/Icingadb/Widget/Detail/TimePeriodDetail.php @@ -0,0 +1,58 @@ + 'common-table']; + + protected Model $timePeriod; + protected Query $range; + + public function __construct(Model $timePeriod, Query $range) + { + $this->timePeriod = $timePeriod; + $this->range = $range; + } + + protected function assemble(): void + { + $this->getHeader()->addHtml(self::row([ +// new Ball(Ball::SIZE_BIG), + $this->timePeriod->display_name, + $this->timePeriod->name, + ], null, 'th')); + $tbody = $this->getBody(); + + $this->addHtml( new HtmlElement('h2', null, Text::create(t('Ranges')))); + + foreach ($this->range as $r) { + $detail = [ + new HorizontalKeyValue(t('Day'), $r->range_key), + new HorizontalKeyValue(t('Time'), $r->range_value), + ]; + + $tbody->addHtml(self::row([ + $detail + ])); + } + + if (empty($detail)) { + $this->addHtml(new EmptyState('No ranges have been configured')); + } + } +} diff --git a/library/Icingadb/Widget/Detail/TimePeriodDetailsTable.php b/library/Icingadb/Widget/Detail/TimePeriodDetailsTable.php deleted file mode 100644 index 7001863c..00000000 --- a/library/Icingadb/Widget/Detail/TimePeriodDetailsTable.php +++ /dev/null @@ -1,38 +0,0 @@ - '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, - ])); - } -} diff --git a/library/Icingadb/Widget/ItemTable/TimePeriodsTable.php b/library/Icingadb/Widget/ItemTable/TimePeriodsTable.php index fae51013..725e606c 100644 --- a/library/Icingadb/Widget/ItemTable/TimePeriodsTable.php +++ b/library/Icingadb/Widget/ItemTable/TimePeriodsTable.php @@ -10,6 +10,8 @@ use ipl\Html\Html; use ipl\Html\Table; use ipl\Orm\Query; use ipl\Web\Url; +use ipl\Web\Widget\Ball; +use ipl\Web\Widget\Icon; use ipl\Web\Widget\ItemTable; use ipl\Web\Widget\Link; @@ -29,14 +31,19 @@ class TimePeriodsTable extends Table $tbody = $this->getBody(); foreach ($this->timePeriods as $timePeriod) { + $displayName = new Link($timePeriod->display_name, Url::fromPath('icingadb/timeperiod/index', ['id' =>$timePeriod->id])); + $icon = new Icon('clock'); +// $icon = new Ball(Ball::SIZE_BIG); $displayName = Html::tag('strong')->add($displayName->setBaseTarget('_next')); - $r = Table::row([ + + $displayNameRow = Table::row([ + $icon, $displayName -// hier muss noch rage rein! ]); - $tbody->addHtml($r); + + $tbody->addHtml($displayNameRow); } }