From caecae57ffa8b6194776f82b327e44e82d2da7fd Mon Sep 17 00:00:00 2001 From: Wolfgang Roese Date: Fri, 24 Nov 2023 12:53:24 +0100 Subject: [PATCH 1/3] restored role-check before hint to create mupro --- .../features/dashboard/dashboard.component.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/app/features/dashboard/dashboard.component.ts b/src/app/features/dashboard/dashboard.component.ts index 38d2e3e0..098efe25 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 } from 'rxjs/operators'; import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; import { Observable, Subscription } from 'rxjs'; import { ActivatedRoute, Router } from '@angular/router'; @@ -115,18 +115,24 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy { this.menuItems = this.authService.currentUser.pipe( map((token) => token!.roles), - map((roles) => 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; - } - }) + map((roles: string[]) => roles.map((role) => ({ routerLink: [`/arpa/dashboard/${role}`], label: role.toUpperCase() }))) ); + this.authService.currentUser + .pipe( + map((token) => token!.roles), + filter((roles: string[]) => roles.includes('Performer')) + ) + .subscribe(() => { + this.hasMusicianProfile$ = this.meService.getProfilesMusician().pipe( + map((profile) => { + if (Array.isArray(profile)) { + return profile.length === 0; + } else { + return !profile || profile.id == null; + } + }) + ); + }); } ngAfterViewInit() { From 49b46e2e411e5581f7bd2e63e8864d2766dbf66a Mon Sep 17 00:00:00 2001 From: wolfgangroese Date: Wed, 6 Dec 2023 21:04:55 +0100 Subject: [PATCH 2/3] 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. --- .../features/dashboard/dashboard.component.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/app/features/dashboard/dashboard.component.ts b/src/app/features/dashboard/dashboard.component.ts index 098efe25..15d67d59 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 { filter, 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'; @@ -109,21 +109,30 @@ 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: string[]) => roles.map((role) => ({ routerLink: [`/arpa/dashboard/${role}`], label: role.toUpperCase() }))) ); - this.authService.currentUser - .pipe( - map((token) => token!.roles), - filter((roles: string[]) => roles.includes('Performer')) - ) - .subscribe(() => { - this.hasMusicianProfile$ = this.meService.getProfilesMusician().pipe( + } + + 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; @@ -131,8 +140,9 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy { return !profile || profile.id == null; } }) - ); - }); + ) + ) + ); } ngAfterViewInit() { From 8c574975e9b8d5ebd639853ce4ea489aa3002c5e Mon Sep 17 00:00:00 2001 From: wolfgangroese Date: Wed, 6 Dec 2023 21:13:25 +0100 Subject: [PATCH 3/3] 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 | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/app/features/dashboard/dashboard.component.ts b/src/app/features/dashboard/dashboard.component.ts index 15d67d59..86a66604 100644 --- a/src/app/features/dashboard/dashboard.component.ts +++ b/src/app/features/dashboard/dashboard.component.ts @@ -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',