11
11
use Icinga \Module \Notifications \Web \Control \SearchBar \ObjectSuggestions ;
12
12
use Icinga \Module \Notifications \Widget \ItemList \EventRuleList ;
13
13
use Icinga \Web \Notification ;
14
- use Icinga \Web \Session ;
15
14
use ipl \Html \Attributes ;
16
15
use ipl \Html \Form ;
17
16
use ipl \Html \FormElement \SubmitButtonElement ;
@@ -34,20 +33,14 @@ class EventRulesController extends CompatController
34
33
/** @var Filter\Rule Filter from query string parameters */
35
34
private $ filter ;
36
35
37
- /** @var Session\SessionNamespace */
38
- private $ sessionNamespace ;
39
-
40
36
public function init ()
41
37
{
42
38
$ this ->assertPermission ('notifications/config/event-rules ' );
43
- $ this ->sessionNamespace = Session::getSession ()->getNamespace ('notifications ' );
44
39
}
45
40
46
41
public function indexAction (): void
47
42
{
48
43
$ eventRules = Rule::on (Database::get ());
49
- $ this ->sessionNamespace ->delete ('-1 ' );
50
-
51
44
$ limitControl = $ this ->createLimitControl ();
52
45
$ paginationControl = $ this ->createPaginationControl ($ eventRules );
53
46
$ sortControl = $ this ->createSortControl (
@@ -109,25 +102,15 @@ public function addAction(): void
109
102
$ this ->addContent (Html::tag ('div ' , ['class ' => 'container ' , 'id ' => 'dummy ' ]));
110
103
111
104
$ this ->controls ->addAttributes (['class ' => 'event-rule-detail ' ]);
112
- /** @var string $ruleId */
113
- $ ruleId = $ this ->params ->get ('id ' ) ?? '-1 ' ;
114
-
115
- $ params = $ this ->params ->toArray (false );
116
- /** @var array<string, mixed>|null $config */
117
- $ config = $ this ->sessionNamespace ->get ($ ruleId );
105
+ /** @var array<string, string> $eventRule */
106
+ $ eventRule = $ this ->params ->toArray (false );
107
+ $ ruleId = $ eventRule ['id ' ] ?? '-1 ' ;
118
108
119
- if ($ config === null ) {
120
- /** @var array<string, mixed> $config */
121
- $ config = $ params ;
122
- }
123
-
124
- /** @var array<string, string> $configFilter */
125
- $ configFilter = $ this ->getRequest ()->get ('config-filter ' );
126
- if ($ this ->getRequest ()->has ('searchbar ' )) {
127
- $ config ['object_filter ' ] = $ this ->getRequest ()->get ('searchbar ' );
128
- } elseif ($ configFilter !== null ) {
129
- if (isset ($ configFilter ['show-searchbar ' ]) && $ configFilter ['show-searchbar ' ] === '0 ' ) {
130
- $ config ['object_filter ' ] = '' ;
109
+ if ($ this ->getRequest ()->isPost ()) {
110
+ if ($ this ->getRequest ()->has ('searchbar ' )) {
111
+ $ eventRule ['object_filter ' ] = $ this ->getRequest ()->get ('searchbar ' );
112
+ } else {
113
+ $ eventRule ['object_filter ' ] = '' ;
131
114
}
132
115
}
133
116
@@ -141,34 +124,29 @@ public function addAction(): void
141
124
))->setWrapper (new HtmlElement ('div ' , Attributes::create (['class ' => ['icinga-controls ' , 'save-config ' ]])));
142
125
143
126
$ eventRuleConfig = (new EventRuleConfigForm (
144
- $ config ,
145
127
Url::fromPath (
146
128
'notifications/event-rules/search-editor ' ,
147
- ['id ' => $ ruleId , 'object_filter ' => $ config ['object_filter ' ] ?? '' ]
129
+ ['id ' => $ ruleId , 'object_filter ' => $ eventRule ['object_filter ' ] ?? '' ]
148
130
)
149
131
))
150
132
->registerElement ($ eventRuleConfigSubmitButton )
151
- ->populate ($ config );
133
+ ->populate ($ eventRule );
152
134
153
135
$ eventRuleConfig
154
- ->on (Form::ON_SENT , function (Form $ form ) use ($ config ) {
155
- $ config = array_merge ($ config , $ form ->getValues ());
156
- $ this ->sessionNamespace ->set ('-1 ' , $ config );
157
- })
158
- ->on (Form::ON_SUCCESS , function (EventRuleConfigForm $ form ) use ($ config ) {
136
+ ->on (Form::ON_SUCCESS , function (EventRuleConfigForm $ form ) use ($ eventRule ) {
159
137
/** @var string $ruleId */
160
- $ ruleId = $ config ['id ' ];
138
+ $ ruleId = $ eventRule ['id ' ];
161
139
/** @var string $ruleName */
162
- $ ruleName = $ config ['name ' ];
163
- $ form -> addOrUpdateRule ( $ ruleId , $ config );
164
- $ this -> sessionNamespace -> delete ($ ruleId );
140
+ $ ruleName = $ eventRule ['name ' ];
141
+ $ eventRuleConfig = array_merge ( $ eventRule , $ form -> getValues () );
142
+ $ form -> addOrUpdateRule ($ ruleId, $ eventRuleConfig );
165
143
Notification::success (sprintf (t ('Successfully add event rule %s ' ), $ ruleName ));
166
144
$ this ->redirectNow ('__CLOSE__ ' );
167
145
})
168
146
->handleRequest ($ this ->getServerRequest ());
169
147
170
148
$ eventRuleForm = Html::tag ('div ' , ['class ' => 'event-rule-form ' ], [
171
- Html::tag ('h2 ' , $ config ['name ' ] ?? '' ),
149
+ Html::tag ('h2 ' , $ eventRule ['name ' ] ?? '' ),
172
150
Html::tag (
173
151
'div ' ,
174
152
[
@@ -233,7 +211,7 @@ public function searchEditorAction(): void
233
211
$ editor ->setSuggestionUrl (
234
212
Url::fromPath (
235
213
"notifications/event-rule/complete " ,
236
- ['_disableLayout ' => true , 'showCompact ' => true , 'id ' => Url:: fromRequest ()-> getParams ()-> get ( ' id ' ) ]
214
+ ['_disableLayout ' => true , 'showCompact ' => true , 'id ' => $ ruleId ]
237
215
)
238
216
);
239
217
0 commit comments