Merge pull request #1294 from Alfresco/dev-pionnegru-ACA-2867

[ACA-2867] User - actions menu extensibility
This commit is contained in:
Denys Vuika 2020-01-08 07:33:12 +00:00 committed by GitHub
commit 289fca759f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 738 additions and 39 deletions

View File

@ -166,6 +166,8 @@ The button will be visible only when the linked rule evaluates to `true`.
| 1.8.0 | canManagePermissions | Checks if user can manage permissions for the selected node. |
| 1.8.0 | canToggleEditOffline | Checks if user can toggle **Edit Offline** mode for selected node. |
| 1.8.0 | user.isAdmin | Checks if user is admin. |
| 1.9.0 | app.canShowLanguagePicker | Whether language picker menu should be present or not. |
| 1.9.0 | app.canShowLogout | Whether logout action should be present or not. |
## Navigation Evaluators

View File

@ -676,6 +676,12 @@
"items": { "$ref": "#/definitions/iconRef" },
"minItems": 1
},
"userActions": {
"description": "User option menu extensions",
"type": "array",
"items": { "$ref": "#/definitions/contentActionRef" },
"minItems": 1
},
"header": {
"description": "Application header extensions",
"type": "array",

View File

@ -439,4 +439,40 @@ describe('app.evaluators', () => {
expect(app.isShared(context)).toBe(true);
});
});
describe('canShowLanguagePicker', () => {
it('should return true when property is true', () => {
const context: any = {
languagePicker: true
};
expect(app.canShowLanguagePicker(context)).toBe(true);
});
it('should return false when property is false', () => {
const context: any = {
languagePicker: false
};
expect(app.canShowLanguagePicker(context)).toBe(false);
});
});
describe('canShowLogout', () => {
it('should return false when `withCredentials` property is true', () => {
const context: any = {
withCredentials: true
};
expect(app.canShowLogout(context)).toBe(false);
});
it('should return true when `withCredentials` property is false', () => {
const context: any = {
withCredentials: false
};
expect(app.canShowLanguagePicker(context)).toBe(true);
});
});
});

View File

@ -27,6 +27,11 @@ import { RuleContext } from '@alfresco/adf-extensions';
import * as navigation from './navigation.rules';
import * as repository from './repository.rules';
export interface AcaRuleContext extends RuleContext {
languagePicker: boolean;
withCredentials: boolean;
}
/**
* Checks if user can copy selected node.
* JSON ref: `app.canCopyNode`
@ -526,3 +531,21 @@ export function canToggleFavorite(context: RuleContext): boolean {
].some(Boolean)
].every(Boolean);
}
/**
* Checks if application should render language picker menu.
* JSON ref: `canShowLanguagePicker`
* @param context Rule execution context
*/
export function canShowLanguagePicker(context: AcaRuleContext): boolean {
return context.languagePicker;
}
/**
* Checks if application should render logout option.
* JSON ref: `canShowLogout`
* @param context Rule execution context
*/
export function canShowLogout(context: AcaRuleContext): boolean {
return !context.withCredentials;
}

View File

@ -30,6 +30,8 @@ import { NgModule } from '@angular/core';
import { GenericErrorModule } from '@alfresco/aca-shared';
import { LocationLinkComponent } from './location-link/location-link.component';
import { ToggleSharedComponent } from './toggle-shared/toggle-shared.component';
import { LanguagePickerComponent } from './language-picker/language-picker.component';
import { LogoutComponent } from './logout/logout.component';
@NgModule({
imports: [
@ -38,13 +40,25 @@ import { ToggleSharedComponent } from './toggle-shared/toggle-shared.component';
ExtensionsModule,
GenericErrorModule
],
declarations: [LocationLinkComponent, ToggleSharedComponent],
declarations: [
LocationLinkComponent,
ToggleSharedComponent,
LanguagePickerComponent,
LogoutComponent
],
exports: [
ExtensionsModule,
LocationLinkComponent,
GenericErrorModule,
ToggleSharedComponent
ToggleSharedComponent,
LanguagePickerComponent,
LogoutComponent
],
entryComponents: [LocationLinkComponent, ToggleSharedComponent]
entryComponents: [
LocationLinkComponent,
ToggleSharedComponent,
LanguagePickerComponent,
LogoutComponent
]
})
export class AppCommonModule {}

