diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index a1630c5..d9f4a37 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -112,7 +112,10 @@ class ListController extends MonitoringAwareController $dataView, null, null, - array_merge(['format', 'stateType', 'addColumns', 'problems'], TimeRangePicker::getAllRangeParameters()) + array_merge( + ['format', 'stateType', 'addColumns', 'problems', 'graphs_limit'], + TimeRangePicker::getAllRangeParameters() + ) ); $this->handleFormatRequest($dataView); } diff --git a/configuration.php b/configuration.php index 4e72f50..79a0c29 100644 --- a/configuration.php +++ b/configuration.php @@ -4,8 +4,8 @@ /** @var \Icinga\Application\Modules\MenuItemContainer $section */ $section = $this->menuSection(N_('Graphite'), ['icon' => 'chart-area']); -$section->add(N_('Hosts'), ['url' => 'graphite/list/hosts']); -$section->add(N_('Services'), ['url' => 'graphite/list/services']); +$section->add(N_('Hosts'), ['url' => 'graphite/list/hosts?graphs_limit=2']); +$section->add(N_('Services'), ['url' => 'graphite/list/services?graphs_limit=2']); $this->provideConfigTab('backend', array( 'title' => $this->translate('Configure the Graphite Web backend'), diff --git a/library/Graphite/Web/Widget/Graphs.php b/library/Graphite/Web/Widget/Graphs.php index 31e76bf..5220ccb 100644 --- a/library/Graphite/Web/Widget/Graphs.php +++ b/library/Graphite/Web/Widget/Graphs.php @@ -297,6 +297,33 @@ abstract class Graphs extends AbstractWidget } unset($graph); + $currentUrl = Icinga::app()->getRequest()->getUrl(); + $limit = (int) $currentUrl->getParam('graphs_limit', 50); + $total = count($result); + + if ($limit < 1) { + $limit = -1; + } + + if ($limit !== -1 && $total > $limit) { + $result = array_slice($result, 0, $limit); + + if (! $this->compact) { + /** @var View $view */ + $view = $this->view(); + + $url = $this->getGraphsListBaseUrl(); + TimeRangePickerTrait::copyAllRangeParameters($url->getParams(), $currentUrl->getParams()); + + $result[] = "

{$view->qlink( + sprintf($view->translate('Load all %d graphs'), $total), + $url->setParam('graphs_limit', '-1'), + null, + ['class' => 'action-link'] + )}

"; + } + } + if ($this->maxVisibleGraphs && count($result) > $this->maxVisibleGraphs) { /** @var View $view */ $view = $this->view(); @@ -412,6 +439,13 @@ abstract class Graphs extends AbstractWidget */ abstract protected function getDummyImageBaseUrl(); + /** + * Get the base URL to the monitored object's graphs list + * + * @return Url + */ + abstract protected function getGraphsListBaseUrl(); + /** * Extend the {@link getImageBaseUrl()}'s result's parameters with the concrete monitored object * diff --git a/library/Graphite/Web/Widget/Graphs/Host.php b/library/Graphite/Web/Widget/Graphs/Host.php index 0cb9ac7..b5f646f 100644 --- a/library/Graphite/Web/Widget/Graphs/Host.php +++ b/library/Graphite/Web/Widget/Graphs/Host.php @@ -40,6 +40,11 @@ class Host extends Graphs return Url::fromPath('graphite/graph-dummy/host'); } + protected function getGraphsListBaseUrl() + { + return Url::fromPath('graphite/list/hosts', ['host' => $this->host]); + } + protected function filterImageUrl(Url $url) { return $url->setParam('host.name', $this->host); diff --git a/library/Graphite/Web/Widget/Graphs/Service.php b/library/Graphite/Web/Widget/Graphs/Service.php index be1138d..734ef37 100644 --- a/library/Graphite/Web/Widget/Graphs/Service.php +++ b/library/Graphite/Web/Widget/Graphs/Service.php @@ -49,6 +49,11 @@ class Service extends Graphs return Url::fromPath('graphite/graph-dummy/service'); } + protected function getGraphsListBaseUrl() + { + return Url::fromPath('graphite/list/services', ['host' => $this->host, 'service' => $this->service]); + } + protected function filterImageUrl(Url $url) { return $url->setParam('host.name', $this->host)->setParam('service.name', $this->service); diff --git a/public/css/module.less b/public/css/module.less index 7a7e60e..8163b18 100644 --- a/public/css/module.less +++ b/public/css/module.less @@ -114,3 +114,8 @@ form[name=form_timerangepickercustom_graphite] { padding: .5em; margin-bottom: 0; } + +p.load-more { + margin-right: 1em; + text-align: right; +}