Skip to content

Commit

Permalink
Post-rebase cleanup
Browse files Browse the repository at this point in the history
Remove stale lines brought in during rebase
  • Loading branch information
smg6511 committed Feb 18, 2024
1 parent 6b90c0f commit e12e827
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 42 deletions.
39 changes: 39 additions & 0 deletions core/src/Revolution/Processors/Model/GetListProcessor.php
Expand Up @@ -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,
Expand Down Expand Up @@ -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
*
Expand Down
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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'];
Expand Down
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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'];
Expand Down
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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'];
Expand Down
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
24 changes: 21 additions & 3 deletions manager/assets/modext/widgets/core/modx.grid.js
Expand Up @@ -224,6 +224,7 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{
this.getView().emptyText = `<div class="error-with-icon">${msg}</div>`;
this.getView().refresh(false);
}

,saveRecord: function(e) {
e.record.data.menu = null;
var p = this.config.saveParams || {};
Expand Down Expand Up @@ -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
}
}
});
Expand All @@ -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();
Expand Down
Expand Up @@ -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: [
Expand Down

1 comment on commit e12e827

@smg6511
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit also contains functional changes made to allow proper sorting/grouping.

Please sign in to comment.