View File

@ -0,0 +1,39 @@
/*!
* @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/>.
*/
import { Component } from '@angular/core';
@Component({
selector: 'aca-language-picker',
template: `
<button mat-menu-item [matMenuTriggerFor]="langMenu">
{{ 'APP.LANGUAGE' | translate }}
</button>
<mat-menu #langMenu="matMenu">
<adf-language-menu></adf-language-menu>
</mat-menu>
`
})
export class LanguagePickerComponent {}

View File

@ -0,0 +1,70 @@
/*!
* @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/>.
*/
import { TestBed, ComponentFixture } from '@angular/core/testing';
import {
TranslateModule,
TranslateLoader,
TranslateFakeLoader
} from '@ngx-translate/core';
import { LogoutComponent } from './logout.component';
import { Store } from '@ngrx/store';
import { SetSelectedNodesAction } from '@alfresco/aca-shared/store';
describe('LogoutComponent', () => {
let fixture: ComponentFixture<LogoutComponent>;
let component: LogoutComponent;
let store;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot({
loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
})
],
declarations: [LogoutComponent],
providers: [
{
provide: Store,
useValue: {
dispatch: jasmine.createSpy('dispatch')
}
}
]
});
store = TestBed.get(Store);
fixture = TestBed.createComponent(LogoutComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should reset selected nodes from store', () => {
component.onLogoutEvent();
expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([]));
});
});

View File

@ -0,0 +1,44 @@
/*!
* @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/>.
*/
import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppStore, SetSelectedNodesAction } from '@alfresco/aca-shared/store';
@Component({
selector: 'aca-logout',
template: `
<button mat-menu-item (click)="onLogoutEvent()" adf-logout>
{{ 'APP.SIGN_OUT' | translate }}
</button>
`
})
export class LogoutComponent {
constructor(private store: Store<AppStore>) {}
onLogoutEvent() {
this.store.dispatch(new SetSelectedNodesAction([]));
}
}

View File

@ -13,21 +13,10 @@
</div>
<mat-menu #userMenu="matMenu" [overlapTrigger]="false">
<button
*ngIf="languagePicker$ | async"
mat-menu-item
[matMenuTriggerFor]="langMenu"
>
{{ 'APP.LANGUAGE' | translate }}
</button>
<ng-container *ngIf="showLogout">
<button mat-menu-item (click)="onLogoutEvent()" adf-logout>
{{ 'APP.SIGN_OUT' | translate }}
</button>
<ng-container *ngFor="let actionRef of actions; trackBy: trackByActionId">
<app-user-menu-item
[actionRef]="actionRef"
color="default"
></app-user-menu-item>
</ng-container>
</mat-menu>
<mat-menu #langMenu="matMenu">
<adf-language-menu></adf-language-menu>
</mat-menu>

View File

