From 294cca91de928ac124e327845ac882c74876a644 Mon Sep 17 00:00:00 2001 From: Will Abson Date: Tue, 7 Jun 2016 14:44:17 +0100 Subject: [PATCH] Use public API content URLs in viewer component - Required a more sophisticated way to detect PDF content --- .../app/components/files/files.component.html | 2 +- .../app/components/files/files.component.ts | 11 +++++---- .../src/services/document-actions.service.ts | 10 ++++++-- .../src/viewer.component.ts | 23 ++++--------------- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/demo-shell-ng2/app/components/files/files.component.html b/demo-shell-ng2/app/components/files/files.component.html index e9a2ac89cf..e49dab14c4 100644 --- a/demo-shell-ng2/app/components/files/files.component.html +++ b/demo-shell-ng2/app/components/files/files.component.html @@ -148,7 +148,7 @@ [multipleFiles]="true" (onSuccess)="refreshDocumentList($event)"> - +
diff --git a/demo-shell-ng2/app/components/files/files.component.ts b/demo-shell-ng2/app/components/files/files.component.ts index 8e2b5b4425..cc9ebb4f29 100644 --- a/demo-shell-ng2/app/components/files/files.component.ts +++ b/demo-shell-ng2/app/components/files/files.component.ts @@ -23,7 +23,8 @@ import { } from 'ng2-alfresco-documentlist/dist/ng2-alfresco-documentlist'; import { MDL, - AlfrescoSettingsService + AlfrescoSettingsService, + AlfrescoContentService } from 'ng2-alfresco-core/dist/ng2-alfresco-core'; import { ALFRESCO_ULPOAD_COMPONENTS } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload'; import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core'; @@ -46,12 +47,14 @@ export class FilesComponent { relativePath: string = ''; urlFile: string; + mimeType: string; fileShowed: boolean = false; acceptedFilesType: string = '.jpg,.pdf,.js'; constructor( private settings: AlfrescoSettingsService, + private contentService: AlfrescoContentService, documentActions: DocumentActionsService) { documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this)); } @@ -74,11 +77,9 @@ export class FilesComponent { showFile(event) { if (event.value.entry.isFile) { - let workSpace = 'workspace/SpacesStore/' + event.value.entry.id; let nameFile = event.value.entry.name; - - this.urlFile = this.settings.host + '/alfresco/s/slingshot/node/content/' + workSpace + '/' + nameFile; - + this.mimeType = event.value.entry.content.mimeType; + this.urlFile = this.contentService.getContentUrl(event.value); this.fileShowed = true; } else { this.fileShowed = false; diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/document-actions.service.ts b/ng2-components/ng2-alfresco-documentlist/src/services/document-actions.service.ts index ce3b921ad4..0bef5b995a 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/document-actions.service.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/services/document-actions.service.ts @@ -18,12 +18,18 @@ import {Injectable} from 'angular2/core'; import {ContentActionHandler} from '../models/content-action.model'; import {AlfrescoService} from './alfresco.service'; +import { + AlfrescoContentService +} from 'ng2-alfresco-core/dist/ng2-alfresco-core'; @Injectable() export class DocumentActionsService { private handlers: { [id: string]: ContentActionHandler; } = {}; - constructor(private _alfrescoService?: AlfrescoService) { + constructor( + private _alfrescoService?: AlfrescoService, + private _contentService?: AlfrescoContentService + ) { this.setupActionHandlers(); } @@ -70,7 +76,7 @@ export class DocumentActionsService { let link = document.createElement('a'); document.body.appendChild(link); link.setAttribute('download', 'download'); - link.href = this._alfrescoService.getContentUrl(obj); + link.href = this._contentService.getContentUrl(obj); link.click(); document.body.removeChild(link); } diff --git a/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts b/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts index c7f620bc32..49ab13d3c5 100644 --- a/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts +++ b/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts @@ -34,6 +34,9 @@ export class ViewerComponent { @Input() urlFile: string; + @Input() + mimeType: string = null; + @Input() overlayMode: boolean = false; @@ -63,8 +66,6 @@ export class ViewerComponent { if (this.urlFile) { this.nameFile = this.getFilenameFromUrl(this.urlFile); this.extension = this.getFileExtension(this.nameFile); - - this.urlFile = this.addAlfrescoTicket(this.urlFile); } resolve(); }); @@ -116,7 +117,7 @@ export class ViewerComponent { * check if the current file is a suppoerted pdf extension */ private isPdf() { - return this.extension === 'pdf'; + return this.extension === 'pdf' || this.mimeType == 'application/pdf'; } /** @@ -142,22 +143,6 @@ export class ViewerComponent { } } - /** - * Add Ticket to the file request - * @returns {string} - */ - private addAlfrescoTicket(url: string) { - return url + '?alf_ticket=' + this.getAlfrescoTicket(); - } - - /** - * Get the token from the local storage - * @returns {string} - */ - private getAlfrescoTicket() { - return localStorage.getItem('token'); - } - /** * Hide the othe possible menu in th eapplication */