Skip to content

Commit

Permalink
User Recent Resources updates
Browse files Browse the repository at this point in the history
Formatting, code style changes only. Also moved menu config from php processor to js class method for consistency.
  • Loading branch information
smg6511 committed Dec 2, 2024
1 parent e1ab50a commit 8b4aa4f
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of MODX Revolution.
*
Expand Down Expand Up @@ -50,7 +51,6 @@ public function initialize()
return parent::initialize();
}


/**
* Filter resources by user
* @param xPDOQuery $c
Expand Down Expand Up @@ -79,7 +79,6 @@ public function prepareQueryBeforeCount(xPDOQuery $c)
return $c;
}


/**
* Prepare the row for iteration
* @param xPDOObject $object
Expand Down Expand Up @@ -116,41 +115,16 @@ public function prepareRow(xPDOObject $object)

/** @var modUser $user */
if ($user = $object->getOne('User')) {
$row = array_merge($row,
/** @disregard P1013 Intelephense can not find this User instance method (getPhoto), but it does exist and is available here */
$row = array_merge(
$row,
$user->get(['username']),
$user->Profile->get(['fullname', 'email']),
['photo' => $user->getPhoto(64, 64)]
);
/** @var modUserGroup $group */
$row['group'] = ($group = $user->getOne('PrimaryGroup')) ? $group->get('name') : '';
}

$row['menu'] = [];
$row['menu'][] = [
'text' => $this->modx->lexicon('resource_overview'),
'params' => [
'a' => 'resource/data',
'id' => $resource->get('id'),
'type' => 'view',
],
];
if ($this->modx->hasPermission('edit_document')) {
$row['menu'][] = [
'text' => $this->modx->lexicon('resource_edit'),
'params' => [
'a' => 'resource/update',
'id' => $resource->get('id'),
'type' => 'edit',
],
];
}

$row['menu'][] = '-';
$row['menu'][] = [
'text' => $this->modx->lexicon('resource_view'),
'handler' => 'this.preview',
];

$row['link'] = $this->modx->makeUrl($resource->get('id'), $resource->get('context_key'));

return $row;
Expand Down
164 changes: 105 additions & 59 deletions manager/assets/modext/widgets/security/modx.grid.user.recent.resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,119 @@
* @param {Object} config An object of options.
* @xtype modx-grid-user-recent-resource
*/
MODx.grid.RecentlyEditedResourcesByUser = function(config) {
config = config || {};
var dateFormat = MODx.config.manager_date_format + ' ' + MODx.config.manager_time_format;
Ext.applyIf(config,{
title: _('recent_docs')
,url: MODx.config.connector_url
,baseParams: {
action: 'Security/User/GetRecentlyEditedResources'
,user: config.user
}
,autosave: true
,save_action: 'Resource/UpdateFromGrid'
,pageSize: 10
,fields: ['id','pagetitle','description','editedon','deleted','published','context_key','menu', 'link', 'occurred']
,columns: [{
header: _('id')
,dataIndex: 'id'
,width: 75
,fixed: true
},{
header: _('pagetitle')
,dataIndex: 'pagetitle'
,renderer: { fn: function(v,md,record) {
return this.renderLink(v, {
href: '?a=resource/update&id=' + record.data.id
,target: '_blank'
});
}, scope: this }
},{
header: _('editedon')
,dataIndex: 'occurred'
,renderer : Ext.util.Format.dateRenderer(dateFormat)
},{
header: _('published')
,dataIndex: 'published'
,width: 120
,fixed: true
,editor: { xtype: 'combo-boolean' ,renderer: 'boolean' }
}]
,paging: true
,listeners: {
afteredit: this.refresh
,afterrender: this.onAfterRender
,scope: this
MODx.grid.RecentlyEditedResourcesByUser = function(config = {}) {
const dateFormat = `${MODx.config.manager_date_format} ${MODx.config.manager_time_format}`;
Ext.applyIf(config, {
title: _('recent_docs'),
url: MODx.config.connector_url,
baseParams: {
action: 'Security/User/GetRecentlyEditedResources',
user: config.user
},
autosave: true,
save_action: 'Resource/UpdateFromGrid',
pageSize: 10,
fields: [
'id',
'pagetitle',
'description',
'editedon',
'deleted',
'published',
'context_key',
'menu',
'link',
'occurred'
],
columns: [{
header: _('id'),
dataIndex: 'id',
width: 75,
fixed: true
}, {
header: _('pagetitle'),
dataIndex: 'pagetitle',
renderer: {
fn: function(value, metaData, record) {
return this.renderLink(value, {
href: `?a=resource/update&id=${record.data.id}`,
target: '_blank'
});
},
scope: this
}
}, {
header: _('editedon'),
dataIndex: 'occurred',
renderer: Ext.util.Format.dateRenderer(dateFormat)
}, {
header: _('published'),
dataIndex: 'published',
width: 120,
fixed: true,
editor: {
xtype: 'combo-boolean',
renderer: 'boolean'
}
}],
paging: true,
listeners: {
afteredit: this.refresh,
afterrender: this.onAfterRender,
scope: this
}
});
MODx.grid.RecentlyEditedResourcesByUser.superclass.constructor.call(this,config);
MODx.grid.RecentlyEditedResourcesByUser.superclass.constructor.call(this, config);
};
Ext.extend(MODx.grid.RecentlyEditedResourcesByUser,MODx.grid.Grid,{
Ext.extend(MODx.grid.RecentlyEditedResourcesByUser, MODx.grid.Grid, {
getMenu: function() {
const
record = this.getSelectionModel().getSelected(),
menu = []
;
menu.push({
text: _('resource_overview'),
params: {
a: 'resource/data',
type: 'view'
}
});
if (MODx.perm.edit_document) {
menu.push({
text: _('resource_edit'),
params: {
a: 'resource/update',
type: 'edit'
}
});
}
menu.push('-');
menu.push({
text: _('resource_view'),
handler: this.preview
});

return menu;
},

preview: function() {
window.open(this.menu.record.link);
}
,refresh: function() {
var tree = Ext.getCmp('modx-resource-tree');
},
refresh: function() {
const tree = Ext.getCmp('modx-resource-tree');
if (tree && tree.rendered) {
tree.refresh();
}
}
},
// Workaround to resize the grid when in a dashboard widget
,onAfterRender: function() {
var cnt = Ext.getCmp('modx-content')
// Dashboard widget "parent" (renderTo)
,parent = Ext.get('modx-grid-user-recent-resource');

if (cnt && parent) {
cnt.on('afterlayout', function(elem, layout) {
var width = parent.getWidth();
onAfterRender: function() {
const
contentCmp = Ext.getCmp('modx-content'),
grid = Ext.get('modx-grid-user-recent-resource')
;
if (contentCmp && grid) {
contentCmp.on('afterlayout', function(elem, layout) {
const width = grid.getWidth();
// Only resize when more than 500px (else let's use/enable the horizontal scrolling)
if (width > 500) {
this.setWidth(width);
Expand All @@ -81,4 +127,4 @@ Ext.extend(MODx.grid.RecentlyEditedResourcesByUser,MODx.grid.Grid,{
}
}
});
Ext.reg('modx-grid-user-recent-resource',MODx.grid.RecentlyEditedResourcesByUser);
Ext.reg('modx-grid-user-recent-resource', MODx.grid.RecentlyEditedResourcesByUser);

0 comments on commit 8b4aa4f

Please sign in to comment.