mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 08:14:03 +02:00
parent
16bd78ac30
commit
027aaacff8
@ -12,6 +12,20 @@ use Icinga\Web\Notification;
|
|||||||
*/
|
*/
|
||||||
class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Feature to label map
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $features;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Feature to feature status map
|
||||||
|
*
|
||||||
|
* @var int[]
|
||||||
|
*/
|
||||||
|
protected $featureStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see \Zend_Form::init() For the method documentation.
|
* @see \Zend_Form::init() For the method documentation.
|
||||||
@ -20,6 +34,21 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
|||||||
{
|
{
|
||||||
$this->setUseFormAutosubmit();
|
$this->setUseFormAutosubmit();
|
||||||
$this->setAttrib('class', 'inline object-features');
|
$this->setAttrib('class', 'inline object-features');
|
||||||
|
|
||||||
|
$features = array(
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS => $this->translate('Active Checks'),
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS => $this->translate('Passive Checks'),
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_OBSESSING => $this->translate('Obsessing'),
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS => $this->translate('Notifications'),
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER => $this->translate('Event Handler'),
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION => $this->translate('Flap Detection')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (preg_match('~^v2\.\d+\.\d+.*$~', $this->getIcingaVersion())) {
|
||||||
|
unset($features[ToggleObjectFeatureCommand::FEATURE_OBSESSING]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->features = $features;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,84 +59,54 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
|||||||
{
|
{
|
||||||
$toggleDisabled = $this->hasPermission('monitoring/command/feature/object') ? null : '';
|
$toggleDisabled = $this->hasPermission('monitoring/command/feature/object') ? null : '';
|
||||||
|
|
||||||
$this->addElement(
|
foreach ($this->features as $feature => $label) {
|
||||||
'checkbox',
|
$options = array(
|
||||||
ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS,
|
|
||||||
array(
|
|
||||||
'label' => $this->translate('Active Checks'),
|
|
||||||
'autosubmit' => true,
|
'autosubmit' => true,
|
||||||
'disabled' => $toggleDisabled
|
'disabled' => $toggleDisabled,
|
||||||
)
|
'label' => $label
|
||||||
);
|
|
||||||
$this->addElement(
|
|
||||||
'checkbox',
|
|
||||||
ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS,
|
|
||||||
array(
|
|
||||||
'label' => $this->translate('Passive Checks'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (! preg_match('~^v2\.\d+\.\d+.*$~', $this->getIcingaVersion())) {
|
|
||||||
$this->addElement(
|
|
||||||
'checkbox',
|
|
||||||
ToggleObjectFeatureCommand::FEATURE_OBSESSING,
|
|
||||||
array(
|
|
||||||
'label' => $this->translate('Obsessing'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
if ($formData[$feature . '_changed']) {
|
||||||
|
$options['description'] = $this->translate('changed');
|
||||||
}
|
}
|
||||||
|
if ($formData[$feature] === 2) {
|
||||||
$this->addElement(
|
$options['multiOptions'] = array(
|
||||||
'checkbox',
|
$this->translate('disable'),
|
||||||
ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS,
|
$this->translate('enable'),
|
||||||
array(
|
|
||||||
'label' => $this->translate('Notifications'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->addElement(
|
|
||||||
'checkbox',
|
|
||||||
ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER,
|
|
||||||
array(
|
|
||||||
'label' => $this->translate('Event Handler'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->addElement(
|
|
||||||
'checkbox',
|
|
||||||
ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION,
|
|
||||||
array(
|
|
||||||
'label' => $this->translate('Flap Detection'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
$options['separator'] = '';
|
||||||
|
$elementType = 'radio';
|
||||||
|
} else {
|
||||||
|
$elementType = 'checkbox';
|
||||||
|
$options['value'] = $formData[$feature];
|
||||||
|
}
|
||||||
|
$this->addElement($elementType, $feature, $options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load feature status
|
* Load feature status
|
||||||
*
|
*
|
||||||
* @param MonitoredObject $object
|
* @param MonitoredObject|object $object
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function load(MonitoredObject $object)
|
public function load($object)
|
||||||
{
|
{
|
||||||
$this->create();
|
$featureStatus = array();
|
||||||
foreach ($this->getValues() as $feature => $enabled) {
|
|
||||||
$element = $this->getElement($feature);
|
foreach (array_keys($this->features) as $feature) {
|
||||||
$element->setChecked($object->{$feature});
|
$featureStatus[$feature] = $object->{$feature};
|
||||||
if ((bool) $object->{$feature . '_changed'} === true) {
|
if (isset($object->{$feature . '_changed'})) {
|
||||||
$element->setDescription($this->translate('changed'));
|
$featureStatus[$feature . '_changed'] = (bool) $object->{$feature . '_changed'};
|
||||||
|
} else {
|
||||||
|
$featureStatus[$feature . '_changed'] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->create($featureStatus);
|
||||||
|
|
||||||
|
$this->featureStatus = $featureStatus;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,9 +145,15 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
foreach ($this->getValues() as $feature => $enabled) {
|
||||||
|
if ($enabled === null
|
||||||
|
|| (int) $enabled === (int) $this->featureStatus[$feature]
|
||||||
|
) {
|
||||||
|
// Ignore unchanged features
|
||||||
|
continue;
|
||||||
|
}
|
||||||
foreach ($this->objects as $object) {
|
foreach ($this->objects as $object) {
|
||||||
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
|
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
|
||||||
foreach ($this->getValues() as $feature => $enabled) {
|
|
||||||
if ((bool) $object->{$feature} !== (bool) $enabled) {
|
if ((bool) $object->{$feature} !== (bool) $enabled) {
|
||||||
$toggleFeature = new ToggleObjectFeatureCommand();
|
$toggleFeature = new ToggleObjectFeatureCommand();
|
||||||
$toggleFeature
|
$toggleFeature
|
||||||
@ -156,13 +161,12 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
|||||||
->setObject($object)
|
->setObject($object)
|
||||||
->setEnabled($enabled);
|
->setEnabled($enabled);
|
||||||
$this->getTransport($this->request)->send($toggleFeature);
|
$this->getTransport($this->request)->send($toggleFeature);
|
||||||
|
}
|
||||||
|
}
|
||||||
Notification::success(
|
Notification::success(
|
||||||
$notifications[$feature][$enabled ? 0 : 1]
|
$notifications[$feature][$enabled ? 0 : 1]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -75,11 +75,12 @@ abstract class MonitoredObjectController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->object->populate();
|
$this->object->populate();
|
||||||
$toggleFeaturesForm = new ToggleObjectFeaturesCommandForm();
|
$toggleFeaturesForm = new ToggleObjectFeaturesCommandForm(array(
|
||||||
|
'backend' => $this->backend,
|
||||||
|
'objects' => $this->object
|
||||||
|
));
|
||||||
$toggleFeaturesForm
|
$toggleFeaturesForm
|
||||||
->setBackend($this->backend)
|
|
||||||
->load($this->object)
|
->load($this->object)
|
||||||
->setObjects($this->object)
|
|
||||||
->handleRequest();
|
->handleRequest();
|
||||||
$this->view->toggleFeaturesForm = $toggleFeaturesForm;
|
$this->view->toggleFeaturesForm = $toggleFeaturesForm;
|
||||||
if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) {
|
if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) {
|
||||||
|
@ -417,7 +417,8 @@ form.instance-features span.description, form.object-features span.description {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="checkbox"] {
|
input[type="checkbox"],
|
||||||
|
input[type="radio"] {
|
||||||
margin: @table-column-padding;
|
margin: @table-column-padding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user