viewer enhancements (#499)

* fix ngOnInit inheritance

* use unified info drawer
This commit is contained in:
Denys Vuika 2018-07-08 15:58:45 +01:00 committed by GitHub
parent 718a32a907
commit f503880f72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 52 deletions

View File

@ -53,6 +53,7 @@ export abstract class PageComponent implements OnInit, OnDestroy {
displayMode = DisplayMode.List; displayMode = DisplayMode.List;
sharedPreviewUrl$: Observable<string>; sharedPreviewUrl$: Observable<string>;
actions: Array<ContentActionExtension> = []; actions: Array<ContentActionExtension> = [];
canUpdateFile = false;
canDelete = false; canDelete = false;
canEditFolder = false; canEditFolder = false;
canUpload = false; canUpload = false;
@ -82,6 +83,7 @@ export abstract class PageComponent implements OnInit, OnDestroy {
this.infoDrawerOpened = false; this.infoDrawerOpened = false;
} }
this.actions = this.extensions.getSelectedContentActions(selection, this.node); this.actions = this.extensions.getSelectedContentActions(selection, this.node);
this.canUpdateFile = this.selection.file && this.content.canUpdateNode(selection.file);
this.canDelete = !this.selection.isEmpty && this.content.canDeleteNodes(selection.nodes); this.canDelete = !this.selection.isEmpty && this.content.canDeleteNodes(selection.nodes);
this.canEditFolder = selection.folder && this.content.canUpdateNode(selection.folder); this.canEditFolder = selection.folder && this.content.canUpdateNode(selection.folder);
this.canDeleteShared = !this.selection.isEmpty && this.content.canDeleteSharedNodes(selection.nodes); this.canDeleteShared = !this.selection.isEmpty && this.content.canDeleteSharedNodes(selection.nodes);

View File

@ -1,33 +1,9 @@
<ng-container *ngIf="nodeId"> <ng-container *ngIf="nodeId">
<ng-template #sidebarTemplate>
<adf-info-drawer [title]="'APP.INFO_DRAWER.TITLE' | translate">
<adf-info-drawer-tab [label]="'APP.INFO_DRAWER.TABS.PROPERTIES' | translate">
<adf-content-metadata-card
[readOnly]="!canUpdatePreview"
[displayEmpty]="canUpdatePreview"
[preset]="'custom'"
[node]="node">
</adf-content-metadata-card>
</adf-info-drawer-tab>
<adf-info-drawer-tab [label]="'APP.INFO_DRAWER.TABS.VERSIONS' | translate">
<ng-container>
<adf-version-manager
[showComments]="'adf-version-manager.allowComments' | adfAppConfig:true"
[allowDownload]="'adf-version-manager.allowDownload' | adfAppConfig:true"
[node]="node">
</adf-version-manager>
</ng-container>
</adf-info-drawer-tab>
</adf-info-drawer>
</ng-template>
<adf-viewer <adf-viewer
[fileNodeId]="nodeId" [fileNodeId]="nodeId"
[allowNavigate]="navigateMultiple" [allowNavigate]="navigateMultiple"
[allowSidebar]="true" [allowSidebar]="true"
[sidebarTemplate]="sidebarTemplate"
[canNavigateBefore]="previousNodeId" [canNavigateBefore]="previousNodeId"
[canNavigateNext]="nextNodeId" [canNavigateNext]="nextNodeId"
[overlayMode]="true" [overlayMode]="true"
@ -35,6 +11,10 @@
(navigateBefore)="onNavigateBefore()" (navigateBefore)="onNavigateBefore()"
(navigateNext)="onNavigateNext()"> (navigateNext)="onNavigateNext()">
<adf-viewer-sidebar>
<aca-info-drawer [node]="selection.file"></aca-info-drawer>
</adf-viewer-sidebar>
<adf-viewer-open-with *ifExperimental="'extensions'"> <adf-viewer-open-with *ifExperimental="'extensions'">
<button *ngFor="let entry of openWith" <button *ngFor="let entry of openWith"
mat-menu-item mat-menu-item
@ -49,7 +29,7 @@
<button <button
mat-menu-item mat-menu-item
#favorites="adfFavorite" #favorites="adfFavorite"
[adf-node-favorite]="selectedEntities"> [adf-node-favorite]="selection.nodes">
<mat-icon color="primary" *ngIf="favorites.hasFavorites()">star</mat-icon> <mat-icon color="primary" *ngIf="favorites.hasFavorites()">star</mat-icon>
<mat-icon *ngIf="!favorites.hasFavorites()">star_border</mat-icon> <mat-icon *ngIf="!favorites.hasFavorites()">star_border</mat-icon>
<span>{{ 'APP.ACTIONS.FAVORITE' | translate }}</span> <span>{{ 'APP.ACTIONS.FAVORITE' | translate }}</span>
@ -59,7 +39,7 @@
<button mat-menu-item <button mat-menu-item
color="primary" color="primary"
[baseShareUrl]="sharedPreviewUrl$ | async" [baseShareUrl]="sharedPreviewUrl$ | async"
[adf-share]="selectedEntities[0]"> [adf-share]="selection.file">
<mat-icon>share</mat-icon> <mat-icon>share</mat-icon>
<span>{{ 'APP.ACTIONS.SHARE' | translate }}</span> <span>{{ 'APP.ACTIONS.SHARE' | translate }}</span>
</button> </button>
@ -67,22 +47,22 @@
<button <button
mat-menu-item mat-menu-item
[acaCopyNode]="selectedEntities"> [acaCopyNode]="selection.nodes">
<mat-icon>content_copy</mat-icon> <mat-icon>content_copy</mat-icon>
<span>{{ 'APP.ACTIONS.COPY' | translate }}</span> <span>{{ 'APP.ACTIONS.COPY' | translate }}</span>
</button> </button>
<button <button
mat-menu-item mat-menu-item
*ngIf="canDeletePreview" *ngIf="canDelete"
[acaMoveNode]="selectedEntities"> [acaMoveNode]="selection.nodes">
<mat-icon>library_books</mat-icon> <mat-icon>library_books</mat-icon>
<span>{{ 'APP.ACTIONS.MOVE' | translate }}</span> <span>{{ 'APP.ACTIONS.MOVE' | translate }}</span>
</button> </button>
<button <button
mat-menu-item mat-menu-item
*ngIf="canDeletePreview" *ngIf="canDelete"
(click)="deleteFile()"> (click)="deleteFile()">
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
<span>{{ 'APP.ACTIONS.DELETE' | translate }}</span> <span>{{ 'APP.ACTIONS.DELETE' | translate }}</span>
@ -90,8 +70,8 @@
<button <button
mat-menu-item mat-menu-item
*ngIf="canUpdatePreview" *ngIf="canUpdateFile"
[acaNodeVersions]="node"> [acaNodeVersions]="selection.file">
<mat-icon>history</mat-icon> <mat-icon>history</mat-icon>
<span>{{ 'APP.ACTIONS.VERSIONS' | translate }}</span> <span>{{ 'APP.ACTIONS.VERSIONS' | translate }}</span>
</button> </button>

View File

@ -26,10 +26,9 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute, Router, UrlTree, UrlSegmentGroup, UrlSegment, PRIMARY_OUTLET } from '@angular/router'; import { ActivatedRoute, Router, UrlTree, UrlSegmentGroup, UrlSegment, PRIMARY_OUTLET } from '@angular/router';
import { UserPreferencesService, ObjectUtils } from '@alfresco/adf-core'; import { UserPreferencesService, ObjectUtils } from '@alfresco/adf-core';
import { Node, MinimalNodeEntity } from 'alfresco-js-api';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppStore } from '../../store/states/app.state'; import { AppStore } from '../../store/states/app.state';
import { DeleteNodesAction } from '../../store/actions'; import { DeleteNodesAction, SetSelectedNodesAction } from '../../store/actions';
import { PageComponent } from '../page.component'; import { PageComponent } from '../page.component';
import { ContentApiService } from '../../services/content-api.service'; import { ContentApiService } from '../../services/content-api.service';
import { ExtensionService } from '../../extensions/extension.service'; import { ExtensionService } from '../../extensions/extension.service';
@ -44,24 +43,17 @@ import { ContentManagementService } from '../../common/services/content-manageme
}) })
export class PreviewComponent extends PageComponent implements OnInit { export class PreviewComponent extends PageComponent implements OnInit {
node: Node;
previewLocation: string = null; previewLocation: string = null;
routesSkipNavigation = [ 'shared', 'recent-files', 'favorites' ]; routesSkipNavigation = [ 'shared', 'recent-files', 'favorites' ];
navigateSource: string = null; navigateSource: string = null;
navigationSources = ['favorites', 'libraries', 'personal-files', 'recent-files', 'shared']; navigationSources = ['favorites', 'libraries', 'personal-files', 'recent-files', 'shared'];
folderId: string = null; folderId: string = null;
nodeId: string = null; nodeId: string = null;
previousNodeId: string; previousNodeId: string;
nextNodeId: string; nextNodeId: string;
navigateMultiple = false; navigateMultiple = false;
selectedEntities: MinimalNodeEntity[] = [];
openWith: Array<OpenWithExtension> = []; openWith: Array<OpenWithExtension> = [];
canDeletePreview = false;
canUpdatePreview = false;
constructor( constructor(
private contentApi: ContentApiService, private contentApi: ContentApiService,
private preferences: UserPreferencesService, private preferences: UserPreferencesService,
@ -74,6 +66,8 @@ export class PreviewComponent extends PageComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
super.ngOnInit();
this.previewLocation = this.router.url this.previewLocation = this.router.url
.substr(0, this.router.url.indexOf('/', 1)) .substr(0, this.router.url.indexOf('/', 1))
.replace(/\//g, ''); .replace(/\//g, '');
@ -110,9 +104,7 @@ export class PreviewComponent extends PageComponent implements OnInit {
if (id) { if (id) {
try { try {
this.node = await this.contentApi.getNodeInfo(id).toPromise(); this.node = await this.contentApi.getNodeInfo(id).toPromise();
this.selectedEntities = [{ entry: this.node }]; this.store.dispatch(new SetSelectedNodesAction([{ entry: this.node }]));
this.canDeletePreview = this.node && this.content.canDeleteNode(this.node);
this.canUpdatePreview = this.node && this.content.canUpdateNode(this.node);
if (this.node && this.node.isFile) { if (this.node && this.node.isFile) {
const nearest = await this.getNearestNodes(this.node.id, this.node.parentId); const nearest = await this.getNearestNodes(this.node.id, this.node.parentId);
@ -364,10 +356,4 @@ export class PreviewComponent extends PageComponent implements OnInit {
return acc; return acc;
}, []); }, []);
} }
// this is where each application decides how to treat an action and what to do
// the ACA maps actions to the NgRx actions as an example
runAction(actionId: string) {
this.extensions.runActionById(actionId);
}
} }

View File

@ -38,7 +38,7 @@ export const EDIT_FOLDER = 'EDIT_FOLDER';
export class SetSelectedNodesAction implements Action { export class SetSelectedNodesAction implements Action {
readonly type = SET_SELECTED_NODES; readonly type = SET_SELECTED_NODES;
constructor(public payload: any[] = []) {} constructor(public payload: MinimalNodeEntity[] = []) {}
} }
export class DeleteNodesAction implements Action { export class DeleteNodesAction implements Action {

View File

@ -179,7 +179,7 @@ function updateSelectedNodes(
if (nodes.length === 1) { if (nodes.length === 1) {
file = nodes.find(entity => { file = nodes.find(entity => {
// workaround Shared // workaround Shared
return entity.entry.isFile || entity.entry.nodeId; return (entity.entry.isFile || entity.entry.nodeId) ? true : false;
}); });
folder = nodes.find(entity => entity.entry.isFolder); folder = nodes.find(entity => entity.entry.isFolder);
} }