From 8a11137eede44b01db4a64338be87264663e01ca Mon Sep 17 00:00:00 2001 From: Suzana Dirla Date: Tue, 18 Sep 2018 18:01:25 +0300 Subject: [PATCH] [ACA-1548][ACA-1807] Set viewer toolbar actions via extensions (#640) * [ACA-1548][ACA-1807] add download action via extension * [ACA-1548][ACA-1807] add print action via extension * [ACA-1548][ACA-1807] add fullscreen viewer action via extension * [ACA-1548][ACA-1807] prettier formatting --- docs/extending.md | 2 + .../components/preview/preview.component.html | 4 +- .../services/content-management.service.ts | 39 ++++++++++++++++++- src/app/store/actions/node.actions.ts | 12 ++++++ src/app/store/effects/node.effects.ts | 33 +++++++++++++++- src/assets/app.extensions.json | 38 +++++++++++++++++- src/assets/i18n/en.json | 4 +- 7 files changed, 126 insertions(+), 6 deletions(-) diff --git a/docs/extending.md b/docs/extending.md index 860603ad3..5bec7c1a2 100644 --- a/docs/extending.md +++ b/docs/extending.md @@ -619,6 +619,8 @@ Below is the list of public actions types you can use in the plugin definitions | UPLOAD_FILES | n/a | Invoke "Upload Files" dialog and upload files to the currently opened folder. | | UPLOAD_FOLDER | n/a | Invoke "Upload Folder" dialog and upload selected folder to the currently opened one. | | VIEW_FILE | MinimalNodeEntity | Preview the file (or selection) in the Viewer. | +| PRINT_FILE | MinimalNodeEntity | Print the file opened in the Viewer (or selected). | +| FULLSCREEN_VIEWER | n/a | Enters fullscreen mode to view the file opened in the Viewer. | ## Rules diff --git a/src/app/components/preview/preview.component.html b/src/app/components/preview/preview.component.html index 13cc1d165..adef146a5 100644 --- a/src/app/components/preview/preview.component.html +++ b/src/app/components/preview/preview.component.html @@ -4,7 +4,9 @@ [fileNodeId]="nodeId" [allowNavigate]="navigateMultiple" [allowSidebar]="true" - [allowPrint] ="true" + [allowPrint] ="false" + [allowDownload]="false" + [allowFullScreen]="false" [canNavigateBefore]="previousNodeId" [canNavigateNext]="nextNodeId" [overlayMode]="true" diff --git a/src/app/services/content-management.service.ts b/src/app/services/content-management.service.ts index 6d799a66c..d48d0d205 100644 --- a/src/app/services/content-management.service.ts +++ b/src/app/services/content-management.service.ts @@ -57,7 +57,7 @@ import { NodeInfo, DeletedNodeInfo, DeleteStatus } from '../store/models'; import { ContentApiService } from './content-api.service'; import { sharedUrl } from '../store/selectors/app.selectors'; import { NodeActionsService } from './node-actions.service'; -import { TranslationService } from '@alfresco/adf-core'; +import { TranslationService, ViewUtilService } from '@alfresco/adf-core'; import { NodeVersionsDialogComponent } from '../dialogs/node-versions/node-versions.dialog'; import { take, map, tap, mergeMap, catchError } from 'rxjs/operators'; import { NodePermissionsDialogComponent } from '../components/permissions/permission-dialog/node-permissions.dialog'; @@ -90,7 +90,8 @@ export class ContentManagementService { private dialogRef: MatDialog, private nodeActionsService: NodeActionsService, private translation: TranslationService, - private snackBar: MatSnackBar + private snackBar: MatSnackBar, + private viewUtils: ViewUtilService ) {} addFavorite(nodes: Array) { @@ -1050,4 +1051,38 @@ export class ContentManagementService { return i18nMessageString; } + + printFile(node: MinimalNodeEntity) { + if (node && node.entry) { + // shared and favorite + const id = node.entry.nodeId || (node).entry.guid || node.entry.id; + const mimeType = node.entry.content.mimeType; + + if (id) { + this.viewUtils.printFileGeneric(id, mimeType); + } + } + } + + /** + * Triggers full screen mode with a main content area displayed. + */ + fullscreenViewer() { + const container = ( + document.documentElement.querySelector( + '.adf-viewer__fullscreen-container' + ) + ); + if (container) { + if (container.requestFullscreen) { + container.requestFullscreen(); + } else if (container.webkitRequestFullscreen) { + container.webkitRequestFullscreen(); + } else if (container.mozRequestFullScreen) { + container.mozRequestFullScreen(); + } else if (container.msRequestFullscreen) { + container.msRequestFullscreen(); + } + } + } } diff --git a/src/app/store/actions/node.actions.ts b/src/app/store/actions/node.actions.ts index 14ced4990..a487b52c6 100644 --- a/src/app/store/actions/node.actions.ts +++ b/src/app/store/actions/node.actions.ts @@ -40,6 +40,8 @@ export const COPY_NODES = 'COPY_NODES'; export const MOVE_NODES = 'MOVE_NODES'; export const MANAGE_PERMISSIONS = 'MANAGE_PERMISSIONS'; export const MANAGE_VERSIONS = 'MANAGE_VERSIONS'; +export const PRINT_FILE = 'PRINT_FILE'; +export const FULLSCREEN_VIEWER = 'FULLSCREEN_VIEWER'; export class SetSelectedNodesAction implements Action { readonly type = SET_SELECTED_NODES; @@ -110,3 +112,13 @@ export class ManageVersionsAction implements Action { readonly type = MANAGE_VERSIONS; constructor(public payload: MinimalNodeEntity) {} } + +export class PrintFileAction implements Action { + readonly type = PRINT_FILE; + constructor(public payload: MinimalNodeEntity) {} +} + +export class FullscreenViewerAction implements Action { + readonly type = FULLSCREEN_VIEWER; + constructor(public payload: MinimalNodeEntity) {} +} diff --git a/src/app/store/effects/node.effects.ts b/src/app/store/effects/node.effects.ts index d4b402ec9..94cbc5359 100644 --- a/src/app/store/effects/node.effects.ts +++ b/src/app/store/effects/node.effects.ts @@ -56,7 +56,11 @@ import { ManagePermissionsAction, MANAGE_PERMISSIONS, ManageVersionsAction, - MANAGE_VERSIONS + MANAGE_VERSIONS, + PRINT_FILE, + PrintFileAction, + FULLSCREEN_VIEWER, + FullscreenViewerAction } from '../actions/node.actions'; @Injectable() @@ -285,4 +289,31 @@ export class NodeEffects { } }) ); + + @Effect({ dispatch: false }) + printFile$ = this.actions$.pipe( + ofType(PRINT_FILE), + map(action => { + if (action && action.payload) { + this.contentService.printFile(action.payload); + } else { + this.store + .select(appSelection) + .pipe(take(1)) + .subscribe(selection => { + if (selection && selection.file) { + this.contentService.printFile(selection.file); + } + }); + } + }) + ); + + @Effect({ dispatch: false }) + fullscreenViewer$ = this.actions$.pipe( + ofType(FULLSCREEN_VIEWER), + map(() => { + this.contentService.fullscreenViewer(); + }) + ); } diff --git a/src/assets/app.extensions.json b/src/assets/app.extensions.json index ad849a7bf..d998252de 100644 --- a/src/assets/app.extensions.json +++ b/src/assets/app.extensions.json @@ -628,8 +628,32 @@ "viewer": { "toolbarActions": [ { - "id": "app.viewer.share", + "id": "app.toolbar.download", "order": 100, + "title": "APP.ACTIONS.DOWNLOAD", + "icon": "get_app", + "actions": { + "click": "DOWNLOAD_NODES" + }, + "rules": { + "visible": "app.toolbar.canDownload" + } + }, + { + "id": "app.viewer.print", + "order": 200, + "title": "APP.ACTIONS.PRINT", + "icon": "print", + "actions": { + "click": "PRINT_FILE" + }, + "rules": { + "visible": "app.toolbar.canViewFile" + } + }, + { + "id": "app.viewer.share", + "order": 300, "title": "APP.ACTIONS.SHARE", "icon": "share", "actions": { @@ -638,6 +662,18 @@ "rules": { "visible": "app.selection.file.canShare" } + }, + { + "id": "app.viewer.fullscreen", + "order": 400, + "title": "APP.ACTIONS.FULLSCREEN", + "icon": "fullscreen", + "actions": { + "click": "FULLSCREEN_VIEWER" + }, + "rules": { + "visible": "app.toolbar.canViewFile" + } } ], "toolbarMoreMenu": [ diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index f60c697e6..f3e480fbf 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -128,7 +128,9 @@ "DETAILS": "View details", "VERSIONS": "Manage Versions", "TOGGLE-SIDENAV": "Toggle side navigation bar", - "SHARE": "Share" + "SHARE": "Share", + "PRINT": "Print", + "FULLSCREEN": "Activate full-screen mode" }, "DIALOGS": { "CONFIRM_PURGE": {