Skip to content

Commit

Permalink
Add favorite toggle to all relevant resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Jan 3, 2025
1 parent ddf7cba commit 9059bd1
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 3 deletions.
17 changes: 17 additions & 0 deletions library/Kubernetes/Web/CronJobListItem.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\Icons;
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\Link;
use ipl\Web\Widget\StateBall;
Expand Down Expand Up @@ -97,5 +101,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/DaemonSetListItem.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 @@ -117,5 +121,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/DeploymentListItem.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 @@ -121,5 +125,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/IngressListItem.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\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\Link;
use ipl\Web\Widget\StateBall;
Expand Down Expand Up @@ -90,5 +94,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/JobListItem.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 @@ -128,5 +132,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/NamespaceListItem.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 @@ -170,5 +172,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/NodeListItem.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 @@ -87,5 +91,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')
);
}
}
19 changes: 18 additions & 1 deletion library/Kubernetes/Web/PersistentVolumeClaimListItem.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 @@ -122,7 +126,20 @@ protected function assembleTitle(BaseHtmlElement $title): void
protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(
new Icon($this->getPhaseIcon(), ['class' => ['pvc-phase-' . strtolower($this->item->phase)]])
new Icon($this->getPhaseIcon(), ['class' => ['pvc-phase', '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')
);
}
}
19 changes: 18 additions & 1 deletion library/Kubernetes/Web/PersistentVolumeListItem.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 @@ -111,7 +115,20 @@ protected function assembleTitle(BaseHtmlElement $title): void
protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(
new Icon($this->getPhaseIcon(), ['class' => ['pv-phase-' . strtolower($this->item->phase)]])
new Icon($this->getPhaseIcon(), ['class' => ['pv-phase', '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/PodListItem.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 @@ -150,5 +154,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 9059bd1

Please sign in to comment.