Skip to content

Commit

Permalink
feat: Refactored behavior of purging resources
Browse files Browse the repository at this point in the history
  • Loading branch information
GulomovCreative committed Aug 16, 2024
1 parent bc83914 commit bb1c3ac
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 112 deletions.
6 changes: 0 additions & 6 deletions _build/templates/default/sass/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,6 @@ html.ext-strict body #modx-container .x-small-editor .x-form-text {
font-weight: 400;
}

.tree-trash > em > button:before {
@extend %pseudo-font;
content: fa-content($fa-var-trash-alt);
font-weight: 400;
}

/* alignment overrides */
#modx-leftbar .x-toolbar-ct .x-btn .tree-new-symlink > em > button {
top: 4px;
Expand Down
7 changes: 4 additions & 3 deletions _build/templates/default/sass/_tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -988,14 +988,15 @@
#modx-leftbar-tabpanel__modx-trash-link {
.icon {
opacity: .5;
&:hover {
color: $red;
}
}

&.active {
.icon {
opacity: 1;
}

&:hover .icon {
color: $red;
}
}
}
11 changes: 10 additions & 1 deletion _build/templates/default/sass/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ a.x-grid-link:focus {
background: scale-color($color: $red, $saturation: -10%, $lightness: 94%);
font-weight: 400;
}
// The "Call Stack" header row
// The "Call Stack" header row
&[bgcolor^="#e9b"] {
background: $colorSplash;
color: $white !important;
Expand Down Expand Up @@ -1684,6 +1684,15 @@ iframe[classname="x-hidden"] {
color: $green;
}

#modx-abtn-purge {
background-color: $red;
color: $white;

&:hover {
background-color: darken($red, 10%);
}
}

#modx-abtn-help {
color: $colorSplash;
}
Expand Down
2 changes: 2 additions & 0 deletions core/lexicon/en/resource.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
$_lang['resource_createdon'] = 'Created On';
$_lang['resource_delete'] = 'Delete';
$_lang['resource_delete_confirm'] = 'Are you sure you want to delete the resource: "[[+resource]]"?<br />NOTE: Any child resources will also be deleted!';
$_lang['resource_purge'] = 'Erase resource';
$_lang['resource_purge_confirm'] = 'Do you really want to finally erase the following resource: "[[+resource]]"?<br />WARNING: This cannot be undone.';
$_lang['resource_description'] = 'Description';
$_lang['resource_description_help'] = 'This is an optional description of the resource.';
$_lang['resource_duplicate'] = 'Duplicate';
Expand Down
1 change: 1 addition & 0 deletions core/src/Revolution/Processors/Resource/GetNodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function prepare()
'edit_document' => $this->modx->hasPermission('edit_document') ? 'pedit' : '',
'delete_document' => $this->modx->hasPermission('delete_document') ? 'pdelete' : '',
'undelete_document' => $this->modx->hasPermission('undelete_document') ? 'pundelete' : '',
'purge_deleted' => $this->modx->hasPermission('purge_deleted') ? 'ppurge' : '',
'publish_document' => $this->modx->hasPermission('publish_document') ? 'ppublish' : '',
'unpublish_document' => $this->modx->hasPermission('unpublish_document') ? 'punpublish' : '',
'resource_duplicate' => $this->modx->hasPermission('resource_duplicate') ? 'pduplicate' : '',
Expand Down
4 changes: 1 addition & 3 deletions core/src/Revolution/Processors/Resource/GetToolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ public function process()

$items[] = [
'id' => 'emptifier',
'cls' => 'tree-trash',
'tooltip' => $this->modx->lexicon('trash.manage_recycle_bin_tooltip', [
'count' => $deletedResources
]),
'disabled' => ($deletedResources == 0) ? true : false,
'handler' => 'new Function("this.redirect(\"?a=resource/trash\");");'
'disabled' => ($deletedResources == 0) ? true : false
];
}

Expand Down
5 changes: 4 additions & 1 deletion core/src/Revolution/Processors/Resource/Trash/Purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,12 @@ public function process()
}
}

$deletedCount = $this->modx->getCount(modResource::class, ['deleted' => 1]);

