Skip to content

Commit

Permalink
chore: TRACEFOSS-604 added dashboard state
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-mwesener committed Nov 24, 2023
1 parent 7a4abe5 commit fa1decf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class DashboardFacade {
private readonly alertsService: AlertsService
) {}

public get dashboardStats$(): Observable<View<DashboardStats>> {
return this.dashboardState.dashboardStats$;
}
public get numberOfTotalMyParts$(): Observable<View<number>> {
return this.dashboardState.numberOfTotalMyParts$;
}
Expand Down Expand Up @@ -129,7 +132,7 @@ export class DashboardFacade {
this.dashboardState.setNumberOfOwnOpenAlertsReceived({data: dashboardStats.ownOpenAlertsReceived})
this.dashboardState.setNumberOfOwnOpenInvestigationsCreated({data: dashboardStats.ownOpenInvestigationsCreated})
this.dashboardState.setNumberOfOwnOpenAlertsCreated({data: dashboardStats.ownOpenAlertsCreated})

this.dashboardState.setDashboardStats({data: dashboardStats})

},
error: error => {
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/app/modules/page/dashboard/core/dashboard.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {Notifications} from '@shared/model/notification.model';
import {State} from '@shared/model/state';
import {Observable} from 'rxjs';
import {View} from 'src/app/modules/shared/model/view.model';
import {DashboardStats} from "@page/dashboard/model/dashboard.model";

@Injectable()
export class DashboardState {
Expand Down Expand Up @@ -52,9 +53,7 @@ export class DashboardState {
private readonly _numberOfOwnOpenInvestigationsCreated$: State<View<number>> = new State<View<number>>({ loader: true });
private readonly _numberOfOwnOpenAlertsReceived$: State<View<number>> = new State<View<number>>({ loader: true });
private readonly _numberOfOwnOpenAlertsCreated$: State<View<number>> = new State<View<number>>({ loader: true });



private readonly _dashboardStats$: State<View<DashboardStats>> = new State<View<DashboardStats>>({ loader: true });

// recent notifications
private readonly _recentReceivedInvestigations$: State<View<Notifications>> = new State<View<Notifications>>({ loader: true });
Expand Down Expand Up @@ -205,12 +204,17 @@ export class DashboardState {
this._numberOfOwnOpenAlertsCreated$.update(count);
}

public setDashboardStats(dashboardStatus: View<DashboardStats>): void {
this._dashboardStats$.update(dashboardStatus);
}

public get dashboardStats$(): Observable<View<DashboardStats>> {
return this._dashboardStats$.observable;
}

/**
* recent notifications getter/setter
*/


public get recentReceivedInvestigations$(): Observable<View<Notifications>> {
return this._recentReceivedInvestigations$.observable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<section class="metrics-section">
<ng-container
*viewContainer="
this.numberOfTotalMyParts$ | async;
this.dashboardStats$ | async;
main: numbersMainTmp;
error: numbersErrorTmp;
loading: numbersLoaderTmp;
Expand All @@ -36,7 +36,7 @@
<section class="metrics-section">
<ng-container
*viewContainer="
this.numberOfTotalOtherParts$ | async;
this.dashboardStats$ | async;
main: numbersMainTmp;
error: numbersErrorTmp;
loading: numbersLoaderTmp;
Expand All @@ -49,7 +49,7 @@
<section class="metrics-section">
<ng-container
*viewContainer="
this.numberOfOwnInvestigationsReceived$ | async;
this.dashboardStats$ | async;
main: numbersMainTmp;
error: numbersErrorTmp;
loading: numbersLoaderTmp;
Expand All @@ -62,7 +62,7 @@
<section class="metrics-section">
<ng-container
*viewContainer="
this.numberOfOwnAlertsReceived$ | async;
this.dashboardStats$ | async;
main: numbersMainTmp;
error: numbersErrorTmp;
loading: numbersLoaderTmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { View } from '@shared/model/view.model';
import { CloseNotificationModalComponent } from '@shared/modules/notification/modal/close/close-notification-modal.component';
import { Observable } from 'rxjs';
import { DashboardFacade } from '../abstraction/dashboard.facade';
import {DashboardStats, DashboardStatsResponse} from "@page/dashboard/model/dashboard.model";

@Component({
selector: 'app-dashboard',
Expand All @@ -51,6 +52,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
public readonly numberOfOwnAlertsReceived$: Observable<View<number>>;
public readonly numberOfOwnAlertsCreated$: Observable<View<number>>;

public readonly dashboardStats$: Observable<View<DashboardStats>>
public readonly investigationsReceived$: Observable<View<Notifications>>;
public readonly investigationsCreated$: Observable<View<Notifications>>;
public readonly alertsReceived$: Observable<View<Notifications>>;
Expand All @@ -71,6 +73,7 @@ export class DashboardComponent implements OnInit, OnDestroy {


constructor(private readonly dashboardFacade: DashboardFacade, private readonly router: Router) {
this.dashboardStats$ = this.dashboardFacade.dashboardStats$;
this.numberOfTotalMyParts$ = this.dashboardFacade.numberOfTotalMyParts$;
this.numberOfTotalOtherParts$ = this.dashboardFacade.numberOfTotalOtherParts$;

Expand All @@ -82,6 +85,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
this.numberOfOwnAlertsCreated$ = this.dashboardFacade.numberOfOwnOpenAlertsCreated$;



this.investigationsReceived$ = this.dashboardFacade.recentReceivedInvestigations$;
this.investigationsCreated$ = this.dashboardFacade.recentCreatedInvestigations$;
this.alertsReceived$ = this.dashboardFacade.recentReceivedAlerts$
Expand All @@ -94,6 +98,12 @@ export class DashboardComponent implements OnInit, OnDestroy {
this.alertLink = alertLink;
this.alertParams = alertQueryParams;

// TODO make sure you load data from dashboard state
this.dashboardStats$.subscribe(value => {
value.data.totalOwnParts;
})
// todo replace attribute with the one from dashboardstate

this.partsMetricData = [
{
metricName: 'totalAmount',
Expand All @@ -102,6 +112,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
}

]
// todo replace attribute with the one from dashboardstate

this.otherPartsMetricData = [
{
Expand All @@ -110,7 +121,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
metricUnit: 'parts'
}
];

// todo replace attribute with the one from dashboardstate
this.investigationsMetricData = [
{
metricName: 'amountReceived',
Expand Down

0 comments on commit fa1decf

Please sign in to comment.