Skip to content

Commit

Permalink
restored role-check before hint to create mupro (#283)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
wolfgangroese authored Dec 10, 2023
1 parent ce35679 commit bd6c95a
Showing 1 changed file with 50 additions and 11 deletions.
61 changes: 50 additions & 11 deletions src/app/features/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 };
Expand All @@ -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]',
Expand All @@ -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<boolean>;
Expand All @@ -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',
Expand Down Expand Up @@ -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;
}
})
)
)
);
}

Expand Down

0 comments on commit bd6c95a

Please sign in to comment.