Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More intuitive incident age configuration #144

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
4 changes: 2 additions & 2 deletions application/controllers/EventRuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Icinga\Module\Notifications\Common\Auth;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Common\Links;
use Icinga\Module\Notifications\Forms\EventRuleForm;
use Icinga\Module\Notifications\Forms\SaveEventRuleForm;
use Icinga\Module\Notifications\Forms\EventRuleConfig\EventRuleForm;
use Icinga\Module\Notifications\Forms\EventRuleConfig\SaveEventRuleForm;
use Icinga\Module\Notifications\Model\Incident;
use Icinga\Module\Notifications\Model\ObjectExtraTag;
use Icinga\Module\Notifications\Model\Rule;
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/EventRulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Common\Links;
use Icinga\Module\Notifications\Forms\EventRuleForm;
use Icinga\Module\Notifications\Forms\SaveEventRuleForm;
use Icinga\Module\Notifications\Forms\EventRuleConfig\EventRuleForm;
use Icinga\Module\Notifications\Forms\EventRuleConfig\SaveEventRuleForm;
use Icinga\Module\Notifications\Model\ObjectExtraTag;
use Icinga\Module\Notifications\Model\Rule;
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Forms;
namespace Icinga\Module\Notifications\Forms\EventRuleConfig;

use Icinga\Web\Session;
use ipl\Html\Form;
Expand All @@ -18,7 +18,7 @@ class AddEscalationForm extends Form
use Translation;

protected $defaultAttributes = [
'class' => ['add-escalation-form', 'icinga-form', 'icinga-controls'],
'class' => ['add-escalation-form', 'icinga-controls'],
'name' => 'add-escalation-form'
];

Expand All @@ -33,7 +33,7 @@ protected function assemble()
'submitButton',
'add',
[
'class' => ['add-button', 'control-button', 'spinner'],
'class' => ['add-button', 'spinner'],
'label' => new Icon('plus'),
'title' => $this->translate('Add a new escalation')
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Forms;
namespace Icinga\Module\Notifications\Forms\EventRuleConfig;

use Icinga\Web\Session;
use ipl\Html\Form;
Expand All @@ -18,7 +18,7 @@ class AddFilterForm extends Form
use Translation;

protected $defaultAttributes = [
'class' => ['add-filter-form', 'icinga-form', 'icinga-controls'],
'class' => ['add-filter-form', 'icinga-controls'],
'name' => 'add-filter-form'
];

Expand All @@ -33,7 +33,7 @@ protected function assemble()
'submitButton',
'add',
[
'class' => ['add-button', 'control-button', 'spinner'],
'class' => ['add-button', 'spinner'],
'label' => new Icon('plus'),
'title' => $this->translate('Add filter')
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Forms;
namespace Icinga\Module\Notifications\Forms\EventRuleConfig;

use Icinga\Module\Notifications\Widget\EventRuleConfig\FlowLine;
use Icinga\Web\Session;
use ipl\Html\Attributes;
use ipl\Html\Contract\FormElement;
use ipl\Html\Form;
use ipl\Html\HtmlElement;
use ipl\Html\ValidHtml;
use ipl\I18n\Translation;
use ipl\Web\Common\CsrfCounterMeasure;
Expand All @@ -19,7 +22,7 @@ abstract class BaseEscalationForm extends Form
use FormUid;
use Translation;

protected $defaultAttributes = ['class' => ['escalation-form', 'icinga-form', 'icinga-controls']];
protected $defaultAttributes = ['class' => ['escalation-form', 'icinga-controls']];

/** @var int The count of existing conditions/recipients */
protected $count;
Expand Down Expand Up @@ -51,7 +54,7 @@ protected function createAddButton(): FormElement
'submitButton',
'add',
[
'class' => ['add-button', 'control-button', 'spinner'],
'class' => ['add-button', 'spinner'],
'label' => new Icon('plus'),
'title' => $this->translate('Add more'),
'formnovalidate' => true
Expand Down Expand Up @@ -79,7 +82,15 @@ protected function assemble()
$this->assembleElements();
}

$this->add($addButton);
if ($this->options) {
$wrapper = new HtmlElement('div', Attributes::create(['class' => 'option-wrapper']));
$wrapper->addHtml(new HtmlElement('ul', Attributes::create(['class' => 'options']), ...$this->options));
$wrapper->addHtml($addButton);
$this->addHtml($wrapper);
} else {
$this->addHtml((new FlowLine())->getRightArrow());
$this->addHtml($addButton);
}
}

public function isAddButtonPressed(): ?bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Forms;
namespace Icinga\Module\Notifications\Forms\EventRuleConfig;

use Icinga\Module\Notifications\Web\FilterRenderer;
use Icinga\Module\Notifications\Web\Form\EventRuleDecorator;
Expand All @@ -11,8 +11,6 @@
use ipl\Stdlib\Filter;
use ipl\Validator\CallbackValidator;
use ipl\Web\Filter\QueryString;
use ipl\Web\Filter\Renderer;
use ipl\Web\Url;
use ipl\Web\Widget\Icon;

class EscalationConditionForm extends BaseEscalationForm
Expand Down Expand Up @@ -154,8 +152,6 @@ protected function assembleElements(): void
}

