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

45 lines
1.4 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-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 {
public resourceIdentificationList: Array<ResourceIdentification>;
constructor(private isService: IsService) { }
2019-09-30 14:32:24 +02:00
ngOnInit() {
// this.isService.getIdentifyingFacets('Service', facets => {this.identifyingFacets = facets;});
this.isService.getIdentifyingFacets('Service', facets => { this.resourceIdentificationList = this.analyseIdentifyingFacets(facets); });
}
analyseIdentifyingFacets(identifyingFacets: any[]): Array<ResourceIdentification> {
const map = new Map<string, ResourceIdentification>();
const facets = new Array<ResourceIdentification>();
for (const facet of identifyingFacets) {
const facetType: string = facet[TYPE_PROPERTY_KEY];
let facetList: ResourceIdentification;
if (map.has(facetType)) {
facetList = map.get(facetType);
} else {
facetList = new ResourceIdentification(facetType);
map.set(facetType, facetList);
facets.push(facetList);
}
facetList.add(facet);
}
return facets;
2019-09-30 14:32:24 +02:00
}
}