From 6b6de30af8bb7c1859e7f0b1d6fba46f139d180f Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 16 Oct 2019 11:02:59 +0200 Subject: [PATCH] Rendered resource list by dientifying facets --- .vscode/launch.json | 12 ++++- is-monitor-frontend/src/app/is.service.ts | 33 +++++++++----- is-monitor-frontend/src/app/list.ts | 38 ++++++++++++++++ .../resource-list.component.html | 45 ++++++++----------- .../resource-list/resource-list.component.ts | 31 ++++++++++++- .../resource-list/resourceidentification.ts | 30 +++++++++++++ .../resource-types-tree.component.ts | 15 +++---- is-monitor-frontend/src/app/type.ts | 2 +- 8 files changed, 158 insertions(+), 48 deletions(-) create mode 100644 is-monitor-frontend/src/app/list.ts create mode 100644 is-monitor-frontend/src/app/resource-list/resourceidentification.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index 461ff7d..756957f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,13 +4,21 @@ { "version": "0.2.0", "configurations": [ + { + "name": "Launch Chrome 127.0.0.1 (2)", + "type": "chrome", + "request": "launch", + "port": 9281, + "webRoot": "${workspaceFolder}", + "url": "http://127.0.0.1:39447/p/is-monitor/is-monitor-frontend/src/index.html?_cmAuth\u003dwfreghlipl" + }, { "name": "Launch Chrome 127.0.0.1", "type": "chrome", "request": "launch", - "port": 9207, + "port": 9225, "webRoot": "${workspaceFolder}", - "url": "http://127.0.0.1:39447/p/is-monitor/is-monitor-frontend/src/index.html?_cmAuth\u003dwfreghlipl" + "url": "http://127.0.0.1:39447/p/is-monitor/is-monitor-frontend/src/app/app.component.html?_cmAuth\u003dwfreghlipl" } ] } \ No newline at end of file diff --git a/is-monitor-frontend/src/app/is.service.ts b/is-monitor-frontend/src/app/is.service.ts index 9ae591c..0ad81ba 100644 --- a/is-monitor-frontend/src/app/is.service.ts +++ b/is-monitor-frontend/src/app/is.service.ts @@ -1,8 +1,10 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, of } from 'rxjs'; +import { catchError } from 'rxjs/operators'; import { ISType } from './ISType'; import { types } from './types'; +import { list } from './list'; @Injectable({ @@ -12,6 +14,12 @@ export class IsService { constructor(private httpClient: HttpClient) { } + private baseURL = 'http://pc-frosini.isti.cnr.it:8080/resource-registry'; + private typesURL = this.baseURL + '/types'; + private instancesURL = this.baseURL + '/instances'; + private queryURL = this.baseURL + '/query'; + + /* NextNext Token */ private token = ''; @@ -23,25 +31,30 @@ export class IsService { */ private handleError(operation = 'operation', result?: T) { return (error: any): Observable => { - console.error(error); - console.error(`${operation} failed: ${error.message}`); // log to console instead - // Let the app keep running by returning an empty result. + console.error(`${operation} failed: ${error.message}`); + if (result) { + console.warn(`${operation} is going to provide hard-coded data which is better than nothing.`); + } return of(result as T); }; } public getResourceTypes(callback: (isTypes: ISType[]) => void): void { - - const url = 'http://pc-frosini.isti.cnr.it:8080/resource-registry/types/Resource?polymorphic=true&gcube-token=' + this.token; + const url = this.typesURL + '/Resource?polymorphic=true&gcube-token=' + this.token; // const observable: Observable = of(types); const observable: Observable = this.httpClient.get(url); - /* observable.pipe( - tap(_ => console.info('Fetched Resource Types')), catchError(this.handleError('getResourceTypes()', types)) - ); - */ - observable.subscribe(data => callback(data)); + ).subscribe(data => callback(data)); + } + + public getIdentifyingFacets(resourceType: string, callback: (instances: any[]) => void): void { + const url = this.queryURL + resourceType + '?polymorphic=true&gcube-token=' + this.token; + // const observable: Observable = of(types); + const observable: Observable = this.httpClient.get(url); + observable.pipe( + catchError(this.handleError('getResourceInstances()', list)) + ).subscribe(data => callback(data)); } } diff --git a/is-monitor-frontend/src/app/list.ts b/is-monitor-frontend/src/app/list.ts new file mode 100644 index 0000000..caa2580 --- /dev/null +++ b/is-monitor-frontend/src/app/list.ts @@ -0,0 +1,38 @@ +export const list: any[] = [ + { + "@class": "SoftwareFacet", + "group": "vre-management", + "name": "whn-manager", + "version": "1.3.0" + }, + { + "@class": "SoftwareFacet", + "group": "vre-management", + "name": "smart-executor", + "version": "2.0.0" + }, + { + "@class": "SoftwareFacet", + "group": "information-system", + "name": "resource-registry", + "version": "2.1.0" + }, + { + "@class": "SoftwareFacet", + "group": "data-publishing", + "name": "gcat", + "version": "2.3.0" + }, + { + "@class": "SoftwareFacet", + "group": "vre-management", + "name": "whn-manager", + "version": "1.3.0" + }, + { + "@class": "SoftwareFacet", + "group": "vre-management", + "name": "whn-manager", + "version": "1.3.0" + } +]; \ No newline at end of file diff --git a/is-monitor-frontend/src/app/resource-list/resource-list.component.html b/is-monitor-frontend/src/app/resource-list/resource-list.component.html index e21a66b..cbef607 100644 --- a/is-monitor-frontend/src/app/resource-list/resource-list.component.html +++ b/is-monitor-frontend/src/app/resource-list/resource-list.component.html @@ -1,26 +1,19 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -
GroupNameVersion
vre-managementsmart-executor2.0.0
information-systemresource-registry2.1.0
data-publishinggcat2.3.0
\ No newline at end of file +
+ + + + + + + + + + + + + + +
{{resourceIdentification.type}}
+ {{ property.charAt(0).toLocaleUpperCase() + property.substr(1) }} +
{{ facet[property] }}
+
\ No newline at end of file diff --git a/is-monitor-frontend/src/app/resource-list/resource-list.component.ts b/is-monitor-frontend/src/app/resource-list/resource-list.component.ts index 374ba3e..6128cdb 100644 --- a/is-monitor-frontend/src/app/resource-list/resource-list.component.ts +++ b/is-monitor-frontend/src/app/resource-list/resource-list.component.ts @@ -1,4 +1,6 @@ import { Component, OnInit } from '@angular/core'; +import { IsService } from '../is.service'; +import { ResourceIdentification, TYPE_PROPERTY_KEY } from './resourceidentification'; @Component({ selector: 'app-resource-list', @@ -7,9 +9,36 @@ import { Component, OnInit } from '@angular/core'; }) export class ResourceListComponent implements OnInit { - constructor() { } + public resourceIdentificationList: Array; + + constructor(private isService: IsService) { } ngOnInit() { + // this.isService.getIdentifyingFacets('Service', facets => {this.identifyingFacets = facets;}); + this.isService.getIdentifyingFacets('Service', facets => { this.resourceIdentificationList = this.analyseIdentifyingFacets(facets); }); + } + + analyseIdentifyingFacets(identifyingFacets: any[]): Array { + + const map = new Map(); + const facets = new Array(); + + 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; } } diff --git a/is-monitor-frontend/src/app/resource-list/resourceidentification.ts b/is-monitor-frontend/src/app/resource-list/resourceidentification.ts new file mode 100644 index 0000000..62dd334 --- /dev/null +++ b/is-monitor-frontend/src/app/resource-list/resourceidentification.ts @@ -0,0 +1,30 @@ +export const TYPE_PROPERTY_KEY = '@class'; + +export class ResourceIdentification { + + public type: string; + public mandatoryProperties: Set; + public instances: any[]; + + private first = true; + + constructor(type: string) { + this.type = type; + this.mandatoryProperties = new Set(); + this.instances = new Array(); + } + + public add(facet: any) { + if (this.first) { + for (const propertyKey in facet) { + if (propertyKey.localeCompare(TYPE_PROPERTY_KEY) === 0) { + continue; + } + this.mandatoryProperties.add(propertyKey); + } + this.first = false; + } + this.instances.push(facet); + } + +} diff --git a/is-monitor-frontend/src/app/resource-types-tree/resource-types-tree.component.ts b/is-monitor-frontend/src/app/resource-types-tree/resource-types-tree.component.ts index ac65024..2cdf7ee 100644 --- a/is-monitor-frontend/src/app/resource-types-tree/resource-types-tree.component.ts +++ b/is-monitor-frontend/src/app/resource-types-tree/resource-types-tree.component.ts @@ -17,10 +17,10 @@ export class ResourceTypesTreeComponent implements OnInit { } ngOnInit() { - this.isService.getResourceTypes(isTypes => {this.resources = this.analyseTypes(isTypes)}); + this.isService.getResourceTypes(isTypes => { this.resources = this.analyseTypes(isTypes); }); } - private analyseUnassociated = function(type: Type, map: Map, unassociated: Map) { + analyseUnassociated(type: Type, map: Map, unassociated: Map) { const associated: string[] = new Array(); for (const name of unassociated.keys()) { @@ -36,9 +36,9 @@ export class ResourceTypesTreeComponent implements OnInit { unassociated.delete(a); } - }; + } - private analyseType = function(isType: ISType, map: Map, unassociated: Map) { + analyseType(isType: ISType, map: Map, unassociated: Map) { const type: Type = new Type(isType); @@ -53,9 +53,9 @@ export class ResourceTypesTreeComponent implements OnInit { unassociated.set(type.name, isType); } } - }; + } - private analyseTypes = function(isTypes: ISType[]): Type[] { + analyseTypes(isTypes: ISType[]): Type[] { const map = new Map(); const unassociated = new Map(); @@ -65,8 +65,7 @@ export class ResourceTypesTreeComponent implements OnInit { } return map.get('Resource').children; - }; - + } loadResources(typeName: string) { window.alert('Loading ' + typeName + ' resources'); diff --git a/is-monitor-frontend/src/app/type.ts b/is-monitor-frontend/src/app/type.ts index 30dc810..5be4fa4 100644 --- a/is-monitor-frontend/src/app/type.ts +++ b/is-monitor-frontend/src/app/type.ts @@ -21,4 +21,4 @@ export class Type { this.children.sort((left, right) => left.name.localeCompare(right.name)); } -} \ No newline at end of file +}