Use public API content URLs in viewer component

- Required a more sophisticated way to detect PDF content
This commit is contained in:
Will Abson
2016-06-07 14:44:17 +01:00
parent e39439b68c
commit 294cca91de
4 changed files with 19 additions and 27 deletions

View File

@@ -148,7 +148,7 @@
[multipleFiles]="true"
(onSuccess)="refreshDocumentList($event)"></alfresco-upload-button>
<alfresco-viewer [(showViewer)]="fileShowed" [urlFile]="urlFile" [overlayMode]="true">
<alfresco-viewer [(showViewer)]="fileShowed" [urlFile]="urlFile" [mimeType]="mimeType" [overlayMode]="true">
<div class="mdl-spinner mdl-js-spinner is-active"></div>
</alfresco-viewer>
<file-uploading-dialog></file-uploading-dialog>

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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
*/