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

44 lines
1.3 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { IsService } from '../is.service';
import { ResourceIdentification, TYPE_PROPERTY_KEY } from './resourceidentification';
import { Resource } from '../is-model/reference/entities/Resource';
@Component({
selector: 'app-resource-list',
templateUrl: './resource-list.component.html',
styleUrls: ['./resource-list.component.css']
})
export class ResourceListComponent implements OnInit {
public resources: Map<string, ResourceIdentification>;
constructor(private isService: IsService) { }
ngOnInit() {
this.isService.getResourceInstances('Service', res => { this.resources = this.analyseResources(res); });
}
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;
}
}