From ea29213178d67c9a0ce3cb146fdedb5d890befa4 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Wed, 4 Oct 2017 12:21:57 +0100 Subject: [PATCH] add presets document list in an external model (#2420) --- .../src/components/document-list.component.ts | 231 +---------------- .../src/models/preset.model.ts | 240 ++++++++++++++++++ 2 files changed, 245 insertions(+), 226 deletions(-) create mode 100644 ng2-components/ng2-alfresco-documentlist/src/models/preset.model.ts 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 91e63f3019..874db4daf3 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 @@ -23,6 +23,7 @@ import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging, Pagination, Pers 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 { presetsDefaultModel } from '../models/preset.model'; import { ImageResolver, RowFilter, ShareDataRow, ShareDataTableAdapter } from './../data/share-datatable-adapter'; import { ContentActionModel } from './../models/content-action.model'; import { PermissionStyleModel } from './../models/permissions-style.model'; @@ -802,236 +803,14 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni } private loadLayoutPresets(): void { - let 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: this.locationFormat, - 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: this.locationFormat, - 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: this.locationFormat, - 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: this.locationFormat, - 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 - } - ] - }; - const externalSettings = this.appConfig.get('document-list.presets', null); + if (externalSettings) { - presets = Object.assign({}, presets, externalSettings); + this.layoutPresets = Object.assign({}, presetsDefaultModel, externalSettings); + } else { + this.layoutPresets = presetsDefaultModel; } - this.layoutPresets = presets; } private getLayoutPreset(name: string = 'default'): DataColumn[] { diff --git a/ng2-components/ng2-alfresco-documentlist/src/models/preset.model.ts b/ng2-components/ng2-alfresco-documentlist/src/models/preset.model.ts new file mode 100644 index 0000000000..112f7bc3a8 --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/src/models/preset.model.ts @@ -0,0 +1,240 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export let presetsDefaultModel = { + '-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: this.locationFormat, + 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: this.locationFormat, + 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: this.locationFormat, + 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: this.locationFormat, + 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 + } + ] +};