3030use ipl \Web \Compat \CompatController ;
3131use ipl \Web \Control \SearchBar \SearchException ;
3232use ipl \Web \Control \SearchEditor ;
33+ use ipl \Web \Filter \Renderer ;
3334use ipl \Web \Url ;
3435use ipl \Web \Widget \Icon ;
3536use ipl \Web \Widget \Link ;
@@ -202,59 +203,77 @@ public function searchEditorAction(): void
202203 $ ruleId = (int ) $ this ->params ->getRequired ('id ' );
203204 $ filter = $ this ->params ->get ('object_filter ' , $ this ->session ->get ('object_filter ' ));
204205 $ hook = $ this ->resolveSourceHook ($ ruleId );
205-
206- if ($ filter ) {
207- try {
208- $ parsedFilter = (new RuleParser ())->parseJson ($ filter );
209- $ applyLabels = function (Filter \Rule $ rule ) use ($ hook , &$ applyLabels ): void {
210- if ($ rule instanceof Filter \Chain) {
211- foreach ($ rule as $ child ) {
212- $ applyLabels ($ child );
206+ $ editor = (new SearchEditor ())
207+ ->setAction (Url::fromRequest ()->with ('object_filter ' , $ filter )->getAbsoluteUrl ());
208+
209+ if ($ hook ) {
210+ if ($ filter ) {
211+ try {
212+ $ parsedFilter = (new RuleParser ())->parseJson ($ filter );
213+ $ applyLabels = function (Filter \Rule $ rule ) use ($ hook , &$ applyLabels ): void {
214+ if ($ rule instanceof Filter \Chain) {
215+ foreach ($ rule as $ child ) {
216+ $ applyLabels ($ child );
217+ }
218+ } else {
219+ /** @var Condition $rule */
220+ $ hook ->enrichCondition ($ rule );
213221 }
214- } else {
215- /** @var Condition $rule */
216- $ hook ->enrichCondition ($ rule );
217- }
218- };
219-
220- $ applyLabels ($ parsedFilter );
221- } catch (JsonException $ e ) {
222- Logger::error ('Failed to parse rule filter configuration: %s (Error: %s) ' , $ filter , $ e );
223- throw new ConfigurationError ($ this ->translate (
224- 'Failed to parse rule filter configuration. Please contact your system administrator. '
225- ));
222+ };
223+
224+ $ applyLabels ($ parsedFilter );
225+ } catch (JsonException $ e ) {
226+ Logger::error ('Failed to parse rule filter configuration: %s (Error: %s) ' , $ filter , $ e );
227+ throw new ConfigurationError (
228+ $ this ->translate (
229+ 'Failed to parse rule filter configuration. Please contact your system administrator. '
230+ )
231+ );
232+ }
226233 }
227- }
228234
229- $ editor = (new SearchEditor ())
230- ->setFilter ($ parsedFilter ?? new Filter \All ())
231- ->setSuggestionUrl (
232- Url::fromPath (
233- 'notifications/event-rule/suggest ' ,
234- ['id ' => $ ruleId , '_disableLayout ' => true , 'showCompact ' => true ]
235+ $ editor
236+ ->setFilter ($ parsedFilter ?? new Filter \All ())
237+ ->setSuggestionUrl (
238+ Url::fromPath (
239+ 'notifications/event-rule/suggest ' ,
240+ ['id ' => $ ruleId , '_disableLayout ' => true , 'showCompact ' => true ]
241+ )
235242 )
236- )
237- ->setAction (Url::fromRequest ()->with ('object_filter ' , $ filter )->getAbsoluteUrl ())
238- ->setMetadataFields ($ hook ->getMetadataKeys ())
239- ->on (
240- SearchEditor::ON_VALIDATE_COLUMN ,
241- function (Condition $ condition ) use ($ hook ) {
242- if (! $ hook ->isValidCondition ($ condition )) {
243- throw new SearchException ($ this ->translate ('Is not a valid column ' ));
244- }
243+ ->setMetadataFields ($ hook ->getMetadataKeys ())
244+ ->on (
245+ SearchEditor::ON_VALIDATE_COLUMN ,
246+ function (Condition $ condition ) use ($ hook ) {
247+ if (! $ hook ->isValidCondition ($ condition )) {
248+ throw new SearchException ($ this ->translate ('Is not a valid column ' ));
249+ }
245250
246- $ condition ->metaData ()->set ('jsonPath ' , $ hook ->getJsonPath ($ condition ));
247- }
248- )
249- ->on (Form::ON_SUBMIT , function (SearchEditor $ form ) use ($ ruleId , $ hook ) {
250- $ this ->session ->set (
251- 'object_filter ' ,
252- (new RuleSerializer ($ form ->getFilter (), $ hook ->getMetadataKeys ()))->getJson ()
251+ $ condition ->metaData ()->set ('jsonPath ' , $ hook ->getJsonPath ($ condition ));
252+ }
253+ )
254+ ->on (Form::ON_SUBMIT , function (SearchEditor $ form ) use ($ ruleId , $ hook ) {
255+ $ this ->session ->set (
256+ 'object_filter ' ,
257+ (new RuleSerializer ($ form ->getFilter (), $ hook ->getMetadataKeys ()))->getJson ()
258+ );
259+ $ this ->redirectNow (Links::eventRule ($ ruleId )->setParam ('_filterOnly ' ));
260+ });
261+ } else {
262+ $ editor
263+ ->setQueryString ($ filter ?? '' )
264+ ->on (
265+ Form::ON_SUBMIT ,
266+ function (SearchEditor $ editor ) use ($ ruleId ) {
267+ $ this ->session ->set (
268+ 'object_filter ' ,
269+ (new Renderer ($ editor ->getFilter ()))->render ()
270+ );
271+ $ this ->redirectNow (Links::eventRule ($ ruleId )->setParam ('_filterOnly ' ));
272+ }
253273 );
254- $ this ->redirectNow (Links::eventRule ($ ruleId )->setParam ('_filterOnly ' ));
255- })
256- ->handleRequest ($ this ->getServerRequest ());
274+ }
257275
276+ $ editor ->handleRequest ($ this ->getServerRequest ());
258277 $ this ->getDocument ()->addHtml ($ editor );
259278
260279 $ this ->setTitle ($ this ->translate ('Adjust Filter ' ));
@@ -267,7 +286,7 @@ public function suggestAction(): void
267286 $ this ->getDocument ()->addHtml ($ suggestions ->forRequest ($ this ->getServerRequest ()));
268287 }
269288
270- protected function resolveSourceHook (int $ ruleId ): SourceHook
289+ protected function resolveSourceHook (int $ ruleId ): ? SourceHook
271290 {
272291 $ source = null ;
273292 if ($ ruleId !== -1 ) {
@@ -289,6 +308,10 @@ protected function resolveSourceHook(int $ruleId): SourceHook
289308 $ this ->httpNotFound ($ this ->translate ('Rule not found ' ));
290309 }
291310
311+ if ($ source ->type === 'generic ' ) {
312+ return null ;
313+ }
314+
292315 $ hook = null ;
293316 foreach (Hook::all ('Notifications/v2/Source ' ) as $ h ) {
294317 /** @var SourceHook $h */
0 commit comments