@ -24,9 +24,91 @@
*/
import { CurrentUserComponent } from './current-user.component';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { AppTestingModule } from '../../testing/app-testing.module';
import { AppExtensionService } from '../../extensions/extension.service';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Store } from '@ngrx/store';
import {
AppState,
SetUserProfileAction,
SetLanguagePickerAction
} from '@alfresco/aca-shared/store';
describe('CurrentUserComponent', () => {
it('should be defined', () => {
expect(CurrentUserComponent).toBeDefined();
let fixture: ComponentFixture<CurrentUserComponent>;
let component: CurrentUserComponent;
let appExtensionService;
let store: Store<AppState>;
const person = {
entry: {
id: 'user-id',
firstName: 'Test',
lastName: 'User',
email: 'user@email.com',
enabled: true,
isAdmin: false,
userName: 'user-name'
}
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [CurrentUserComponent],
providers: [AppExtensionService],
schemas: [NO_ERRORS_SCHEMA]
});
fixture = TestBed.createComponent(CurrentUserComponent);
appExtensionService = TestBed.get(AppExtensionService);
store = TestBed.get(Store);
component = fixture.componentInstance;
});
it('should get profile data', done => {
const expectedProfile = {
firstName: 'Test',
lastName: 'User',
userName: 'Test User',
isAdmin: true,
id: 'user-id',
groups: []
};
fixture.detectChanges();
store.dispatch(
new SetUserProfileAction({ person: person.entry, groups: [] })
);
component.profile$.subscribe((profile: any) => {
expect(profile).toEqual(jasmine.objectContaining(expectedProfile));
done();
});
});
it('should set language picker state', done => {
fixture.detectChanges();
store.dispatch(new SetLanguagePickerAction(true));
component.languagePicker$.subscribe((languagePicker: boolean) => {
expect(languagePicker).toBe(true);
done();
});
});
it('should set menu actions', () => {
const actions = <any>[
{
id: 'action-id'
}
];
spyOn(appExtensionService, 'getUserActions').and.returnValue(actions);
fixture.detectChanges();
expect(component.actions).toBe(actions);
});
});

View File

