|
| 1 | +<?php |
| 2 | + |
| 3 | +/* Icinga for Kubernetes Web | (c) 2025 Icinga GmbH | AGPLv3 */ |
| 4 | + |
| 5 | +namespace Icinga\Module\Kubernetes\Web; |
| 6 | + |
| 7 | +use Icinga\Web\Widget\Dashboard\Dashlet; |
| 8 | +use ipl\Html\Attributes; |
| 9 | +use ipl\Html\BaseHtmlElement; |
| 10 | +use ipl\Html\Html; |
| 11 | + |
| 12 | +class FavoriteDashlet extends BaseHtmlElement |
| 13 | +{ |
| 14 | + /** @var Dashlet The dashlet to show all favorites of a resource. */ |
| 15 | + protected Dashlet $dashlet; |
| 16 | + |
| 17 | + protected $tag = 'div'; |
| 18 | + |
| 19 | + protected $defaultAttributes = [ |
| 20 | + 'class' => 'container', |
| 21 | + 'data-last-update' => -1, |
| 22 | + 'data-icinga-refresh' => 60 |
| 23 | + ]; |
| 24 | + |
| 25 | + public function __construct(Dashlet $dashlet) |
| 26 | + { |
| 27 | + $this->dashlet = $dashlet; |
| 28 | + } |
| 29 | + |
| 30 | + public function assemble() |
| 31 | + { |
| 32 | + $url = $this->dashlet->getUrl()->setParam('showCompact'); |
| 33 | + $fullUrl = $url->getUrlWithout(['showCompact', 'view']); |
| 34 | + $tooltip = sprintf('Show %s', $this->dashlet->getTitle()); |
| 35 | + $progressLabel = $this->dashlet->getProgressLabe(); |
| 36 | + |
| 37 | + $this->addAttributes(['data-icinga-url' => $url]); |
| 38 | + |
| 39 | + $this->addHtml( |
| 40 | + Html::tag( |
| 41 | + 'h1', |
| 42 | + null, |
| 43 | + Html::tag( |
| 44 | + 'a', |
| 45 | + Attributes::create([ |
| 46 | + 'href' => $fullUrl, |
| 47 | + 'aria-label' => $tooltip, |
| 48 | + 'title' => $tooltip, |
| 49 | + 'data-base-target' => 'col1' |
| 50 | + ]), |
| 51 | + $this->dashlet->getName() |
| 52 | + ) |
| 53 | + ), |
| 54 | + Html::tag( |
| 55 | + 'p', |
| 56 | + Attributes::create(['class' => 'progress-label']), |
| 57 | + [ |
| 58 | + $progressLabel, |
| 59 | + Html::tag('span', null, '.'), |
| 60 | + Html::tag('span', null, '.'), |
| 61 | + Html::tag('span', null, '.') |
| 62 | + ] |
| 63 | + ), |
| 64 | + Html::tag('div', Attributes::create(['class' => 'content'])) |
| 65 | + ); |
| 66 | + } |
| 67 | +} |
0 commit comments