mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
support for basic mime types (#2229)
This commit is contained in:
committed by
Eugenio Romano
parent
4aa3377641
commit
731ce5fa8a
@@ -6,6 +6,25 @@
|
|||||||
<span>{{ fileName }}</span>
|
<span>{{ fileName }}</span>
|
||||||
</adf-toolbar-title>
|
</adf-toolbar-title>
|
||||||
|
|
||||||
|
<button md-button [mdMenuTriggerFor]="mnuOpenWith">
|
||||||
|
Open with
|
||||||
|
<md-icon>arrow_drop_down</md-icon>
|
||||||
|
</button>
|
||||||
|
<md-menu #mnuOpenWith="mdMenu" [overlapTrigger]="false">
|
||||||
|
<button md-menu-item>
|
||||||
|
<md-icon>dialpad</md-icon>
|
||||||
|
<span>Option 1</span>
|
||||||
|
</button>
|
||||||
|
<button md-menu-item disabled>
|
||||||
|
<md-icon>voicemail</md-icon>
|
||||||
|
<span>Option 2</span>
|
||||||
|
</button>
|
||||||
|
<button md-menu-item>
|
||||||
|
<md-icon>notifications_off</md-icon>
|
||||||
|
<span>Option 3</span>
|
||||||
|
</button>
|
||||||
|
</md-menu>
|
||||||
|
|
||||||
<adf-toolbar-divider></adf-toolbar-divider>
|
<adf-toolbar-divider></adf-toolbar-divider>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -15,17 +34,14 @@
|
|||||||
(click)="download()">
|
(click)="download()">
|
||||||
<md-icon>file_download</md-icon>
|
<md-icon>file_download</md-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button md-icon-button mdTooltip="Print">
|
<button md-icon-button mdTooltip="Print">
|
||||||
<md-icon>print</md-icon>
|
<md-icon>print</md-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button md-icon-button mdTooltip="Share">
|
<button md-icon-button mdTooltip="Share">
|
||||||
<md-icon>share</md-icon>
|
<md-icon>share</md-icon>
|
||||||
</button>
|
</button>
|
||||||
<button md-icon-button mdTooltip="Info">
|
|
||||||
<md-icon>info_outline</md-icon>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<adf-toolbar-divider></adf-toolbar-divider>
|
|
||||||
|
|
||||||
<button md-icon-button [mdMenuTriggerFor]="menu">
|
<button md-icon-button [mdMenuTriggerFor]="menu">
|
||||||
<md-icon>more_vert</md-icon>
|
<md-icon>more_vert</md-icon>
|
||||||
@@ -44,16 +60,53 @@
|
|||||||
<span>Disable alerts</span>
|
<span>Disable alerts</span>
|
||||||
</button>
|
</button>
|
||||||
</md-menu>
|
</md-menu>
|
||||||
|
|
||||||
|
<adf-toolbar-divider></adf-toolbar-divider>
|
||||||
|
|
||||||
|
<button md-icon-button mdTooltip="Info">
|
||||||
|
<md-icon>info_outline</md-icon>
|
||||||
|
</button>
|
||||||
|
|
||||||
</adf-toolbar>
|
</adf-toolbar>
|
||||||
|
|
||||||
<md-dialog-content>
|
<md-dialog-content>
|
||||||
<ng-container [ngSwitch]="viewerType">
|
<ng-container [ngSwitch]="viewerType">
|
||||||
|
|
||||||
<ng-container *ngSwitchCase="'image'">
|
<ng-container *ngSwitchCase="'image'">
|
||||||
<div class="adf-viewer-dialog-image-view">
|
<div class="adf-viewer-dialog__image-view">
|
||||||
<img *ngIf="fileUrl" [src]="fileUrl">
|
<img *ngIf="fileUrl" [src]="fileUrl">
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container *ngSwitchCase="'text'">
|
||||||
|
<div class="adf-viewer-dialog__text-view">
|
||||||
|
<pre>{{ asText | async }}</pre>
|
||||||
|
</div>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container *ngSwitchCase="'pdf'">
|
||||||
|
<adf-pdf-viewer class="adf-viewer-dialog__pdf-view"
|
||||||
|
[showToolbar]="true"
|
||||||
|
[urlFile]="fileUrl">
|
||||||
|
</adf-pdf-viewer>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container *ngSwitchCase="'video'">
|
||||||
|
<div class="adf-viewer-dialog__video-view">
|
||||||
|
<video controls>
|
||||||
|
<source [src]="fileUrl" [type]="fileMimeType">
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container *ngSwitchCase="'audio'">
|
||||||
|
<div class="adf-viewer-dialog__audio-view">
|
||||||
|
<video controls>
|
||||||
|
<source [src]="fileUrl" [type]="fileMimeType">
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
<ng-container *ngSwitchDefault>
|
<ng-container *ngSwitchDefault>
|
||||||
<div class="adf-viewer-dialog-unknown-view">
|
<div class="adf-viewer-dialog-unknown-view">
|
||||||
<div>
|
<div>
|
||||||
@@ -62,5 +115,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</md-dialog-content>
|
</md-dialog-content>
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
.mat-dialog-content {
|
.mat-dialog-content {
|
||||||
display: flex;
|
display: flex;
|
||||||
max-height: 90vh;
|
max-height: 90vh;
|
||||||
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-unknown-view {
|
&-unknown-view {
|
||||||
@@ -22,7 +23,7 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-image-view {
|
&__image-view {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -33,4 +34,42 @@
|
|||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__text-view {
|
||||||
|
display: flex;
|
||||||
|
background-color: white;
|
||||||
|
width: 100vw;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
& > pre {
|
||||||
|
overflow: auto;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__video-view {
|
||||||
|
video {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
max-height: 90vh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__audio-view {
|
||||||
|
video {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
max-height: 90vh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__pdf-view {
|
||||||
|
.viewer-pdf-container {
|
||||||
|
top: 52px;
|
||||||
|
left: 7px;
|
||||||
|
right: 7px;
|
||||||
|
border: 1px solid lightgray;
|
||||||
|
background-color: lightgray;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
|
||||||
|
import { Http, Response } from '@angular/http';
|
||||||
import { MD_DIALOG_DATA, MdDialogRef } from '@angular/material';
|
import { MD_DIALOG_DATA, MdDialogRef } from '@angular/material';
|
||||||
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
import { ViewerDialogSettings } from './viewer-dialog.settings';
|
import { ViewerDialogSettings } from './viewer-dialog.settings';
|
||||||
|
|
||||||
@@ -38,25 +40,52 @@ export class ViewerDialogComponent implements OnInit {
|
|||||||
unknownFormatText = 'Document preview could not be loaded.';
|
unknownFormatText = 'Document preview could not be loaded.';
|
||||||
|
|
||||||
viewerType: string = null;
|
viewerType: string = null;
|
||||||
|
asText: Observable<string>;
|
||||||
|
|
||||||
|
private types = [
|
||||||
|
{ mimeType: 'application/x-javascript', type: 'text' },
|
||||||
|
{ mimeType: 'application/pdf', type: 'pdf' }
|
||||||
|
];
|
||||||
|
|
||||||
constructor(private dialogRef: MdDialogRef<ViewerDialogComponent>,
|
constructor(private dialogRef: MdDialogRef<ViewerDialogComponent>,
|
||||||
@Inject(MD_DIALOG_DATA) settings: ViewerDialogSettings) {
|
@Inject(MD_DIALOG_DATA) settings: ViewerDialogSettings,
|
||||||
|
private http: Http) {
|
||||||
this.fileUrl = settings.fileUrl;
|
this.fileUrl = settings.fileUrl;
|
||||||
this.fileName = settings.fileName;
|
this.fileName = settings.fileName;
|
||||||
this.fileMimeType = settings.fileMimeType;
|
this.fileMimeType = settings.fileMimeType;
|
||||||
this.downloadUrl = settings.downloadUrl;
|
this.downloadUrl = settings.downloadUrl;
|
||||||
|
// console.log(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.viewerType = this.detectViewerType(this.fileMimeType);
|
this.viewerType = this.detectViewerType(this.fileMimeType);
|
||||||
|
this.asText = this.getAsText();
|
||||||
}
|
}
|
||||||
|
|
||||||
private detectViewerType(mimeType: string) {
|
private detectViewerType(mimeType: string) {
|
||||||
if (mimeType) {
|
if (mimeType) {
|
||||||
mimeType = mimeType.toLowerCase();
|
mimeType = mimeType.toLowerCase();
|
||||||
|
|
||||||
if (mimeType.startsWith('image/')) {
|
if (mimeType.startsWith('image/')) {
|
||||||
return 'image';
|
return 'image';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mimeType.startsWith('text/')) {
|
||||||
|
return 'text';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mimeType.startsWith('video/')) {
|
||||||
|
return 'video';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mimeType.startsWith('audio/')) {
|
||||||
|
return 'audio';
|
||||||
|
}
|
||||||
|
|
||||||
|
const registered = this.types.find(t => t.mimeType === mimeType);
|
||||||
|
if (registered) {
|
||||||
|
return registered.type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
}
|
}
|
||||||
@@ -75,6 +104,10 @@ export class ViewerDialogComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getAsText(): Observable<string> {
|
||||||
|
return this.http.get(this.fileUrl).map((res: Response) => res.text());
|
||||||
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this.dialogRef.close(true);
|
this.dialogRef.close(true);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user