From 24f9d8ec1962b114ea5ed4be50c3167dc7f1a136 Mon Sep 17 00:00:00 2001 From: mariateresa Date: Mon, 23 Oct 2023 12:12:17 +0200 Subject: [PATCH] updating jhipster endpoints for REST APIs --- .classpath | 7 +- .settings/org.eclipse.jdt.core.prefs | 10 +- package-lock.json | 21 ++++ package.json | 1 + .../service/ContextService.java | 4 + .../service/InformationSystemService.java | 60 +++++++-- .../service/dto/ResourceTypeDTO.java | 15 +++ .../web/rest/ContextResource.java | 4 +- .../web/rest/InformationSystemResource.java | 115 ++++++++++++++++-- src/main/webapp/app/app.module.ts | 4 +- src/main/webapp/app/config/app-properties.ts | 2 +- src/main/webapp/app/home/home.component.html | 4 - src/main/webapp/app/home/home.component.ts | 3 +- src/main/webapp/app/home/home.module.ts | 4 +- src/main/webapp/app/i-tabbed-entity.ts | 7 ++ .../webapp/app/rsc-tree/rsc-tree.component.ts | 23 ++-- .../app/rsc-tree/rsc-tree.component.ts.OLD | 41 +++++++ .../app/services/contexts-loader.service.ts | 10 +- src/main/webapp/app/services/i-resource.ts | 2 +- .../app/services/resources-loader.service.ts | 13 +- .../webapp/app/services/restypes.service.ts | 26 ++++ .../table-nodes/table-nodes.component.html | 2 + .../app/table-nodes/table-nodes.component.ts | 64 +++++++++- 23 files changed, 371 insertions(+), 71 deletions(-) create mode 100644 src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/dto/ResourceTypeDTO.java create mode 100644 src/main/webapp/app/i-tabbed-entity.ts create mode 100644 src/main/webapp/app/rsc-tree/rsc-tree.component.ts.OLD create mode 100644 src/main/webapp/app/services/restypes.service.ts diff --git a/.classpath b/.classpath index cf1a3c1..32eaa78 100644 --- a/.classpath +++ b/.classpath @@ -18,6 +18,7 @@ + @@ -32,18 +33,12 @@ - - - - - - diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 2985089..93d8913 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,17 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.processAnnotations=enabled org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=11 diff --git a/package-lock.json b/package-lock.json index 95b991b..e4b00cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "bootstrap-icons": "^1.11.1", "cytoscape": "3.25.0", "dayjs": "1.11.5", + "mat-select-filter": "^2.4.1", "material-icons-font": "^2.1.0", "mdb-angular-ui-kit": "^3.0.1", "ngx-infinite-scroll": "14.0.0", @@ -17774,6 +17775,18 @@ "node": ">=6" } }, + "node_modules/mat-select-filter": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/mat-select-filter/-/mat-select-filter-2.4.1.tgz", + "integrity": "sha512-8MhkuFlWNACOGdR2F/YskeeZ17U1ym4dXIfyfewotjMO9KZ+t9M++WKUD6pZ6n/0EpSx24CvsEeTL79eOtiJiQ==", + "dependencies": { + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@angular/common": ">=9.0.0 <14.0.0", + "@angular/core": ">=9.0.0 <14.0.0" + } + }, "node_modules/material-icons-font": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/material-icons-font/-/material-icons-font-2.1.0.tgz", @@ -39165,6 +39178,14 @@ "p-defer": "^1.0.0" } }, + "mat-select-filter": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/mat-select-filter/-/mat-select-filter-2.4.1.tgz", + "integrity": "sha512-8MhkuFlWNACOGdR2F/YskeeZ17U1ym4dXIfyfewotjMO9KZ+t9M++WKUD6pZ6n/0EpSx24CvsEeTL79eOtiJiQ==", + "requires": { + "tslib": "^2.0.0" + } + }, "material-icons-font": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/material-icons-font/-/material-icons-font-2.1.0.tgz", diff --git a/package.json b/package.json index f6dded7..d7a8f3d 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "bootstrap-icons": "^1.11.1", "cytoscape": "3.25.0", "dayjs": "1.11.5", + "mat-select-filter": "^2.4.1", "material-icons-font": "^2.1.0", "mdb-angular-ui-kit": "^3.0.1", "ngx-infinite-scroll": "14.0.0", diff --git a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/ContextService.java b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/ContextService.java index a029a26..f0747d0 100644 --- a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/ContextService.java +++ b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/ContextService.java @@ -2,6 +2,7 @@ package org.gcube.fullstackapps.informationsystemmonitor.service; import java.util.ArrayList; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.Authentication; @@ -9,6 +10,9 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; import org.springframework.security.web.authentication.WebAuthenticationDetails; import org.springframework.stereotype.Service; +/* + * Servizio per layer jhipster + */ @Service public class ContextService { diff --git a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/InformationSystemService.java b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/InformationSystemService.java index 8ef3590..3639297 100644 --- a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/InformationSystemService.java +++ b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/InformationSystemService.java @@ -1,14 +1,20 @@ package org.gcube.fullstackapps.informationsystemmonitor.service; import java.util.List; +import java.util.concurrent.ExecutorService; import org.gcube.common.authorization.utils.manager.SecretManager; import org.gcube.common.authorization.utils.manager.SecretManagerProvider; import org.gcube.common.authorization.utils.secret.JWTSecret; import org.gcube.common.authorization.utils.secret.Secret; import org.gcube.informationsystem.contexts.reference.entities.Context; +import org.gcube.informationsystem.model.reference.entities.Resource; +import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; +import org.gcube.informationsystem.serialization.ElementMapper; +import org.gcube.informationsystem.types.reference.Type; +import org.gcube.informationsystem.types.reference.entities.ResourceType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -37,23 +43,53 @@ public class InformationSystemService { public List getAllContext(String rootCtx) throws Exception { log.debug("GetAllContext: [rootCtx=]",rootCtx); ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(rootCtx); - //List contexts=new ArrayList<>(); - //contexts.add(new ContextImpl("/gcube")); Listcontexts=resourceRegistryClient.getAllContext(); log.debug("AllContext: {}",contexts); return contexts; } - public List testResources(String rootCtx) throws Exception { - log.debug("GetAllContext: [rootCtx=]",rootCtx); - ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(rootCtx); - //TODO: cosa ritornano questi metodi? - //resourceRegistryClient.getFilteredResources(null, null, null, false, null); - //resourceRegistryClient.getFilteredResources(rootCtx, rootCtx, rootCtx, false, null) - Listcontexts=resourceRegistryClient.getAllContext(); - log.debug("AllContext: {}",contexts); - return contexts; - } + /* + * per prendere tutti i tipi (albero a sin) + */ + public List getResourceTypes() throws Exception { + + String currentCtx = SecretManagerProvider.instance.get().getContext(); + log.debug("getResourceTypes : [currentCtx=]",currentCtx); + ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx); + List types = resourceRegistryClient.getType(Resource.class, true); + /* + for(Type t : types) { + ResourceType rt = (ResourceType) t; + rt.getExtendedTypes(); + } + */ + log.debug("getResourceTypes:",types); + return types; + } + + /* + * per prendere tutti le istanze di un certo tipo (per riempire la tabella) + */ + //TODO: per ora fare EService e HostingNode + public List getResourceInstances(String resourceType) throws Exception { + String currentCtx = SecretManagerProvider.instance.get().getContext(); + List instancesAsObject; + log.debug("getResourceInstances : [currentCtx=]",currentCtx); + ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx); + String instances = resourceRegistryClient.getInstances(resourceType, false); + instancesAsObject = ElementMapper.unmarshalList(Resource.class, instances); + for(Resource r : instancesAsObject) { + r.getFacets(); + } + + /* + for(Type t : types) { + ResourceType rt = (ResourceType) t; + rt.getExtendedTypes(); + } + */ + return instancesAsObject; + } } diff --git a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/dto/ResourceTypeDTO.java b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/dto/ResourceTypeDTO.java new file mode 100644 index 0000000..2063a87 --- /dev/null +++ b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/dto/ResourceTypeDTO.java @@ -0,0 +1,15 @@ +package org.gcube.fullstackapps.informationsystemmonitor.service.dto; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ResourceTypeDTO { + private String id; + private String name; + private ResourceTypeDTO[] children; +} diff --git a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/web/rest/ContextResource.java b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/web/rest/ContextResource.java index c11dc1d..2f2e386 100644 --- a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/web/rest/ContextResource.java +++ b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/web/rest/ContextResource.java @@ -58,12 +58,10 @@ public class ContextResource { model.addAttribute("name", userAttributes.get("name")); }*/ - - return contextService.all(); } - + @GetMapping("/encode") public String encodeContext() { String contextEncoded=UriUtils.encode("/gcube", "UTF-8"); diff --git a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/web/rest/InformationSystemResource.java b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/web/rest/InformationSystemResource.java index a3c1a00..d3e02b7 100644 --- a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/web/rest/InformationSystemResource.java +++ b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/web/rest/InformationSystemResource.java @@ -1,20 +1,30 @@ package org.gcube.fullstackapps.informationsystemmonitor.web.rest; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import javax.annotation.Nullable; + import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.fullstackapps.informationsystemmonitor.config.TokenManager; import org.gcube.fullstackapps.informationsystemmonitor.service.InformationSystemService; +import org.gcube.fullstackapps.informationsystemmonitor.service.dto.ResourceTypeDTO; import org.gcube.informationsystem.contexts.reference.entities.Context; +import org.gcube.informationsystem.model.reference.entities.Resource; +import org.gcube.informationsystem.serialization.ElementMapper; +import org.gcube.informationsystem.types.reference.Type; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.util.UriUtils; +import io.swagger.v3.core.util.Json; import lombok.RequiredArgsConstructor; import tech.jhipster.web.util.HeaderUtil; @@ -33,22 +43,28 @@ public class InformationSystemResource { private final TokenManager tokenManager; private final InformationSystemService informationSystemService; - - @GetMapping("/allcontext") - public ResponseEntity allcontext() { + + private String createUmaToken(String currentContext) { log.debug("Request uma token"); - String rootContext = tokenManager.getRootContext(); - String contextEncoded = UriUtils.encode(rootContext, "UTF-8"); - String umaToken = tokenManager.getUmaToken(contextEncoded); - + if(currentContext==null || currentContext.isBlank()) { + currentContext = tokenManager.getRootContext(); + } + String umaToken = tokenManager.getUmaToken(UriUtils.encode(currentContext, "UTF-8")); + return umaToken; + } + + @GetMapping("/allcontext") + public ResponseEntity allContext(@RequestParam String currentContext) { try { - informationSystemService.setUma(umaToken); - List contexts = informationSystemService.getAllContext(rootContext); - ObjectMapper om = new ObjectMapper(); - String sc = om.writeValueAsString(contexts); + informationSystemService.setUma(createUmaToken(currentContext)); + List contexts = informationSystemService.getAllContext(currentContext); + /* + for(Context c : contexts) { + c.getID(); + c.getName(); + }*/ + String sc = ElementMapper.marshal(contexts); return ResponseEntity.ok().body(sc); - - //return new ResponseEntity>(contexts, HttpStatus.OK); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); return ResponseEntity.noContent() @@ -56,5 +72,78 @@ public class InformationSystemResource { } } + + @GetMapping("/resourcetypes") + public ResponseEntity resourceTypes(@RequestParam @Nullable String currentContext) { + log.debug("******Request resource types"); + List typeDtos = new ArrayList(); + try { + informationSystemService.setUma(createUmaToken(currentContext)); + List resTypes = informationSystemService.getResourceTypes(); + Iterator it = resTypes.iterator(); + while (it.hasNext()) { + Type t = it.next(); + //at the moment, an empty array + ResourceTypeDTO[] children = new ResourceTypeDTO[0]; + ResourceTypeDTO dto = new ResourceTypeDTO(t.getID().toString(),t.getName(),children); + typeDtos.add(dto); + } + ObjectMapper objectMapper = new ObjectMapper(); + String sc = objectMapper.writeValueAsString(typeDtos); + return ResponseEntity.ok().body(sc); + } catch (Exception e) { + log.error(e.getLocalizedMessage(), e); + return ResponseEntity.noContent() + .headers(HeaderUtil.createAlert(applicationName, e.getLocalizedMessage(), "")).build(); + } + } + + + /* + @GetMapping("/resourcetypes") + public ResponseEntity resourceTypes2(@RequestParam String currentContext) { + log.debug("Request resource types"); + + try { + informationSystemService.setUma(createUmaToken(currentContext)); + List resTypes = informationSystemService.getResourceTypes(); + String sc = ElementMapper.marshal(resTypes); + return ResponseEntity.ok().body(sc); + } catch (Exception e) { + log.error(e.getLocalizedMessage(), e); + return ResponseEntity.noContent() + .headers(HeaderUtil.createAlert(applicationName, e.getLocalizedMessage(), "")).build(); + } + } + */ + /* + * ritorna le istanze delle risorse di un certo tipo + */ + @GetMapping("/resourceinstances") + public ResponseEntity resourceInstances(@RequestParam String currentContext, @RequestParam String resourceType) { + log.debug("Request resource types"); + + try { + informationSystemService.setUma(createUmaToken(currentContext)); + List resIntances = informationSystemService.getResourceInstances(resourceType); + /* + for(Type t : resTypes) { + t.getID(); + t.getName(); + } + */ + /* + informationSystemService.setUma(umaToken); + List resTypes = informationSystemService.getResourceTypes(currentContext); + */ + + String sc = ElementMapper.marshal(resIntances); + return ResponseEntity.ok().body(sc); + } catch (Exception e) { + log.error(e.getLocalizedMessage(), e); + return ResponseEntity.noContent() + .headers(HeaderUtil.createAlert(applicationName, e.getLocalizedMessage(), "")).build(); + } + } } diff --git a/src/main/webapp/app/app.module.ts b/src/main/webapp/app/app.module.ts index 9e9e8b3..0ef239c 100644 --- a/src/main/webapp/app/app.module.ts +++ b/src/main/webapp/app/app.module.ts @@ -1,4 +1,4 @@ -import { NgModule, LOCALE_ID } from '@angular/core'; +import { NgModule, LOCALE_ID, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { registerLocaleData } from '@angular/common'; import { HttpClientModule } from '@angular/common/http'; import locale from '@angular/common/locales/en'; @@ -47,7 +47,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; NgbModule, RawjsonPaneComponent, ClipboardModule, - BrowserAnimationsModule + BrowserAnimationsModule, ], providers: [ Title, diff --git a/src/main/webapp/app/config/app-properties.ts b/src/main/webapp/app/config/app-properties.ts index 61ff985..a778010 100644 --- a/src/main/webapp/app/config/app-properties.ts +++ b/src/main/webapp/app/config/app-properties.ts @@ -1,5 +1,5 @@ export class appProperties { - public static BASEURL_API = "http://localhost:8080/"; + public static BASEURL_API = "http://localhost:9000"; } \ No newline at end of file diff --git a/src/main/webapp/app/home/home.component.html b/src/main/webapp/app/home/home.component.html index 0fa5b36..12d6e67 100644 --- a/src/main/webapp/app/home/home.component.html +++ b/src/main/webapp/app/home/home.component.html @@ -31,13 +31,9 @@ - -
- -
diff --git a/src/main/webapp/app/home/home.component.ts b/src/main/webapp/app/home/home.component.ts index 43e46bf..79e6461 100644 --- a/src/main/webapp/app/home/home.component.ts +++ b/src/main/webapp/app/home/home.component.ts @@ -9,7 +9,7 @@ import { Account } from 'app/core/auth/account.model'; import { AbstractControl, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { Clipboard } from '@angular/cdk/clipboard' import { Observable, map, startWith } from 'rxjs'; -import { IContextNode } from 'app/services/i-context-node'; + @Component({ selector: 'jhi-home', @@ -114,7 +114,6 @@ export class HomeComponent implements OnInit { return tmp; } - getContexts(): string[] { if (this.account != null && this.account.resourceAccessDTO != null) { // eslint-disable-next-line no-console diff --git a/src/main/webapp/app/home/home.module.ts b/src/main/webapp/app/home/home.module.ts index 11c9646..b993c16 100644 --- a/src/main/webapp/app/home/home.module.ts +++ b/src/main/webapp/app/home/home.module.ts @@ -11,6 +11,7 @@ import { RawjsonPaneComponent } from 'app/rawjson-pane/rawjson-pane.component'; import { ClipboardModule } from '@angular/cdk/clipboard'; import { MatTabsModule } from '@angular/material/tabs'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { MatSelectFilterModule } from 'mat-select-filter'; @NgModule({ imports: [SharedModule, @@ -21,7 +22,8 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; RawjsonPaneComponent, ClipboardModule, MatTabsModule, - BrowserAnimationsModule + BrowserAnimationsModule, + MatSelectFilterModule ], declarations: [HomeComponent], schemas:[CUSTOM_ELEMENTS_SCHEMA] diff --git a/src/main/webapp/app/i-tabbed-entity.ts b/src/main/webapp/app/i-tabbed-entity.ts new file mode 100644 index 0000000..3313628 --- /dev/null +++ b/src/main/webapp/app/i-tabbed-entity.ts @@ -0,0 +1,7 @@ +export interface ITabbedEntity { + id: string; + title: string; + content: string; + //prevediamo contenuti di tipo diverso (quindi switch al momento della costruzione dei tab) + type: number; +} diff --git a/src/main/webapp/app/rsc-tree/rsc-tree.component.ts b/src/main/webapp/app/rsc-tree/rsc-tree.component.ts index fcdebb1..795f9da 100644 --- a/src/main/webapp/app/rsc-tree/rsc-tree.component.ts +++ b/src/main/webapp/app/rsc-tree/rsc-tree.component.ts @@ -2,26 +2,33 @@ import { Component , OnInit } from '@angular/core'; import { MatTreeNestedDataSource } from '@angular/material/tree'; import { NestedTreeControl } from '@angular/cdk/tree'; -//import { IContextNode } from 'app/services/i-context-node'; -import { RESOURCES } from 'app/services/restypes'; import { IResource } from 'app/services/i-resource'; +import { RestypesService } from 'app/services/restypes.service'; @Component({ selector: 'jhi-rsc-tree', templateUrl: './rsc-tree.component.html', styleUrls: ['./rsc-tree.component.scss'], + providers: [RestypesService], }) -export class RscTreeComponent{ +export class RscTreeComponent implements OnInit{ nestedTreeControl = new NestedTreeControl(node => node.children); nestedDataSource = new MatTreeNestedDataSource(); - //@Output() treeNode = new EventEmitter(); //emitting event to parent - - constructor() { - this.nestedDataSource.data = RESOURCES; + constructor(private rtService:RestypesService) { } - + + ngOnInit(): void { + this.rtService.fetchAll().subscribe(res => { + this.nestedDataSource.data = res; + console.debug("*****"); + console.debug(JSON.stringify(res)); + console.debug("*****"); + }); + } + + hasNestedChild(_: number, node: IResource): boolean { if (node.children == null) { return false; diff --git a/src/main/webapp/app/rsc-tree/rsc-tree.component.ts.OLD b/src/main/webapp/app/rsc-tree/rsc-tree.component.ts.OLD new file mode 100644 index 0000000..fcdebb1 --- /dev/null +++ b/src/main/webapp/app/rsc-tree/rsc-tree.component.ts.OLD @@ -0,0 +1,41 @@ +/* eslint-disable no-console */ +import { Component , OnInit } from '@angular/core'; +import { MatTreeNestedDataSource } from '@angular/material/tree'; +import { NestedTreeControl } from '@angular/cdk/tree'; +//import { IContextNode } from 'app/services/i-context-node'; +import { RESOURCES } from 'app/services/restypes'; +import { IResource } from 'app/services/i-resource'; + +@Component({ + selector: 'jhi-rsc-tree', + templateUrl: './rsc-tree.component.html', + styleUrls: ['./rsc-tree.component.scss'], +}) + +export class RscTreeComponent{ + nestedTreeControl = new NestedTreeControl(node => node.children); + nestedDataSource = new MatTreeNestedDataSource(); + //@Output() treeNode = new EventEmitter(); //emitting event to parent + + + constructor() { + this.nestedDataSource.data = RESOURCES; + } + +hasNestedChild(_: number, node: IResource): boolean { + if (node.children == null) { + return false; + } else { + return node.children.length > 0; + } + } + + loadTable(choosenResType:IResource):boolean{ + //TODO: qui va chiamato il componente hnodes-table e conseguentemente visualizzato + //this.showTable = true; + //return this.showTable; + return true; + } + + +} diff --git a/src/main/webapp/app/services/contexts-loader.service.ts b/src/main/webapp/app/services/contexts-loader.service.ts index 66b49c8..6c44d10 100644 --- a/src/main/webapp/app/services/contexts-loader.service.ts +++ b/src/main/webapp/app/services/contexts-loader.service.ts @@ -2,7 +2,6 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable, map, tap } from 'rxjs'; import { appProperties } from 'app/config/app-properties'; -import { IContextNode } from './i-context-node'; @Injectable({ providedIn: 'root', @@ -13,15 +12,10 @@ export class ContextsLoaderService { }; constructor(private http: HttpClient) {} -/* - getData(): Observable { - //TODO: pipe per gestione errori - return this.http.get(appProperties.MOCK_BASEURL_API + '/allcontext'); - } - */ getRawData(): Observable { //TODO: pipe per gestione errori - return this.http.get(appProperties.BASEURL_API + 'is/allcontext'); + return this.http.get(appProperties.BASEURL_API + 'is/resourcetypes'); } + } diff --git a/src/main/webapp/app/services/i-resource.ts b/src/main/webapp/app/services/i-resource.ts index 72b7490..44a8320 100644 --- a/src/main/webapp/app/services/i-resource.ts +++ b/src/main/webapp/app/services/i-resource.ts @@ -1,6 +1,6 @@ export interface IResource { name: string; id: string; - type: number; //TODO: codice da assegnare in constants per ogni tipo di risorsa + //type: number; //TODO: codice da assegnare in constants per ogni tipo di risorsa children?: IResource[]; } diff --git a/src/main/webapp/app/services/resources-loader.service.ts b/src/main/webapp/app/services/resources-loader.service.ts index 65b9289..dffa165 100644 --- a/src/main/webapp/app/services/resources-loader.service.ts +++ b/src/main/webapp/app/services/resources-loader.service.ts @@ -14,26 +14,25 @@ export class ResourcesLoaderService { constructor(private http: HttpClient) {} - //TODO: a regime questo metodo prende un parametro nella get + +/* metodi mock + //TODO: pipe per gestione errori + */ + getHostingNodes(): Observable { - //TODO: pipe per gestione errori return this.http.get('http://localhost:3002/is/hostingnodes/all'); } getResourcesByContext(): Observable { - //TODO: pipe per gestione errori return this.http.get('http://localhost:3002/is/ctxresources'); } - //TODO: a regime questo metodo prende un parametro nella get - //(e probabilmente anche un tipo per fare uno switch sul tipo di risorsa da prendere) getJsonDetail(uid: string): Observable { - //TODO: pipe per gestione errori return this.http.get('http://localhost:3002/is/hostingnodes/detail'); } getHostingNodeDetail(): Observable { - //TODO: pipe per gestione errori + return this.http.get('http://localhost:3002/is/hostingnodes/detail'); } diff --git a/src/main/webapp/app/services/restypes.service.ts b/src/main/webapp/app/services/restypes.service.ts new file mode 100644 index 0000000..78cbb55 --- /dev/null +++ b/src/main/webapp/app/services/restypes.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { IResource} from './i-resource'; +import { appProperties } from 'app/config/app-properties'; + +@Injectable({ + providedIn: 'root', +}) + +export class RestypesService { + httpOptions = { + headers: new HttpHeaders({ 'Content-Type': 'application/json' }), + }; + + constructor(private http: HttpClient) {} + + //TODO: pipe per gestione errori + + fetchAll(): Observable { + return this.http.get(appProperties.BASEURL_API+'/is/resourcetypes'); + } + + + +} diff --git a/src/main/webapp/app/table-nodes/table-nodes.component.html b/src/main/webapp/app/table-nodes/table-nodes.component.html index 8e07243..6e83e64 100644 --- a/src/main/webapp/app/table-nodes/table-nodes.component.html +++ b/src/main/webapp/app/table-nodes/table-nodes.component.html @@ -20,6 +20,7 @@ Last Modified Available Memory HD Space + @@ -30,6 +31,7 @@ + diff --git a/src/main/webapp/app/table-nodes/table-nodes.component.ts b/src/main/webapp/app/table-nodes/table-nodes.component.ts index 4df74c0..0157d94 100644 --- a/src/main/webapp/app/table-nodes/table-nodes.component.ts +++ b/src/main/webapp/app/table-nodes/table-nodes.component.ts @@ -1,9 +1,11 @@ -import { Component, QueryList, ViewChildren } from '@angular/core'; +import { Component, QueryList, ViewChild, ViewChildren } from '@angular/core'; import { IHostingnode } from 'app/services/i-hostinngnode'; import { HnodesLoaderService } from 'app/services/hnodes-loader.service'; import { DecimalPipe, NgIf } from '@angular/common'; import { Observable } from 'rxjs'; import { SortableDirective, SortEvent } from './sortable.directive'; +import { MatTab, MatTabGroup } from '@angular/material/tabs'; +import { ITabbedEntity } from 'app/i-tabbed-entity'; /* Tabella con paginazione, ordinamento e ricerca - dati presi da servizio @@ -18,9 +20,22 @@ Tabella con paginazione, ordinamento e ricerca - dati presi da servizio }) export class TableNodesComponent{ + + //per tabbed view + @ViewChild(MatTab) + public tabGroup: MatTabGroup | any; + public tabNodes: QueryList | any; + public closedTabs = []; + public tabs: ITabbedEntity[] = [{ title: 'JSON View', content: '', type: 0, id: '' }]; + selectedIdx = 0; + chosenIds: string[] = []; + ////////// fine tabbed view(MatTab) + + - hnodes$: Observable; + hnodes$: Observable; total$: Observable; + @ViewChildren(SortableDirective) headers: QueryList|any; @@ -41,5 +56,50 @@ export class TableNodesComponent{ this.service.sortColumn = column; this.service.sortDirection = direction; } + /* + addTab(id:string):void{ + alert("id?..."+id); + } + */ + // per tabbed pane (versione con aggiunta dinamica) + + removeTab(index: number): void { + this.tabs.splice(index, 1); + } + + addTab(itemId: string): void { + if (!this.chosenIds.includes(itemId)) { + const newItem = { + id: itemId, + title: itemId.substring(0, 20) + '...', + //TODO: content a regime รจ la stringa JSON + content: itemId, + type: 0, + }; + this.selectedIdx++; + this.chosenIds.push(itemId); + this.tabs.push(newItem); + } + } + + closeTab(index: number): void { + /* + console.debug('---------'); + console.debug(index); + console.debug('---IDs:'); + console.debug(this.chosenIds); + console.debug(this.tabs[index].id); + console.debug('++++++++++'); + */ + const x = this.chosenIds.indexOf(this.tabs[index].id); + if (x !== -1) { + this.chosenIds.splice(x, 1); + } + + // this.closedTabs.push(index); + this.tabGroup.selectedIndex = this.tabs.length - 1; + //this.chosenIds.indexOf(); + this.tabs.splice(index, 1); + } }