From f503880f729938a108c85e0020bf8fb6c4e64ecd Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Sun, 8 Jul 2018 15:58:45 +0100 Subject: [PATCH] viewer enhancements (#499) * fix ngOnInit inheritance * use unified info drawer --- src/app/components/page.component.ts | 2 + .../components/preview/preview.component.html | 44 +++++-------------- .../components/preview/preview.component.ts | 22 ++-------- src/app/store/actions/node.actions.ts | 2 +- src/app/store/reducers/app.reducer.ts | 2 +- 5 files changed, 20 insertions(+), 52 deletions(-) diff --git a/src/app/components/page.component.ts b/src/app/components/page.component.ts index 68792524a..363f1c769 100644 --- a/src/app/components/page.component.ts +++ b/src/app/components/page.component.ts @@ -53,6 +53,7 @@ export abstract class PageComponent implements OnInit, OnDestroy { displayMode = DisplayMode.List; sharedPreviewUrl$: Observable; actions: Array = []; + canUpdateFile = false; canDelete = false; canEditFolder = false; canUpload = false; @@ -82,6 +83,7 @@ export abstract class PageComponent implements OnInit, OnDestroy { this.infoDrawerOpened = false; } 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.canEditFolder = selection.folder && this.content.canUpdateNode(selection.folder); this.canDeleteShared = !this.selection.isEmpty && this.content.canDeleteSharedNodes(selection.nodes); diff --git a/src/app/components/preview/preview.component.html b/src/app/components/preview/preview.component.html index a26409164..b7c360023 100644 --- a/src/app/components/preview/preview.component.html +++ b/src/app/components/preview/preview.component.html @@ -1,33 +1,9 @@ - - - - - - - - - - - - - - - - + + + + @@ -67,22 +47,22 @@ diff --git a/src/app/components/preview/preview.component.ts b/src/app/components/preview/preview.component.ts index 2fe5d3bb8..6d0816f10 100644 --- a/src/app/components/preview/preview.component.ts +++ b/src/app/components/preview/preview.component.ts @@ -26,10 +26,9 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute, Router, UrlTree, UrlSegmentGroup, UrlSegment, PRIMARY_OUTLET } from '@angular/router'; import { UserPreferencesService, ObjectUtils } from '@alfresco/adf-core'; -import { Node, MinimalNodeEntity } from 'alfresco-js-api'; import { Store } from '@ngrx/store'; import { AppStore } from '../../store/states/app.state'; -import { DeleteNodesAction } from '../../store/actions'; +import { DeleteNodesAction, SetSelectedNodesAction } from '../../store/actions'; import { PageComponent } from '../page.component'; import { ContentApiService } from '../../services/content-api.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 { - node: Node; previewLocation: string = null; routesSkipNavigation = [ 'shared', 'recent-files', 'favorites' ]; navigateSource: string = null; navigationSources = ['favorites', 'libraries', 'personal-files', 'recent-files', 'shared']; - folderId: string = null; nodeId: string = null; previousNodeId: string; nextNodeId: string; navigateMultiple = false; - - selectedEntities: MinimalNodeEntity[] = []; openWith: Array = []; - canDeletePreview = false; - canUpdatePreview = false; - constructor( private contentApi: ContentApiService, private preferences: UserPreferencesService, @@ -74,6 +66,8 @@ export class PreviewComponent extends PageComponent implements OnInit { } ngOnInit() { + super.ngOnInit(); + this.previewLocation = this.router.url .substr(0, this.router.url.indexOf('/', 1)) .replace(/\//g, ''); @@ -110,9 +104,7 @@ export class PreviewComponent extends PageComponent implements OnInit { if (id) { try { this.node = await this.contentApi.getNodeInfo(id).toPromise(); - this.selectedEntities = [{ entry: this.node }]; - this.canDeletePreview = this.node && this.content.canDeleteNode(this.node); - this.canUpdatePreview = this.node && this.content.canUpdateNode(this.node); + this.store.dispatch(new SetSelectedNodesAction([{ entry: this.node }])); if (this.node && this.node.isFile) { const nearest = await this.getNearestNodes(this.node.id, this.node.parentId); @@ -364,10 +356,4 @@ export class PreviewComponent extends PageComponent implements OnInit { 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); - } } diff --git a/src/app/store/actions/node.actions.ts b/src/app/store/actions/node.actions.ts index 04a57c3aa..6a8b54380 100644 --- a/src/app/store/actions/node.actions.ts +++ b/src/app/store/actions/node.actions.ts @@ -38,7 +38,7 @@ export const EDIT_FOLDER = 'EDIT_FOLDER'; export class SetSelectedNodesAction implements Action { readonly type = SET_SELECTED_NODES; - constructor(public payload: any[] = []) {} + constructor(public payload: MinimalNodeEntity[] = []) {} } export class DeleteNodesAction implements Action { diff --git a/src/app/store/reducers/app.reducer.ts b/src/app/store/reducers/app.reducer.ts index caa6b7377..208bca31c 100644 --- a/src/app/store/reducers/app.reducer.ts +++ b/src/app/store/reducers/app.reducer.ts @@ -179,7 +179,7 @@ function updateSelectedNodes( if (nodes.length === 1) { file = nodes.find(entity => { // 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); }