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

44 lines
1.3 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';
import { ResourceIdentification, TYPE_PROPERTY_KEY } from './resourceidentification';
2019-10-16 15:25:51 +02:00
import { Resource } from '../is-model/reference/entities/Resource';
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 {
2019-10-17 15:45:13 +02:00
public resources: Map<string, ResourceIdentification>;
2019-10-16 15:25:51 +02:00
constructor(private isService: IsService) { }
2019-09-30 14:32:24 +02:00
ngOnInit() {
2019-10-17 15:45:13 +02:00
this.isService.getResourceInstances('Service', res => { this.resources = this.analyseResources(res); });
2019-09-30 14:32:24 +02:00
}
2019-10-16 15:25:51 +02:00
analyseResources(resources: Resource[]): Map<string, ResourceIdentification> {
const map = new Map<string, ResourceIdentification>();
for (const resource of resources) {
const facetType: string = resource.consistsOf[0].target[TYPE_PROPERTY_KEY];
let resourceIdentification: ResourceIdentification;
if (map.has(facetType)) {
resourceIdentification = map.get(facetType);
} else {
resourceIdentification = new ResourceIdentification(facetType);
map.set(facetType, resourceIdentification);
}
resourceIdentification.addResource(resource);
}
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
}