diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index 6dfcb7e..526539a 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -43,7 +43,7 @@ class ListController extends MonitoringAwareController $this->setupSortControl(['host_display_name' => mt('monitoring', 'Hostname')], $hosts); $this->handleTimeRangePickerRequest(); - $this->view->timeRangePicker = $this->renderTimeRangePicker($this->view); + $this->view->timeRangePicker = $this->renderTimeRangePicker(); } public function servicesAction() @@ -74,7 +74,7 @@ class ListController extends MonitoringAwareController ], $services); $this->handleTimeRangePickerRequest(); - $this->view->timeRangePicker = $this->renderTimeRangePicker($this->view); + $this->view->timeRangePicker = $this->renderTimeRangePicker(); } /** diff --git a/application/controllers/SubcontainerController.php b/application/controllers/SubcontainerController.php new file mode 100644 index 0000000..a1e47be --- /dev/null +++ b/application/controllers/SubcontainerController.php @@ -0,0 +1,16 @@ +view->form = $form = new CustomForm(); + $form->setRedirectUrl($this->getRequest()->getUrl()->getParams()->getRequired('redirect')) + ->handleRequest(); + } +} diff --git a/application/forms/TimeRangePicker/CommonForm.php b/application/forms/TimeRangePicker/CommonForm.php index b3f099f..eec33b8 100644 --- a/application/forms/TimeRangePicker/CommonForm.php +++ b/application/forms/TimeRangePicker/CommonForm.php @@ -3,7 +3,9 @@ namespace Icinga\Module\Graphite\Forms\TimeRangePicker; use Icinga\Web\Form; +use Icinga\Web\View; use Zend_Form_Decorator_HtmlTag; +use Zend_Form_Element; use Zend_Form_Element_Select; class CommonForm extends Form @@ -41,6 +43,38 @@ class CommonForm extends Form public function createElements(array $formData) { + /** @var View $view */ + $view = $this->getView(); + + $this->addElement($this->reduceDecorators($this->createElement( + 'note', + 'custom_range', + [ + 'description' => $this->translate('Specify custom time range'), + 'escape' => false, + 'value' => sprintf( + '%s%s', + md5($this->getRequest()->getUrl()->getAbsoluteUrl()), + $view->qlink( + null, + '#', + null, + [ + 'class' => 'button-link subcontainer-toggle', + 'icon' => 'service' + ] + ), + sprintf( + '
', + $view->url( + 'graphite/subcontainer/customtimerangepicker', + ['redirect' => $this->getRequest()->getUrl()->getAbsoluteUrl()] + ) + ) + ) + ] + ))); + $this->addElements([ $this->createSelect( 'minutes', @@ -129,16 +163,27 @@ class CommonForm extends Form 'autosubmit' => true ]); + return $this->reduceDecorators($element); + } + + /** + * Reduce the decorators set of the given element to the minimum + * + * @param Zend_Form_Element $element + * + * @return Zend_Form_Element + */ + protected function reduceDecorators(Zend_Form_Element $element) + { $decorators = $element->getDecorators(); - $element->setDecorators([ + + return $element->setDecorators([ 'Zend_Form_Decorator_ViewHelper' => $decorators['Zend_Form_Decorator_ViewHelper'], 'Zend_Form_Decorator_HtmlTag' => new Zend_Form_Decorator_HtmlTag([ 'tag' => 'span', - 'title' => $description + 'title' => $element->getDescription() ]) ]); - - return $element; } /** diff --git a/application/views/scripts/subcontainer/customtimerangepicker.phtml b/application/views/scripts/subcontainer/customtimerangepicker.phtml new file mode 100644 index 0000000..ba6a81a --- /dev/null +++ b/application/views/scripts/subcontainer/customtimerangepicker.phtml @@ -0,0 +1,3 @@ +
+ +
diff --git a/library/Graphite/ProvidedHook/Monitoring/DetailviewExtension.php b/library/Graphite/ProvidedHook/Monitoring/DetailviewExtension.php index b044ddd..cc0d00e 100644 --- a/library/Graphite/ProvidedHook/Monitoring/DetailviewExtension.php +++ b/library/Graphite/ProvidedHook/Monitoring/DetailviewExtension.php @@ -15,7 +15,7 @@ class DetailviewExtension extends DetailviewExtensionHook { $this->handleTimeRangePickerRequest(); return '

' . mt('graphite', 'Graphs') . '

' - . $this->renderTimeRangePicker($this->getView()) + . $this->renderTimeRangePicker() . Graphs::forMonitoredObject($object) ->setCompact() ->setWidth(440) diff --git a/library/Graphite/Web/Controller/TimeRangePickerTrait.php b/library/Graphite/Web/Controller/TimeRangePickerTrait.php index 807785d..a001ecc 100644 --- a/library/Graphite/Web/Controller/TimeRangePickerTrait.php +++ b/library/Graphite/Web/Controller/TimeRangePickerTrait.php @@ -37,30 +37,11 @@ trait TimeRangePickerTrait /** * Render all needed forms and links * - * @param View $view - * * @return string */ - protected function renderTimeRangePicker(View $view) + protected function renderTimeRangePicker() { - $result = $this->getTimeRangePickerCommonForm(); - $url = Url::fromRequest(); - - if ($url->hasParam(TimeRangePicker::getRangeCustomizationParameter())) { - $result .= $this->getTimeRangePickerCustomForm(); - } else { - $result .= $view->qlink( - $view->translate('Custom', 'TimeRangePicker'), - $url->with(TimeRangePicker::getRangeCustomizationParameter(), '1'), - null, - [ - 'class' => 'button-link', - 'data-base-target' => '_self' - ] - ); - } - - return '
' . $result . '
'; + return '
' . $this->getTimeRangePickerCommonForm() . '
'; } /** diff --git a/public/css/module.less b/public/css/module.less index 8699853..721e39e 100644 --- a/public/css/module.less +++ b/public/css/module.less @@ -90,3 +90,16 @@ form[name=form_timerangepickercustom_graphite] { margin: 0.25em; } } + +form[name="form_timerangepickercommon_graphite"] span[title] .subcontainer { + position: relative; + + .subcontainer-content { + position: absolute; + + .content { + background-color: #ffffff; + border: thin dotted #000000; + } + } +}