mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
allow toggling viwer dialog toolbar elements (#2319)
This commit is contained in:
parent
aed9532d9d
commit
5dd666f423
@ -9,7 +9,10 @@
|
||||
</span>
|
||||
</adf-toolbar-title>
|
||||
|
||||
<button md-button [mdMenuTriggerFor]="mnuOpenWith">
|
||||
<button
|
||||
*ngIf="settings.allowOpenWith"
|
||||
md-button
|
||||
[mdMenuTriggerFor]="mnuOpenWith">
|
||||
Open with
|
||||
<md-icon>arrow_drop_down</md-icon>
|
||||
</button>
|
||||
@ -31,22 +34,31 @@
|
||||
<adf-toolbar-divider></adf-toolbar-divider>
|
||||
|
||||
<button
|
||||
*ngIf="downloadUrl"
|
||||
*ngIf="settings.allowDownload && settings.downloadUrl"
|
||||
md-icon-button
|
||||
mdTooltip="Download"
|
||||
(click)="download()">
|
||||
<md-icon>file_download</md-icon>
|
||||
</button>
|
||||
|
||||
<button md-icon-button mdTooltip="Print">
|
||||
<button
|
||||
*ngIf="settings.allowPrint"
|
||||
md-icon-button
|
||||
mdTooltip="Print">
|
||||
<md-icon>print</md-icon>
|
||||
</button>
|
||||
|
||||
<button md-icon-button mdTooltip="Share">
|
||||
<button
|
||||
*ngIf="settings.allowShare"
|
||||
md-icon-button
|
||||
mdTooltip="Share">
|
||||
<md-icon>share</md-icon>
|
||||
</button>
|
||||
|
||||
<button md-icon-button [mdMenuTriggerFor]="menu">
|
||||
<button
|
||||
*ngIf="settings.allowMoreMenu"
|
||||
md-icon-button
|
||||
[mdMenuTriggerFor]="menu">
|
||||
<md-icon>more_vert</md-icon>
|
||||
</button>
|
||||
<md-menu #menu="mdMenu">
|
||||
@ -64,7 +76,7 @@
|
||||
</button>
|
||||
</md-menu>
|
||||
|
||||
<ng-container *ngIf="allowInfoDrawer">
|
||||
<ng-container *ngIf="settings.allowInfoDrawer">
|
||||
<adf-toolbar-divider></adf-toolbar-divider>
|
||||
|
||||
<button md-icon-button mdTooltip="Info"
|
||||
|
@ -35,20 +35,23 @@ export class ViewerDialogComponent implements OnInit {
|
||||
fileName: string = 'Unknown file';
|
||||
fileUrl: string = null;
|
||||
fileMimeType: string = null;
|
||||
downloadUrl: string = null;
|
||||
|
||||
allowInfoDrawer = false;
|
||||
showInfoDrawer = false;
|
||||
|
||||
unknownFormatIcon = 'wifi_tethering';
|
||||
unknownFormatText = 'Document preview could not be loaded.';
|
||||
|
||||
isLoading: boolean = false;
|
||||
|
||||
showInfoDrawer = false;
|
||||
viewerType: string = null;
|
||||
asText: Observable<string>;
|
||||
|
||||
private nodeId: string;
|
||||
settings: ViewerDialogSettings = {
|
||||
allowDownload: true,
|
||||
allowPrint: true,
|
||||
allowShare: true,
|
||||
allowOpenWith: true,
|
||||
allowMoreMenu: true,
|
||||
allowInfoDrawer: true
|
||||
};
|
||||
|
||||
private types = [
|
||||
{ mimeType: 'application/x-javascript', type: 'text' },
|
||||
@ -59,22 +62,25 @@ export class ViewerDialogComponent implements OnInit {
|
||||
@Inject(MD_DIALOG_DATA) settings: ViewerDialogSettings,
|
||||
private http: Http,
|
||||
private renditionService: RenditionsService) {
|
||||
this.settings = Object.assign({}, this.settings, settings);
|
||||
this.setupDialog(this.settings);
|
||||
}
|
||||
|
||||
private setupDialog(settings: ViewerDialogSettings) {
|
||||
this.fileUrl = settings.fileUrl;
|
||||
this.fileName = settings.fileName;
|
||||
this.fileMimeType = settings.fileMimeType;
|
||||
this.downloadUrl = settings.downloadUrl;
|
||||
this.nodeId = settings.nodeId;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.viewerType = this.detectViewerType(this.fileMimeType);
|
||||
this.asText = this.getAsText();
|
||||
|
||||
if (this.viewerType !== 'unknown') {
|
||||
this.allowInfoDrawer = true;
|
||||
} else {
|
||||
if (this.nodeId) {
|
||||
this.displayAsPdf(this.nodeId);
|
||||
if (this.viewerType === 'unknown') {
|
||||
this.settings.allowInfoDrawer = false;
|
||||
|
||||
if (this.settings.nodeId) {
|
||||
this.displayAsPdf(this.settings.nodeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -108,12 +114,12 @@ export class ViewerDialogComponent implements OnInit {
|
||||
}
|
||||
|
||||
download() {
|
||||
if (this.downloadUrl && this.fileName) {
|
||||
if (this.settings.downloadUrl && this.fileName) {
|
||||
const link = document.createElement('a');
|
||||
|
||||
link.style.display = 'none';
|
||||
link.download = this.fileName;
|
||||
link.href = this.downloadUrl;
|
||||
link.href = this.settings.downloadUrl;
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
@ -20,6 +20,12 @@ export interface ViewerDialogSettings {
|
||||
fileMimeType?: string;
|
||||
fileName?: string;
|
||||
downloadUrl?: string;
|
||||
|
||||
nodeId?: string;
|
||||
|
||||
allowDownload?: boolean;
|
||||
allowPrint?: boolean;
|
||||
allowShare?: boolean;
|
||||
allowOpenWith?: boolean;
|
||||
allowMoreMenu?: boolean;
|
||||
allowInfoDrawer?: boolean;
|
||||
}
|
||||
|
@ -30,19 +30,19 @@ export class ViewerService {
|
||||
private apiService: AlfrescoApiService) {
|
||||
}
|
||||
|
||||
showViewerForNode(node: MinimalNodeEntryEntity): Promise<boolean> {
|
||||
showViewerForNode(node: MinimalNodeEntryEntity, settings: ViewerDialogSettings = {}): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
const settings: ViewerDialogSettings = {
|
||||
const dialogSettings = Object.assign({}, settings, {
|
||||
fileName: node.name,
|
||||
fileMimeType: node.content.mimeType,
|
||||
fileUrl: this.apiService.contentApi.getContentUrl(node.id, false),
|
||||
downloadUrl: this.apiService.contentApi.getContentUrl(node.id, true),
|
||||
nodeId: node.id
|
||||
};
|
||||
});
|
||||
|
||||
const dialogRef = this.dialog.open(ViewerDialogComponent, {
|
||||
panelClass: 'adf-viewer-dialog-panel',
|
||||
data: settings
|
||||
data: dialogSettings
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
@ -51,12 +51,12 @@ export class ViewerService {
|
||||
});
|
||||
}
|
||||
|
||||
showViewerForNodeId(nodeId: string): Promise<boolean> {
|
||||
showViewerForNodeId(nodeId: string, settings: ViewerDialogSettings = {}): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
this.apiService.nodesApi.getNode(nodeId).then(
|
||||
(node: MinimalNodeEntity) => {
|
||||
if (node && node.entry && node.entry.isFile) {
|
||||
return this.showViewerForNode(node.entry);
|
||||
return this.showViewerForNode(node.entry, settings);
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user