80 lines
1.8 KiB
TypeScript
80 lines
1.8 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { IsService } from '../is.service';
|
|
import { Type } from '../type';
|
|
import { ISType } from '../ISType';
|
|
|
|
@Component({
|
|
selector: 'app-resource-types-tree',
|
|
templateUrl: './resource-types-tree.component.html',
|
|
styleUrls: ['./resource-types-tree.component.css']
|
|
})
|
|
export class ResourceTypesTreeComponent implements OnInit {
|
|
|
|
resources: Type[];
|
|
|
|
constructor(private isService: IsService) { }
|
|
|
|
ngOnInit() {
|
|
this.getResourceTypes();
|
|
}
|
|
|
|
private analyseTypes(isTypes: ISType[]): void {
|
|
|
|
const map = new Map<string, Type>();
|
|
const unassociated = new Map<string, ISType>();
|
|
|
|
const analyseUnassociated = function(type: Type) {
|
|
const associated: string[] = new Array();
|
|
|
|
for (const name of unassociated.keys()) {
|
|
const t = unassociated.get(name);
|
|
const parent = t.superClasses[0];
|
|
if (parent === type.name) {
|
|
type.addChild(map.get(t.name));
|
|
associated.push(t.name);
|
|
}
|
|
}
|
|
|
|
for (const a of associated) {
|
|
unassociated.delete(a);
|
|
}
|
|
|
|
};
|
|
|
|
const analyseType = function(isType: ISType) {
|
|
|
|
const type: Type = new Type(isType);
|
|
|
|
map.set(type.name, type);
|
|
|
|
if (type.name !== 'Resource') {
|
|
const parent = isType.superClasses[0];
|
|
if (map.has(parent)) {
|
|
map.get(parent).addChild(type);
|
|
} else {
|
|
analyseUnassociated(type);
|
|
unassociated.set(type.name, isType);
|
|
}
|
|
}
|
|
};
|
|
|
|
for (const isType of isTypes) {
|
|
analyseType(isType);
|
|
}
|
|
|
|
this.resources = map.get('Resource').children;
|
|
}
|
|
|
|
private getResourceTypes(): void {
|
|
this.isService.getResourceTypes().subscribe(this.analyseTypes);
|
|
}
|
|
|
|
loadResources(typeName: string) {
|
|
window.alert('Loading ' + typeName + ' resources');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|