@ -23,17 +23,16 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, ViewEncapsulation } from '@angular/core';
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { ProfileState } from '@alfresco/adf-extensions';
import { ProfileState, ContentActionRef } from '@alfresco/adf-extensions';
import {
AppStore,
SetSelectedNodesAction,
getUserProfile,
getLanguagePickerState
} from '@alfresco/aca-shared/store';
import { AppService } from '@alfresco/aca-shared';
import { AppExtensionService } from '../../extensions/extension.service';
@Component({
selector: 'aca-current-user',
@ -41,20 +40,23 @@ import { AppService } from '@alfresco/aca-shared';
encapsulation: ViewEncapsulation.None,
host: { class: 'aca-current-user' }
})
export class CurrentUserComponent {
export class CurrentUserComponent implements OnInit {
profile$: Observable<ProfileState>;
languagePicker$: Observable<boolean>;
actions: Array<ContentActionRef> = [];
get showLogout(): boolean {
return !this.appService.withCredentials;
}
constructor(
private store: Store<AppStore>,
private extensions: AppExtensionService
) {}
constructor(private store: Store<AppStore>, private appService: AppService) {
ngOnInit() {
this.profile$ = this.store.select(getUserProfile);
this.languagePicker$ = store.select(getLanguagePickerState);
this.languagePicker$ = this.store.select(getLanguagePickerState);
this.actions = this.extensions.getUserActions();
}
onLogoutEvent() {
this.store.dispatch(new SetSelectedNodesAction([]));
trackByActionId(_: number, action: ContentActionRef) {
return action.id;
}
}

View File

@ -26,12 +26,19 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CoreModule } from '@alfresco/adf-core';
import { ExtensionsModule } from '@alfresco/adf-extensions';
import { CurrentUserComponent } from './current-user.component';
import { UserMenuItemComponent } from './user-menu-item.component';
import { RouterModule } from '@angular/router';
@NgModule({
imports: [CommonModule, CoreModule.forChild(), RouterModule],
declarations: [CurrentUserComponent],
exports: [CurrentUserComponent]
imports: [
CommonModule,
CoreModule.forChild(),
RouterModule,
ExtensionsModule
],
declarations: [CurrentUserComponent, UserMenuItemComponent],
exports: [CurrentUserComponent, UserMenuItemComponent]
})
export class AppCurrentUserModule {}

View File

@ -0,0 +1,36 @@
<div class="aca-user-actions-menu">
<ng-container [ngSwitch]="actionRef.type">
<ng-container *ngSwitchCase="'menu'">
<button mat-menu-item [id]="actionRef.id" [matMenuTriggerFor]="childMenu">
<span>{{ actionRef.title | translate }}</span>
</button>
<mat-menu #childMenu="matMenu">
<ng-container
*ngFor="let child of actionRef.children; trackBy: trackById"
>
<app-user-menu-item [actionRef]="child"></app-user-menu-item>
</ng-container>
</mat-menu>
</ng-container>
<ng-container *ngSwitchCase="'separator'">
<mat-divider></mat-divider>
</ng-container>
<ng-container *ngSwitchCase="'custom'">
<adf-dynamic-component [id]="actionRef.component"></adf-dynamic-component>
</ng-container>
<ng-container *ngSwitchDefault>
<button
mat-menu-item
color="primary"
[id]="actionRef.id"
(click)="runAction()"
>
<span>{{ actionRef.title | translate }}</span>
</button>
</ng-container>
</ng-container>
</div>

View File

@ -0,0 +1,126 @@
/*!
* @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/>.
*/
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { AppTestingModule } from '../../testing/app-testing.module';
import { AppExtensionService } from '../../extensions/extension.service';
import { UserMenuItemComponent } from './user-menu-item.component';
import {
TranslateModule,
TranslateLoader,
TranslateFakeLoader
} from '@ngx-translate/core';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ContentActionRef } from '@alfresco/adf-extensions';
describe('UserMenuItemComponent', () => {
let fixture: ComponentFixture<UserMenuItemComponent>;
let component: UserMenuItemComponent;
let appExtensionService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
AppTestingModule,
TranslateModule.forRoot({
loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
})
],
declarations: [UserMenuItemComponent],
providers: [AppExtensionService],
schemas: [NO_ERRORS_SCHEMA]
});
fixture = TestBed.createComponent(UserMenuItemComponent);
appExtensionService = TestBed.get(AppExtensionService);
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
});
it('should render button action', () => {
component.actionRef = {
id: 'action-button',
title: 'Test Button',
actions: {
click: 'TEST_EVENT'
}
} as ContentActionRef;
fixture.detectChanges();
const buttonElement = fixture.nativeElement.querySelector('#action-button');
expect(buttonElement).not.toBe(null);
});
it('should render menu action', () => {
component.actionRef = {
type: 'menu',
id: 'action-menu',
title: 'Test Button',
actions: {
click: 'TEST_EVENT'
}
} as ContentActionRef;
fixture.detectChanges();
const menuElement = fixture.nativeElement.querySelector('#action-menu');
expect(menuElement).not.toBe(null);
});
it('should render custom action', () => {
component.actionRef = {
type: 'custom',
id: 'action-custom',
component: 'custom-component'
} as ContentActionRef;
fixture.detectChanges();
const componentElement = fixture.nativeElement.querySelector(
'#custom-component'
);
expect(componentElement).not.toBe(null);
});
it('should run defined action', () => {
spyOn(appExtensionService, 'runActionById');
component.actionRef = {
id: 'action-button',
title: 'Test Button',
actions: {
click: 'TEST_EVENT'
}
} as ContentActionRef;
fixture.detectChanges();
const buttonElement = fixture.nativeElement.querySelector('#action-button');
buttonElement.dispatchEvent(new MouseEvent('click'));
expect(appExtensionService.runActionById).toHaveBeenCalledWith(
'TEST_EVENT'
);
});
});

View File

@ -0,0 +1,58 @@
/*!
* @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/>.
*/
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { ContentActionRef } from '@alfresco/adf-extensions';
import { AppExtensionService } from '../../extensions/extension.service';
@Component({
selector: 'app-user-menu-item',
templateUrl: 'user-menu-item.component.html',
encapsulation: ViewEncapsulation.None,
host: { class: 'app-user-menu-item' }
})
export class UserMenuItemComponent {
@Input()
actionRef: ContentActionRef;
constructor(private extensions: AppExtensionService) {}
runAction() {
if (this.hasClickAction(this.actionRef)) {
this.extensions.runActionById(this.actionRef.actions.click);
}
}
private hasClickAction(actionRef: ContentActionRef): boolean {
if (actionRef && actionRef.actions && actionRef.actions.click) {
return true;
}
return false;
}
trackById(_: number, obj: { id: string }) {
return obj.id;
}
}

