From c0b0f82daa1d025577ece4b59581f3883bfb6695 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 14 Mar 2025 16:11:43 +0100 Subject: [PATCH] Introduce class `RedundancyGroupRenderer` --- .../Icingadb/View/RedundancyGroupRenderer.php | 91 +++++++++++++++++++ .../redundancy-group.less} | 6 +- 2 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 library/Icingadb/View/RedundancyGroupRenderer.php rename public/css/{list/redundancy-group-list-item.less => item/redundancy-group.less} (56%) diff --git a/library/Icingadb/View/RedundancyGroupRenderer.php b/library/Icingadb/View/RedundancyGroupRenderer.php new file mode 100644 index 00000000..8bb6ff5c --- /dev/null +++ b/library/Icingadb/View/RedundancyGroupRenderer.php @@ -0,0 +1,91 @@ + */ +class RedundancyGroupRenderer implements ItemRenderer +{ + use Translation; + + public function assembleAttributes($item, Attributes $attributes, string $layout): void + { + $attributes->get('class')->addValue('redundancy-group'); + } + + public function assembleVisual($item, HtmlDocument $visual, string $layout): void + { + $ballSize = StateBall::SIZE_LARGE; + if ($layout === 'minimal' || $layout === 'header') { + $ballSize = StateBall::SIZE_BIG; + } + + $stateBall = new StateBall($item->state->getStateText(), $ballSize); + $stateBall->add($item->state->getIcon()); + + $visual->addHtml($stateBall); + } + + public function assembleCaption($item, HtmlDocument $caption, string $layout): void + { + $caption->addHtml(new DependencyNodeStatistics($item->summary)); + } + + public function assembleFooter($item, HtmlDocument $footer, string $layout): void + { + } + + public function assembleTitle($item, HtmlDocument $title, string $layout): void + { + if ($layout === 'header') { + $subject = new HtmlElement( + 'span', + Attributes::create(['class' => 'subject']), + Text::create($item->display_name) + ); + } else { + $subject = new Link( + $item->display_name, + Url::fromPath('icingadb/redundancygroup', ['id' => bin2hex($item->id)]), + ['class' => 'subject'] + ); + } + + if ($item->state->failed) { + $title->addHtml(Html::sprintf( + $this->translate('%s has no working objects', ' has ...'), + $subject + )); + } else { + $title->addHtml(Html::sprintf( + $this->translate('%s has working objects', ' has ...'), + $subject + )); + } + } + + public function assembleExtendedInfo($item, HtmlDocument $info, string $layout): void + { + $info->addHtml(new TimeSince($item->state->last_state_change->getTimestamp())); + } + + public function assemble($item, string $name, HtmlDocument $element, string $layout): bool + { + return $name === 'icon-image'; // Always add the icon-image section + } +} diff --git a/public/css/list/redundancy-group-list-item.less b/public/css/item/redundancy-group.less similarity index 56% rename from public/css/list/redundancy-group-list-item.less rename to public/css/item/redundancy-group.less index 5fec5aef..ca5dea1e 100644 --- a/public/css/list/redundancy-group-list-item.less +++ b/public/css/item/redundancy-group.less @@ -1,16 +1,16 @@ -.redundancy-group-list-item { +.item-layout.redundancy-group { .caption .object-statistics { justify-self: end; } } -.item-list.minimal > .redundancy-group-list-item { +.minimal-item-layout.redundancy-group { .caption .object-statistics { font-size: 0.75em; } } -.item-list.default-layout > .redundancy-group-list-item { +.default-item-layout.redundancy-group { .title > .subject { margin-right: .28125em; }