Skip to content

Commit

Permalink
Adjust visuals for view modes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Jan 15, 2025
1 parent c544b56 commit ce895b1
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 52 deletions.
22 changes: 0 additions & 22 deletions library/Kubernetes/Web/ConfigMapListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\Auth;
use Icinga\Module\Kubernetes\Common\BaseListItem;
use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Common\Links;
use Icinga\Module\Kubernetes\Model\Favorite;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\TimeAgo;

Expand Down Expand Up @@ -52,22 +48,4 @@ protected function assembleTitle(BaseHtmlElement $title): void
)
);
}

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall('none', StateBall::SIZE_MEDIUM));

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Filter::equal('resource_uuid', $this->item->uuid),
Filter::equal('username', Auth::getInstance()->getUser()->getUsername())
))
->execute();

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-m')
->setAttribute('data-base-target', '_self')
);
}
}
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/CronJobListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall('none', 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall('none', $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Expand All @@ -122,7 +131,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/DaemonSetListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,16 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall($this->item->icinga_state, $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Expand All @@ -142,7 +151,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/DeploymentListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,16 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall($this->item->icinga_state, $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Expand All @@ -146,7 +155,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/IngressListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,16 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall('none', 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall('none', $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Expand All @@ -115,7 +124,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/JobListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,16 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall($this->item->icinga_state, $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Expand All @@ -153,7 +162,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
16 changes: 10 additions & 6 deletions library/Kubernetes/Web/NamespaceListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Icinga\Module\Kubernetes\Model\Deployment;
use Icinga\Module\Kubernetes\Model\Favorite;
use Icinga\Module\Kubernetes\Model\Ingress;
use Icinga\Module\Kubernetes\Model\NamespaceModel;
use Icinga\Module\Kubernetes\Model\PersistentVolume;
use Icinga\Module\Kubernetes\Model\PersistentVolumeClaim;
use Icinga\Module\Kubernetes\Model\Pod;
Expand Down Expand Up @@ -204,10 +203,15 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
if ($this->item->phase === NamespaceModel::PHASE_ACTIVE) {
$visual->addHtml(new StateBall('ok', 'sm'));
} else {
$visual->addHtml(new StateBall('none', 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall('none', $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
Expand All @@ -219,7 +223,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/NodeListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,16 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall($this->item->icinga_state, $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Expand All @@ -111,7 +120,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/PersistentVolumeClaimListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,19 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(
new Icon($this->getPhaseIcon(), ['class' => ['phase-size-sm', 'pvc-phase-' . strtolower($this->item->phase)]])
new Icon($this->getPhaseIcon(), ['class' => ["phase-size-$size", 'pvc-phase-' . strtolower($this->item->phase)]])
);

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Filter::equal('resource_uuid', $this->item->uuid),
Expand All @@ -149,7 +158,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/PersistentVolumeListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,19 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(
new Icon($this->getPhaseIcon(), ['class' => ['phase-size-sm', 'pv-phase-' . strtolower($this->item->phase)]])
new Icon($this->getPhaseIcon(), ['class' => ["phase-size-$size", 'pv-phase-' . strtolower($this->item->phase)]])
);

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Filter::equal('resource_uuid', $this->item->uuid),
Expand All @@ -138,7 +147,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/PodListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,16 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall($this->item->icinga_state, $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Expand All @@ -175,7 +184,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/ReplicaSetListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall($this->item->icinga_state, $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Expand All @@ -137,7 +146,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
13 changes: 11 additions & 2 deletions library/Kubernetes/Web/ServiceListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall('none', 'sm'));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
ViewModeSwitcher::VIEW_MODE_DETAILED => 'm',
};

$visual->addHtml(new StateBall('none', $size));

if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_MINIMAL) {
return;
}

$rs = Favorite::on(Database::connection())
->filter(Filter::all(
Expand All @@ -107,7 +116,7 @@ protected function assembleVisual(BaseHtmlElement $visual): void

$visual->addHtml((new FavoriteToggleForm($rs->hasResult()))
->setAction(Links::toggleFavorite($this->item->uuid)->getAbsoluteUrl())
->setAttribute('class', 'favorite-toggle favorite-toggle-sm')
->setAttribute('class', sprintf("favorite-toggle favorite-toggle-$size"))
->setAttribute('data-base-target', '_self')
);
}
Expand Down
Loading

0 comments on commit ce895b1

Please sign in to comment.