From 0e219687ecf25a531d6d61b6ea0ec1497c6c7d13 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Fri, 8 Sep 2017 15:25:35 +0100 Subject: [PATCH] allow loading layout presets from app.config (#2310) --- demo-shell-ng2/app.config-dev.json | 225 ++++++++++++++++++ demo-shell-ng2/app.config-prod.json | 225 ++++++++++++++++++ .../src/components/document-list.component.ts | 22 +- 3 files changed, 467 insertions(+), 5 deletions(-) diff --git a/demo-shell-ng2/app.config-dev.json b/demo-shell-ng2/app.config-dev.json index d596b1c58b..9ae8783b2a 100644 --- a/demo-shell-ng2/app.config-dev.json +++ b/demo-shell-ng2/app.config-dev.json @@ -25,5 +25,230 @@ } ] } + }, + "document-list": { + "presets": { + "-trashcan-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "path", + "type": "location", + "title": "ADF-DOCUMENT-LIST.LAYOUT.LOCATION", + "format": "/files", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "archivedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.DELETED_ON", + "format": "timeAgo", + "sortable": true + }, + { + "key": "archivedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.DELETED_BY", + "sortable": true + } + ], + "-sites-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "title", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "visibility", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.STATUS", + "sortable": true + } + ], + "-favorites-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "path", + "type": "location", + "title": "ADF-DOCUMENT-LIST.LAYOUT.LOCATION", + "format": "/files", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "modifiedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_ON", + "format": "timeAgo", + "sortable": true + }, + { + "key": "modifiedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_BY", + "sortable": true + } + ], + "-recent-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "path", + "type": "location", + "title": "ADF-DOCUMENT-LIST.LAYOUT.LOCATION", + "cssClass": "ellipsis-cell", + "format": "/files", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "modifiedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_ON", + "format": "timeAgo", + "sortable": true + } + ], + "-sharedlinks-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "path", + "type": "location", + "title": "ADF-DOCUMENT-LIST.LAYOUT.LOCATION", + "cssClass": "ellipsis-cell", + "format": "/files", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "modifiedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_ON", + "format": "timeAgo", + "sortable": true + }, + { + "key": "modifiedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_BY", + "sortable": true + }, + { + "key": "sharedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SHARED_BY", + "sortable": true + } + ], + "default": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "modifiedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_ON", + "format": "timeAgo", + "sortable": true + }, + { + "key": "modifiedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_BY", + "sortable": true + } + ] + } } } diff --git a/demo-shell-ng2/app.config-prod.json b/demo-shell-ng2/app.config-prod.json index fb64e6299f..524f6f7bd6 100644 --- a/demo-shell-ng2/app.config-prod.json +++ b/demo-shell-ng2/app.config-prod.json @@ -25,5 +25,230 @@ } ] } + }, + "document-list": { + "presets": { + "-trashcan-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "path", + "type": "location", + "title": "ADF-DOCUMENT-LIST.LAYOUT.LOCATION", + "format": "/files", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "archivedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.DELETED_ON", + "format": "timeAgo", + "sortable": true + }, + { + "key": "archivedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.DELETED_BY", + "sortable": true + } + ], + "-sites-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "title", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "visibility", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.STATUS", + "sortable": true + } + ], + "-favorites-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "path", + "type": "location", + "title": "ADF-DOCUMENT-LIST.LAYOUT.LOCATION", + "format": "/files", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "modifiedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_ON", + "format": "timeAgo", + "sortable": true + }, + { + "key": "modifiedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_BY", + "sortable": true + } + ], + "-recent-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "path", + "type": "location", + "title": "ADF-DOCUMENT-LIST.LAYOUT.LOCATION", + "cssClass": "ellipsis-cell", + "format": "/files", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "modifiedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_ON", + "format": "timeAgo", + "sortable": true + } + ], + "-sharedlinks-": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "path", + "type": "location", + "title": "ADF-DOCUMENT-LIST.LAYOUT.LOCATION", + "cssClass": "ellipsis-cell", + "format": "/files", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "modifiedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_ON", + "format": "timeAgo", + "sortable": true + }, + { + "key": "modifiedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_BY", + "sortable": true + }, + { + "key": "sharedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SHARED_BY", + "sortable": true + } + ], + "default": [ + { + "key": "$thumbnail", + "type": "image", + "srTitle": "ADF-DOCUMENT-LIST.LAYOUT.THUMBNAIL", + "sortable": false + }, + { + "key": "name", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.NAME", + "cssClass": "full-width ellipsis-cell", + "sortable": true + }, + { + "key": "content.sizeInBytes", + "type": "fileSize", + "title": "ADF-DOCUMENT-LIST.LAYOUT.SIZE", + "sortable": true + }, + { + "key": "modifiedAt", + "type": "date", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_ON", + "format": "timeAgo", + "sortable": true + }, + { + "key": "modifiedByUser.displayName", + "type": "text", + "title": "ADF-DOCUMENT-LIST.LAYOUT.MODIFIED_BY", + "sortable": true + } + ] + } } } diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts index 6d466ba7ce..1307449e5d 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts @@ -20,7 +20,7 @@ import { OnChanges, OnInit, Output, SimpleChanges, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core'; import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging, Pagination, PersonEntry } from 'alfresco-js-api'; -import { AlfrescoApiService, DataColumnListComponent } from 'ng2-alfresco-core'; +import { AlfrescoApiService, AppConfigService, DataColumnListComponent } from 'ng2-alfresco-core'; import { DataCellEvent, DataColumn, DataRowActionEvent, DataSorting, DataTableComponent, ObjectDataColumn } from 'ng2-alfresco-datatable'; import { Observable, Subject } from 'rxjs/Rx'; import { ImageResolver, RowFilter, ShareDataRow, ShareDataTableAdapter } from './../data/share-datatable-adapter'; @@ -146,13 +146,15 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni contextActionHandler: Subject = new Subject(); data: ShareDataTableAdapter; + private layoutPresets = {}; private currentNodeAllowableOperations: string[] = []; private CREATE_PERMISSION = 'create'; constructor(private documentListService: DocumentListService, private ngZone: NgZone, private elementRef: ElementRef, - private apiService: AlfrescoApiService) { + private apiService: AlfrescoApiService, + private appConfig: AppConfigService) { } private get nodesApi() { @@ -206,6 +208,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni } ngOnInit() { + this.loadLayoutPresets(); this.data = new ShareDataTableAdapter(this.documentListService, null, this.getDefaultSorting()); this.data.thumbnails = this.thumbnails; this.data.permissionsStyle = this.permissionsStyle; @@ -758,8 +761,8 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni return this.hasCurrentNodePermission(this.CREATE_PERMISSION); } - private getLayoutPreset(name: string = 'default'): DataColumn[] { - const presets = { + private loadLayoutPresets(): void { + let presets = { '-trashcan-': [ { key: '$thumbnail', @@ -983,6 +986,15 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni ] }; - return (presets[name] || presets['default']).map(col => new ObjectDataColumn(col)); + const externalSettings = this.appConfig.get('document-list.presets', null); + if (externalSettings) { + presets = Object.assign({}, presets, externalSettings); + } + + this.layoutPresets = presets; + } + + private getLayoutPreset(name: string = 'default'): DataColumn[] { + return (this.layoutPresets[name] || this.layoutPresets['default']).map(col => new ObjectDataColumn(col)); } }