import { Component, OnInit } from '@angular/core'; import { IsService } from '../is.service'; import { Type } from './type'; import { TypeDefinition } from '../is-model/types/TypeDefinition'; @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.isService.getTypeDefinition('Resource', true, isTypes => { this.resources = this.analyseTypes(isTypes); }); } analyseUnassociated(type: Type, map: Map, unassociated: Map) { 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); } } analyseType(isType: TypeDefinition, map: Map, unassociated: Map) { 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 { this.analyseUnassociated(type, map, unassociated); unassociated.set(type.name, isType); } } } analyseTypes(isTypes: TypeDefinition[]): Type[] { const map = new Map(); const unassociated = new Map(); for (const isType of isTypes) { this.analyseType(isType, map, unassociated); } return map.get('Resource').children; } }