$this->handleRemove();

$this->add(Html::tag('ul', ['class' => 'options'], $this->options));
}

public function getValues()
Expand Down Expand Up @@ -223,7 +219,7 @@ protected function createRemoveButton(int $count): ?FormElement
'submitButton',
'remove_' . $count,
[
'class' => ['remove-button', 'control-button', 'spinner'],
'class' => ['remove-button', 'spinner'],
'label' => new Icon('minus'),
'title' => $this->translate('Remove'),
'formnovalidate' => true
Expand Down Expand Up @@ -262,6 +258,10 @@ protected function handleRemove(): void
}
}

if (! $this->deleteRemoveButton || $this->count > 1) {
$this->addAttributes(['class' => 'removal-allowed']);
}

if (empty($this->options)) {
$this->addAttributes(['class' => 'count-zero-escalation-condition-form']);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Forms;
namespace Icinga\Module\Notifications\Forms\EventRuleConfig;

use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Model\Channel;
Expand Down Expand Up @@ -114,8 +114,6 @@ protected function assembleElements(): void
}

$this->handleRemove();

$this->add(Html::tag('ul', ['class' => 'options'], $this->options));
}

public function getValues()
Expand Down Expand Up @@ -189,7 +187,7 @@ protected function createRemoveButton(int $count): ?FormElement
'submitButton',
'remove_' . $count,
[
'class' => ['remove-button', 'control-button', 'spinner'],
'class' => ['remove-button', 'spinner'],
'label' => new Icon('minus'),
'title' => $this->translate('Remove'),
'formnovalidate' => true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Forms;
namespace Icinga\Module\Notifications\Forms\EventRuleConfig;

use Icinga\Web\Session;
use ipl\Html\Form;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Forms;
namespace Icinga\Module\Notifications\Forms\EventRuleConfig;

use Icinga\Web\Session;
use ipl\Html\Form;
Expand All @@ -18,11 +18,11 @@ class RemoveEscalationForm extends Form
use Translation;

protected $defaultAttributes = [
'class' => ['remove-escalation-form', 'icinga-form', 'icinga-controls'],
'class' => ['remove-escalation-form', 'icinga-controls'],
];

/** @var bool */
private $disableRemoveButtton;
/** @var string */
private $disableReason;

protected function assemble()
{
Expand All @@ -33,37 +33,31 @@ protected function assemble()
'submitButton',
'remove',
[
'class' => ['remove-button', 'control-button', 'spinner'],
'class' => ['remove-button', 'spinner'],
'label' => new Icon('minus')
]
);

$this->getElement('remove')
->getAttributes()
->registerAttributeCallback('disabled', function () {
return $this->disableRemoveButtton;
return $this->disableReason !== null;
})
->registerAttributeCallback('title', function () {
if ($this->disableRemoveButtton) {
return $this->translate(
'There exist active incidents for this escalation and hence cannot be removed'
);
}

return $this->translate('Remove escalation');
return $this->disableReason ?? $this->translate('Remove escalation');
});
}

/**
* Method to set disabled state of remove button
* Disable the button and show the given reason in the title
*
* @param bool $disable
* @param string $reason
*
* @return $this
*/
public function setRemoveButtonDisabled(bool $state = false)
public function setRemoveButtonDisabled(string $reason)
{
$this->disableRemoveButtton = $state;
$this->disableReason = $reason;

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Forms;
namespace Icinga\Module\Notifications\Forms\EventRuleConfig;

use Exception;
use Icinga\Module\Notifications\Common\Database;
Expand Down
64 changes: 0 additions & 64 deletions library/Notifications/Widget/Escalations.php

This file was deleted.

Loading