diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:21:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:21:16 +0000 |
commit | 2e582fe0b8b6a8e67982ddb84935db1bd3b401fe (patch) | |
tree | dd511b321f308264952cffb005a4288ea4e478e6 /library/Graphite/Web/Controller/TimeRangePickerTrait.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-graphite-2e582fe0b8b6a8e67982ddb84935db1bd3b401fe.tar.xz icingaweb2-module-graphite-2e582fe0b8b6a8e67982ddb84935db1bd3b401fe.zip |
Adding upstream version 1.2.2.upstream/1.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Graphite/Web/Controller/TimeRangePickerTrait.php')
-rw-r--r-- | library/Graphite/Web/Controller/TimeRangePickerTrait.php | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/library/Graphite/Web/Controller/TimeRangePickerTrait.php b/library/Graphite/Web/Controller/TimeRangePickerTrait.php new file mode 100644 index 0000000..7352b1b --- /dev/null +++ b/library/Graphite/Web/Controller/TimeRangePickerTrait.php @@ -0,0 +1,115 @@ +<?php + +namespace Icinga\Module\Graphite\Web\Controller; + +use Icinga\Module\Graphite\Forms\TimeRangePicker\CommonForm; +use Icinga\Module\Graphite\Forms\TimeRangePicker\CustomForm; +use Icinga\Web\Request; +use Icinga\Web\Url; +use Icinga\Web\View; + +trait TimeRangePickerTrait +{ + /** + * @var CommonForm + */ + protected $timeRangePickerCommonForm; + + /** + * @var CustomForm + */ + protected $timeRangePickerCustomForm; + + /** + * Process the given request using the forms + * + * @param Request $request The request to be processed + * + * @return Request The request supposed to be processed + */ + protected function handleTimeRangePickerRequest(Request $request = null) + { + $this->getTimeRangePickerCommonForm()->handleRequest($request); + return $this->getTimeRangePickerCustomForm()->handleRequest($request); + } + + /** + * Render all needed forms and links + * + * @param View $view + * + * @return string + */ + protected function renderTimeRangePicker(View $view) + { + $url = Url::fromRequest()->getAbsoluteUrl(); + + return '<div class="timerangepicker-container">' + . $this->getTimeRangePickerCommonForm() + . '<div class="flyover flyover-arrow-top" data-flyover-suspends-auto-refresh id="' + . $view->protectId('graphite-customrange') + . '">' + . $view->qlink(null, '#', null, [ + 'title' => $view->translate('Specify custom time range'), + 'class' => 'button-link flyover-toggle', + 'icon' => 'service' + ]) + . '<div class="flyover-content">' . $this->getTimeRangePickerCustomForm() . '</div>' + . '</div>' + . '</div>'; + } + + /** + * Get {@link timeRangePickerCommonForm} + * + * @return CommonForm + */ + public function getTimeRangePickerCommonForm() + { + if ($this->timeRangePickerCommonForm === null) { + $this->timeRangePickerCommonForm = new CommonForm(); + } + + return $this->timeRangePickerCommonForm; + } + + /** + * Set {@link timeRangePickerCommonForm} + * + * @param CommonForm $timeRangePickerCommonForm + * + * @return $this + */ + public function setTimeRangePickerCommonForm(CommonForm $timeRangePickerCommonForm) + { + $this->timeRangePickerCommonForm = $timeRangePickerCommonForm; + return $this; + } + + /** + * Get {@link timeRangePickerCustomForm} + * + * @return CustomForm + */ + public function getTimeRangePickerCustomForm() + { + if ($this->timeRangePickerCustomForm === null) { + $this->timeRangePickerCustomForm = new CustomForm(); + } + + return $this->timeRangePickerCustomForm; + } + + /** + * Set {@link timeRangePickerCustomForm} + * + * @param CustomForm $timeRangePickerCustomForm + * + * @return $this + */ + public function setTimeRangePickerCustomForm(CustomForm $timeRangePickerCustomForm) + { + $this->timeRangePickerCustomForm = $timeRangePickerCustomForm; + return $this; + } +} |