Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const routes: Routes = [
{ path: ':first/:second/:third', component: OrganigramComponent },
{ path: ':first/:second/:third/:fourth', component: OrganigramComponent },
{ path: ':first/:second/:third/:fourth/:fifth', component: OrganigramComponent },
{ path: ':first/:second/:third/:fourth/:fifth/:sixth', component: OrganigramComponent },
];

@NgModule({
Expand Down
26 changes: 13 additions & 13 deletions Phonebook.Frontend/src/app/modules/table/table-logic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Table Logic - Sort', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
new Person(
PersonStatus.Interner_Mitarbeiter,
Expand All @@ -36,7 +36,7 @@ describe('Table Logic - Sort', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
];
expect(
Expand All @@ -55,7 +55,7 @@ describe('Table Logic - Sort', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
new Person(
PersonStatus.Interner_Mitarbeiter,
Expand All @@ -67,7 +67,7 @@ describe('Table Logic - Sort', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
]);
});
Expand All @@ -83,7 +83,7 @@ describe('Table Logic - Sort', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
new Person(
PersonStatus.Interner_Mitarbeiter,
Expand All @@ -95,7 +95,7 @@ describe('Table Logic - Sort', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
];

Expand All @@ -115,7 +115,7 @@ describe('Table Logic - Sort', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
new Person(
PersonStatus.Interner_Mitarbeiter,
Expand All @@ -127,7 +127,7 @@ describe('Table Logic - Sort', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
]);
});
Expand All @@ -146,7 +146,7 @@ describe('Table Logic - Filter', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
];
expect(
Expand All @@ -162,7 +162,7 @@ describe('Table Logic - Filter', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
]);
});
Expand All @@ -179,7 +179,7 @@ describe('Table Logic - Filter', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
];
expect(
Expand All @@ -199,7 +199,7 @@ describe('Table Logic - Filter', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
];
expect(
Expand All @@ -219,7 +219,7 @@ describe('Table Logic - Filter', () => {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), []),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
),
]);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { inject, TestBed } from '@angular/core/testing';
import { OrganigramService } from './organigram.service';
import { PersonService } from './person.service';
import { HttpClient } from '@angular/common/http';

describe('OrganigramService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [OrganigramService, { provide: PersonService, useValue: null }],
providers: [
OrganigramService,
{ provide: PersonService, useValue: null },
{ provide: HttpClient, useValue: null },
],
});
});

Expand Down
135 changes: 77 additions & 58 deletions Phonebook.Frontend/src/app/services/api/organigram.service.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,62 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Observable, forkJoin, of } from 'rxjs';
import { map, flatMap, publishReplay, refCount } from 'rxjs/operators';
import { Person } from 'src/app/shared/models';
import { PersonService } from './person.service';
import { HttpClient } from '@angular/common/http';

