-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Overview ready * Limit to top five only * BE adjustments * PR fix
- Loading branch information
1 parent
212c3f0
commit 5d2da16
Showing
4 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,39 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Store } from '@ngrx/store'; | ||
import { Observable, zip } from 'rxjs'; | ||
import { Dashboard } from 'src/app/models/dashboard.model'; | ||
import { DashboardService } from 'src/app/services/dashboard.service'; | ||
import { selectProfile } from 'src/app/state/profile/profile.selectors'; | ||
|
||
@Component({ | ||
selector: 'app-dashboard', | ||
templateUrl: './dashboard.component.html', | ||
}) | ||
export class DashboardComponent {} | ||
export class DashboardComponent implements OnInit { | ||
dashboardData$?: Observable<Dashboard>; | ||
myRank?: number; | ||
|
||
constructor( | ||
private readonly dashboardService: DashboardService, | ||
private readonly store: Store, | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.dashboardData$ = this.dashboardService.getDashboardData( | ||
this.store.select(selectProfile), | ||
); | ||
|
||
zip([this.dashboardData$, this.store.select(selectProfile)]).subscribe( | ||
([dashboardData, user]) => { | ||
if (!user) { | ||
this.myRank = undefined; | ||
} else { | ||
this.myRank = this.dashboardService.getRankOf( | ||
user.userPrincipalName, | ||
dashboardData.rankingList, | ||
); | ||
} | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export interface Dashboard { | ||
myCardsCount: number; | ||
myUniqueCardsCount: number; | ||
allCardsCount: number; | ||
duplicateCardsCount: number; | ||
rankingList: Ranking[]; | ||
} | ||
|
||
export interface Ranking { | ||
rank: number; | ||
cardsCount: number; | ||
displayName: string; | ||
userEmail: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Dashboard, Ranking } from '../models/dashboard.model'; | ||
import { environment } from 'src/environments/environment'; | ||
import { Profile } from '../models/profile.model'; | ||
import { Observable, of, switchMap, defaultIfEmpty } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class DashboardService { | ||
constructor(private readonly http: HttpClient) {} | ||
|
||
getDashboardData(user: Observable<Profile | null>): Observable<Dashboard> { | ||
return user.pipe( | ||
switchMap((user) => { | ||
// Return empty dashboard if no user is found | ||
if (user === null) { | ||
return of<Dashboard>({ | ||
myCardsCount: 0, | ||
myUniqueCardsCount: 0, | ||
allCardsCount: 0, | ||
duplicateCardsCount: 0, | ||
rankingList: [], | ||
}); | ||
} | ||
|
||
return this.http.get<Dashboard>(`${environment.backendUri}/overview`); | ||
}), | ||
); | ||
} | ||
|
||
getRankOf(userEmail: string, rankingList: Ranking[]): number { | ||
return ( | ||
rankingList.find((ranking) => ranking.userEmail === userEmail)?.rank ?? 0 | ||
); | ||
} | ||
} |