mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2859] fixes for the conditional visibility and disabled states (#3465)
* fixes for the conditional visibility and disabled states * update docs * cleanup code * remove unused code
This commit is contained in:
committed by
Eugenio Romano
parent
1d69f5c407
commit
6f2cbdf697
@@ -42,4 +42,15 @@ export class ContentActionListComponent {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unregisterAction(action: ContentActionModel): boolean {
|
||||
if (this.documentList && action) {
|
||||
const idx = this.documentList.actions.indexOf(action);
|
||||
if (idx >= 0) {
|
||||
this.documentList.actions.splice(idx, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -132,8 +132,15 @@ export class ContentActionComponent implements OnInit, OnChanges, OnDestroy {
|
||||
this.subscriptions.forEach(subscription => subscription.unsubscribe());
|
||||
this.subscriptions = [];
|
||||
|
||||
this.documentActionModel = null;
|
||||
this.folderActionModel = null;
|
||||
if (this.documentActionModel) {
|
||||
this.unregister(this.documentActionModel);
|
||||
this.documentActionModel = null;
|
||||
}
|
||||
|
||||
if (this.folderActionModel) {
|
||||
this.unregister(this.folderActionModel);
|
||||
this.folderActionModel = null;
|
||||
}
|
||||
}
|
||||
|
||||
register(model: ContentActionModel): boolean {
|
||||
@@ -143,6 +150,13 @@ export class ContentActionComponent implements OnInit, OnChanges, OnDestroy {
|
||||
return false;
|
||||
}
|
||||
|
||||
unregister(model: ContentActionModel): boolean {
|
||||
if (this.list) {
|
||||
return this.list.unregisterAction(model);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private generateAction(target: string): ContentActionModel {
|
||||
const model = new ContentActionModel({
|
||||
title: this.title,
|
||||
|
@@ -13,6 +13,7 @@
|
||||
[display]="display"
|
||||
[noPermission]="noPermission"
|
||||
[showHeader]="!isEmpty() && showHeader"
|
||||
[rowMenuCacheEnabled]="false"
|
||||
(showRowContextMenu)="onShowRowContextMenu($event)"
|
||||
(showRowActionsMenu)="onShowRowActionsMenu($event)"
|
||||
(executeRowAction)="onExecuteRowAction($event)"
|
||||
|
@@ -236,6 +236,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
private _pagination: BehaviorSubject<PaginationModel>;
|
||||
private layoutPresets = {};
|
||||
private subscriptions: Subscription[] = [];
|
||||
private rowMenuCache: { [key: string]: ContentActionModel[] } = {};
|
||||
|
||||
constructor(private documentListService: DocumentListService,
|
||||
private ngZone: NgZone,
|
||||
@@ -333,6 +334,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.rowMenuCache = {};
|
||||
this.loadLayoutPresets();
|
||||
this.data = new ShareDataTableAdapter(this.documentListService, this.thumbnailService, null, this.getDefaultSorting(), this.sortingMode);
|
||||
this.data.thumbnails = this.thumbnails;
|
||||
@@ -444,9 +446,10 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
|
||||
getNodeActions(node: MinimalNodeEntity | any): ContentActionModel[] {
|
||||
let target = null;
|
||||
|
||||
if (node && node.entry) {
|
||||
let target = null;
|
||||
|
||||
if (node.entry.isFile) {
|
||||
target = 'document';
|
||||
} else if (node.entry.isFolder) {
|
||||
@@ -454,6 +457,14 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
|
||||
if (target) {
|
||||
const actions = this.rowMenuCache[node.entry.id];
|
||||
if (actions) {
|
||||
actions.forEach(action => {
|
||||
this.refreshAction(action, node);
|
||||
});
|
||||
return actions;
|
||||
}
|
||||
|
||||
let actionsByTarget = this.actions
|
||||
.filter(entry => {
|
||||
const isVisible = (typeof entry.visible === 'function')
|
||||
@@ -465,9 +476,10 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
.map(action => new ContentActionModel(action));
|
||||
|
||||
actionsByTarget.forEach((action) => {
|
||||
action.disabled = this.isActionDisabled(action, node);
|
||||
this.refreshAction(action, node);
|
||||
});
|
||||
|
||||
this.rowMenuCache[node.entry.id] = actionsByTarget;
|
||||
return actionsByTarget;
|
||||
}
|
||||
}
|
||||
@@ -475,6 +487,19 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
return [];
|
||||
}
|
||||
|
||||
private refreshAction(action: ContentActionModel, node: MinimalNodeEntity) {
|
||||
action.disabled = this.isActionDisabled(action, node);
|
||||
action.visible = this.isActionVisible(action, node);
|
||||
}
|
||||
|
||||
private isActionVisible(action: ContentActionModel, node: MinimalNodeEntity): boolean {
|
||||
if (typeof action.visible === 'function') {
|
||||
return action.visible(node);
|
||||
}
|
||||
|
||||
return action.visible;
|
||||
}
|
||||
|
||||
private isActionDisabled(action: ContentActionModel, node: MinimalNodeEntity): boolean {
|
||||
if (typeof action.disabled === 'function') {
|
||||
return action.disabled(node);
|
||||
@@ -484,7 +509,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return action.disabled;
|
||||
}
|
||||
|
||||
@HostListener('contextmenu', ['$event'])
|
||||
|
Reference in New Issue
Block a user