is-monitor/is-monitor-frontend/src/app/resource-list/resource-list.component.ts

67 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-09-30 14:32:24 +02:00
import { Component, OnInit } from '@angular/core';
import { IsService } from '../is.service';
2019-10-18 14:45:01 +02:00
import { FacetDefinition, CLASS_PROPERTY_KEY } from './resourceidentification';
2019-10-16 15:25:51 +02:00
import { Resource } from '../is-model/reference/entities/Resource';
2019-10-18 14:45:01 +02:00
import { TypeDefinition } from '../is-model/types/TypeDefinition';
2019-09-30 14:32:24 +02:00
@Component({
selector: 'app-resource-list',
templateUrl: './resource-list.component.html',
styleUrls: ['./resource-list.component.css']
})
export class ResourceListComponent implements OnInit {
constructor(private isService: IsService) { }
2019-09-30 14:32:24 +02:00
2019-10-18 14:45:01 +02:00
set resourceType(resourceType: string) {
// tslint:disable-next-line: no-console
console.debug('Going to retrieve ' + resourceType + ' instances');
this._resourceType = resourceType;
this.isService.getResourceInstances(this._resourceType, res => { this.resources = this.analyseResources(res); });
}
get resourceType(): string {
return this._resourceType;
}
public static facetTypes: Map<string, TypeDefinition> = new Map<string, TypeDefinition>();
// <FacetType, Array<Resource>>
public resources: Map<string, Array<Resource>>;
// tslint:disable-next-line: variable-name
private _resourceType: string;
2019-09-30 14:32:24 +02:00
ngOnInit() {
2019-10-18 14:45:01 +02:00
this.resourceType = 'Service';
2019-09-30 14:32:24 +02:00
}
2019-10-18 14:45:01 +02:00
analyseResources(resources: Resource[]): Map<string, Array<Resource>> {
2019-10-16 15:25:51 +02:00
2019-10-18 14:45:01 +02:00
const map = new Map<string, Array<Resource>>();
2019-10-16 15:25:51 +02:00
for (const resource of resources) {
2019-10-18 14:45:01 +02:00
const facetType: string = resource.consistsOf[0].target[CLASS_PROPERTY_KEY];
let res: Array<Resource>;
2019-10-16 15:25:51 +02:00
if (map.has(facetType)) {
2019-10-18 14:45:01 +02:00
if (!ResourceListComponent.facetTypes.has(facetType)) {
let typeDefinition: TypeDefinition;
this.isService.getTypeDefinition(facetType, false, types => { typeDefinition = types[0]; } );
ResourceListComponent.facetTypes.set(facetType, typeDefinition);
}
res = map.get(facetType);
2019-10-16 15:25:51 +02:00
} else {
2019-10-18 14:45:01 +02:00
res = new Array<Resource>();
map.set(facetType, res);
2019-10-16 15:25:51 +02:00
}
2019-10-18 14:45:01 +02:00
res.push(resource);
2019-10-16 15:25:51 +02:00
}
return map;
2019-10-17 15:45:13 +02:00
2019-10-16 15:25:51 +02:00
}
2019-09-30 14:32:24 +02:00
}