View File

@ -51,6 +51,8 @@ import {
} from '@alfresco/adf-content-services';
import { ToggleSharedComponent } from '../components/common/toggle-shared/toggle-shared.component';
import { ViewNodeComponent } from '../components/toolbar/view-node/view-node.component';
import { LanguagePickerComponent } from '../components/common/language-picker/language-picker.component';
import { LogoutComponent } from '../components/common/logout/logout.component';
export function setupExtensions(service: AppExtensionService): Function {
return () => service.load();
@ -101,7 +103,9 @@ export class CoreExtensionsModule {
'app.columns.trashcanName': TrashcanNameColumnComponent,
'app.columns.location': LocationLinkComponent,
'app.toolbar.toggleEditOffline': ToggleEditOfflineComponent,
'app.toolbar.viewNode': ViewNodeComponent
'app.toolbar.viewNode': ViewNodeComponent,
'app.languagePicker': LanguagePickerComponent,
'app.logout': LogoutComponent
});
extensions.setAuthGuards({
@ -166,7 +170,9 @@ export class CoreExtensionsModule {
'app.navigation.isSharedFileViewer': rules.isSharedFileViewer,
'repository.isQuickShareEnabled': rules.hasQuickShareEnabled,
'user.isAdmin': rules.isAdmin
'user.isAdmin': rules.isAdmin,
'app.canShowLanguagePicker': rules.canShowLanguagePicker,
'app.canShowLogout': rules.canShowLogout
});
}
}

View File

@ -39,18 +39,21 @@ import {
ExtensionConfig,
ComponentRegisterService
} from '@alfresco/adf-extensions';
import { AppConfigService } from '@alfresco/adf-core';
describe('AppExtensionService', () => {
let service: AppExtensionService;
let store: Store<AppStore>;
let extensions: ExtensionService;
let components: ComponentRegisterService;
let appConfigService: AppConfigService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule]
});
appConfigService = TestBed.get(AppConfigService);
store = TestBed.get(Store);
service = TestBed.get(AppExtensionService);
extensions = TestBed.get(ExtensionService);
@ -784,4 +787,114 @@ describe('AppExtensionService', () => {
expect(service.getSharedLinkViewerToolbarActions()).toEqual(<any>actions);
});
});
describe('withCredentials', () => {
it('should set `withCredentials` to true from app configuration', () => {
appConfigService.config = {
auth: { withCredentials: true }
};
applyConfig({
$id: 'test',
$name: 'test',
$version: '1.0.0',
$license: 'MIT',
$vendor: 'Good company',
$runtime: '1.5.0'
});
expect(service.withCredentials).toBe(true);
});
it('should set `withCredentials` to false from app configuration', () => {
appConfigService.config = {
auth: { withCredentials: false }
};
applyConfig({
$id: 'test',
$name: 'test',
$version: '1.0.0',
$license: 'MIT',
$vendor: 'Good company',
$runtime: '1.5.0'
});
expect(service.withCredentials).toBe(false);
});
it('should set `withCredentials` to false as default value if no app configuration', () => {
appConfigService.config = {};
applyConfig({
$id: 'test',
$name: 'test',
$version: '1.0.0',
$license: 'MIT',
$vendor: 'Good company',
$runtime: '1.5.0'
});
expect(service.withCredentials).toBe(false);
});
});
describe('userActions', () => {
it('should load user actions from the config', () => {
applyConfig({
$id: 'test',
$name: 'test',
$version: '1.0.0',
$license: 'MIT',
$vendor: 'Good company',
$runtime: '1.5.0',
features: {
userActions: [
{
id: 'aca:toolbar/separator-1',
order: 1,
type: ContentActionType.separator,
title: 'action1'
},
{
id: 'aca:toolbar/separator-2',
order: 2,
type: ContentActionType.separator,
title: 'action2'
}
]
}
});
expect(service.userActions.length).toBe(2);
});
it('should sort user actions by order', () => {
applyConfig({
$id: 'test',
$name: 'test',
$version: '1.0.0',
$license: 'MIT',
$vendor: 'Good company',
$runtime: '1.5.0',
features: {
userActions: [
{
id: 'aca:toolbar/separator-2',
order: 2,
type: ContentActionType.separator,
title: 'action2'
},
{
id: 'aca:toolbar/separator-1',
order: 1,
type: ContentActionType.separator,
title: 'action1'
}
]
}
});
expect(service.userActions.length).toBe(2);
expect(service.userActions[0].id).toBe('aca:toolbar/separator-1');
expect(service.userActions[1].id).toBe('aca:toolbar/separator-2');
});
});
});

