mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
chaining rules, "not" evaluator (#527)
* chaining rules, "not" evaluator * improved evaluators * fix code
This commit is contained in:
parent
a684bad6c7
commit
98906942dc
@ -36,6 +36,12 @@
|
|||||||
"value": {
|
"value": {
|
||||||
"description": "Rule parameter value",
|
"description": "Rule parameter value",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"description": "Parameters",
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "#/definitions/ruleParameter" },
|
||||||
|
"minItems": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -41,7 +41,8 @@ import {
|
|||||||
SetLanguagePickerAction,
|
SetLanguagePickerAction,
|
||||||
SetLogoPathAction,
|
SetLogoPathAction,
|
||||||
SetSharedUrlAction,
|
SetSharedUrlAction,
|
||||||
SnackbarErrorAction
|
SnackbarErrorAction,
|
||||||
|
SetCurrentUrlAction
|
||||||
} from './store/actions';
|
} from './store/actions';
|
||||||
import { AppStore } from './store/states/app.state';
|
import { AppStore } from './store/states/app.state';
|
||||||
|
|
||||||
@ -89,6 +90,8 @@ export class AppComponent implements OnInit {
|
|||||||
const data: any = snapshot.data || {};
|
const data: any = snapshot.data || {};
|
||||||
|
|
||||||
pageTitle.setTitle(data.title || '');
|
pageTitle.setTitle(data.title || '');
|
||||||
|
|
||||||
|
this.store.dispatch(new SetCurrentUrlAction(router.url));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.router.config.unshift(...this.extensions.getApplicationRoutes());
|
this.router.config.unshift(...this.extensions.getApplicationRoutes());
|
||||||
|
@ -23,21 +23,15 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { NgModule, ModuleWithProviders, APP_INITIALIZER } from '@angular/core';
|
|
||||||
import { AuthGuardEcm, CoreModule } from '@alfresco/adf-core';
|
import { AuthGuardEcm, CoreModule } from '@alfresco/adf-core';
|
||||||
import { ExtensionService } from './extension.service';
|
|
||||||
import { LayoutComponent } from '../components/layout/layout.component';
|
|
||||||
import { ToolbarActionComponent } from './components/toolbar-action/toolbar-action.component';
|
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { every, some } from './evaluators/core.evaluators';
|
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';
|
||||||
import {
|
import { LayoutComponent } from '../components/layout/layout.component';
|
||||||
canCreateFolder,
|
|
||||||
hasFolderSelected,
|
|
||||||
canUpdateSelectedFolder,
|
|
||||||
hasFileSelected,
|
|
||||||
canDownloadSelection
|
|
||||||
} from './evaluators/app.evaluators';
|
|
||||||
import { TrashcanComponent } from '../components/trashcan/trashcan.component';
|
import { TrashcanComponent } from '../components/trashcan/trashcan.component';
|
||||||
|
import { ToolbarActionComponent } from './components/toolbar-action/toolbar-action.component';
|
||||||
|
import * as app from './evaluators/app.evaluators';
|
||||||
|
import * as core from './evaluators/core.evaluators';
|
||||||
|
import { ExtensionService } from './extension.service';
|
||||||
|
|
||||||
export function setupExtensions(extensions: ExtensionService): Function {
|
export function setupExtensions(extensions: ExtensionService): Function {
|
||||||
return () =>
|
return () =>
|
||||||
@ -47,19 +41,25 @@ export function setupExtensions(extensions: ExtensionService): Function {
|
|||||||
.setComponent('app.components.trashcan', TrashcanComponent)
|
.setComponent('app.components.trashcan', TrashcanComponent)
|
||||||
.setAuthGuard('app.auth', AuthGuardEcm)
|
.setAuthGuard('app.auth', AuthGuardEcm)
|
||||||
|
|
||||||
.setEvaluator('core.every', every)
|
.setEvaluator('core.every', core.every)
|
||||||
.setEvaluator('core.some', some)
|
.setEvaluator('core.some', core.some)
|
||||||
.setEvaluator('app.selection.canDownload', canDownloadSelection)
|
.setEvaluator('core.not', core.not)
|
||||||
.setEvaluator('app.selection.file', hasFileSelected)
|
.setEvaluator(
|
||||||
.setEvaluator('app.selection.folder', hasFolderSelected)
|
'app.selection.canDownload',
|
||||||
|
app.canDownloadSelection
|
||||||
|
)
|
||||||
|
.setEvaluator('app.selection.file', app.hasFileSelected)
|
||||||
|
.setEvaluator('app.selection.folder', app.hasFolderSelected)
|
||||||
.setEvaluator(
|
.setEvaluator(
|
||||||
'app.selection.folder.canUpdate',
|
'app.selection.folder.canUpdate',
|
||||||
canUpdateSelectedFolder
|
app.canUpdateSelectedFolder
|
||||||
)
|
)
|
||||||
.setEvaluator(
|
.setEvaluator(
|
||||||
'app.navigation.folder.canCreate',
|
'app.navigation.folder.canCreate',
|
||||||
canCreateFolder
|
app.canCreateFolder
|
||||||
);
|
)
|
||||||
|
.setEvaluator('app.navigation.isTrashcan', app.isTrashcan)
|
||||||
|
.setEvaluator('app.navigation.isNotTrashcan', app.isNotTrashcan);
|
||||||
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
|
@ -26,6 +26,15 @@
|
|||||||
import { Node } from 'alfresco-js-api';
|
import { Node } from 'alfresco-js-api';
|
||||||
import { RuleContext, RuleParameter } from '../rule.extensions';
|
import { RuleContext, RuleParameter } from '../rule.extensions';
|
||||||
|
|
||||||
|
export function isTrashcan(context: RuleContext, ...args: RuleParameter[]): boolean {
|
||||||
|
const { url } = context.navigation;
|
||||||
|
return url && url.startsWith('/trashcan');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isNotTrashcan(context: RuleContext, ...args: RuleParameter[]): boolean {
|
||||||
|
return !isTrashcan(context, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
export function canCreateFolder(context: RuleContext, ...args: RuleParameter[]): boolean {
|
export function canCreateFolder(context: RuleContext, ...args: RuleParameter[]): boolean {
|
||||||
const folder = context.navigation.currentFolder;
|
const folder = context.navigation.currentFolder;
|
||||||
if (folder) {
|
if (folder) {
|
||||||
@ -37,7 +46,7 @@ export function canCreateFolder(context: RuleContext, ...args: RuleParameter[]):
|
|||||||
export function canDownloadSelection(context: RuleContext, ...args: RuleParameter[]): boolean {
|
export function canDownloadSelection(context: RuleContext, ...args: RuleParameter[]): boolean {
|
||||||
if (!context.selection.isEmpty) {
|
if (!context.selection.isEmpty) {
|
||||||
return context.selection.nodes.every(node => {
|
return context.selection.nodes.every(node => {
|
||||||
return node.entry && (node.entry.isFile || node.entry.isFolder);
|
return node.entry && (node.entry.isFile || node.entry.isFolder || !!node.entry.nodeId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -25,14 +25,34 @@
|
|||||||
|
|
||||||
import { RuleContext, RuleParameter } from '../rule.extensions';
|
import { RuleContext, RuleParameter } from '../rule.extensions';
|
||||||
|
|
||||||
|
export function not(context: RuleContext, ...args: RuleParameter[]): boolean {
|
||||||
|
if (!args || args.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return args
|
||||||
|
.every(arg => {
|
||||||
|
const evaluator = context.evaluators[arg.value];
|
||||||
|
if (!evaluator) {
|
||||||
|
console.warn('evaluator not found: ' + arg.value);
|
||||||
|
}
|
||||||
|
return !evaluator(context, ...arg.parameters);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function every(context: RuleContext, ...args: RuleParameter[]): boolean {
|
export function every(context: RuleContext, ...args: RuleParameter[]): boolean {
|
||||||
if (!args || args.length === 0) {
|
if (!args || args.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return args
|
return args
|
||||||
.map(arg => context.evaluators[arg.value])
|
.every(arg => {
|
||||||
.every(evaluator => evaluator(context));
|
const evaluator = context.evaluators[arg.value];
|
||||||
|
if (!evaluator) {
|
||||||
|
console.warn('evaluator not found: ' + arg.value);
|
||||||
|
}
|
||||||
|
return evaluator(context, ...arg.parameters);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function some(context: RuleContext, ...args: RuleParameter[]): boolean {
|
export function some(context: RuleContext, ...args: RuleParameter[]): boolean {
|
||||||
@ -41,6 +61,11 @@ export function some(context: RuleContext, ...args: RuleParameter[]): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return args
|
return args
|
||||||
.map(arg => context.evaluators[arg.value])
|
.some(arg => {
|
||||||
.some(evaluator => evaluator(context));
|
const evaluator = context.evaluators[arg.value];
|
||||||
|
if (!evaluator) {
|
||||||
|
console.warn('evaluator not found: ' + arg.value);
|
||||||
|
}
|
||||||
|
return evaluator(context, ...arg.parameters);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -43,4 +43,5 @@ export class RuleRef {
|
|||||||
export interface RuleParameter {
|
export interface RuleParameter {
|
||||||
type: string;
|
type: string;
|
||||||
value: any;
|
value: any;
|
||||||
|
parameters?: Array<RuleParameter>;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ export const SET_LOGO_PATH = 'SET_LOGO_PATH';
|
|||||||
export const SET_LANGUAGE_PICKER = 'SET_LANGUAGE_PICKER';
|
export const SET_LANGUAGE_PICKER = 'SET_LANGUAGE_PICKER';
|
||||||
export const SET_SHARED_URL = 'SET_SHARED_URL';
|
export const SET_SHARED_URL = 'SET_SHARED_URL';
|
||||||
export const SET_CURRENT_FOLDER = 'SET_CURRENT_FOLDER';
|
export const SET_CURRENT_FOLDER = 'SET_CURRENT_FOLDER';
|
||||||
|
export const SET_CURRENT_URL = 'SET_CURRENT_URL';
|
||||||
|
|
||||||
export class SetAppNameAction implements Action {
|
export class SetAppNameAction implements Action {
|
||||||
readonly type = SET_APP_NAME;
|
readonly type = SET_APP_NAME;
|
||||||
@ -62,3 +63,8 @@ export class SetCurrentFolderAction implements Action {
|
|||||||
readonly type = SET_CURRENT_FOLDER;
|
readonly type = SET_CURRENT_FOLDER;
|
||||||
constructor(public payload: Node) {}
|
constructor(public payload: Node) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class SetCurrentUrlAction implements Action {
|
||||||
|
readonly type = SET_CURRENT_URL;
|
||||||
|
constructor(public payload: string) {}
|
||||||
|
}
|
||||||
|
@ -32,9 +32,12 @@ import {
|
|||||||
NavigateRouteAction,
|
NavigateRouteAction,
|
||||||
NavigateToParentFolder,
|
NavigateToParentFolder,
|
||||||
NAVIGATE_PARENT_FOLDER,
|
NAVIGATE_PARENT_FOLDER,
|
||||||
NAVIGATE_ROUTE
|
NAVIGATE_ROUTE,
|
||||||
|
NavigateToFolder,
|
||||||
|
NAVIGATE_FOLDER,
|
||||||
|
NavigateUrlAction,
|
||||||
|
NAVIGATE_URL
|
||||||
} from '../actions';
|
} from '../actions';
|
||||||
import { NavigateToFolder, NAVIGATE_FOLDER, NavigateUrlAction, NAVIGATE_URL } from '../actions/router.actions';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RouterEffects {
|
export class RouterEffects {
|
||||||
|
@ -40,9 +40,10 @@ import {
|
|||||||
SetLanguagePickerAction,
|
SetLanguagePickerAction,
|
||||||
SET_SHARED_URL,
|
SET_SHARED_URL,
|
||||||
SetSharedUrlAction,
|
SetSharedUrlAction,
|
||||||
SET_CURRENT_FOLDER
|
SET_CURRENT_FOLDER,
|
||||||
|
SetCurrentFolderAction,
|
||||||
|
SET_CURRENT_URL, SetCurrentUrlAction
|
||||||
} from '../actions';
|
} from '../actions';
|
||||||
import { SetCurrentFolderAction } from '../actions/app.actions';
|
|
||||||
|
|
||||||
export function appReducer(
|
export function appReducer(
|
||||||
state: AppState = INITIAL_APP_STATE,
|
state: AppState = INITIAL_APP_STATE,
|
||||||
@ -81,6 +82,9 @@ export function appReducer(
|
|||||||
action
|
action
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
|
case SET_CURRENT_URL:
|
||||||
|
newState = updateCurrentUrl(state, <SetCurrentUrlAction>action);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
newState = Object.assign({}, state);
|
newState = Object.assign({}, state);
|
||||||
}
|
}
|
||||||
@ -158,6 +162,12 @@ function updateCurrentFolder(state: AppState, action: SetCurrentFolderAction) {
|
|||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateCurrentUrl(state: AppState, action: SetCurrentUrlAction) {
|
||||||
|
const newState = Object.assign({}, state);
|
||||||
|
newState.navigation.url = action.payload;
|
||||||
|
return newState;
|
||||||
|
}
|
||||||
|
|
||||||
function updateSelectedNodes(
|
function updateSelectedNodes(
|
||||||
state: AppState,
|
state: AppState,
|
||||||
action: SetSelectedNodesAction
|
action: SetSelectedNodesAction
|
||||||
@ -179,7 +189,9 @@ 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) ? true : false;
|
return entity.entry.isFile || entity.entry.nodeId
|
||||||
|
? true
|
||||||
|
: false;
|
||||||
});
|
});
|
||||||
folder = nodes.find(entity => entity.entry.isFolder);
|
folder = nodes.find(entity => entity.entry.isFolder);
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,5 @@ import { Node } from 'alfresco-js-api';
|
|||||||
|
|
||||||
export interface NavigationState {
|
export interface NavigationState {
|
||||||
currentFolder?: Node;
|
currentFolder?: Node;
|
||||||
|
url?: string;
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,28 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "app.toolbar.canViewFile",
|
"id": "app.toolbar.canViewFile",
|
||||||
"type": "app.selection.file"
|
"type": "core.every",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "rule",
|
||||||
|
"value": "app.selection.file"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "rule",
|
||||||
|
"value": "core.not",
|
||||||
|
"parameters": [
|
||||||
|
{ "type": "rule", "value": "app.navigation.isTrashcan" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "app.toolbar.canDownload",
|
"id": "app.toolbar.canDownload",
|
||||||
"type": "app.selection.canDownload"
|
"type": "core.every",
|
||||||
|
"parameters": [
|
||||||
|
{ "type": "rule", "value": "app.selection.canDownload" },
|
||||||
|
{ "type": "rule", "value": "app.navigation.isNotTrashcan" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user