From 7fe9b33ee823f46301186b400e5e20afee298ef2 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 23 Aug 2021 11:43:54 +0200 Subject: [PATCH] Remove showMore from contoller and create it through HistoryList class --- application/controllers/HostController.php | 22 +++++-------------- application/controllers/ServiceController.php | 22 +++++-------------- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 6e30acbc..c7eb39d5 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -23,7 +23,6 @@ use Icinga\Module\Icingadb\Widget\Detail\QuickActions; use Icinga\Module\Icingadb\Widget\ItemList\HostList; use Icinga\Module\Icingadb\Widget\ItemList\HistoryList; use Icinga\Module\Icingadb\Widget\ItemList\ServiceList; -use Icinga\Module\Icingadb\Widget\ShowMore; class HostController extends Controller { @@ -131,7 +130,7 @@ class HostController extends Controller } $limitControl = $this->createLimitControl(); - + $url->setParam('limit', $limitControl->getLimit()); $history->peekAhead(); $history->limit($limitControl->getLimit()); if ($page > 1) { @@ -144,29 +143,18 @@ class HostController extends Controller yield $this->export($history); - $results = $history->execute(); - - $showMore = (new ShowMore( - $results, - $url->setParam('page', $page + 1) - ->setAnchor('page-' . ($page + 1)) - )) - ->setLabel(t('Load More')) - ->setAttribute('data-no-icinga-ajax', true); - $this->addControl((new HostList([$this->host]))->setViewMode('minimal')); $this->addControl($limitControl); - $historyList = (new HistoryList($results)) - ->setPageSize($limitControl->getLimit()); + $historyList = (new HistoryList($history->execute())) + ->setPageSize($limitControl->getLimit()) + ->setLoadMoreUrl($url); if ($compact) { $historyList->setPageNumber($page); } - // TODO: Dirty, really dirty, find a better solution (And I don't just mean `getContent()` !) - $historyList->add($showMore->setTag('li')->addAttributes(['class' => 'list-item'])); if ($compact && $page > 1) { - $this->document->add($historyList->getContent()); + $this->document->addFrom($historyList); } else { $this->addContent($historyList); } diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index e5d862c0..7c0f2f90 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -19,7 +19,6 @@ use Icinga\Module\Icingadb\Widget\Detail\ServiceDetail; use Icinga\Module\Icingadb\Widget\Detail\ServiceInspectionDetail; use Icinga\Module\Icingadb\Widget\ItemList\HistoryList; use Icinga\Module\Icingadb\Widget\ItemList\ServiceList; -use Icinga\Module\Icingadb\Widget\ShowMore; class ServiceController extends Controller { @@ -130,7 +129,7 @@ class ServiceController extends Controller } $limitControl = $this->createLimitControl(); - + $url->setParam('limit', $limitControl->getLimit()); $history->peekAhead(); $history->limit($limitControl->getLimit()); if ($page > 1) { @@ -143,29 +142,18 @@ class ServiceController extends Controller yield $this->export($history); - $results = $history->execute(); - - $showMore = (new ShowMore( - $results, - $url->setParam('page', $page + 1) - ->setAnchor('page-' . ($page + 1)) - )) - ->setLabel(t('Load More')) - ->setAttribute('data-no-icinga-ajax', true); - $this->addControl((new ServiceList([$this->service]))->setViewMode('minimal')); $this->addControl($limitControl); - $historyList = (new HistoryList($results)) - ->setPageSize($limitControl->getLimit()); + $historyList = (new HistoryList($history->execute())) + ->setPageSize($limitControl->getLimit()) + ->setLoadMoreUrl($url); if ($compact) { $historyList->setPageNumber($page); } - // TODO: Dirty, really dirty, find a better solution (And I don't just mean `getContent()` !) - $historyList->add($showMore->setTag('li')->addAttributes(['class' => 'list-item'])); if ($compact && $page > 1) { - $this->document->add($historyList->getContent()); + $this->document->addFrom($historyList); } else { $this->addContent($historyList); }