@@ -74,7 +74,7 @@ public function indexAction(): void
74
74
return ;
75
75
}
76
76
77
- $ form ->addOrUpdateRule ($ ruleId , $ diff );
77
+ $ form ->updateRule ($ ruleId , $ diff );
78
78
Notification::success (sprintf (
79
79
t ('Successfully saved event rule %s ' ),
80
80
$ eventRuleConfigValues ['name ' ]
@@ -272,68 +272,6 @@ public static function createFilterString(Filter\Rule $filters): ?string
272
272
return $ filterStr !== '' ? rawurldecode ($ filterStr ) : null ;
273
273
}
274
274
275
- public function addAction (): void
276
- {
277
- $ this ->addTitleTab (t ('Add Event Rule ' ));
278
- $ this ->getTabs ()->setRefreshUrl (Url::fromRequest ());
279
-
280
- // Add an empty container and set it as the X-Icinga-Container when sending extra updates
281
- // from the modal for filter or event rule
282
- $ this ->addContent (Html::tag ('div ' , ['class ' => 'container ' , 'id ' => 'dummy-event-rule-container ' ]));
283
-
284
- $ this ->controls ->addAttributes (['class ' => 'event-rule-detail ' ]);
285
- $ ruleId = $ this ->params ->get ('id ' );
286
-
287
- if ($ this ->getRequest ()->isPost ()) {
288
- if ($ this ->getRequest ()->has ('searchbar ' )) {
289
- $ eventRule ['object_filter ' ] = $ this ->getRequest ()->get ('searchbar ' );
290
- } else {
291
- $ eventRule ['object_filter ' ] = null ;
292
- }
293
- }
294
-
295
- $ eventRuleConfig = new EventRuleConfigForm (
296
- $ eventRule ,
297
- Url::fromPath (
298
- 'notifications/event-rule/search-editor ' ,
299
- ['id ' => $ ruleId , 'object_filter ' => $ eventRule ['object_filter ' ]]
300
- )
301
- );
302
-
303
- $ eventRuleConfig
304
- ->on (Form::ON_SUCCESS , function (EventRuleConfigForm $ form ) use ($ eventRule ) {
305
- $ eventRuleConfig = array_merge ($ eventRule , $ form ->getValues ());
306
- $ ruleId = $ form ->addOrUpdateRule ((int ) $ eventRule ['id ' ], $ eventRuleConfig );
307
- Notification::success (sprintf (t ('Successfully add event rule %s ' ), $ eventRule ['name ' ]));
308
-
309
- $ this ->sendExtraUpdates (['#col1 ' ]);
310
- $ this ->redirectNow (Links::eventRule ($ ruleId ));
311
- })
312
- ->handleRequest ($ this ->getServerRequest ());
313
-
314
- $ eventRuleForm = Html::tag ('div ' , ['class ' => 'event-rule-form ' ], [
315
- Html::tag ('h2 ' , $ eventRule ['name ' ] ?? '' ),
316
- Html::tag (
317
- 'div ' ,
318
- [
319
- 'class ' => 'not-allowed ' ,
320
- 'title ' => $ this ->translate ('Cannot edit event rule until it is saved to database ' )
321
- ],
322
- (new Link (
323
- new Icon ('edit ' ),
324
- Url::fromPath ('notifications/event-rule/edit ' , [
325
- 'id ' => -1
326
- ]),
327
- ['class ' => ['control-button ' , 'disabled ' ]]
328
- ))->openInModal ()
329
- )
330
- ]);
331
-
332
- $ this ->addControl ($ eventRuleForm );
333
- $ this ->addControl ($ eventRuleConfig ->createFormSubmitButtons ());
334
- $ this ->addContent ($ eventRuleConfig );
335
- }
336
-
337
275
public function editAction (): void
338
276
{
339
277
/** @var string $ruleId */
@@ -351,18 +289,24 @@ public function editAction(): void
351
289
$ eventRuleForm = (new EventRuleForm ())
352
290
->populate ($ config )
353
291
->setAction (Url::fromRequest ()->getAbsoluteUrl ())
354
- ->on (Form::ON_SUCCESS , function ($ form ) use ($ ruleId , $ config , $ db ) {
355
- $ config ['name ' ] = $ form ->getValue ('name ' );
356
- $ config ['is_active ' ] = $ form ->getValue ('is_active ' );
357
-
292
+ ->on (Form::ON_SUCCESS , function ($ form ) use ($ ruleId , $ db ) {
358
293
if ($ ruleId === '-1 ' ) {
359
- $ redirectUrl = Url::fromPath ('notifications/event-rules/add ' , ['id ' => '-1 ' ]);
294
+ $ db ->insert ('rule ' , [
295
+ 'name ' => $ form ->getValue ('name ' ),
296
+ 'timeperiod_id ' => null ,
297
+ 'object_filter ' => null ,
298
+ 'is_active ' => $ form ->getValue ('is_active ' )
299
+ ]);
300
+
301
+ $ id = $ db ->lastInsertId ();
302
+
360
303
$ this ->getResponse ()->setHeader ('X-Icinga-Container ' , 'col2 ' );
361
- $ this ->redirectNow ($ redirectUrl );
304
+ $ this ->sendExtraUpdates (['#col1 ' ]);
305
+ $ this ->redirectNow (Links::eventRule ($ id ));
362
306
} else {
363
307
$ db ->update ('rule ' , [
364
- 'name ' => $ config [ 'name ' ] ,
365
- 'is_active ' => $ config [ 'is_active ' ] ?? ' n '
308
+ 'name ' => $ form -> getValue ( 'name ' ) ,
309
+ 'is_active ' => $ form -> getValue ( 'is_active ' )
366
310
], ['id = ? ' => $ ruleId ]);
367
311
368
312
$ this ->sendExtraUpdates ([
0 commit comments