From 8d04c8548ad220a309dc5b04b1db278b16981b93 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 10 Nov 2015 11:51:26 +0100 Subject: [PATCH] Do not hardcode action specific parameters to preserve in the FilterEditor This should only happen for other control parameters or framework specific stuff. This is still subject to improvement, as this solution is rather ugly imho.. refs #10370 --- application/controllers/GroupController.php | 2 +- application/controllers/UserController.php | 3 +- library/Icinga/Web/Controller.php | 36 ++++++++++--------- .../controllers/ListController.php | 7 +++- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/application/controllers/GroupController.php b/application/controllers/GroupController.php index 21fba5ebb..949aa8fc6 100644 --- a/application/controllers/GroupController.php +++ b/application/controllers/GroupController.php @@ -97,7 +97,7 @@ class GroupController extends AuthBackendController ->from('group_membership', array('user_name')) ->where('group_name', $groupName); - $this->setupFilterControl($members, null, array('user')); + $this->setupFilterControl($members, null, array('user'), array('group')); $this->setupPaginationControl($members); $this->setupLimitControl(); $this->setupSortControl( diff --git a/application/controllers/UserController.php b/application/controllers/UserController.php index 69d4a71a5..573d85c93 100644 --- a/application/controllers/UserController.php +++ b/application/controllers/UserController.php @@ -99,7 +99,8 @@ class UserController extends AuthBackendController $this->setupFilterControl( $memberships, array('group_name' => t('User Group')), - array('group_name') + array('group_name'), + array('user') ); $this->setupPaginationControl($memberships); $this->setupLimitControl(); diff --git a/library/Icinga/Web/Controller.php b/library/Icinga/Web/Controller.php index ac92e45b6..891b70329 100644 --- a/library/Icinga/Web/Controller.php +++ b/library/Icinga/Web/Controller.php @@ -186,6 +186,7 @@ class Controller extends ModuleActionController * @param Filterable $filterable The filterable to create a filter editor for * @param array $filterColumns The filter columns to offer to the user * @param array $searchColumns The search columns to utilize for quick searches + * @param array $preserveParams The url parameters to preserve * * @return $this * @@ -194,25 +195,26 @@ class Controller extends ModuleActionController protected function setupFilterControl( Filterable $filterable, array $filterColumns = null, - array $searchColumns = null + array $searchColumns = null, + array $preserveParams = null ) { - $editor = Widget::create('filterEditor') + $defaultPreservedParams = array( + 'limit', // setupPaginationControl() + 'sort', // setupSortControl() + 'dir', // setupSortControl() + 'backend', // Framework + '_dev' // Framework + ); + + $editor = Widget::create('filterEditor'); + call_user_func_array( + array($editor, 'preserveParams'), + array_merge($defaultPreservedParams, $preserveParams ?: array()) + ); + + $editor ->setQuery($filterable) - ->preserveParams( - 'limit', - 'sort', - 'dir', - 'format', - 'view', - 'user', - 'group', - 'backend', - 'stateType', - 'addColumns', - 'problems', - '_dev' - ) - ->ignoreParams('page') + ->ignoreParams('page') // setupPaginationControl() ->setColumns($filterColumns) ->setSearchColumns($searchColumns) ->handleRequest($this->getRequest()); diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index d08257557..c0ae1133f 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -574,7 +574,12 @@ class ListController extends Controller */ protected function filterQuery(DataView $dataView) { - $this->setupFilterControl($dataView); + $this->setupFilterControl($dataView, null, null, array( + 'format', // handleFormatRequest() + 'stateType', // hostsAction() and servicesAction() + 'addColumns', // addColumns() + 'problems' // servicegridAction() + )); $this->handleFormatRequest($dataView); return $dataView; }