/** * @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. */ import {Component, OnInit, Input, Output, EventEmitter} from 'angular2/core'; import {AlfrescoService} from './../services/alfresco.service'; import {FolderEntity} from './../core/entities/folder.entity'; import {DocumentEntity} from './../core/entities/document.entity'; import {ContentActionModel} from './../models/content-action.model'; @Component({ selector: 'alfresco-document-list', styles: [ ` :host .breadcrumb { margin-bottom: 4px; } :host .folder-icon { float: left; margin-right: 10px; font-size: 4em; } :host .file-icon { width: 52px; height: 52px; float: left; margin-right: 10px; } :host .document-header { font-size: 24px; line-height: 32px; } :host .document-header:hover { text-decoration: underline; } ` ], template: `
...

{{document.displayName}}

{{document.description}}

Modified {{document.modifiedOn}} by {{document.modifiedBy}}
`, providers: [AlfrescoService] }) export class DocumentList implements OnInit { @Input() navigate: boolean = true; @Input() breadcrumb: boolean = false; @Input('folder-icon') folderIconClass: string; @Input() thumbnails: boolean = true; @Input() downloads: boolean = true; @Output() itemClick: EventEmitter = new EventEmitter(); rootFolder = { name: 'Document Library', path: 'swsdp/documentLibrary' }; currentFolderPath: string = 'swsdp/documentLibrary'; folder: FolderEntity; errorMessage; route: any[] = []; documentActions: ContentActionModel[] = []; quickDocumentActions: ContentActionModel[] = []; folderActions: ContentActionModel[] = []; quickFolderActions: ContentActionModel[] = []; canNavigateParent(): boolean { return this.navigate && !this.breadcrumb && this.currentFolderPath !== this.rootFolder.path; } constructor ( private _alfrescoService: AlfrescoService ) {} ngOnInit() { this.route.push(this.rootFolder); this.displayFolderContent(this.rootFolder.path); } onNavigateParentClick($event) { if ($event) { $event.preventDefault(); } if (this.navigate) { this.route.pop(); let parent = this.route.length > 0 ? this.route[this.route.length - 1] : this.rootFolder; if (parent) { this.displayFolderContent(parent.path); } } } onItemClick(item: DocumentEntity, $event) { if ($event) { $event.preventDefault(); } this.itemClick.emit({ value: item }); if (this.navigate && item) { if (item.isFolder) { let path = this.getItemPath(item); this.route.push({ name: item.displayName, path: path }); this.displayFolderContent(path); } } } goToRoute(r, $event) { if ($event) { $event.preventDefault(); } if (this.navigate) { let idx = this.route.indexOf(r); if (idx > -1) { this.route.splice(idx + 1); this.displayFolderContent(r.path); } } } getContentUrl(document: DocumentEntity) { return this._alfrescoService.getContentUrl(document); } getDocumentThumbnailUrl(document: DocumentEntity) { return this._alfrescoService.getDocumentThumbnailUrl(document); } registerDocumentAction(action: ContentActionModel) { if (action) { this.documentActions.push(action); } } executeContentAction(document:DocumentEntity, action: ContentActionModel) { // todo: safety checks action.handler(document); } private getItemPath(item: DocumentEntity):string { let container = item.location.container; let path = item.location.path !== '/' ? (item.location.path + '/' ) : '/'; let relativePath = container + path + item.fileName; return item.location.site + '/' + relativePath; } private displayFolderContent(path) { this.currentFolderPath = path; this._alfrescoService .getFolder(path) .subscribe( folder => this.folder = folder, error => this.errorMessage = error ); } }