From dc05b2e933f32feb81c5cd24c1bbbbb27b997dba Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Mon, 15 Sep 2014 11:38:36 +0200 Subject: [PATCH] Transform TimelineIntervalBox into a generic ListBox Add options to control the changed url parameter and the displayed label to make it usable in generic cases. --- .../controllers/TimelineController.php | 8 +++-- ...{TimelineIntervalBox.php => SelectBox.php} | 29 ++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) rename modules/monitoring/library/Monitoring/Web/Widget/{TimelineIntervalBox.php => SelectBox.php} (77%) diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php index 2da29a0b9..7b4ab139f 100644 --- a/modules/monitoring/application/controllers/TimelineController.php +++ b/modules/monitoring/application/controllers/TimelineController.php @@ -12,7 +12,7 @@ use Icinga\Util\DateTimeFactory; use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Timeline\TimeLine; use Icinga\Module\Monitoring\Timeline\TimeRange; -use Icinga\Module\Monitoring\Web\Widget\TimelineIntervalBox; +use Icinga\Module\Monitoring\Web\Widget\SelectBox; use Icinga\Module\Monitoring\DataView\EventHistory as EventHistoryView; class Monitoring_TimelineController extends Controller @@ -85,7 +85,7 @@ class Monitoring_TimelineController extends Controller */ private function setupIntervalBox() { - $box = new TimelineIntervalBox( + $box = new SelectBox( 'intervalBox', array( '4h' => t('4 Hours'), @@ -93,7 +93,9 @@ class Monitoring_TimelineController extends Controller '1w' => t('One week'), '1m' => t('One month'), '1y' => t('One year') - ) + ), + t('TimeLine interval'), + 'interval' ); $box->applyRequest($this->getRequest()); $this->view->intervalBox = $box; diff --git a/modules/monitoring/library/Monitoring/Web/Widget/TimelineIntervalBox.php b/modules/monitoring/library/Monitoring/Web/Widget/SelectBox.php similarity index 77% rename from modules/monitoring/library/Monitoring/Web/Widget/TimelineIntervalBox.php rename to modules/monitoring/library/Monitoring/Web/Widget/SelectBox.php index 307fffba8..244a5d88e 100644 --- a/modules/monitoring/library/Monitoring/Web/Widget/TimelineIntervalBox.php +++ b/modules/monitoring/library/Monitoring/Web/Widget/SelectBox.php @@ -8,10 +8,7 @@ use Icinga\Web\Form; use Icinga\Web\Request; use Icinga\Web\Widget\AbstractWidget; -/** - * @todo Might be better if this is a generic selection widget. - */ -class TimelineIntervalBox extends AbstractWidget +class SelectBox extends AbstractWidget { /** * The name of the form that will be created @@ -27,6 +24,20 @@ class TimelineIntervalBox extends AbstractWidget */ private $values; + /** + * The label displayed next to the select box + * + * @var string + */ + private $label; + + /** + * The name of the url parameter to set + * + * @var string + */ + private $parameter; + /** * A request object used for initial form population * @@ -39,11 +50,15 @@ class TimelineIntervalBox extends AbstractWidget * * @param string $name The name of the form that will be created * @param array $values An array containing all intervals with their associated labels + * @param string $label The label displayed next to the select box + * @param string $param The request parameter name to set */ - public function __construct($name, array $values) + public function __construct($name, array $values, $label = 'Select', $param = 'selection') { $this->name = $name; $this->values = $values; + $this->label = $label; + $this->parameter = $param; } /** @@ -88,9 +103,9 @@ class TimelineIntervalBox extends AbstractWidget $form->setName($this->name); $form->addElement( 'select', - 'interval', + $this->parameter, array( - 'label' => 'Timeline Interval', + 'label' => $this->label, 'multiOptions' => $this->values, 'class' => 'autosubmit' )