mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Use public API content URLs in viewer component
- Required a more sophisticated way to detect PDF content
This commit is contained in:
@@ -148,7 +148,7 @@
|
|||||||
[multipleFiles]="true"
|
[multipleFiles]="true"
|
||||||
(onSuccess)="refreshDocumentList($event)"></alfresco-upload-button>
|
(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>
|
<div class="mdl-spinner mdl-js-spinner is-active"></div>
|
||||||
</alfresco-viewer>
|
</alfresco-viewer>
|
||||||
<file-uploading-dialog></file-uploading-dialog>
|
<file-uploading-dialog></file-uploading-dialog>
|
||||||
|
@@ -23,7 +23,8 @@ import {
|
|||||||
} from 'ng2-alfresco-documentlist/dist/ng2-alfresco-documentlist';
|
} from 'ng2-alfresco-documentlist/dist/ng2-alfresco-documentlist';
|
||||||
import {
|
import {
|
||||||
MDL,
|
MDL,
|
||||||
AlfrescoSettingsService
|
AlfrescoSettingsService,
|
||||||
|
AlfrescoContentService
|
||||||
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
import { ALFRESCO_ULPOAD_COMPONENTS } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
|
import { ALFRESCO_ULPOAD_COMPONENTS } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
|
||||||
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
@@ -46,12 +47,14 @@ export class FilesComponent {
|
|||||||
relativePath: string = '';
|
relativePath: string = '';
|
||||||
|
|
||||||
urlFile: string;
|
urlFile: string;
|
||||||
|
mimeType: string;
|
||||||
fileShowed: boolean = false;
|
fileShowed: boolean = false;
|
||||||
|
|
||||||
acceptedFilesType: string = '.jpg,.pdf,.js';
|
acceptedFilesType: string = '.jpg,.pdf,.js';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private settings: AlfrescoSettingsService,
|
private settings: AlfrescoSettingsService,
|
||||||
|
private contentService: AlfrescoContentService,
|
||||||
documentActions: DocumentActionsService) {
|
documentActions: DocumentActionsService) {
|
||||||
documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this));
|
documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this));
|
||||||
}
|
}
|
||||||
@@ -74,11 +77,9 @@ export class FilesComponent {
|
|||||||
|
|
||||||
showFile(event) {
|
showFile(event) {
|
||||||
if (event.value.entry.isFile) {
|
if (event.value.entry.isFile) {
|
||||||
let workSpace = 'workspace/SpacesStore/' + event.value.entry.id;
|
|
||||||
let nameFile = event.value.entry.name;
|
let nameFile = event.value.entry.name;
|
||||||
|
this.mimeType = event.value.entry.content.mimeType;
|
||||||
this.urlFile = this.settings.host + '/alfresco/s/slingshot/node/content/' + workSpace + '/' + nameFile;
|
this.urlFile = this.contentService.getContentUrl(event.value);
|
||||||
|
|
||||||
this.fileShowed = true;
|
this.fileShowed = true;
|
||||||
} else {
|
} else {
|
||||||
this.fileShowed = false;
|
this.fileShowed = false;
|
||||||
|
@@ -18,12 +18,18 @@
|
|||||||
import {Injectable} from 'angular2/core';
|
import {Injectable} from 'angular2/core';
|
||||||
import {ContentActionHandler} from '../models/content-action.model';
|
import {ContentActionHandler} from '../models/content-action.model';
|
||||||
import {AlfrescoService} from './alfresco.service';
|
import {AlfrescoService} from './alfresco.service';
|
||||||
|
import {
|
||||||
|
AlfrescoContentService
|
||||||
|
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DocumentActionsService {
|
export class DocumentActionsService {
|
||||||
private handlers: { [id: string]: ContentActionHandler; } = {};
|
private handlers: { [id: string]: ContentActionHandler; } = {};
|
||||||
|
|
||||||
constructor(private _alfrescoService?: AlfrescoService) {
|
constructor(
|
||||||
|
private _alfrescoService?: AlfrescoService,
|
||||||
|
private _contentService?: AlfrescoContentService
|
||||||
|
) {
|
||||||
this.setupActionHandlers();
|
this.setupActionHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +76,7 @@ export class DocumentActionsService {
|
|||||||
let link = document.createElement('a');
|
let link = document.createElement('a');
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.setAttribute('download', 'download');
|
link.setAttribute('download', 'download');
|
||||||
link.href = this._alfrescoService.getContentUrl(obj);
|
link.href = this._contentService.getContentUrl(obj);
|
||||||
link.click();
|
link.click();
|
||||||
document.body.removeChild(link);
|
document.body.removeChild(link);
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,9 @@ export class ViewerComponent {
|
|||||||
@Input()
|
@Input()
|
||||||
urlFile: string;
|
urlFile: string;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
mimeType: string = null;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
overlayMode: boolean = false;
|
overlayMode: boolean = false;
|
||||||
|
|
||||||
@@ -63,8 +66,6 @@ export class ViewerComponent {
|
|||||||
if (this.urlFile) {
|
if (this.urlFile) {
|
||||||
this.nameFile = this.getFilenameFromUrl(this.urlFile);
|
this.nameFile = this.getFilenameFromUrl(this.urlFile);
|
||||||
this.extension = this.getFileExtension(this.nameFile);
|
this.extension = this.getFileExtension(this.nameFile);
|
||||||
|
|
||||||
this.urlFile = this.addAlfrescoTicket(this.urlFile);
|
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@@ -116,7 +117,7 @@ export class ViewerComponent {
|
|||||||
* check if the current file is a suppoerted pdf extension
|
* check if the current file is a suppoerted pdf extension
|
||||||
*/
|
*/
|
||||||
private isPdf() {
|
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
|
* Hide the othe possible menu in th eapplication
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user