|
| 1 | +<?php |
| 2 | + |
| 3 | +/* Icinga Kubernetes Web | (c) 2023 Icinga GmbH | GPLv2 */ |
| 4 | + |
| 5 | +namespace Icinga\Module\Kubernetes\Controllers; |
| 6 | + |
| 7 | +use Icinga\Module\Kubernetes\Common\Database; |
| 8 | +use Icinga\Module\Kubernetes\Model\PersistentVolumeClaim; |
| 9 | +use Icinga\Module\Kubernetes\Model\Pod; |
| 10 | +use Icinga\Module\Kubernetes\TBD\ObjectSuggestions; |
| 11 | +use Icinga\Module\Kubernetes\Web\Controller; |
| 12 | +use Icinga\Module\Kubernetes\Web\PersistentVolumeClaimList; |
| 13 | +use Icinga\Module\Kubernetes\Web\PodList; |
| 14 | +use ipl\Web\Compat\SearchControls; |
| 15 | +use ipl\Web\Control\LimitControl; |
| 16 | +use ipl\Web\Control\SortControl; |
| 17 | + |
| 18 | +class PersistentvolumeclaimsController extends Controller |
| 19 | +{ |
| 20 | + use SearchControls; |
| 21 | + |
| 22 | + public function indexAction(): void |
| 23 | + { |
| 24 | + $this->addTitleTab($this->translate('Persistent Volume Claims')); |
| 25 | + |
| 26 | + $pvcs = PersistentVolumeClaim::on(Database::connection()); |
| 27 | + |
| 28 | + $limitControl = $this->createLimitControl(); |
| 29 | + $sortControl = $this->createSortControl( |
| 30 | + $pvcs, |
| 31 | + [ |
| 32 | + 'pvc.name' => $this->translate('Name'), |
| 33 | + 'pvc.created' => $this->translate('Created') |
| 34 | + ] |
| 35 | + ); |
| 36 | + |
| 37 | + $paginationControl = $this->createPaginationControl($pvcs); |
| 38 | + $searchBar = $this->createSearchBar($pvcs, [ |
| 39 | + $limitControl->getLimitParam(), |
| 40 | + $sortControl->getSortParam(), |
| 41 | + ]); |
| 42 | + |
| 43 | + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { |
| 44 | + if ($searchBar->hasBeenSubmitted()) { |
| 45 | + $filter = $this->getFilter(); |
| 46 | + } else { |
| 47 | + $this->addControl($searchBar); |
| 48 | + $this->sendMultipartUpdate(); |
| 49 | + |
| 50 | + return; |
| 51 | + } |
| 52 | + } else { |
| 53 | + $filter = $searchBar->getFilter(); |
| 54 | + } |
| 55 | + |
| 56 | + $pvcs->filter($filter); |
| 57 | + |
| 58 | + $this->addControl($paginationControl); |
| 59 | + $this->addControl($sortControl); |
| 60 | + $this->addControl($limitControl); |
| 61 | + $this->addControl($searchBar); |
| 62 | + |
| 63 | + $this->addContent(new PersistentVolumeClaimList($pvcs)); |
| 64 | + |
| 65 | + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { |
| 66 | + $this->sendMultipartUpdate(); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + public function completeAction(): void |
| 71 | + { |
| 72 | + $suggestions = new ObjectSuggestions(); |
| 73 | + $suggestions->setModel(PersistentVolumeClaim::class); |
| 74 | + $suggestions->forRequest($this->getServerRequest()); |
| 75 | + $this->getDocument()->add($suggestions); |
| 76 | + } |
| 77 | + |
| 78 | + public function searchEditorAction(): void |
| 79 | + { |
| 80 | + $editor = $this->createSearchEditor(PersistentVolumeClaim::on(Database::connection()), [ |
| 81 | + LimitControl::DEFAULT_LIMIT_PARAM, |
| 82 | + SortControl::DEFAULT_SORT_PARAM, |
| 83 | + ]); |
| 84 | + |
| 85 | + $this->getDocument()->add($editor); |
| 86 | + $this->setTitle(t('Adjust Filter')); |
| 87 | + } |
| 88 | + |
| 89 | + protected function getPageSize($default) |
| 90 | + { |
| 91 | + return parent::getPageSize($default ?? 50); |
| 92 | + } |
| 93 | +} |
0 commit comments