diff --git a/application/forms/EventRuleConfigElements/EscalationCondition.php b/application/forms/EventRuleConfigElements/EscalationCondition.php index 4e1c0b865..c84404163 100644 --- a/application/forms/EventRuleConfigElements/EscalationCondition.php +++ b/application/forms/EventRuleConfigElements/EscalationCondition.php @@ -106,6 +106,7 @@ protected function assemble(): void ] ); + $valUnit = null; switch ($this->getPopulatedValue('column_' . $i)) { case 'incident_severity': $val = $this->createElement( @@ -130,28 +131,25 @@ protected function assemble(): void break; case 'incident_age': $val = $this->createElement( - 'text', + 'number', $valName, [ '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' - ) - ); - - return false; - } - - $validator->clearMessages(); - return true; - }) - ] + 'class' => ['right-operand'], + 'value' => 1 + ] + ); + + $valUnit = $this->createElement( + 'select', + 'age_unit_' . $i, + [ + 'options' => [ + 's' => 's', + 'm' => 'm', + 'h' => 'h' + ], + 'class' => 'age-unit' ] ); @@ -167,6 +165,9 @@ protected function assemble(): void $this->registerElement($col); $this->registerElement($op); $this->registerElement($val); + if ($valUnit) { + $this->registerElement($valUnit); + } (new EventRuleDecorator())->decorate($val); $this->conditions[$i] = new EscalationConditionListItem($col, $op, $val, $this->createRemoveButton($i)); @@ -268,7 +269,8 @@ public function getCondition(): string $filterStr = $chosenType . $this->getValue('operator_' . $count) - . ($this->getValue('val_' . $count) ?? ($chosenType === 'incident_severity' ? 'ok' : '')); + . ($this->getValue('val_' . $count) ?? ($chosenType === 'incident_severity' ? 'ok' : '')) + . $this->getValue('age_unit_' . $count, ''); $filter->add(QueryString::parse($filterStr)); } diff --git a/application/forms/EventRuleConfigForm.php b/application/forms/EventRuleConfigForm.php index f0a049499..42086b2ad 100644 --- a/application/forms/EventRuleConfigForm.php +++ b/application/forms/EventRuleConfigForm.php @@ -333,7 +333,16 @@ public function populate($values): self } $conditionFormValues['operator_' . $count] = QueryString::getRuleSymbol($filter); - $conditionFormValues['val_' . $count] = $filter->getValue(); + $conditionValue = $filter->getValue(); + if ( + preg_match('~^(\d+(?:\.?\d*))?([hms])$~', $conditionValue, $matches) + && count($matches) === 3 + ) { + $conditionFormValues['val_' . $count] = $matches[1]; + $conditionFormValues['age_unit_' . $count] = $matches[2]; + } else { + $conditionFormValues['val_' . $count] = $conditionValue; + } } $formValues['escalation-condition_' . bin2hex($position)] = $conditionFormValues; diff --git a/library/Notifications/Widget/ItemList/EscalationConditionListItem.php b/library/Notifications/Widget/ItemList/EscalationConditionListItem.php index e21ff873e..3bb0c1d16 100644 --- a/library/Notifications/Widget/ItemList/EscalationConditionListItem.php +++ b/library/Notifications/Widget/ItemList/EscalationConditionListItem.php @@ -26,15 +26,20 @@ class EscalationConditionListItem extends BaseHtmlElement /** @var FormElement Condition value */ public $conditionVal; + /** @var ?FormElement Condition value */ + public $conditionUnit; + public function __construct( FormElement $conditionType, FormElement $operator, FormElement $conditionVal, + ?FormElement $conditionUnit, ?SubmitButtonElement $removeButton ) { $this->conditionType = $conditionType; $this->operator = $operator; $this->conditionVal = $conditionVal; + $this->conditionUnit = $conditionUnit; $this->removeButton = $removeButton; } @@ -44,6 +49,7 @@ protected function assemble(): void $this->conditionType, $this->operator, $this->conditionVal, + $this->conditionUnit, $this->removeButton ]); } diff --git a/public/css/event-rule-config.less b/public/css/event-rule-config.less index 241976a90..602d4713f 100644 --- a/public/css/event-rule-config.less +++ b/public/css/event-rule-config.less @@ -178,6 +178,12 @@ margin: 0; } + .age-unit { + border-radius: 0.4em; + min-width: 3.5em; + margin-left: 1px; + } + .errors + .remove-button { margin: 0; }