Skip to content

Commit

Permalink
Apply grid filtering persistence via URL parameters to most grids in …
Browse files Browse the repository at this point in the history
…the manager (#16369)

Merge remote-tracking branch 'upstream/pr/16369' into 3.x

* upstream/pr/16369: (33 commits)
  Remove Ext Statefulness from TVs Panel
  Update UserGroup Namespaces Access Grid
  Filter Persistence: Lexicons Grid
  Filter Persistence: System Events Grid
  Filter Persistence: Settings Grids (4)
  Filter Persistence: User Messages Grid
  Filter Persistence: TV Templates Grid
  Filter Persistence: Template TVs Grid
  Filter Persistence: Groups Panel and Users Grid
  Filter Persistence: Users Grid
  Update related to commit c7fd92b
  Update related to commit 0e0778d
  Filter Persistence: Media Sources Grid
  Filter Persistence: Packages Grid
  Filter Persistence: Dashboard Widgets Grid
  Filter Persistence: Dashboards Grid
  Filter Persistence: Form Customization Sets Grid
  Filter Persistence: Form Customization Profiles Grid
  Filter Persistence: Contexts Grid
  Filter Persistence: Namespaces Grid
  ...
  • Loading branch information
Mark-H committed Feb 10, 2024
2 parents 7a54b6e + 4ac23c3 commit 73ae298
Show file tree
Hide file tree
Showing 72 changed files with 2,174 additions and 2,302 deletions.
14 changes: 13 additions & 1 deletion _build/templates/default/sass/_toolbars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,25 @@
/* top toolbars */
.x-panel-tbar {
overflow: visible; /* prevent cut off box-shadows in FF */
padding-bottom: 2px;
padding-bottom: 4px;

.x-toolbar {
/*background-color: #F5F5F5;*/
border: 0;
padding: 5px 0;
overflow: visible; /* prevent cut off box-shadows in FF */

td {
vertical-align: bottom;
}

input {
&.filter-query {
/* fix positioning issue with query field */
position: relative;
bottom: -1px;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MODX Revolution 3.0.3-pl (January 17, 2023)
- Fix Validation Error When Switching TV Types (#16319)
- Fix TypeError exceptions when restoring deleted resources (#16303)
- Permissions Combo Fix (#16273)
- Grid filtering via URL parameters -- Usergroup ACL (#16089)
- Grid filtering via URL parameters added to most grids in the manager (#16089, #16369)
- Fix issues with TV Media Sources upgrading from 2.x (#16338)
- Update legacy Element class references for PropertySets (#16337)
- Ensure modHashing::getHash is limited to modHash instances (#16320)
Expand Down
4 changes: 2 additions & 2 deletions core/lexicon/en/dashboards.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$_lang['dashboards'] = 'Dashboards';
$_lang['dashboards.intro_msg'] = 'Here you can manage all the available Dashboards for this MODX manager.';
$_lang['rank'] = 'Rank';
$_lang['user_group_filter'] = 'By User Group';
$_lang['user_group_filter'] = 'Filter by User Group...';
$_lang['widget'] = 'Widget';
$_lang['widget_content'] = 'Widget Content';
$_lang['widget_err_ae_name'] = 'A widget with the name "[[+name]]" already exists! Please try another name.';
Expand Down Expand Up @@ -99,4 +99,4 @@
$_lang['w_whosonline'] = 'Who\'s Online';
$_lang['w_whosonline_desc'] = 'Shows a list of online users.';
$_lang['w_view_all'] = 'View all';
$_lang['w_no_data'] = 'No data to display';
$_lang['w_no_data'] = 'No data to display';
3 changes: 2 additions & 1 deletion core/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
$_lang['filter_clear'] = 'Clear Filter';
$_lang['filter_by_key'] = 'Filter by Key...';
$_lang['filter_by_name'] = 'Filter by name...';
$_lang['filter_by_event_group'] = 'Filter by event group...';
$_lang['filter_by_username'] = 'Filter by user name...';
$_lang['finish'] = 'Finish';
$_lang['folder'] = 'Folder';
Expand Down Expand Up @@ -314,7 +315,7 @@
$_lang['orm_container_rename'] = 'Rename Container';
$_lang['orm_container_remove'] = 'Delete Container';
$_lang['orm_container_remove_confirm'] = 'Are you sure you want to delete this container and all attributes below it? This is irreversible.';
$_lang['pagetitle'] = 'Resource\'s title';
$_lang['pagetitle'] = 'Resource‘s Title';
$_lang['page_title'] = 'Resource Title';
$_lang['parameter'] = 'Parameter';
$_lang['parameters'] = 'Parameters';
Expand Down
59 changes: 39 additions & 20 deletions core/src/Revolution/Processors/Context/GetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use MODX\Revolution\modContext;
use MODX\Revolution\modAccessContext;
use MODX\Revolution\modResource;
use MODX\Revolution\modUserGroup;
use MODX\Revolution\Processors\Model\GetListProcessor;
use xPDO\Om\xPDOObject;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function initialize()
{
$initialized = parent::initialize();
$this->setDefaultProperties([
'search' => '',
'query' => '',
'exclude' => '',
]);
$this->canCreate = $this->modx->hasPermission('new_context');
Expand All @@ -71,11 +72,11 @@ public function initialize()
*/
public function prepareQueryBeforeCount(xPDOQuery $c)
{
$search = $this->getProperty('search');
if (!empty($search)) {
$query = $this->getProperty('query');
if (!empty($query)) {
$c->where([
'key:LIKE' => '%' . $search . '%',
'OR:description:LIKE' => '%' . $search . '%',
'key:LIKE' => '%' . $query . '%',
'OR:description:LIKE' => '%' . $query . '%',
]);
}
$exclude = $this->getProperty('exclude');
Expand All @@ -89,21 +90,39 @@ public function prepareQueryBeforeCount(xPDOQuery $c)
limit results to only those contexts present in the current grid.
*/
if ($this->isGridFilter) {
if ($userGroup = $this->getProperty('usergroup', false)) {
$c->innerJoin(
modAccessContext::class,
'modAccessContext',
[
'`modAccessContext`.`target` = `modContext`.`key`',
'`modAccessContext`.`principal` = ' . (int)$userGroup,
'`modAccessContext`.`principal_class` = ' . $this->modx->quote(modUserGroup::class)
]
);
if ($policy = $this->getProperty('policy', false)) {
$c->where([
'`modAccessContext`.`policy`' => (int)$policy
]);
}
$targetGrid = $this->getProperty('targetGrid', '');
switch ($targetGrid) {
case 'MODx.grid.UserGroupContext':
if ($userGroup = $this->getProperty('usergroup', false)) {
$c->innerJoin(
modAccessContext::class,
'modAccessContext',
[
'`modAccessContext`.`target` = `modContext`.`key`',
'`modAccessContext`.`principal` = ' . (int)$userGroup,
'`modAccessContext`.`principal_class` = ' . $this->modx->quote(modUserGroup::class)
]
);
if ($policy = $this->getProperty('policy', false)) {
$c->where([
'`modAccessContext`.`policy`' => (int)$policy
]);
}
}
break;

case 'MODx.grid.Trash':
$c->innerJoin(
modResource::class,
'modResource',
[
'`modResource`.`context_key` = `modContext`.`key`',
'`modResource`.`deleted` = 1'
]
);
break;

// no default case
}
}
return $c;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of the MODX Revolution package.
*
Expand All @@ -10,7 +11,6 @@

namespace MODX\Revolution\Processors\Element\Plugin\Event;


use MODX\Revolution\modEvent;
use MODX\Revolution\Processors\ModelProcessor;
use MODX\Revolution\modPluginEvent;
Expand Down Expand Up @@ -49,13 +49,6 @@ public function process()
foreach ($data['results'] as $event) {
$eventArray = $event->toArray();
$eventArray['enabled'] = $event->get('enabled') ? 1 : 0;

$eventArray['menu'] = [
[
'text' => $this->modx->lexicon('edit'),
'handler' => 'this.updateEvent',
],
];
$list[] = $eventArray;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of the MODX Revolution package.
*
Expand All @@ -10,10 +11,11 @@

namespace MODX\Revolution\Processors\Element\Template\TemplateVar;


use MODX\Revolution\Processors\Model\GetListProcessor;
use MODX\Revolution\modTemplate;
use MODX\Revolution\modTemplateVar;
use xPDO\Om\xPDOObject;
use xPDO\Om\xPDOQuery;

/**
* Gets a list of TVs, marking ones associated with the template.
Expand All @@ -36,26 +38,41 @@ class GetList extends GetListProcessor
public $permission = ['view_tv' => true, 'view_template' => true];
public $languageTopics = ['template'];

protected $category = 0;
protected $query = '';
protected $isFiltered = false;

/**
* {@inheritDoc}
*/
public function initialize()
{
$this->category = (int)$this->getProperty('category', 0);
$this->query = $this->getProperty('query', '');
$this->isFiltered = $this->category > 0 || $this->query;
return parent::initialize();
}

/**
* Prepare conditions for TV list
*
* @return array
*/
public function prepareConditions()
public function prepareConditions(): array
{
$conditions = [];

$category = (integer)$this->getProperty('category', 0);
if ($category) {
$conditions[] = ['category' => $category];
if (!$this->isFiltered) {
return $conditions;
}

if ($this->category) {
$conditions[] = ['category' => $this->category];
}

$query = $this->getProperty('query', '');
if (!empty($query)) {
if (!empty($this->query)) {
$conditions[] = [
'name:LIKE' => '%' . $query . '%',
'OR:caption:LIKE' => '%' . $query . '%',
'OR:description:LIKE' => '%' . $query . '%',
'name:LIKE' => '%' . $this->query . '%',
'OR:caption:LIKE' => '%' . $this->query . '%',
'OR:description:LIKE' => '%' . $this->query . '%'
];
}

Expand All @@ -79,37 +96,71 @@ public function loadTemplate()
}

/**
* {@inheritdoc}
* @return array
* {@inheritDoc}
*/
public function getData()
public function getData(): array
{
$sort = $this->getProperty('sort');
$dir = $this->getProperty('dir');
$limit = intval($this->getProperty('limit'));
$start = intval($this->getProperty('start'));
$limit = (int)$this->getProperty('limit');
$start = (int)$this->getProperty('start');
$conditions = $this->prepareConditions();

$template = $this->loadTemplate();
$tvList = $template->getTemplateVarList([$sort => $dir], $limit, $start, $conditions);

$data = [
'total' => $tvList['total'],
'total' => $this->isFiltered ? $this->getFilteredCount() : $tvList['total'],
'results' => $tvList['collection'],
];

return $data;
}

/**
* {@inheritdoc}
* @param xPDOObject $object
*
* @return array|mixed
* Workaround to get correct total count when list is filtered
*/
public function getFilteredCount(): int
{
$c = $this->modx->newQuery(modTemplateVar::class);
$c = $this->prepareQueryBeforeCount($c);
$filteredCount = $this->modx->getCount(modTemplateVar::class, $c);

return $filteredCount;
}

/**
* {@inheritDoc}
*/
public function prepareQueryBeforeCount(xPDOQuery $c)
{
if (!$this->isFiltered) {
return $c;
}

if ($this->category) {
$c->where(
['category' => $this->category]
);
}

if ($this->query) {
$c->where([
'name:LIKE' => '%' . $this->query . '%',
'OR:caption:LIKE' => '%' . $this->query . '%',
'OR:description:LIKE' => '%' . $this->query . '%',
]);
}
return $c;
}

/**
* {@inheritDoc}
*/
public function prepareRow(xPDOObject $object)
{
$tvArray = $object->get(['id', 'name', 'caption', 'tv_rank', 'category_name']);
$tvArray['access'] = (boolean)$object->get('access');
$tvArray['access'] = (bool)$object->get('access');

$tvArray['perm'] = [];
if ($this->modx->hasPermission('edit_tv')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of the MODX Revolution package.
*
Expand All @@ -10,7 +11,6 @@

namespace MODX\Revolution\Processors\Element\TemplateVar\Template;


use MODX\Revolution\modCategory;
use MODX\Revolution\Processors\Processor;
use MODX\Revolution\modTemplate;
Expand Down Expand Up @@ -82,10 +82,11 @@ public function getData()

/* query for templates */
$c = $this->modx->newQuery(modTemplate::class);
$query = $this->getProperty('query');
$query = $this->getProperty('query', '');
if (!empty($query)) {
$c->where([
'templatename:LIKE' => "%$query%",
'templatename:LIKE' => '%' . $query . '%',
'OR:description:LIKE' => '%' . $query . '%'
]);
}
$c->leftJoin(modCategory::class, 'Category');
Expand All @@ -107,8 +108,12 @@ public function getData()
$c->select([
'category_name' => 'Category.category',
]);
$c->select($this->modx->getSelectColumns(modTemplateVarTemplate::class, 'TemplateVarTemplates', '',
['tmplvarid']));
$c->select($this->modx->getSelectColumns(
modTemplateVarTemplate::class,
'TemplateVarTemplates',
'',
['tmplvarid']
));
$c->select(['access' => 'TemplateVarTemplates.tmplvarid']);
$c->sortby($this->getProperty('sort'), $this->getProperty('dir'));
if ($isLimit) {
Expand Down
10 changes: 10 additions & 0 deletions core/src/Revolution/Processors/Resource/Trash/GetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public function prepareQueryBeforeCount(xPDOQuery $c)
$c->leftJoin(modUser::class, 'User', 'modResource.deletedby = User.id');
$c->leftJoin(modContext::class, 'Context', 'modResource.context_key = Context.key');

// TODO add only resources if we have the save permission here (on the context!!)
// we need the following permissions:
// undelete_document - to restore the document
// delete_document - thats perhaps not necessary, because all documents are already deleted
// but we need the purge_deleted permission - for every single file
if ($deleted = $this->getDeleted()) {
$c->where(['modResource.id:IN' => $deleted]);
} else {
$c->where(['modResource.id:IN' => 0]);
}
if (!empty($query)) {
$c->where([
'modResource.pagetitle:LIKE' => '%' . $query . '%',
Expand Down
Loading

0 comments on commit 73ae298

Please sign in to comment.