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.
This commit is contained in:
Matthias Jentsch 2014-09-15 11:38:36 +02:00
parent ef2f332869
commit dc05b2e933
2 changed files with 27 additions and 10 deletions

View File

@ -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;

View File

@ -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'
)