Skip to content

Commit

Permalink
Add favorite toggle to detailed view
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Jan 3, 2025
1 parent 9059bd1 commit b78f1e0
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 0 deletions.
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/CronJobListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

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\Icons;
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\I18n\Translation;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBall;
Expand Down Expand Up @@ -91,5 +95,18 @@ 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')
->setAttribute('data-base-target', '_self')
);
}
}
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/DaemonSetListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

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\Format;
use Icinga\Module\Kubernetes\Common\Links;
use Icinga\Module\Kubernetes\Model\Favorite;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
Expand Down Expand Up @@ -112,5 +116,18 @@ protected function assembleTitle(BaseHtmlElement $title): void
protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 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')
->setAttribute('data-base-target', '_self')
);
}
}
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/DeploymentListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

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\Format;
use Icinga\Module\Kubernetes\Common\Links;
use Icinga\Module\Kubernetes\Model\Favorite;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
Expand Down Expand Up @@ -116,5 +120,18 @@ protected function assembleTitle(BaseHtmlElement $title): void
protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 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')
->setAttribute('data-base-target', '_self')
);
}
}
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/IngressListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

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\I18n\Translation;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBall;
Expand Down Expand Up @@ -84,5 +88,18 @@ 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')
->setAttribute('data-base-target', '_self')
);
}
}
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/JobListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

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\Format;
use Icinga\Module\Kubernetes\Common\Links;
use Icinga\Module\Kubernetes\Model\Favorite;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
Expand Down Expand Up @@ -123,5 +127,18 @@ protected function assembleTitle(BaseHtmlElement $title): void
protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 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')
->setAttribute('data-base-target', '_self')
);
}
}
15 changes: 15 additions & 0 deletions library/Kubernetes/Web/NamespaceListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +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\DaemonSet;
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;
Expand Down Expand Up @@ -165,5 +167,18 @@ protected function assembleVisual(BaseHtmlElement $visual): void
} else {
$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')
->setAttribute('data-base-target', '_self')
);
}
}
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/NodeListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

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 Icinga\Util\Format;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
Expand All @@ -14,6 +17,7 @@
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
Expand Down Expand Up @@ -80,5 +84,18 @@ protected function assembleTitle(BaseHtmlElement $title): void
protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 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')
->setAttribute('data-base-target', '_self')
);
}
}
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/PersistentVolumeClaimListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\AccessModes;
use Icinga\Module\Kubernetes\Common\Auth;
use Icinga\Module\Kubernetes\Common\BaseListItem;
use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Common\Icons;
use Icinga\Module\Kubernetes\Common\Links;
use Icinga\Module\Kubernetes\Model\Favorite;
use Icinga\Module\Kubernetes\Model\PersistentVolumeClaim;
use Icinga\Util\Format;
use ipl\Html\Attributes;
Expand All @@ -17,6 +20,7 @@
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\EmptyState;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Icon;
Expand Down Expand Up @@ -119,5 +123,18 @@ protected function assembleVisual(BaseHtmlElement $visual): void
$visual->addHtml(
new Icon($this->getPhaseIcon(), ['class' => ['pvc-phase-' . strtolower($this->item->phase)]])
);

$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')
->setAttribute('data-base-target', '_self')
);
}
}
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/PersistentVolumeListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\AccessModes;
use Icinga\Module\Kubernetes\Common\Auth;
use Icinga\Module\Kubernetes\Common\BaseListItem;
use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Common\Icons;
use Icinga\Module\Kubernetes\Common\Links;
use Icinga\Module\Kubernetes\Model\Favorite;
use Icinga\Module\Kubernetes\Model\PersistentVolume;
use Icinga\Util\Format;
use ipl\Html\Attributes;
Expand All @@ -17,6 +20,7 @@
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
Expand Down Expand Up @@ -108,5 +112,18 @@ protected function assembleVisual(BaseHtmlElement $visual): void
$visual->addHtml(
new Icon($this->getPhaseIcon(), ['class' => ['pv-phase-' . strtolower($this->item->phase)]])
);

$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')
->setAttribute('data-base-target', '_self')
);
}
}
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/PodListItemDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

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\Container;
use Icinga\Module\Kubernetes\Model\Favorite;
use Icinga\Module\Kubernetes\Model\InitContainer;
use Icinga\Module\Kubernetes\Model\SidecarContainer;
use ipl\Html\Attributes;
Expand All @@ -16,6 +19,7 @@
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
Expand Down Expand Up @@ -145,5 +149,18 @@ protected function assembleTitle(BaseHtmlElement $title): void
protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, 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')
->setAttribute('data-base-target', '_self')
);
}
}
Loading

0 comments on commit b78f1e0

Please sign in to comment.