dynamically load user menu options

This commit is contained in:
pionnegru
2020-01-07 20:37:16 +02:00
parent 75b9b017dd
commit a8776241b6
3 changed files with 29 additions and 31 deletions

View File

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

View File

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

View File

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