From e12e827fd47a056b833708b3fee804dc8d072186 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Sun, 18 Feb 2024 02:12:43 -0500 Subject: [PATCH] Post-rebase cleanup Remove stale lines brought in during rebase --- .../Processors/Model/GetListProcessor.php | 39 +++++++++++++++++ .../UserGroup/AccessNamespace/GetList.php | 37 +++++++++++++--- .../Access/UserGroup/Category/GetList.php | 39 +++++++++++++---- .../Access/UserGroup/Context/GetList.php | 35 ++++++++++++---- .../UserGroup/ResourceGroup/GetList.php | 42 ++++++++++++++----- .../Access/UserGroup/Source/GetList.php | 38 ++++++++++++++--- .../assets/modext/widgets/core/modx.grid.js | 24 +++++++++-- .../security/modx.grid.user.group.category.js | 1 - .../security/modx.grid.user.group.context.js | 1 - .../security/modx.grid.user.group.resource.js | 1 - .../security/modx.grid.user.group.source.js | 1 - 11 files changed, 216 insertions(+), 42 deletions(-) diff --git a/core/src/Revolution/Processors/Model/GetListProcessor.php b/core/src/Revolution/Processors/Model/GetListProcessor.php index 0df7face444..37a65870741 100644 --- a/core/src/Revolution/Processors/Model/GetListProcessor.php +++ b/core/src/Revolution/Processors/Model/GetListProcessor.php @@ -48,6 +48,9 @@ public function initialize() $this->setDefaultProperties([ 'start' => 0, 'limit' => 20, + 'isGroupingGrid' => false, + 'groupBy' => null, + 'groupDir' => 'ASC', 'sort' => $this->defaultSortField, 'dir' => $this->defaultSortDirection, 'combo' => false, @@ -187,6 +190,42 @@ public function getSortClassKey() return $this->classKey; } + /** + * Adds additional sortby criteria for grouping grids when the column being sorted is different than the one being grouped. + * Grouping is handled internally by Ext JS, so we do not (and should not) use groupby criteria in the query. + * + * @param xPDOQuery $c A reference to the current query being built + * @param string $sortBy The data index of the selected sorting column + * @param string $groupBy The data index of the selected grouping column + * @param string $groupKey The grouping column's fully qualified SQL column name + * @param string $gridCategory An identifier used when additional grid category-specific condition(s) are required + * + * @return void + */ + public function setGroupSort(xPDOQuery &$c, string $sortBy, string $groupBy, string $groupKey, string $gridCategory = '') + { + /* + When group sort and column sort are the same data index, sort the groups + based on the current column sort direction. Otherwise, add an initial sortby + to specify the group sort; the secondary (sorting within the groups) is subsequently + added later in the getData method. + */ + switch ($gridCategory) { + case 'usergroup-acl': + $secondaryCondition = $sortBy === 'authority' && $groupBy === 'role_display'; + break; + default: + $secondaryCondition = false; + break; + } + + if ($sortBy === $groupBy || $secondaryCondition) { + $this->setProperty('groupDir', $this->getProperty('dir')); + } else { + $c->sortby($groupKey, $this->getProperty('groupDir')); + } + } + /** * Can be used to adjust the query prior to the COUNT statement * diff --git a/core/src/Revolution/Processors/Security/Access/UserGroup/AccessNamespace/GetList.php b/core/src/Revolution/Processors/Security/Access/UserGroup/AccessNamespace/GetList.php index 77faee7faeb..880766ba3ff 100644 --- a/core/src/Revolution/Processors/Security/Access/UserGroup/AccessNamespace/GetList.php +++ b/core/src/Revolution/Processors/Security/Access/UserGroup/AccessNamespace/GetList.php @@ -57,6 +57,13 @@ public function initialize() if (!empty($userGroup)) { $this->userGroup = $this->modx->getObject(modUserGroup::class, $userGroup); } + /* + Need to sort on the int field (authority) instead of the composite string field + (role_display) to order properly with the format of '[authority] - [role_name]' + */ + if ($this->getProperty('sort') == 'role_display') { + $this->setProperty('sort', 'authority'); + } return $initialized; } @@ -94,12 +101,32 @@ public function prepareQueryAfterCount(xPDOQuery $c) $c->leftJoin(modAccessPolicy::class, 'Policy'); $c->select($this->modx->getSelectColumns(modAccessNamespace::class, 'modAccessNamespace')); $c->select([ - 'name' => 'Target.name', - 'role_name' => 'Role.name', - 'policy_name' => 'Policy.name', - 'policy_data' => 'Policy.data', + 'name' => '`Target`.`name`', + 'policy_name' => '`Policy`.`name`', + 'policy_data' => '`Policy`.`data`', + 'role_display' => 'CONCAT_WS(\' - \',`modAccessNamespace`.`authority`,`Role`.`name`)' ]); - + if ($this->getProperty('isGroupingGrid')) { + $groupBy = $this->getProperty('groupBy'); + $sortBy = $this->getProperty('sort'); + if (!empty($groupBy)) { + switch ($groupBy) { + case 'name': + $groupKey = '`Target`.`name`'; + break; + case 'role_display': + $groupKey = '`modAccessNamespace`.`authority`'; + break; + case 'policy_name': + $groupKey = '`Policy`.`name`'; + break; + default: + $groupKey = '`modAccessNamespace`.`' . $groupBy . '`'; + break; + } + $this->setGroupSort($c, $sortBy, $groupBy, $groupKey, 'usergroup-acl'); + } + } return $c; } diff --git a/core/src/Revolution/Processors/Security/Access/UserGroup/Category/GetList.php b/core/src/Revolution/Processors/Security/Access/UserGroup/Category/GetList.php index ee2fa900819..2dfc74737ef 100644 --- a/core/src/Revolution/Processors/Security/Access/UserGroup/Category/GetList.php +++ b/core/src/Revolution/Processors/Security/Access/UserGroup/Category/GetList.php @@ -58,7 +58,13 @@ public function initialize() if (!empty($userGroup)) { $this->userGroup = $this->modx->getObject(modUserGroup::class, $userGroup); } - + /* + Need to sort on the int field (authority) instead of the composite string field + (role_display) to order properly with the format of '[authority] - [role_name]' + */ + if ($this->getProperty('sort') == 'role_display') { + $this->setProperty('sort', 'authority'); + } return $initialized; } @@ -96,12 +102,32 @@ public function prepareQueryAfterCount(xPDOQuery $c) $c->leftJoin(modAccessPolicy::class, 'Policy'); $c->select($this->modx->getSelectColumns(modAccessCategory::class, 'modAccessCategory')); $c->select([ - 'name' => 'Target.category', - 'role_name' => 'Role.name', - 'policy_name' => 'Policy.name', - 'policy_data' => 'Policy.data', + 'name' => '`Target`.`category`', + 'policy_name' => '`Policy`.`name`', + 'policy_data' => '`Policy`.`data`', + 'role_display' => 'CONCAT_WS(\' - \',`modAccessCategory`.`authority`,`Role`.`name`)' ]); - + if ($this->getProperty('isGroupingGrid')) { + $groupBy = $this->getProperty('groupBy'); + $sortBy = $this->getProperty('sort'); + if (!empty($groupBy)) { + switch ($groupBy) { + case 'name': + $groupKey = '`Target`.`category`'; + break; + case 'role_display': + $groupKey = '`modAccessCategory`.`authority`'; + break; + case 'policy_name': + $groupKey = '`Policy`.`name`'; + break; + default: + $groupKey = '`modAccessCategory`.`' . $groupBy . '`'; + break; + } + $this->setGroupSort($c, $sortBy, $groupBy, $groupKey, 'usergroup-acl'); + } + } return $c; } @@ -116,7 +142,6 @@ public function prepareRow(xPDOObject $object) if (empty($objectArray['name'])) { $objectArray['name'] = '(' . $this->modx->lexicon('none') . ')'; } - $objectArray['authority_name'] = !empty($objectArray['role_name']) ? $objectArray['role_name'] . ' - ' . $objectArray['authority'] : $objectArray['authority']; /* get permissions list */ $data = $objectArray['policy_data']; diff --git a/core/src/Revolution/Processors/Security/Access/UserGroup/Context/GetList.php b/core/src/Revolution/Processors/Security/Access/UserGroup/Context/GetList.php index c9aa91d880b..51914d57bb2 100644 --- a/core/src/Revolution/Processors/Security/Access/UserGroup/Context/GetList.php +++ b/core/src/Revolution/Processors/Security/Access/UserGroup/Context/GetList.php @@ -56,6 +56,13 @@ public function initialize() if (!empty($userGroup)) { $this->userGroup = $this->modx->getObject(modUserGroup::class, $userGroup); } + /* + Need to sort on the int field (authority) instead of the composite string field + (role_display) to order properly with the format of '[authority] - [role_name]' + */ + if ($this->getProperty('sort') == 'role_display') { + $this->setProperty('sort', 'authority'); + } return $initialized; } @@ -91,10 +98,28 @@ public function prepareQueryAfterCount(xPDOQuery $c) $c->leftJoin(modAccessPolicy::class, 'Policy'); $c->select($this->modx->getSelectColumns(modAccessContext::class, 'modAccessContext')); $c->select([ - 'role_name' => 'Role.name', - 'policy_name' => 'Policy.name', - 'policy_data' => 'Policy.data', + 'policy_name' => '`Policy`.`name`', + 'policy_data' => '`Policy`.`data`', + 'role_display' => 'CONCAT_WS(\' - \',`modAccessContext`.`authority`,`Role`.`name`)' ]); + if ($this->getProperty('isGroupingGrid')) { + $groupBy = $this->getProperty('groupBy'); + $sortBy = $this->getProperty('sort'); + if (!empty($groupBy)) { + switch ($groupBy) { + case 'role_display': + $groupKey = '`modAccessContext`.`authority`'; + break; + case 'policy_name': + $groupKey = '`Policy`.`name`'; + break; + default: + $groupKey = '`modAccessContext`.`' . $groupBy . '`'; + break; + } + $this->setGroupSort($c, $sortBy, $groupBy, $groupKey, 'usergroup-acl'); + } + } return $c; } @@ -109,10 +134,6 @@ public function prepareRow(xPDOObject $object) if (empty($objectArray['name'])) { $objectArray['name'] = '(' . $this->modx->lexicon('none') . ')'; } - $objectArray['authority_name'] = !empty($objectArray['role_name']) - ? $objectArray['role_name'] . ' - ' . $objectArray['authority'] - : $objectArray['authority'] - ; /* get permissions list */ $data = $objectArray['policy_data']; diff --git a/core/src/Revolution/Processors/Security/Access/UserGroup/ResourceGroup/GetList.php b/core/src/Revolution/Processors/Security/Access/UserGroup/ResourceGroup/GetList.php index 770e183747b..c23d74e77dd 100644 --- a/core/src/Revolution/Processors/Security/Access/UserGroup/ResourceGroup/GetList.php +++ b/core/src/Revolution/Processors/Security/Access/UserGroup/ResourceGroup/GetList.php @@ -58,7 +58,13 @@ public function initialize() if (!empty($userGroup)) { $this->userGroup = $this->modx->getObject(modUserGroup::class, $userGroup); } - + /* + Need to sort on the int field (authority) instead of the composite string field + (role_display) to order properly with the format of '[authority] - [role_name]' + */ + if ($this->getProperty('sort') == 'role_display') { + $this->setProperty('sort', 'authority'); + } return $initialized; } @@ -96,12 +102,32 @@ public function prepareQueryAfterCount(xPDOQuery $c) $c->leftJoin(modAccessPolicy::class, 'Policy'); $c->select($this->modx->getSelectColumns(modAccessResourceGroup::class, 'modAccessResourceGroup')); $c->select([ - 'name' => 'Target.name', - 'role_name' => 'Role.name', - 'policy_name' => 'Policy.name', - 'policy_data' => 'Policy.data', + 'name' => '`Target`.`name`', + 'policy_name' => '`Policy`.`name`', + 'policy_data' => '`Policy`.`data`', + 'role_display' => 'CONCAT_WS(\' - \',`modAccessResourceGroup`.`authority`,`Role`.`name`)' ]); - + if ($this->getProperty('isGroupingGrid')) { + $groupBy = $this->getProperty('groupBy'); + $sortBy = $this->getProperty('sort'); + if (!empty($groupBy)) { + switch ($groupBy) { + case 'name': + $groupKey = '`Target`.`name`'; + break; + case 'role_display': + $groupKey = '`modAccessResourceGroup`.`authority`'; + break; + case 'policy_name': + $groupKey = '`Policy`.`name`'; + break; + default: + $groupKey = '`modAccessResourceGroup`.`' . $groupBy . '`'; + break; + } + $this->setGroupSort($c, $sortBy, $groupBy, $groupKey, 'usergroup-acl'); + } + } return $c; } @@ -116,10 +142,6 @@ public function prepareRow(xPDOObject $object) if (empty($objectArray['name'])) { $objectArray['name'] = '(' . $this->modx->lexicon('none') . ')'; } - $objectArray['authority_name'] = !empty($objectArray['role_name']) - ? $objectArray['role_name'] . ' - ' . $objectArray['authority'] - : $objectArray['authority'] - ; /* get permissions list */ $data = $objectArray['policy_data']; diff --git a/core/src/Revolution/Processors/Security/Access/UserGroup/Source/GetList.php b/core/src/Revolution/Processors/Security/Access/UserGroup/Source/GetList.php index b35edd2dd1f..f0d3e9c26f6 100644 --- a/core/src/Revolution/Processors/Security/Access/UserGroup/Source/GetList.php +++ b/core/src/Revolution/Processors/Security/Access/UserGroup/Source/GetList.php @@ -57,7 +57,13 @@ public function initialize() if (!empty($userGroup)) { $this->userGroup = $this->modx->getObject(modUserGroup::class, $userGroup); } - + /* + Need to sort on the int field (authority) instead of the composite string field + (role_display) to order properly with the format of '[authority] - [role_name]' + */ + if ($this->getProperty('sort') == 'role_display') { + $this->setProperty('sort', 'authority'); + } return $initialized; } @@ -102,12 +108,32 @@ public function prepareQueryAfterCount(xPDOQuery $c) $c->leftJoin(modAccessPolicy::class, 'Policy'); $c->select($this->modx->getSelectColumns(modAccessMediaSource::class, 'modAccessMediaSource')); $c->select([ - 'name' => 'Target.name', - 'role_name' => 'Role.name', - 'policy_name' => 'Policy.name', - 'policy_data' => 'Policy.data', + 'name' => '`Target`.`name`', + 'policy_name' => '`Policy`.`name`', + 'policy_data' => '`Policy`.`data`', + 'role_display' => 'CONCAT_WS(\' - \',`modAccessMediaSource`.`authority`,`Role`.`name`)' ]); - + if ($this->getProperty('isGroupingGrid')) { + $groupBy = $this->getProperty('groupBy'); + $sortBy = $this->getProperty('sort'); + if (!empty($groupBy)) { + switch ($groupBy) { + case 'name': + $groupKey = '`Target`.`name`'; + break; + case 'role_display': + $groupKey = '`modAccessMediaSource`.`authority`'; + break; + case 'policy_name': + $groupKey = '`Policy`.`name`'; + break; + default: + $groupKey = '`modAccessMediaSource`.`' . $groupBy . '`'; + break; + } + $this->setGroupSort($c, $sortBy, $groupBy, $groupKey, 'usergroup-acl'); + } + } return $c; } diff --git a/manager/assets/modext/widgets/core/modx.grid.js b/manager/assets/modext/widgets/core/modx.grid.js index c1a6c83abdf..0ae010f1d5e 100644 --- a/manager/assets/modext/widgets/core/modx.grid.js +++ b/manager/assets/modext/widgets/core/modx.grid.js @@ -224,6 +224,7 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{ this.getView().emptyText = `
${msg}
`; this.getView().refresh(false); } + ,saveRecord: function(e) { e.record.data.menu = null; var p = this.config.saveParams || {}; @@ -406,14 +407,31 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{ ,remoteSort: this.config.remoteSort || false ,remoteGroup: this.config.remoteGroup || false ,groupField: this.config.groupBy || 'name' + ,groupDir: this.config.groupDir || 'ASC' ,storeId: this.config.storeId || Ext.id() ,autoDestroy: true - ,listeners:{ - load: function(){ + ,listeners: { + beforeload: function(store, options) { + const changedGroupDir = store.groupField === store.sortInfo.field && store.groupDir !== store.sortInfo.direction; + if (changedGroupDir) { + store.groupDir = store.sortInfo.direction; + store.baseParams.groupDir = store.sortInfo.direction; + } + }, + load: function(store, records, options) { const cmp = Ext.getCmp('modx-content'); if (cmp) { cmp.doLayout(); } + }, + groupchange: { + fn: function(store, groupField) { + store.groupDir = this.config.groupDir || 'ASC'; + store.baseParams.groupDir = store.groupDir; + store.sortInfo.direction = this.config.sortDir || 'ASC'; + store.load(); + }, + scope: this } } }); @@ -428,7 +446,7 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{ ,storeId: this.config.storeId || Ext.id() ,autoDestroy: true ,listeners:{ - load: function(){ + load: function() { const cmp = Ext.getCmp('modx-content'); if (cmp) { cmp.doLayout(); diff --git a/manager/assets/modext/widgets/security/modx.grid.user.group.category.js b/manager/assets/modext/widgets/security/modx.grid.user.group.category.js index 03ff3d71fa6..4fc422b7b26 100644 --- a/manager/assets/modext/widgets/security/modx.grid.user.group.category.js +++ b/manager/assets/modext/widgets/security/modx.grid.user.group.category.js @@ -18,7 +18,6 @@ MODx.grid.UserGroupCategory = function(config = {}) { ,usergroup: config.usergroup ,category: MODx.request.category || null ,policy: this.applyRequestFilter(2) - // ,policy: MODx.request.policy || null ,isGroupingGrid: true } ,fields: [ diff --git a/manager/assets/modext/widgets/security/modx.grid.user.group.context.js b/manager/assets/modext/widgets/security/modx.grid.user.group.context.js index 074a750f903..8c55f9e27f0 100644 --- a/manager/assets/modext/widgets/security/modx.grid.user.group.context.js +++ b/manager/assets/modext/widgets/security/modx.grid.user.group.context.js @@ -18,7 +18,6 @@ MODx.grid.UserGroupContext = function(config = {}) { ,usergroup: config.usergroup ,context: MODx.request.context || null ,policy: this.applyRequestFilter(0) - // ,policy: MODx.request.policy || null ,isGroupingGrid: true } ,fields: [ diff --git a/manager/assets/modext/widgets/security/modx.grid.user.group.resource.js b/manager/assets/modext/widgets/security/modx.grid.user.group.resource.js index 00f55a07e35..340207c93d6 100644 --- a/manager/assets/modext/widgets/security/modx.grid.user.group.resource.js +++ b/manager/assets/modext/widgets/security/modx.grid.user.group.resource.js @@ -18,7 +18,6 @@ MODx.grid.UserGroupResourceGroup = function(config = {}) { ,usergroup: config.usergroup ,resourceGroup: MODx.request.resourceGroup || null ,policy: this.applyRequestFilter(1) - // ,policy: MODx.request.policy || null ,isGroupingGrid: true } ,fields: [ diff --git a/manager/assets/modext/widgets/security/modx.grid.user.group.source.js b/manager/assets/modext/widgets/security/modx.grid.user.group.source.js index 1e01a22fea0..7d32f1faf0b 100644 --- a/manager/assets/modext/widgets/security/modx.grid.user.group.source.js +++ b/manager/assets/modext/widgets/security/modx.grid.user.group.source.js @@ -18,7 +18,6 @@ MODx.grid.UserGroupSource = function(config = {}) { ,usergroup: config.usergroup ,source: MODx.request.source || null ,policy: this.applyRequestFilter(3) - // ,policy: MODx.request.policy || null ,isGroupingGrid: true } ,fields: [