View File

@ -28,7 +28,11 @@ import { Store } from '@ngrx/store';
import { Route } from '@angular/router';
import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer } from '@angular/platform-browser';
import { AppStore, getRuleContext } from '@alfresco/aca-shared/store';
import {
AppStore,
getRuleContext,
getLanguagePickerState
} from '@alfresco/aca-shared/store';
import { NodePermissionService } from '@alfresco/aca-shared';
import {
SelectionState,
@ -78,6 +82,7 @@ export class AppExtensionService implements RuleContext {
sidebar: Array<SidebarTabRef> = [];
contentMetadata: any;
viewerRules: ViewerRules = {};
userActions: Array<ContentActionRef> = [];
documentListPresets: {
files: Array<DocumentListPresetRef>;
@ -103,6 +108,8 @@ export class AppExtensionService implements RuleContext {
navigation: NavigationState;
profile: ProfileState;
repository: RepositoryInfo;
withCredentials: boolean;
languagePicker: boolean;
references$: Observable<ExtensionRef[]>;
@ -124,6 +131,10 @@ export class AppExtensionService implements RuleContext {
this.profile = result.profile;
this.repository = result.repository;
});
this.store.select(getLanguagePickerState).subscribe(result => {
this.languagePicker = result;
});
}
async load() {
@ -170,6 +181,10 @@ export class AppExtensionService implements RuleContext {
config,
'features.sidebar'
);
this.userActions = this.loader.getContentActions(
config,
'features.userActions'
);
this.contentMetadata = this.loadContentMetadata(config);
this.documentListPresets = {
@ -186,6 +201,11 @@ export class AppExtensionService implements RuleContext {
searchLibraries: this.getDocumentListPreset(config, 'search-libraries')
};
this.withCredentials = this.appConfig.get<boolean>(
'auth.withCredentials',
false
);
if (config.features && config.features.viewer) {
this.viewerRules = <ViewerRules>(config.features.viewer['rules'] || {});
}
@ -473,6 +493,12 @@ export class AppExtensionService implements RuleContext {
return this.getAllowedActions(this.contextMenuActions);
}
getUserActions(): Array<ContentActionRef> {
return this.userActions
.filter(action => this.filterVisible(action))
.sort(sortByOrder);
}
copyAction(action: ContentActionRef): ContentActionRef {
return {
...action,

View File

@ -22,6 +22,26 @@
],
"features": {
"userActions": [
{
"id": "app.languagePicker",
"order": 100,
"type": "custom",
"component": "app.languagePicker",
"rules": {
"visible": "app.canShowLanguagePicker"
}
},
{
"id": "app.logout",
"order": 200,
"type": "custom",
"component": "app.logout",
"rules": {
"visible": "app.canShowLogout"
}
}
],
"header": [
{
"id": "app.header.more",