Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conditions #91

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 49 additions & 45 deletions library/Kubernetes/Web/Conditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,79 @@
namespace Icinga\Module\Kubernetes\Web;

use ipl\Html\Attributes;
use ipl\Html\HtmlDocument;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Web\Widget\EmptyState;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\TimeAgo;

abstract class Conditions extends HtmlDocument
use function Icinga\Module\Kubernetes\yield_iterable;

abstract class Conditions extends BaseHtmlElement
{
use Translation;

protected $tag = 'section';

protected $defaultAttributes = ['class' => 'conditions'];

abstract protected function getConditions(): iterable;

abstract protected function getVisual(string $status, string $type): array;

protected function assemble(): void
{
$conditions = $this->getConditions();
if (empty($conditions)) {
return;
}
$this->addHtml(new HtmlElement('h2', null, new Text($this->translate('Conditions'))));

$listItems = [];

foreach ($conditions as $condition) {
$message = $condition->reason;
$message .= $condition->message ? ': ' . $condition->message : '';
$conditions = yield_iterable($this->getConditions());
if ($conditions->valid()) {
foreach ($conditions as $condition) {
$message = $condition->reason;
$message .= $condition->message ? ': ' . $condition->message : '';

[$status, $icon] = $this->getVisual($condition->status, $condition->type);
[$status, $icon] = $this->getVisual($condition->status, $condition->type);

$listItem = new HtmlElement(
'li',
new Attributes(['class' => 'list-item']),
new HtmlElement(
$listItem = new HtmlElement(
'li',
new Attributes(['class' => 'list-item']),
new HtmlElement(
'div',
new Attributes(['class' => 'visual ' . $status]),
new Icon($icon)
)
);

$main = new HtmlElement(
'div',
new Attributes(['class' => 'visual ' . $status]),
new Icon($icon)
)
);

$main = new HtmlElement(
'div',
new Attributes(['class' => 'main']),
new HtmlElement(
'header',
null,
new HtmlElement('h3', null, new Text($condition->type)),
new TimeAgo($condition->last_transition->getTimestamp())
)
);

if (! empty($message)) {
$caption = new HtmlElement(
'section',
null,
new IcingaStateReason($message)
new Attributes(['class' => 'main']),
new HtmlElement(
'header',
null,
new HtmlElement('h3', null, new Text($condition->type)),
new TimeAgo($condition->last_transition->getTimestamp())
)
);
$main->addHtml($caption);

if (! empty($message)) {
$caption = new HtmlElement(
'div',
null,
new IcingaStateReason($message)
);
$main->addHtml($caption);
}

$listItem->addHtml($main);
$listItems[] = $listItem;
}

$listItem->addHtml($main);
$listItems[] = $listItem;
$this->addHtml(new HtmlElement('ul', new Attributes(['class' => 'conditions item-list']), ...$listItems));
} else {
$this->addHtml(new EmptyState($this->translate('No items to display')));
}

$this->addWrapper(new HtmlElement(
'section',
null,
new HtmlElement('h2', null, new Text($this->translate('Conditions'))),
new HtmlElement('ul', new Attributes(['class' => 'conditions item-list']), ...$listItems)
));
}
}
Loading