mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-19 17:14:45 +00:00
[ACA-2364] support 'canPreview' rule for the Viewer (#1102)
* support `canPreview` rule for the Viewer * update plint settings * update prettier settings for plint * test fixes * update config
This commit is contained in:
parent
d5f8699976
commit
d8e3b9ada0
10
.github/plint.yml
vendored
10
.github/plint.yml
vendored
@ -2,11 +2,21 @@ modules:
|
|||||||
- pr.prettier
|
- pr.prettier
|
||||||
- pr.spellcheck
|
- pr.spellcheck
|
||||||
|
|
||||||
|
prettier:
|
||||||
|
exclude:
|
||||||
|
- '*.json'
|
||||||
|
|
||||||
spellcheck:
|
spellcheck:
|
||||||
|
dictionaries:
|
||||||
|
- html
|
||||||
|
- en-gb
|
||||||
|
- en_US
|
||||||
words:
|
words:
|
||||||
- plint
|
- plint
|
||||||
- ngrx
|
- ngrx
|
||||||
- qshare
|
- qshare
|
||||||
- snackbar
|
- snackbar
|
||||||
|
- exif
|
||||||
|
- docx
|
||||||
exclude:
|
exclude:
|
||||||
- src/assets/app.extensions.json
|
- src/assets/app.extensions.json
|
||||||
|
@ -363,6 +363,7 @@ Viewer component in ACA supports the following extension points:
|
|||||||
- Toolbar actions
|
- Toolbar actions
|
||||||
- `More` toolbar actions
|
- `More` toolbar actions
|
||||||
- `Open With` actions
|
- `Open With` actions
|
||||||
|
- Rules
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@ -547,6 +548,35 @@ and invoke it from the custom `Open With` menu entry called `Snackbar`.
|
|||||||
|
|
||||||
As with other content actions, custom plugins can disable, update or extend `Open With` actions.
|
As with other content actions, custom plugins can disable, update or extend `Open With` actions.
|
||||||
|
|
||||||
|
### Rules
|
||||||
|
|
||||||
|
You can provide global rules for the Viewer by utilizing the `features.viewer.rules` object:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export interface ViewerRules {
|
||||||
|
/**
|
||||||
|
* Checks if user can preview the node.
|
||||||
|
*/
|
||||||
|
canPreview?: string;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"features": {
|
||||||
|
"viewer": {
|
||||||
|
"rules": {
|
||||||
|
"canPreview": "customRule"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The rule should return `true` if node preview is allowed, otherwise `false`.
|
||||||
|
|
||||||
## Content metadata presets
|
## Content metadata presets
|
||||||
|
|
||||||
The content metadata presets are needed by the [Content Metadata Component](https://www.alfresco.com/abn/adf/docs/content-services/content-metadata-card.component/) to render the properties of metadata aspects for a given node.
|
The content metadata presets are needed by the [Content Metadata Component](https://www.alfresco.com/abn/adf/docs/content-services/content-metadata-card.component/) to render the properties of metadata aspects for a given node.
|
||||||
|
@ -684,6 +684,16 @@
|
|||||||
"description": "Viewer component extensions",
|
"description": "Viewer component extensions",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"rules": {
|
||||||
|
"description": "Viewer rules",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"canPreview": {
|
||||||
|
"description": "Controls whether preview is enabled for particular node",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"openWith": {
|
"openWith": {
|
||||||
"description": "The [Open With] menu extensions",
|
"description": "The [Open With] menu extensions",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
|
@ -53,7 +53,8 @@ import {
|
|||||||
} from '@alfresco/adf-extensions';
|
} from '@alfresco/adf-extensions';
|
||||||
import { AppConfigService, AuthenticationService } from '@alfresco/adf-core';
|
import { AppConfigService, AuthenticationService } from '@alfresco/adf-core';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
import { RepositoryInfo } from '@alfresco/js-api';
|
import { RepositoryInfo, NodeEntry } from '@alfresco/js-api';
|
||||||
|
import { ViewerRules } from './viewer.rules';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -76,6 +77,7 @@ export class AppExtensionService implements RuleContext {
|
|||||||
navbar: Array<NavBarGroupRef> = [];
|
navbar: Array<NavBarGroupRef> = [];
|
||||||
sidebar: Array<SidebarTabRef> = [];
|
sidebar: Array<SidebarTabRef> = [];
|
||||||
contentMetadata: any;
|
contentMetadata: any;
|
||||||
|
viewerRules: ViewerRules = {};
|
||||||
|
|
||||||
documentListPresets: {
|
documentListPresets: {
|
||||||
files: Array<DocumentListPresetRef>;
|
files: Array<DocumentListPresetRef>;
|
||||||
@ -184,6 +186,10 @@ export class AppExtensionService implements RuleContext {
|
|||||||
searchLibraries: this.getDocumentListPreset(config, 'search-libraries')
|
searchLibraries: this.getDocumentListPreset(config, 'search-libraries')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (config.features && config.features.viewer) {
|
||||||
|
this.viewerRules = <ViewerRules>(config.features.viewer['rules'] || {});
|
||||||
|
}
|
||||||
|
|
||||||
this.registerIcons(config);
|
this.registerIcons(config);
|
||||||
|
|
||||||
const references = (config.$references || [])
|
const references = (config.$references || [])
|
||||||
@ -504,7 +510,37 @@ export class AppExtensionService implements RuleContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: move to ADF/RuleService
|
||||||
|
isRuleDefined(ruleId: string): boolean {
|
||||||
|
return ruleId && this.getEvaluator(ruleId) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: move to ADF/RuleService
|
||||||
|
evaluateRule(ruleId: string, ...args: any[]): boolean {
|
||||||
|
const evaluator = this.getEvaluator(ruleId);
|
||||||
|
|
||||||
|
if (evaluator) {
|
||||||
|
return evaluator(this, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
getEvaluator(key: string): RuleEvaluator {
|
getEvaluator(key: string): RuleEvaluator {
|
||||||
return this.extensions.getEvaluator(key);
|
return this.extensions.getEvaluator(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canPreviewNode(node: NodeEntry) {
|
||||||
|
const rules = this.viewerRules;
|
||||||
|
|
||||||
|
if (this.isRuleDefined(rules.canPreview)) {
|
||||||
|
const canPreview = this.evaluateRule(rules.canPreview, node);
|
||||||
|
|
||||||
|
if (!canPreview) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
31
src/app/extensions/viewer.rules.ts
Normal file
31
src/app/extensions/viewer.rules.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 - 2019 Alfresco Software Limited
|
||||||
|
*
|
||||||
|
* This file is part of the Alfresco Example Content Application.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface ViewerRules {
|
||||||
|
/**
|
||||||
|
* Checks if user can preview the node.
|
||||||
|
*/
|
||||||
|
canPreview?: string;
|
||||||
|
}
|
@ -37,6 +37,7 @@ import {
|
|||||||
} from '@alfresco/aca-shared/store';
|
} from '@alfresco/aca-shared/store';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { Store, createSelector } from '@ngrx/store';
|
import { Store, createSelector } from '@ngrx/store';
|
||||||
|
import { AppExtensionService } from '../../extensions/extension.service';
|
||||||
|
|
||||||
export const fileToPreview = createSelector(
|
export const fileToPreview = createSelector(
|
||||||
getAppSelection,
|
getAppSelection,
|
||||||
@ -54,7 +55,8 @@ export class ViewerEffects {
|
|||||||
constructor(
|
constructor(
|
||||||
private store: Store<AppStore>,
|
private store: Store<AppStore>,
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
private router: Router
|
private router: Router,
|
||||||
|
private extensions: AppExtensionService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Effect({ dispatch: false })
|
@Effect({ dispatch: false })
|
||||||
@ -94,7 +96,10 @@ export class ViewerEffects {
|
|||||||
if (action.payload && action.payload.entry) {
|
if (action.payload && action.payload.entry) {
|
||||||
const { id, nodeId, isFile } = <any>action.payload.entry;
|
const { id, nodeId, isFile } = <any>action.payload.entry;
|
||||||
|
|
||||||
if (isFile || nodeId) {
|
if (
|
||||||
|
this.extensions.canPreviewNode(action.payload) &&
|
||||||
|
(isFile || nodeId)
|
||||||
|
) {
|
||||||
this.displayPreview(nodeId || id, action.parentId);
|
this.displayPreview(nodeId || id, action.parentId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -105,7 +110,10 @@ export class ViewerEffects {
|
|||||||
if (result.selection && result.selection.file) {
|
if (result.selection && result.selection.file) {
|
||||||
const { id, nodeId, isFile } = <any>result.selection.file.entry;
|
const { id, nodeId, isFile } = <any>result.selection.file.entry;
|
||||||
|
|
||||||
if (isFile || nodeId) {
|
if (
|
||||||
|
this.extensions.canPreviewNode(action.payload) &&
|
||||||
|
(isFile || nodeId)
|
||||||
|
) {
|
||||||
const parentId = result.folder ? result.folder.id : null;
|
const parentId = result.folder ? result.folder.id : null;
|
||||||
this.displayPreview(nodeId || id, parentId);
|
this.displayPreview(nodeId || id, parentId);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user