Skip to content

Commit

Permalink
WIP: Recheck implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Mar 18, 2024
1 parent 163112c commit 4b1380c
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 146 deletions.
22 changes: 13 additions & 9 deletions application/controllers/EventRuleController.php
Expand Up @@ -83,10 +83,12 @@ public function indexAction(): void
})
->on(EventRuleConfigForm::ON_DISCARD, function () use ($ruleId, $configValues) {
$this->sessionNamespace->delete($ruleId);
Notification::success(sprintf(
t('Successfully discarded changes to event rule %s'),
$configValues['name']
));
Notification::success(
sprintf(
t('Successfully discarded changes to event rule %s'),
$configValues['name']
)
);
$this->redirectNow(Links::eventRule((int) $ruleId));
})
->on(EventRuleConfigForm::ON_CHANGE, function (EventRuleConfigForm $form) use ($ruleId, $configValues) {
Expand Down Expand Up @@ -195,7 +197,7 @@ public function fromDb(int $ruleId): array
$requiredValues = [];

foreach ($recipient as $k => $v) {
if (in_array($k, ['contact_id', 'contactgroup_id', 'schedule_id']) && $v !== null) {
if (in_array($k, ['contact_id', 'contactgroup_id', 'schedule_id']) && $v !== null) {
$requiredValues[$k] = (string) $v;
} elseif (in_array($k, ['id', 'channel_id'])) {
$requiredValues[$k] = $v ? (string) $v : null;
Expand Down Expand Up @@ -247,10 +249,12 @@ public function searchEditorAction(): void
$objectFilter = $eventRule['object_filter'] ?? '';
$editor->setQueryString($objectFilter);
$editor->setAction(Url::fromRequest()->getAbsoluteUrl());
$editor->setSuggestionUrl(Url::fromPath(
"notifications/event-rule/complete",
['_disableLayout' => true, 'showCompact' => true, 'id' => Url::fromRequest()->getParams()->get('id')]
));
$editor->setSuggestionUrl(
Url::fromPath(
"notifications/event-rule/complete",
['_disableLayout' => true, 'showCompact' => true, 'id' => Url::fromRequest()->getParams()->get('id')]
)
);

$editor->on(SearchEditor::ON_SUCCESS, function (SearchEditor $form) use ($ruleId, $eventRule) {
$filter = self::createFilterString($form->getFilter());
Expand Down
15 changes: 8 additions & 7 deletions application/controllers/EventRulesController.php
Expand Up @@ -8,7 +8,6 @@
use Icinga\Module\Notifications\Forms\EventRuleConfigForm;
use Icinga\Module\Notifications\Model\Rule;
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
use Icinga\Module\Notifications\Widget\EventRuleConfig;
use Icinga\Module\Notifications\Widget\ItemList\EventRuleList;
use Icinga\Web\Notification;
use Icinga\Web\Session;
Expand Down Expand Up @@ -122,8 +121,8 @@ public function addAction(): void
$eventRuleConfigSubmitButton = (new SubmitButtonElement(
'save',
[
'label' => t('Add Event Rule'),
'form' => 'event-rule-config-form',
'label' => t('Add Event Rule'),
'form' => 'event-rule-config-form',
'formnovalidate' => true
]
))->setWrapper(new HtmlElement('div', Attributes::create(['class' => ['icinga-controls', 'save-config']])));
Expand Down Expand Up @@ -197,10 +196,12 @@ public function searchEditorAction(): void
$objectFilter = $eventRule['object_filter'] ?? '';
$editor->setQueryString($objectFilter);
$editor->setAction(Url::fromRequest()->getAbsoluteUrl());
$editor->setSuggestionUrl(Url::fromPath(
"notifications/event-rule/complete",
['_disableLayout' => true, 'showCompact' => true, 'id' => Url::fromRequest()->getParams()->get('id')]
));
$editor->setSuggestionUrl(
Url::fromPath(
"notifications/event-rule/complete",
['_disableLayout' => true, 'showCompact' => true, 'id' => Url::fromRequest()->getParams()->get('id')]
)
);

$editor->on(SearchEditor::ON_SUCCESS, function (SearchEditor $form) use ($ruleId, $eventRule) {
$filter = self::createFilterString($form->getFilter());
Expand Down
55 changes: 29 additions & 26 deletions application/forms/EventRuleConfigElements/EscalationCondition.php
Expand Up @@ -60,24 +60,25 @@ protected function assemble(): void
'submitButton',
'add-condition',
[
'class' => ['add-button', 'control-button', 'spinner'],
'label' => new Icon('plus'),
'title' => $this->translate('Add Condition'),
'formnovalidate' => true
'class' => ['add-button', 'control-button', 'spinner'],
'label' => new Icon('plus'),
'title' => $this->translate('Add Condition'),
'formnovalidate' => true
]
);

$this->registerElement($addCondition);

/** @var string|int $conditionCount */
$conditionCount = $this->getValue('condition-count');
$conditionCount = (int) $conditionCount;
$this->addElement(
'hidden',
'id'
);

if ($addCondition->hasBeenPressed()) {
$conditionCount += 1;
$conditionCount = $conditionCount + 1;
$this->getElement('condition-count')->setValue($conditionCount);
}

Expand All @@ -92,14 +93,14 @@ protected function assemble(): void
'select',
$colName,
[
'class' => ['autosubmit', 'left-operand'],
'options' => [
'' => sprintf(' - %s - ', $this->translate('Please choose')),
'class' => ['autosubmit', 'left-operand'],
'options' => [
'' => sprintf(' - %s - ', $this->translate('Please choose')),
'incident_severity' => $this->translate('Incident Severity'),
'incident_age' => $this->translate('Incident Age')
'incident_age' => $this->translate('Incident Age')
],
'disabledOptions' => [''],
'required' => true
'disabledOptions' => [''],
'required' => true
]
);

Expand All @@ -109,8 +110,8 @@ protected function assemble(): void
'select',
$opName,
[
'class' => ['class' => 'operator-input', 'autosubmit'],
'options' => array_combine($operators, $operators),
'class' => ['class' => 'operator-input', 'autosubmit'],
'options' => array_combine($operators, $operators),
'required' => true
]
);
Expand Down Expand Up @@ -146,7 +147,7 @@ protected function assemble(): void
}

$this->addElement('hidden', $typeName, [
'value' => 'incident_severity'
'value' => 'incident_severity'
]);

break;
Expand All @@ -156,15 +157,17 @@ protected function assemble(): void
'text',
$valName,
[
'required' => true,
'class' => ['autosubmit', 'right-operand'],
'required' => true,
'class' => ['autosubmit', 'right-operand'],
'validators' => [
new CallbackValidator(function ($value, $validator) {
if (! preg_match('~^\d+(?:\.?\d*)?[hms]{1}$~', $value)) {
$validator->addMessage($this->translate(
'Only numbers with optional fractions (separated by a dot)'
. ' and one of these suffixes are allowed: h, m, s'
));
$validator->addMessage(
$this->translate(
'Only numbers with optional fractions (separated by a dot)'
. ' and one of these suffixes are allowed: h, m, s'
)
);

return false;
}
Expand Down Expand Up @@ -194,7 +197,7 @@ protected function assemble(): void
$val = $this->createElement('text', $valName, [
'class' => 'right-operand',
'placeholder' => $this->translate('Please make a decision'),
'disabled' => true
'disabled' => true
]);
}

Expand Down Expand Up @@ -269,11 +272,11 @@ protected function createRemoveButton(int $count): ?SubmitButtonElement
'submitButton',
'remove',
[
'class' => ['remove-button', 'control-button', 'spinner'],
'label' => new Icon('minus'),
'title' => $this->translate('Remove'),
'formnovalidate' => true,
'value' => (string) $count
'class' => ['remove-button', 'control-button', 'spinner'],
'label' => new Icon('minus'),
'title' => $this->translate('Remove'),
'formnovalidate' => true,
'value' => (string) $count
]
);

Expand Down
36 changes: 18 additions & 18 deletions application/forms/EventRuleConfigElements/EscalationRecipient.php
Expand Up @@ -20,7 +20,7 @@ class EscalationRecipient extends FieldsetElement
{
protected $defaultAttributes = ['class' => 'escalation-recipient'];

/** @var EscalationRecipientListItem[] */
/** @var EscalationRecipientListItem[] */
protected $recipients = [];

protected function assemble(): void
Expand All @@ -36,9 +36,9 @@ protected function assemble(): void
'submitButton',
'add-recipient',
[
'class' => ['add-button', 'control-button', 'spinner'],
'label' => new Icon('plus'),
'title' => $this->translate('Add Recipient'),
'class' => ['add-button', 'control-button', 'spinner'],
'label' => new Icon('plus'),
'title' => $this->translate('Add Recipient'),
'formnovalidate' => true
]
);
Expand All @@ -63,13 +63,13 @@ protected function assemble(): void
'select',
'column_' . $i,
[
'class' => ['autosubmit', 'left-operand'],
'options' => [
'class' => ['autosubmit', 'left-operand'],
'options' => [
'' => sprintf(' - %s - ', $this->translate('Please choose'))
] + $this->fetchOptions(),
'disabledOptions' => [''],
'required' => true,
'value' => $this->getPopulatedValue('column_' . $i)
'disabledOptions' => [''],
'required' => true,
'value' => $this->getPopulatedValue('column_' . $i)
]
);

Expand All @@ -83,10 +83,10 @@ protected function assemble(): void
'select',
'val_' . $i,
[
'class' => ['autosubmit', 'right-operand'],
'options' => $options,
'disabledOptions' => [''],
'value' => $this->getPopulatedValue('val_' . $i)
'class' => ['autosubmit', 'right-operand'],
'options' => $options,
'disabledOptions' => [''],
'value' => $this->getPopulatedValue('val_' . $i)
]
);

Expand Down Expand Up @@ -200,11 +200,11 @@ protected function createRemoveButton(int $pos): ?FormElement
'submitButton',
'remove',
[
'class' => ['remove-button', 'control-button', 'spinner'],
'label' => new Icon('minus'),
'title' => $this->translate('Remove'),
'formnovalidate' => true,
'value' => (string) $pos
'class' => ['remove-button', 'control-button', 'spinner'],
'label' => new Icon('minus'),
'title' => $this->translate('Remove'),
'formnovalidate' => true,
'value' => (string) $pos
]
);

Expand Down
22 changes: 11 additions & 11 deletions application/forms/EventRuleConfigElements/EventRuleConfigFilter.php
Expand Up @@ -16,7 +16,7 @@ class EventRuleConfigFilter extends FieldsetElement
/** @var Url Url of the search editor */
protected $searchEditorUrl;

/** @var ?string Event rule's object filter*/
/** @var ?string Event rule's object filter */
protected $objectFilter;

protected $defaultAttributes = ['class' => 'config-filter'];
Expand All @@ -34,10 +34,10 @@ protected function assemble(): void
'submitButton',
'add-filter',
[
'class' => ['add-button', 'control-button', 'spinner'],
'label' => new Icon('plus'),
'class' => ['add-button', 'control-button', 'spinner'],
'label' => new Icon('plus'),
'formnovalidate' => true,
'title' => $this->translate('Add filter')
'title' => $this->translate('Add filter')
]
);

Expand All @@ -57,19 +57,19 @@ protected function assemble(): void
new Icon('cog'),
$this->getSearchEditorUrl(),
Attributes::create([
'class' => 'search-editor-opener control-button',
'title' => t('Adjust Filter'),
'data-icinga-modal' => true,
'data-no-icinga-ajax' => true,
'class' => 'search-editor-opener control-button',
'title' => t('Adjust Filter'),
'data-icinga-modal' => true,
'data-no-icinga-ajax' => true,
])
);

$searchBar = new TextElement(
'searchbar',
[
'class' => 'filter-input control-button',
'readonly' => true,
'value' => $this->objectFilter
'class' => 'filter-input control-button',
'readonly' => true,
'value' => $this->objectFilter
]
);

Expand Down

0 comments on commit 4b1380c

Please sign in to comment.