2019-09-30 14:32:24 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2019-10-11 18:16:14 +02:00
|
|
|
import { IsService } from '../is.service';
|
2019-10-17 16:44:15 +02:00
|
|
|
import { Type } from './type';
|
2019-10-16 11:48:47 +02:00
|
|
|
import { TypeDefinition } from '../is-model/types/TypeDefinition';
|
2019-09-30 14:32:24 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-resource-types-tree',
|
|
|
|
templateUrl: './resource-types-tree.component.html',
|
|
|
|
styleUrls: ['./resource-types-tree.component.css']
|
|
|
|
})
|
|
|
|
export class ResourceTypesTreeComponent implements OnInit {
|
|
|
|
|
2019-10-02 17:58:41 +02:00
|
|
|
resources: Type[];
|
|
|
|
|
2019-10-14 15:42:34 +02:00
|
|
|
constructor(private isService: IsService) {
|
2019-10-11 18:16:14 +02:00
|
|
|
|
|
|
|
}
|
2019-10-02 17:58:41 +02:00
|
|
|
|
2019-10-14 15:42:34 +02:00
|
|
|
ngOnInit() {
|
2019-10-18 14:45:01 +02:00
|
|
|
this.isService.getTypeDefinition('Resource', true, isTypes => { this.resources = this.analyseTypes(isTypes); });
|
2019-10-14 15:42:34 +02:00
|
|
|
}
|
2019-09-30 14:32:24 +02:00
|
|
|
|
2019-10-16 11:48:47 +02:00
|
|
|
analyseUnassociated(type: Type, map: Map<string, Type>, unassociated: Map<string, TypeDefinition>) {
|
2019-10-14 15:42:34 +02:00
|
|
|
const associated: string[] = new Array();
|
2019-10-02 17:58:41 +02:00
|
|
|
|
2019-10-14 15:42:34 +02:00
|
|
|
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);
|
2019-10-11 18:16:14 +02:00
|
|
|
}
|
2019-10-14 15:42:34 +02:00
|
|
|
}
|
2019-10-02 17:58:41 +02:00
|
|
|
|
2019-10-14 15:42:34 +02:00
|
|
|
for (const a of associated) {
|
|
|
|
unassociated.delete(a);
|
|
|
|
}
|
2019-10-02 17:58:41 +02:00
|
|
|
|
2019-10-16 11:02:59 +02:00
|
|
|
}
|
2019-10-02 17:58:41 +02:00
|
|
|
|
2019-10-16 11:48:47 +02:00
|
|
|
analyseType(isType: TypeDefinition, map: Map<string, Type>, unassociated: Map<string, TypeDefinition>) {
|
2019-10-02 17:58:41 +02:00
|
|
|
|
2019-10-14 15:42:34 +02:00
|
|
|
const type: Type = new Type(isType);
|
2019-10-02 17:58:41 +02:00
|
|
|
|
2019-10-14 15:42:34 +02:00
|
|
|
map.set(type.name, type);
|
2019-10-02 17:58:41 +02:00
|
|
|
|
2019-10-14 15:42:34 +02:00
|
|
|
if (type.name !== 'Resource') {
|
|
|
|
const parent = isType.superClasses[0];
|
|
|
|
if (map.has(parent)) {
|
|
|
|
map.get(parent).addChild(type);
|
|
|
|
} else {
|
|
|
|
this.analyseUnassociated(type, map, unassociated);
|
|
|
|
unassociated.set(type.name, isType);
|
2019-10-02 17:58:41 +02:00
|
|
|
}
|
2019-10-14 15:42:34 +02:00
|
|
|
}
|
2019-10-16 11:02:59 +02:00
|
|
|
}
|
2019-10-14 15:42:34 +02:00
|
|
|
|
2019-10-16 11:48:47 +02:00
|
|
|
analyseTypes(isTypes: TypeDefinition[]): Type[] {
|
2019-10-14 15:42:34 +02:00
|
|
|
|
|
|
|
const map = new Map<string, Type>();
|
2019-10-16 11:48:47 +02:00
|
|
|
const unassociated = new Map<string, TypeDefinition>();
|
2019-10-11 18:16:14 +02:00
|
|
|
|
|
|
|
for (const isType of isTypes) {
|
2019-10-14 15:42:34 +02:00
|
|
|
this.analyseType(isType, map, unassociated);
|
2019-10-02 17:58:41 +02:00
|
|
|
}
|
|
|
|
|
2019-10-14 15:42:34 +02:00
|
|
|
return map.get('Resource').children;
|
2019-10-16 11:02:59 +02:00
|
|
|
}
|
2019-10-02 17:58:41 +02:00
|
|
|
|
2019-09-30 14:32:24 +02:00
|
|
|
}
|
2019-10-02 17:58:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|