return $this->success($msg, [
'count_success' => count($success),
'count_failures' => count($this->failures)
'count_failures' => count($this->failures),
'deletedCount' => $deletedCount,
]);
}
}
28 changes: 23 additions & 5 deletions manager/assets/modext/core/modx.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ Ext.extend(MODx.Layout, Ext.Viewport, {
,listeners: {
afterrender: function() {
const baseTabs = this,
header = Ext.get('modx-leftbar-header')
header = Ext.get('modx-leftbar-header')
;
MODx.Ajax.request({
url: MODx.config.connector_url,
Expand All @@ -301,11 +301,29 @@ Ext.extend(MODx.Layout, Ext.Viewport, {
fn: function(response) {
const trashTrigger = Object.values(response.object).find(item => item.id === 'emptifier');
if (trashTrigger) {
const trashTab = baseTabs.add({
const trashTab = baseTabs.add(new Ext.Panel({
id: 'modx-trash-link',
title: '<i class="icon icon-trash-o"></i>',
handler: trashTrigger.handler
});
title: '<a href="?resource/trash"><i class="icon icon-trash-o"></i></a>',
// handler: trashTrigger.handler,
updateState(deletedCount = 0) {
const tab = this;
const tabEl = tab.tabEl;
const tooltipTarget = new Ext.Element(tabEl);

if (deletedCount === 0) {
tab.disable();
tabEl.classList.remove('active');
} else {
tab.enable();
tabEl.classList.add('active');
}

tab.tooltip = new Ext.ToolTip({
target: tooltipTarget,
title: _('trash.manage_recycle_bin_tooltip', { count: deletedCount }),
});
},
}));
if (!trashTrigger.disabled) {
trashTab.tabEl.classList.add('active');
}
Expand Down
42 changes: 41 additions & 1 deletion manager/assets/modext/sections/resource/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ Ext.extend(MODx.page.UpdateResource,MODx.Component,{
}
,listeners: {
success: {fn:function(r) {
var panel = Ext.getCmp('modx-panel-resource');
const panel = Ext.getCmp('modx-panel-resource');
if (panel) {
panel.handlePreview(true);
panel.handleDeleted(true);
}

Ext.getCmp('modx-resource-tree')?.refresh();
Ext.getCmp('modx-trash-link')?.updateState(+r.object.deletedCount);
},scope:this}
}
});
Expand All @@ -131,11 +134,38 @@ Ext.extend(MODx.page.UpdateResource,MODx.Component,{
panel.handlePreview(false);
panel.handleDeleted(false);
}

const tree = Ext.getCmp('modx-resource-tree');
if (tree?.rendered) {
tree.refresh();
}

Ext.getCmp('modx-trash-link')?.updateState(+r.object.deletedCount);
},scope:this}
}
});
}

,purgeResource: function() {
MODx.msg.confirm({
text: _('resource_purge_confirm',{
resource: Ext.util.Format.htmlEncode(this.config.record.pagetitle) + ' ('+ this.config.resource + ')'
})
,url: MODx.config.connector_url
,params: {
action: 'Resource/Trash/Purge'
,ids: this.config.resource
}
,listeners: {
success: {fn:function() {
const fp = Ext.getCmp(this.config.formpanel);
fp.warnUnsavedChanges = false;
MODx.loadPage('?');
},scope:this},
}
});
}

,cancel: function(btn,e) {
var fp = Ext.getCmp(this.config.formpanel);
if (fp && fp.isDirty()) {
Expand Down Expand Up @@ -213,6 +243,16 @@ Ext.extend(MODx.page.UpdateResource,MODx.Component,{
});
}

if (config.canPurge == 1) {
buttons.push({
text: '<i class="icon icon-remove"></i>'
,id: 'modx-abtn-purge'
,handler: this.purgeResource
,hidden: !config.record.deleted
,scope: this
});
}

buttons.push({
text: '<i class="icon icon-question-circle"></i>'
,id: 'modx-abtn-help'
Expand Down
22 changes: 2 additions & 20 deletions manager/assets/modext/widgets/resource/modx.grid.trash.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Ext.extend(MODx.grid.Trash, MODx.grid.Grid, {
'success': {
fn: function (data) {
this.getSelectionModel().clearSelections(true);
this.refreshEverything(data.total);
this.refreshEverything(data.object.deletedCount);
}, scope: this
},
'error': {
Expand Down Expand Up @@ -404,25 +404,7 @@ Ext.extend(MODx.grid.Trash, MODx.grid.Grid, {
},

refreshRecycleBinButton: function (total) {
var trashButton = Ext.getCmp('modx-trash-link');

if (total !== undefined) {
// if no resource is deleted, we disable the icon.
// otherwise we have to update the tooltip
if (total == 0) {
trashButton.disable();
trashButton.tooltip = new Ext.ToolTip({
target: trashButton.tabEl,
title: _('trash.manage_recycle_bin_tooltip')
});
} else {
trashButton.enable();
trashButton.tooltip = new Ext.ToolTip({
target: trashButton.tabEl,
title: _('trash.manage_recycle_bin_tooltip', {count: total})
});
}
}
Ext.getCmp('modx-trash-link')?.updateState(+total);
},

listResources: function (separator) {
Expand Down
41 changes: 25 additions & 16 deletions manager/assets/modext/widgets/resource/modx.panel.resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,33 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
}
}

,handleDeleted: function(deleted) {
if (this.config.canDelete == 1 && !this.config.locked) {
var deleteBtn = Ext.getCmp('modx-abtn-delete');
var unDeleteBtn = Ext.getCmp('modx-abtn-undelete');
var deleteChk = Ext.getCmp('modx-resource-deleted');
if (deleteBtn && unDeleteBtn) {
if (deleted) {
deleteBtn.hide();
unDeleteBtn.show();
} else {
unDeleteBtn.hide();
deleteBtn.show();
}
}
if (deleteChk) {
deleteChk.setValue(deleted);
,handleDeleted: function(isDeleted) {
const canDelete = this.config.canDelete === 1 && !this.config.locked;

if (!canDelete) {
return;
}

const deleteButton = Ext.getCmp('modx-abtn-delete');
const purgeButton = Ext.getCmp('modx-abtn-purge');
const unDeleteButton = Ext.getCmp('modx-abtn-undelete');
const deletedCheckbox = Ext.getCmp('modx-resource-deleted');

if (deleteButton && unDeleteButton) {
if (isDeleted) {
deleteButton.hide();
purgeButton.show();
unDeleteButton.show();
} else {
unDeleteButton.hide();
purgeButton.hide();
deleteButton.show();
}
}

if (deletedCheckbox) {
deletedCheckbox.setValue(isDeleted);
}
}

,updateTree: function() {
Expand Down
Loading

0 comments on commit bb1c3ac

Please sign in to comment.