From bd6c95ac0cf72aa67f8daf6912050c0683e78609 Mon Sep 17 00:00:00 2001 From: Wolfgang Roese Date: Sun, 10 Dec 2023 19:16:16 +0100 Subject: [PATCH] restored role-check before hint to create mupro (#283) * restored role-check before hint to create mupro * Refactor dashboard initialization in dashboard.component.ts The dashboard initialization code has been refactored for better readability and maintainability. The RxJS operator 'switchMap' has been added to handle async code more efficiently within the 'checkIfUserHasMusicianProfile' method. Additionally, the method 'ngOnInit()' has been cleaned up by extracting its logic into separate, newly created methods. * Enhance documentation for DashboardComponent & related classes Significant updates were made to improve the clarity and detail of documentation within the DashboardComponent file. Notably, descriptions were added to CardLayout interface, ArpaWidgetConfigDirective, and WidgetStateService classes. In addition, annotation for the directive and its usage was provided, and a more comprehensive explanation was attached to the DashboardComponent. --- .../features/dashboard/dashboard.component.ts | 61 +++++++++++++++---- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/src/app/features/dashboard/dashboard.component.ts b/src/app/features/dashboard/dashboard.component.ts index 38d2e3e0..86a66604 100644 --- a/src/app/features/dashboard/dashboard.component.ts +++ b/src/app/features/dashboard/dashboard.component.ts @@ -13,7 +13,7 @@ import { ViewChildren, ViewContainerRef, } from '@angular/core'; -import { map } from 'rxjs/operators'; +import { filter, map, switchMap } from 'rxjs/operators'; import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; import { Observable, Subscription } from 'rxjs'; import { ActivatedRoute, Router } from '@angular/router'; @@ -24,6 +24,10 @@ import { LoadingService } from '@arpa/services'; import { dashboards, widgets } from './dashboard.config'; import { MeService } from '@arpa/services'; +/** + * Represents a card layout that defines the number of columns and the dimensions of various card types. + * @interface + */ interface CardLayout { columns: number; chart: { cols: number; rows: number }; @@ -33,6 +37,18 @@ interface CardLayout { /** * Template directive which holds a widget configuration. + * + * @directive + * @usageNotes + * This directive can be applied to a HTML element using the selector '[arpaWidgetConfig]'. + * + * @input arpaWidgetConfig - The widget configuration. + * @input collection - The collection name. + * + * @constructor + * Creates an instance of ArpaWidgetConfigDirective. + * + * @param viewRef - The reference to the ViewContainerRef. */ @Directive({ selector: '[arpaWidgetConfig]', @@ -48,7 +64,8 @@ export class ArpaWidgetConfigDirective { } /** - * An instance gets injected into each widget and is available to the projected component. + * Widget State Service provides functionality for managing the state of a widget. + * This service is injected into each widget and is available to the projected component. */ export class WidgetStateService { public loading: Observable; @@ -63,6 +80,12 @@ export class WidgetStateService { } } +/** + * Represents the DashboardComponent class. + * This component displays the dashboard for a specific role. + * It contains menu items, widget layout, and functionality to create and render widgets. + * @Component + */ @Component({ selector: 'arpa-dashboard', templateUrl: './dashboard.component.html', @@ -109,23 +132,39 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy { ) {} ngOnInit() { + this.subscribeToDashboardRole(); + this.createMenuItems(); + this.checkIfUserHasMusicianProfile(); + } + + subscribeToDashboardRole() { this.routeRoleSubscription = this.route.data.subscribe((data) => { this.dashboardRole = data.dashboardRole.toLowerCase(); }); + } + createMenuItems() { this.menuItems = this.authService.currentUser.pipe( map((token) => token!.roles), - map((roles) => roles.map((role) => ({ routerLink: [`/arpa/dashboard/${role}`], label: role.toUpperCase() }))) + map((roles: string[]) => roles.map((role) => ({ routerLink: [`/arpa/dashboard/${role}`], label: role.toUpperCase() }))) ); + } - this.hasMusicianProfile$ = this.meService.getProfilesMusician().pipe( - map((profile) => { - if (Array.isArray(profile)) { - return profile.length === 0; - } else { - return !profile || profile.id == null; - } - }) + checkIfUserHasMusicianProfile() { + this.hasMusicianProfile$ = this.authService.currentUser.pipe( + map((token) => token!.roles), + filter((roles: string[]) => roles.includes('Performer')), + switchMap(() => + this.meService.getProfilesMusician().pipe( + map((profile) => { + if (Array.isArray(profile)) { + return profile.length === 0; + } else { + return !profile || profile.id == null; + } + }) + ) + ) ); }