Skip to content

Commit 048cb1d

Browse files
added function
1 parent 5c0547c commit 048cb1d

File tree

9 files changed

+40
-18
lines changed

9 files changed

+40
-18
lines changed

Phonebook.Frontend/src/app/app-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NgModule } from '@angular/core';
22
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
3-
import { DashboardComponent } from 'src/app/pages/dashboard/components/overview/dashboard.component';
3+
import { DashboardComponent } from 'src/app/pages/dashboard/components/dashboard/dashboard.component';
44
import { SettingsComponent } from 'src/app/pages/settings/settings.component';
55
import { environment } from 'src/environments/environment';
66
import { TeamComponent } from './pages/dashboard/components/team/team.component';

Phonebook.Frontend/src/app/modules/organigram/pages/organigram/organigram.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class OrganigramComponent implements OnInit {
1313
constructor(private organigramService: OrganigramService) {}
1414

1515
public ngOnInit() {
16-
this.organigramService.getOrganigram().subscribe((organigram) => {
16+
this.organigramService.getOrganigramTree().subscribe((organigram) => {
1717
this.nodes = organigram;
1818
});
1919
}

Phonebook.Frontend/src/app/pages/dashboard/components/overview/dashboard.component.html renamed to Phonebook.Frontend/src/app/pages/dashboard/components/dashboard/dashboard.component.html

File renamed without changes.

Phonebook.Frontend/src/app/pages/dashboard/components/overview/dashboard.component.scss renamed to Phonebook.Frontend/src/app/pages/dashboard/components/dashboard/dashboard.component.scss

File renamed without changes.

Phonebook.Frontend/src/app/pages/dashboard/components/overview/dashboard.component.ts renamed to Phonebook.Frontend/src/app/pages/dashboard/components/dashboard/dashboard.component.ts

File renamed without changes.

Phonebook.Frontend/src/app/pages/dashboard/components/team/team.component.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { Select, Store } from '@ngxs/store';
3-
import { Observable, Subscription } from 'rxjs';
4-
import { map } from 'rxjs/operators';
5-
import { Person, PhonebookSortDirection } from 'src/app/shared/models';
6-
import { BookmarksState, AppState } from 'src/app/shared/states';
7-
import { OrganigramService, UnitTreeNode } from 'src/app/services/api/organigram.service';
3+
import { Observable } from 'rxjs';
4+
import { Person } from 'src/app/shared/models';
5+
import { AppState } from 'src/app/shared/states';
6+
import { OrganigramService } from 'src/app/services/api/organigram.service';
87
import { CurrentUserService } from 'src/app/services/api/current-user.service';
9-
import { untilComponentDestroyed } from 'ng2-rx-componentdestroyed';
108
import { Router } from '@angular/router';
119
import { Layout } from 'src/app/shared/models/enumerables/Layout';
1210

@@ -26,14 +24,12 @@ export class TeamComponent implements OnInit, OnDestroy {
2624
public layout: typeof Layout = Layout;
2725

2826
constructor(
29-
private store: Store,
30-
private organigramService: OrganigramService,
31-
private currentUserService: CurrentUserService,
32-
private router: Router
27+
private organigramService: OrganigramService
3328
) {}
3429

3530
public ngOnInit() {
36-
this.organigramService.getNodeForCurrentUser().subscribe((node) => {
31+
if (this.currentUser != null) {
32+
this.organigramService.getOrganigramById(this.currentUser.Id).subscribe((node) => {
3733
if (node != null) {
3834
this.teamPersons = [
3935
...node.supervisors,
@@ -44,6 +40,7 @@ export class TeamComponent implements OnInit, OnDestroy {
4440
}
4541
});
4642
}
43+
}
4744

4845
public ngOnDestroy(): void {}
4946
}

Phonebook.Frontend/src/app/pages/dashboard/dashboard-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NgModule } from '@angular/core';
22
import { RouterModule, Routes } from '@angular/router';
3-
import { DashboardComponent } from 'src/app/pages/dashboard/components/overview/dashboard.component';
3+
import { DashboardComponent } from 'src/app/pages/dashboard/components/dashboard/dashboard.component';
44
import { BookmarkedComponent } from 'src/app/pages/dashboard/components/bookmarked/bookmarked.component';
55
import { TeamComponent } from 'src/app/pages/dashboard/components/team/team.component';
66
import { HasBookmarksGuard } from 'src/app/pages/dashboard/has-bookmarks.guard';

Phonebook.Frontend/src/app/pages/dashboard/dashboard.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DragDropModule } from '@angular/cdk/drag-drop';
22
import { NgModule } from '@angular/core';
3-
import { DashboardComponent } from 'src/app/pages/dashboard/components/overview/dashboard.component';
3+
import { DashboardComponent } from 'src/app/pages/dashboard/components/dashboard/dashboard.component';
44
import { UserModule } from 'src/app/shared/components/user/user.module';
55
import { MaterialModule } from 'src/app/shared/material.module';
66
import { BookmarkedComponent } from 'src/app/pages/dashboard/components/bookmarked/bookmarked.component';

Phonebook.Frontend/src/app/services/api/organigram.service.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,44 @@ export class OrganigramService {
1414
private currentUserService: CurrentUserService
1515
) {}
1616
public organigram: Observable<UnitTreeNode[]>;
17+
public orgUnits: Observable<OrgUnit[]>;
1718
public team: UnitTreeNode;
1819

19-
public getOrganigram(): Observable<UnitTreeNode[]> {
20+
public getOrgUnits(): Observable<OrgUnit[]> {
21+
if (this.orgUnits != null) {
22+
return this.orgUnits;
23+
}
24+
this.orgUnits = this.http.get<OrgUnit[]>('/api/OrgUnit').pipe(
25+
publishReplay(1), // this tells Rx to cache the latest emitted
26+
refCount()
27+
);
28+
return this.orgUnits;
29+
}
30+
31+
public getOrganigramTree(): Observable<UnitTreeNode[]> {
2032
if (this.organigram != null) {
2133
return this.organigram;
2234
}
23-
this.organigram = this.http.get<OrgUnit[]>('/api/OrgUnit').pipe(
35+
this.organigram = this.getOrgUnits().pipe(
2436
flatMap((d) => this.ConvertOrgUnitsToUnitTree(d)),
2537
publishReplay(1), // this tells Rx to cache the latest emitted
2638
refCount()
2739
);
2840
return this.organigram;
2941
}
42+
public getOrganigramById(id: string): Observable<UnitTreeNode | null> {
43+
return this.getOrganigramTree().pipe(
44+
map((orgUnitArray) => {
45+
const orgUnit = orgUnitArray.find((x) => {
46+
return x.id === id;
47+
});
48+
if (orgUnit === undefined) {
49+
return null;
50+
}
51+
return orgUnit;
52+
})
53+
);
54+
}
3055
private ConvertOrgUnitsToUnitTree(
3156
orgUnits: OrgUnit[],
3257
depth: number = 0
@@ -67,7 +92,7 @@ export class OrganigramService {
6792
}
6893

6994
public getNodeForCurrentUser(): Observable<UnitTreeNode | null> {
70-
return combineLatest([this.currentUserService.getCurrentUser(), this.getOrganigram()]).pipe(
95+
return combineLatest([this.currentUserService.getCurrentUser(), this.getOrganigramTree()]).pipe(
7196
map(([user, organigram]) => {
7297
if (user === null) {
7398
return null;

0 commit comments

Comments
 (0)