@Injectable()
export class OrganigramService {
constructor(private personService: PersonService) {}

constructor(private http: HttpClient, private personService: PersonService) {}
public organigram: Observable<UnitTreeNode[]>;
public getOrganigram(): Observable<UnitTreeNode[]> {
return this.personService.getAll().pipe(
map((users) => {
const tree: UnitTreeNode[] = [];
users.forEach((person) => {
if (person.Business.ShortOrgUnit.length === 0) {
return;
}
this.findNodeForPerson(person, tree, 0);
});
return tree;
})
);
}

/**
* Finds the Person's Node in the Hierarchical Structure of Units (generates the Units along its way.)
* @param person The person for whom you like to find the node
* @param nodeChilds The Childs of the node your are currently searching in.
* @param depth The depth of the Tree (to map the Persons Array of Units to the Tree structure)
*/
public findNodeForPerson(person: Person, nodeChilds: UnitTreeNode[], depth: number) {
const firstnode = nodeChilds.find((node) => {
return node.id === person.Business.ShortOrgUnit[depth];
});
if (firstnode === undefined) {
const newNode = new UnitTreeNode(
person.Business.ShortOrgUnit[depth],
person.Business.OrgUnit[depth],
depth
);
if (depth === person.Business.ShortOrgUnit.length - 1) {
this.pushToSpecificGroup(newNode, person);
} else if (person.Business.ShortOrgUnit.length - 1 > depth) {
this.findNodeForPerson(person, newNode.children, depth + 1);
}
nodeChilds.push(newNode);
} else {
if (depth === person.Business.ShortOrgUnit.length - 1) {
this.pushToSpecificGroup(firstnode, person);
return;
} else {
this.findNodeForPerson(person, firstnode.children, depth + 1);
}
if (this.organigram != null) {
return this.organigram;
}
this.organigram = this.http.get<OrgUnit[]>('/api/OrgUnit').pipe(
flatMap((d) => this.ConvertOrgUnitsToUnitTree(d)),
publishReplay(1), // this tells Rx to cache the latest emitted
refCount()
);
return this.organigram;
}

public pushToSpecificGroup(node: UnitTreeNode, person: Person) {
if (person.isLearner()) {
node.learners.push(person);
} else if (person.isSupervisor()) {
node.supervisors.push(person);
} else if (person.isAssistent()) {
node.assistents.push(person);
} else {
node.employees.push(person);
}
private ConvertOrgUnitsToUnitTree(
orgUnits: OrgUnit[],
depth: number = 0
): Observable<UnitTreeNode[]> {
return forkJoin(
orgUnits.map((o) => {
var TaShortNames = o.OrgUnitToFunctions.filter((f) => f.RoleName == 'TA').map(
(t) => t.Person.ShortName
);
return forkJoin(
o.ChildOrgUnits == null || o.ChildOrgUnits.length == 0
? of([])
: this.ConvertOrgUnitsToUnitTree(o.ChildOrgUnits, depth + 1),
o.HeadOfOrgUnit == null
? of(null)
: this.personService.getById(o.HeadOfOrgUnit.ShortName),
TaShortNames.length == 0
? of([])
: forkJoin(TaShortNames.map((shortName) => this.personService.getById(shortName))),
o.ShortName == null ? of([]) : this.personService.getByOrgUnit(o.ShortName)
).pipe(
map(([childs, headofOrgUnit, assistents, members]) => {
var tree = new UnitTreeNode(
o.ShortName == null ? '' : o.ShortName,
o.Name == null ? '' : o.Name,
depth,
o.ChildOrgUnits == null ? [] : childs,
headofOrgUnit == null ? [] : [headofOrgUnit],
assistents.filter((a) => a != null) as Person[],
members.filter((p) => p.isLearner() == false),
members.filter((p) => p.isLearner())
);
return tree;
})
);
})
);
}
}

Expand Down Expand Up @@ -97,3 +89,30 @@ export class UnitTreeNode {
this.learners = learners;
}
}

class OrgUnit {
public Id: number;

public Name?: string;

public ShortName?: string;

public ParentId?: number;
public Parent?: OrgUnit;
public ChildOrgUnits?: OrgUnit[];

public HeadOfOrgUnitId?: number;

public HeadOfOrgUnit?: {
ShortName: string;
};

public CostCenter?: string;
public OrgUnitToFunctions: {
PersonId?: number;
Person: {
ShortName: string;
};
RoleName: string;
}[];
}
12 changes: 12 additions & 0 deletions Phonebook.Frontend/src/app/services/api/person.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class PersonService {
item.Location.LinkRoutingInfo
),
new Business(
item.Business.Id,
item.Business.ShortBusinessunitTeamassistent,
item.Business.ShortSupervisor,
item.Business.ShortOrgUnit,
Expand Down Expand Up @@ -110,6 +111,17 @@ export class PersonService {
);
}

public getByOrgUnit(name: string): Observable<Person[]> {
return this.getAll().pipe(
map((personArray) => {
return personArray.filter((p) => {
var personOrgUnit = p.Business.ShortOrgUnit[p.Business.ShortOrgUnit.length - 1];
return personOrgUnit == name;
});
})
);
}

public getPersonsByRoom(roomId: string): Observable<Person[]> {
return this.getAll().pipe(
map((personArray) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const personA = new Person(
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', '', ''), [new Room('', '', 0, '', '', '', '', '', '')]),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
);

const personB = new Person(
Expand All @@ -35,7 +35,7 @@ const personB = new Person(
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', '', ''), [new Room('', '', 0, '', '', '', '', '', '')]),
new Business([], [], [], [], [], [], '')
new Business(null, [], [], [], [], [], [], '')
);

describe('Column Filter Functions: ', () => {
Expand Down
1 change: 1 addition & 0 deletions Phonebook.Frontend/src/app/shared/mocks/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const mockPerson: Person = new Person(
],
},
{
Id: null,
ShortBusinessunitTeamassistent: ['ABC'],
ShortSupervisor: ['ABC'],
ShortOrgUnit: ['AB_1', 'AD CD', 'AB CD'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* tslint:disable:variable-name */

export class Business {
public Id: number;
public ShortBusinessunitTeamassistent: string[];
public ShortSupervisor: string[];
public ShortOrgUnit: string[];
Expand All @@ -10,6 +11,7 @@ export class Business {
public Costcenter: string;

constructor(
Id: number,
shortBusinessunitTeamassistent: string[],
shortSupervisor: string[],
shortOrgUnit: string[],
Expand All @@ -18,6 +20,7 @@ export class Business {
supervisor: string[],
costcenter: string
) {
this.Id = Id;
this.ShortBusinessunitTeamassistent = shortBusinessunitTeamassistent;
this.ShortSupervisor = shortSupervisor;
this.ShortOrgUnit = shortOrgUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Person {
false,
new Contacts('', '', '', '', new Messenger('', 0)),
new Location(new City('', ''), [new Room('', '', 0, '', '', '', '', '', '')]),
new Business([], [], [], [], [], [], '')
new Business(NaN, [], [], [], [], [], [], '')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.ToTable("V_ORGEINHEIT")
.HasMany<Person>(o => o.Members)
.WithOne(p => p.OrgUnit);
modelBuilder
.Entity<OrgUnit>()
.ToTable("V_ORGEINHEIT")
.HasMany<OrgUnit>(o => o.ChildOrgUnits)
.WithOne(p => p.Parent);
modelBuilder
.Entity<OrgUnit>()
.ToTable("V_ORGEINHEIT")
Expand Down
Loading