Skip to content

Commit

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

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

* upstream/pr/16369: (47 commits)
  Base class updates
  UG Category tweaks
  Post-review fixes for packages grid
  Post-review fixes for system settings grids
  ACLs - User Group Permissions fixes
  Dashboards grid fixes
  ACL tab content updates
  Settings grid updates
  Required base class and utilities updates
  Update modx.panel.template.js
  Make requested review change
  Fix one missed CQ problem
  Fix code quality issues
  Minor refinements for better Extras suppport
  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
  ...
  • Loading branch information
Mark-H committed Feb 10, 2024
2 parents 5461b72 + 334d553 commit 5162df4
Show file tree
Hide file tree
Showing 73 changed files with 2,361 additions and 2,407 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
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
Expand Up @@ -181,7 +181,7 @@ public function prepareQueryBeforeCount(xPDOQuery $c)

public function prepareQueryAfterCount(xPDOQuery $c)
{
if ($this->getProperty('sort') == 'category') {
if (!$this->isGridFilter && $this->getProperty('sort') == 'category') {
$c->sortby('parent', $this->getProperty('dir', 'ASC'));
}
$id = $this->getProperty('id', '');
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

0 comments on commit 5162df4

Please sign in to comment.