support for explicit viewer type for URL (#2688)

This commit is contained in:
Denys Vuika
2017-12-04 09:49:03 +00:00
committed by Eugenio Romano
parent dc213adf55
commit 6c8ed9eae0
2 changed files with 14 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ Using with file url:
| --- | --- | --- | --- |
| fileNodeId | string | | Node Id of the file to load |
| urlFile | string | | If you want to load an external file that does not come from ECM you can use this Url where to load the file |
| urlFileViewer | string | null | Viewer to use with the `urlFile` address (`pdf`, `image`, `media`, `text`). Used when `urlFile` has no filename and extension. |
| urlBlob | Blob | | If you want to load a Blob File |
| overlayMode | boolean | false | If `true` show the Viewer full page over the present content otherwise will fit the parent div |
| showViewer | boolean | true | Hide or show the viewer |

View File

@@ -54,6 +54,9 @@ export class ViewerComponent implements OnChanges {
@Input()
urlFile = '';
@Input()
urlFileViewer: string = null;
@Input()
blobFile: Blob;
@@ -176,7 +179,7 @@ export class ViewerComponent implements OnChanges {
this.downloadUrl = this.urlFile;
this.fileName = this.displayName;
this.viewerType = this.getViewerTypeByExtension(this.extension);
this.viewerType = this.urlFileViewer || this.getViewerTypeByExtension(this.extension);
if (this.viewerType === 'unknown') {
this.viewerType = this.getViewerTypeByMimeType(this.mimeType);
}
@@ -328,13 +331,20 @@ export class ViewerComponent implements OnChanges {
}
/**
* Get the token from the local storage
* Get file extension from the string.
* Supports the URL formats like:
* http://localhost/test.jpg?cache=1000
* http://localhost/test.jpg#cache=1000
*
* @param {string} fileName - file name
* @returns {string} file name extension
*/
getFileExtension(fileName: string): string {
return fileName.split('.').pop().toLowerCase();
if (fileName) {
const match = fileName.match(/\.([^\./\?\#]+)($|\?|\#)/);
return match ? match[1] : null;
}
return null;
}
isCustomViewerExtension(extension: string): boolean {