Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
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;
}
}

export 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
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public Business(Models.OrgUnit orgUnit, bool forOwners = false)
var currentOrgUnit = orgUnit;
var orgUnitStructur = new List<OrgUnit>();
orgUnitStructur.Add(orgUnit);
while (currentOrgUnit.Parent != null)
do
{
orgUnitStructur.Add(currentOrgUnit.Parent);
currentOrgUnit = currentOrgUnit.Parent;
}
} while (currentOrgUnit.Parent != null);
orgUnitStructur.Reverse();
this.orgUnitStructur = orgUnitStructur;
if (forOwners)
Expand All @@ -31,12 +31,13 @@ public Business(Models.OrgUnit orgUnit, bool forOwners = false)
changeOwner.HeadOfOrgUnitId = newHeadOf?.Id;
}
}
public int Id { get { return orgUnit.Id; } }
public IEnumerable<string?>? ShortBusinessunitTeamassistent { get { return orgUnit?.OrgUnitToFunctions?.Where(d => d.RoleName == "TA")?.Select(d => d?.Person?.ShortName); } }
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() }; } }
public IEnumerable<string?>? ShortOrgUnit { get { return orgUnitStructur?.Where(d => d?.Id != 110 && string.IsNullOrWhiteSpace(d?.HeadOfOrgUnit?.ShortName) == false).Select(d => d?.ShortName); } }
public IEnumerable<string?>? OrgUnit { get { return orgUnitStructur?.Where(d => d?.Id != 110 && d?.HeadOfOrgUnit != null).Select(d => d?.Name); } }
public IEnumerable<string?>? ShortSupervisor { get { yield return orgUnitStructur?.Where(d => !string.IsNullOrWhiteSpace(d?.HeadOfOrgUnit?.ShortName)).Select(d => d?.HeadOfOrgUnit?.ShortName).LastOrDefault(); } }
public IEnumerable<string?>? ShortOrgUnit { get { return orgUnitStructur?.Where(d => d?.HeadOfOrgUnit != null).Select(d => d?.ShortName); } }
public IEnumerable<string?>? OrgUnit { get { return orgUnitStructur?.Where(d => d?.HeadOfOrgUnit != null).Select(d => d?.Name); } }
public IEnumerable<string> BusinessunitTeamassistent { get { return orgUnit.OrgUnitToFunctions.Where(d => d.RoleName == "TA").Select(d => $"{d.Person.FirstName} {d.Person.LastName}"); } }
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() }; } }
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(); } }
public string? Costcenter { get { return orgUnit?.CostCenter; } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class OrgUnit
[Column(name:"VATER")]
public int? ParentId { get; set; }
public virtual OrgUnit? Parent { get; set; }
public virtual IEnumerable<OrgUnit>? ChildOrgUnits { get; set; }
[Column(name: "LEITER_ORG_EINHEIT")]
public int? HeadOfOrgUnitId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class OrgUnitToFunction
public virtual Person Person { get; set; }
[Column(name: "ORG_EINHEIT_ID")]
public int? OrgUnitId { get; set; }
public virtual OrgUnit OrgUnit { get; set; }
public virtual OrgUnit? OrgUnit { get; set; }
[Column(name: "FUNKTIONSROLLE_ID")]
public int? FunctionId { get; set; }
public virtual Function? Function { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.EntityFrameworkCore;
using Phonebook.Source.PeopleSoft.Models;
using Phonebook.Source.PeopleSoft.Models.Context;
using Phonebook.Source.PeopleSoft.Repositories;

namespace Phonebook.Source.PeopleSoft.Controllers
{
Expand All @@ -13,34 +14,25 @@ namespace Phonebook.Source.PeopleSoft.Controllers
[Authorize]
public class OrgUnitController : ControllerBase
{
public ModelContext Context { get; }
public IRepository<OrgUnit> Context { get; }

public OrgUnitController(ModelContext context)
public OrgUnitController(IRepository<OrgUnit> context)
{
Context = context;
}
// GET: api/OrgUnit
[HttpGet]
public IEnumerable<OrgUnit> Get()
{
return this.inlcudeDependencies(Context.OrgUnits);
return Context.Get();

}

// GET: api/OrgUnit/5
[HttpGet("{id}")]
public OrgUnit Get(int id)
{
return this.inlcudeDependencies(Context.OrgUnits).First(o => o.Id == id);
}

private IQueryable<OrgUnit> inlcudeDependencies(IQueryable<OrgUnit> query)
{
return query
.AsNoTracking()
.Include(o => o.Members)
.Include(o => o.Parent);

}
return Context.Get(id);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Phonebook.Source.PeopleSoft.Repositories
{
public interface IRepository<T> where T: class
{
IEnumerable<T> Get();
T Get(int id);

}
}
Loading