Skip to content

Commit a97fb2b

Browse files
committed
use the new database in the organigramm
1 parent 79869c6 commit a97fb2b

File tree

13 files changed

+207
-81
lines changed

13 files changed

+207
-81
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const routes: Routes = [
99
{ path: ':first/:second/:third', component: OrganigramComponent },
1010
{ path: ':first/:second/:third/:fourth', component: OrganigramComponent },
1111
{ path: ':first/:second/:third/:fourth/:fifth', component: OrganigramComponent },
12+
{ path: ':first/:second/:third/:fourth/:fifth/:sixth', component: OrganigramComponent },
1213
];
1314

1415
@NgModule({
Lines changed: 77 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,62 @@
11
import { Injectable } from '@angular/core';
2-
import { Observable } from 'rxjs';
3-
import { map } from 'rxjs/operators';
2+
import { Observable, forkJoin, of } from 'rxjs';
3+
import { map, flatMap, publishReplay, refCount } from 'rxjs/operators';
44
import { Person } from 'src/app/shared/models';
55
import { PersonService } from './person.service';
6+
import { HttpClient } from '@angular/common/http';
67

78
@Injectable()
89
export class OrganigramService {
9-
constructor(private personService: PersonService) {}
10-
10+
constructor(private http: HttpClient, private personService: PersonService) {}
11+
public organigram: Observable<UnitTreeNode[]>;
1112
public getOrganigram(): Observable<UnitTreeNode[]> {
12-
return this.personService.getAll().pipe(
13-
map((users) => {
14-
const tree: UnitTreeNode[] = [];
15-
users.forEach((person) => {
16-
if (person.Business.ShortOrgUnit.length === 0) {
17-
return;
18-
}
19-
this.findNodeForPerson(person, tree, 0);
20-
});
21-
return tree;
22-
})
23-
);
24-
}
25-
26-
/**
27-
* Finds the Person's Node in the Hierarchical Structure of Units (generates the Units along its way.)
28-
* @param person The person for whom you like to find the node
29-
* @param nodeChilds The Childs of the node your are currently searching in.
30-
* @param depth The depth of the Tree (to map the Persons Array of Units to the Tree structure)
31-
*/
32-
public findNodeForPerson(person: Person, nodeChilds: UnitTreeNode[], depth: number) {
33-
const firstnode = nodeChilds.find((node) => {
34-
return node.id === person.Business.ShortOrgUnit[depth];
35-
});
36-
if (firstnode === undefined) {
37-
const newNode = new UnitTreeNode(
38-
person.Business.ShortOrgUnit[depth],
39-
person.Business.OrgUnit[depth],
40-
depth
41-
);
42-
if (depth === person.Business.ShortOrgUnit.length - 1) {
43-
this.pushToSpecificGroup(newNode, person);
44-
} else if (person.Business.ShortOrgUnit.length - 1 > depth) {
45-
this.findNodeForPerson(person, newNode.children, depth + 1);
46-
}
47-
nodeChilds.push(newNode);
48-
} else {
49-
if (depth === person.Business.ShortOrgUnit.length - 1) {
50-
this.pushToSpecificGroup(firstnode, person);
51-
return;
52-
} else {
53-
this.findNodeForPerson(person, firstnode.children, depth + 1);
54-
}
13+
if (this.organigram != null) {
14+
return this.organigram;
5515
}
16+
this.organigram = this.http.get<OrgUnit[]>('/api/OrgUnit').pipe(
17+
flatMap((d) => this.ConvertOrgUnitsToUnitTree(d)),
18+
publishReplay(1), // this tells Rx to cache the latest emitted
19+
refCount()
20+
);
21+
return this.organigram;
5622
}
57-
58-
public pushToSpecificGroup(node: UnitTreeNode, person: Person) {
59-
if (person.isLearner()) {
60-
node.learners.push(person);
61-
} else if (person.isSupervisor()) {
62-
node.supervisors.push(person);
63-
} else if (person.isAssistent()) {
64-
node.assistents.push(person);
65-
} else {
66-
node.employees.push(person);
67-
}
23+
private ConvertOrgUnitsToUnitTree(
24+
orgUnits: OrgUnit[],
25+
depth: number = 0
26+
): Observable<UnitTreeNode[]> {
27+
return forkJoin(
28+
orgUnits.map((o) => {
29+
var TaShortNames = o.OrgUnitToFunctions.filter((f) => f.RoleName == 'TA').map(
30+
(t) => t.Person.ShortName
31+
);
32+
return forkJoin(
33+
o.ChildOrgUnits == null || o.ChildOrgUnits.length == 0
34+
? of([])
35+
: this.ConvertOrgUnitsToUnitTree(o.ChildOrgUnits, depth + 1),
36+
o.HeadOfOrgUnit == null
37+
? of(null)
38+
: this.personService.getById(o.HeadOfOrgUnit.ShortName),
39+
TaShortNames.length == 0
40+
? of([])
41+
: forkJoin(TaShortNames.map((shortName) => this.personService.getById(shortName))),
42+
o.ShortName == null ? of([]) : this.personService.getByOrgUnit(o.ShortName)
43+
).pipe(
44+
map(([childs, headofOrgUnit, assistents, members]) => {
45+
var tree = new UnitTreeNode(
46+
o.ShortName == null ? '' : o.ShortName,
47+
o.Name == null ? '' : o.Name,
48+
depth,
49+
o.ChildOrgUnits == null ? [] : childs,
50+
headofOrgUnit == null ? [] : [headofOrgUnit],
51+
assistents.filter((a) => a != null) as Person[],
52+
members.filter((p) => p.isLearner() == false),
53+
members.filter((p) => p.isLearner())
54+
);
55+
return tree;
56+
})
57+
);
58+
})
59+
);
6860
}
6961
}
7062

@@ -97,3 +89,30 @@ export class UnitTreeNode {
9789
this.learners = learners;
9890
}
9991
}
92+
93+
export class OrgUnit {
94+
public Id: number;
95+
96+
public Name?: string;
97+
98+
public ShortName?: string;
99+
100+
public ParentId?: number;
101+
public Parent?: OrgUnit;
102+
public ChildOrgUnits?: OrgUnit[];
103+
104+
public HeadOfOrgUnitId?: number;
105+
106+
public HeadOfOrgUnit?: {
107+
ShortName: string;
108+
};
109+
110+
public CostCenter?: string;
111+
public OrgUnitToFunctions: {
112+
PersonId?: number;
113+
Person: {
114+
ShortName: string;
115+
};
116+
RoleName: string;
117+
}[];
118+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class PersonService {
6565
item.Location.LinkRoutingInfo
6666
),
6767
new Business(
68+
item.Business.Id,
6869
item.Business.ShortBusinessunitTeamassistent,
6970
item.Business.ShortSupervisor,
7071
item.Business.ShortOrgUnit,
@@ -110,6 +111,17 @@ export class PersonService {
110111
);
111112
}
112113

114+
public getByOrgUnit(name: string): Observable<Person[]> {
115+
return this.getAll().pipe(
116+
map((personArray) => {
117+
return personArray.filter((p) => {
118+
var personOrgUnit = p.Business.ShortOrgUnit[p.Business.ShortOrgUnit.length - 1];
119+
return personOrgUnit == name;
120+
});
121+
})
122+
);
123+
}
124+
113125
public getPersonsByRoom(roomId: string): Observable<Person[]> {
114126
return this.getAll().pipe(
115127
map((personArray) => {

Phonebook.Frontend/src/app/shared/models/classes/Business.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* tslint:disable:variable-name */
22

33
export class Business {
4+
public Id: number;
45
public ShortBusinessunitTeamassistent: string[];
56
public ShortSupervisor: string[];
67
public ShortOrgUnit: string[];
@@ -10,6 +11,7 @@ export class Business {
1011
public Costcenter: string;
1112

1213
constructor(
14+
Id: number,
1315
shortBusinessunitTeamassistent: string[],
1416
shortSupervisor: string[],
1517
shortOrgUnit: string[],
@@ -18,6 +20,7 @@ export class Business {
1820
supervisor: string[],
1921
costcenter: string
2022
) {
23+
this.Id = Id;
2124
this.ShortBusinessunitTeamassistent = shortBusinessunitTeamassistent;
2225
this.ShortSupervisor = shortSupervisor;
2326
this.ShortOrgUnit = shortOrgUnit;

Phonebook.Frontend/src/app/shared/models/classes/Person.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class Person {
6969
false,
7070
new Contacts('', '', '', '', new Messenger('', 0)),
7171
new Location(new City('', ''), [new Room('', '', 0, '', '', '', '', '', '')]),
72-
new Business([], [], [], [], [], [], '')
72+
new Business(NaN, [], [], [], [], [], [], '')
7373
);
7474
}
7575
}

Phonebook.Source.PeopleSoft/src/Phonebook.Source.PeopleSoft.Models/Context/ModelContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
9696
.ToTable("V_ORGEINHEIT")
9797
.HasMany<Person>(o => o.Members)
9898
.WithOne(p => p.OrgUnit);
99+
modelBuilder
100+
.Entity<OrgUnit>()
101+
.ToTable("V_ORGEINHEIT")
102+
.HasMany<OrgUnit>(o => o.ChildOrgUnits)
103+
.WithOne(p => p.Parent);
99104
modelBuilder
100105
.Entity<OrgUnit>()
101106
.ToTable("V_ORGEINHEIT")

Phonebook.Source.PeopleSoft/src/Phonebook.Source.PeopleSoft.Models/Old/Business.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public Business(Models.OrgUnit orgUnit, bool forOwners = false)
1616
var currentOrgUnit = orgUnit;
1717
var orgUnitStructur = new List<OrgUnit>();
1818
orgUnitStructur.Add(orgUnit);
19-
while (currentOrgUnit.Parent != null)
19+
do
2020
{
2121
orgUnitStructur.Add(currentOrgUnit.Parent);
2222
currentOrgUnit = currentOrgUnit.Parent;
23-
}
23+
} while (currentOrgUnit.Parent != null);
2424
orgUnitStructur.Reverse();
2525
this.orgUnitStructur = orgUnitStructur;
2626
if (forOwners)
@@ -31,12 +31,13 @@ public Business(Models.OrgUnit orgUnit, bool forOwners = false)
3131
changeOwner.HeadOfOrgUnitId = newHeadOf?.Id;
3232
}
3333
}
34+
public int Id { get { return orgUnit.Id; } }
3435
public IEnumerable<string?>? ShortBusinessunitTeamassistent { get { return orgUnit?.OrgUnitToFunctions?.Where(d => d.RoleName == "TA")?.Select(d => d?.Person?.ShortName); } }
35-
public IEnumerable<string?>? ShortSupervisor { get { return new string?[] { orgUnitStructur?.Where(d => d?.Id != 110 && !string.IsNullOrWhiteSpace(d?.HeadOfOrgUnit?.ShortName)).Select(d => d?.HeadOfOrgUnit?.ShortName).LastOrDefault() }; } }
36-
public IEnumerable<string?>? ShortOrgUnit { get { return orgUnitStructur?.Where(d => d?.Id != 110 && string.IsNullOrWhiteSpace(d?.HeadOfOrgUnit?.ShortName) == false).Select(d => d?.ShortName); } }
37-
public IEnumerable<string?>? OrgUnit { get { return orgUnitStructur?.Where(d => d?.Id != 110 && d?.HeadOfOrgUnit != null).Select(d => d?.Name); } }
36+
public IEnumerable<string?>? ShortSupervisor { get { yield return orgUnitStructur?.Where(d => !string.IsNullOrWhiteSpace(d?.HeadOfOrgUnit?.ShortName)).Select(d => d?.HeadOfOrgUnit?.ShortName).LastOrDefault(); } }
37+
public IEnumerable<string?>? ShortOrgUnit { get { return orgUnitStructur?.Where(d => d?.HeadOfOrgUnit != null).Select(d => d?.ShortName); } }
38+
public IEnumerable<string?>? OrgUnit { get { return orgUnitStructur?.Where(d => d?.HeadOfOrgUnit != null).Select(d => d?.Name); } }
3839
public IEnumerable<string> BusinessunitTeamassistent { get { return orgUnit.OrgUnitToFunctions.Where(d => d.RoleName == "TA").Select(d => $"{d.Person.FirstName} {d.Person.LastName}"); } }
39-
public IEnumerable<string> Supervisor { get { return new string[] { orgUnitStructur.Where(d => d.Id != 110 && string.IsNullOrWhiteSpace(d?.HeadOfOrgUnit?.FirstName) == false && string.IsNullOrWhiteSpace(d?.HeadOfOrgUnit?.LastName) == false).Select(d => $"{d?.HeadOfOrgUnit?.FirstName} {d?.HeadOfOrgUnit?.LastName}").LastOrDefault() }; } }
40+
public IEnumerable<string> Supervisor { get { yield return orgUnitStructur.Where(d => string.IsNullOrWhiteSpace(d?.HeadOfOrgUnit?.FirstName) == false && string.IsNullOrWhiteSpace(d?.HeadOfOrgUnit?.LastName) == false).Select(d => $"{d?.HeadOfOrgUnit?.FirstName} {d?.HeadOfOrgUnit?.LastName}").LastOrDefault(); } }
4041
public string? Costcenter { get { return orgUnit?.CostCenter; } }
4142
}
4243
}

Phonebook.Source.PeopleSoft/src/Phonebook.Source.PeopleSoft.Models/OrgUnit.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class OrgUnit
1414
[Column(name:"VATER")]
1515
public int? ParentId { get; set; }
1616
public virtual OrgUnit? Parent { get; set; }
17+
public virtual IEnumerable<OrgUnit>? ChildOrgUnits { get; set; }
1718
[Column(name: "LEITER_ORG_EINHEIT")]
1819
public int? HeadOfOrgUnitId { get; set; }
1920

Phonebook.Source.PeopleSoft/src/Phonebook.Source.PeopleSoft.Models/OrgUnitToFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class OrgUnitToFunction
1414
public virtual Person Person { get; set; }
1515
[Column(name: "ORG_EINHEIT_ID")]
1616
public int? OrgUnitId { get; set; }
17-
public virtual OrgUnit OrgUnit { get; set; }
17+
public virtual OrgUnit? OrgUnit { get; set; }
1818
[Column(name: "FUNKTIONSROLLE_ID")]
1919
public int? FunctionId { get; set; }
2020
public virtual Function? Function { get; set; }

Phonebook.Source.PeopleSoft/src/Phonebook.Source.PeopleSoft/Controllers/OrgUnitController.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.EntityFrameworkCore;
66
using Phonebook.Source.PeopleSoft.Models;
77
using Phonebook.Source.PeopleSoft.Models.Context;
8+
using Phonebook.Source.PeopleSoft.Repositories;
89

910
namespace Phonebook.Source.PeopleSoft.Controllers
1011
{
@@ -13,34 +14,25 @@ namespace Phonebook.Source.PeopleSoft.Controllers
1314
[Authorize]
1415
public class OrgUnitController : ControllerBase
1516
{
16-
public ModelContext Context { get; }
17+
public IRepository<OrgUnit> Context { get; }
1718

18-
public OrgUnitController(ModelContext context)
19+
public OrgUnitController(IRepository<OrgUnit> context)
1920
{
2021
Context = context;
2122
}
2223
// GET: api/OrgUnit
2324
[HttpGet]
2425
public IEnumerable<OrgUnit> Get()
2526
{
26-
return this.inlcudeDependencies(Context.OrgUnits);
27+
return Context.Get();
2728

2829
}
2930

3031
// GET: api/OrgUnit/5
3132
[HttpGet("{id}")]
3233
public OrgUnit Get(int id)
3334
{
34-
return this.inlcudeDependencies(Context.OrgUnits).First(o => o.Id == id);
35-
}
36-
37-
private IQueryable<OrgUnit> inlcudeDependencies(IQueryable<OrgUnit> query)
38-
{
39-
return query
40-
.AsNoTracking()
41-
.Include(o => o.Members)
42-
.Include(o => o.Parent);
43-
44-
}
35+
return Context.Get(id);
36+
}
4537
}
4638
}

0 commit comments

Comments
 (0)