From affff0e800d61d29fb23692d5f0b8de106fb4e17 Mon Sep 17 00:00:00 2001 From: mariateresa Date: Wed, 18 Oct 2023 18:17:59 +0200 Subject: [PATCH] added support for material dropdown and autocompletion (work in progress) --- .../service/InformationSystemService.java | 13 +- src/main/webapp/app/app.module.ts | 6 +- src/main/webapp/app/home/home.component.html | 79 ++++++++---- src/main/webapp/app/home/home.component.ts | 113 +++++++++++++++++- src/main/webapp/app/home/home.module.ts | 14 ++- .../app/rsc-tree/rsc-tree.component.html | 1 - 6 files changed, 196 insertions(+), 30 deletions(-) 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 ab6dd4d..8ef3590 100644 --- a/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/InformationSystemService.java +++ b/src/main/java/org/gcube/fullstackapps/informationsystemmonitor/service/InformationSystemService.java @@ -1,13 +1,11 @@ package org.gcube.fullstackapps.informationsystemmonitor.service; -import java.util.ArrayList; import java.util.List; 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.impl.entities.ContextImpl; import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; @@ -45,6 +43,17 @@ public class InformationSystemService { 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; + } } diff --git a/src/main/webapp/app/app.module.ts b/src/main/webapp/app/app.module.ts index 70d3df9..9e9e8b3 100644 --- a/src/main/webapp/app/app.module.ts +++ b/src/main/webapp/app/app.module.ts @@ -28,6 +28,8 @@ import { ErrorComponent } from './layouts/error/error.component'; import { SortableDirective } from './table-nodes/sortable.directive'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { RawjsonPaneComponent } from './rawjson-pane/rawjson-pane.component'; +import { ClipboardModule } from '@angular/cdk/clipboard'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; @NgModule({ imports: [ @@ -43,7 +45,9 @@ import { RawjsonPaneComponent } from './rawjson-pane/rawjson-pane.component'; TranslationModule, SortableDirective, NgbModule, - RawjsonPaneComponent + RawjsonPaneComponent, + ClipboardModule, + BrowserAnimationsModule ], providers: [ Title, diff --git a/src/main/webapp/app/home/home.component.html b/src/main/webapp/app/home/home.component.html index 1385e44..0fa5b36 100644 --- a/src/main/webapp/app/home/home.component.html +++ b/src/main/webapp/app/home/home.component.html @@ -1,30 +1,71 @@
-
- +
+
+ + + + + +
+

Available Resources

+
+ +
+
-

Welcome!

You are logged in as user "{{ - account.login}}". -
-
-
- -
-
- -
-
+ [translateValues]="{ username: account.login }">You are logged in as user "{{account.login}}". +
+
+ + Your Contexts + + + {{context|contexttransform}} + + + +
-
+ +
- +
+ + + +
+
+ + Context name + + {{ checkForErrorsIn(namefield) }} + + + {{fctx}} + + + + + + Context UUID + + + +
+
+ + +
@@ -33,6 +74,4 @@
-
-
diff --git a/src/main/webapp/app/home/home.component.ts b/src/main/webapp/app/home/home.component.ts index 51dde0f..43e46bf 100644 --- a/src/main/webapp/app/home/home.component.ts +++ b/src/main/webapp/app/home/home.component.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /* eslint-disable @typescript-eslint/no-unnecessary-condition */ /* eslint-disable @typescript-eslint/restrict-plus-operands */ import { Component, OnInit } from '@angular/core'; @@ -5,21 +6,114 @@ import { Component, OnInit } from '@angular/core'; import { LoginService } from 'app/login/login.service'; import { AccountService } from 'app/core/auth/account.service'; 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', templateUrl: './home.component.html', - styleUrls: ['./home.component.scss'] + styleUrls: ['./home.component.scss'], }) export class HomeComponent implements OnInit { account: Account | null = null; - - constructor(private accountService: AccountService, private loginService: LoginService) { } + + stringCtxs: string[]; + //contexts: IContextNode[]; + //public filteredContexts: Observable | undefined; + public filteredContextsStr: Observable| undefined; + chooseContextForm: FormGroup | any; + + + + constructor( + private accountService: AccountService, + private loginService: LoginService, + private fb: FormBuilder, + private clipboard: Clipboard) { + //this.contexts = []; + this.stringCtxs = []; + this.chooseContextForm = this.fb.group({ + namefield: ['', [Validators.required]], + uidfield: [''], + }); + } + + get namefield(): any { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return this.chooseContextForm.get('namefield'); + } + get uidfield(): any { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return this.chooseContextForm.get('uidfield'); + } + + ngOnInit(): void { //questo identifica l'utente e riempie il campo account this.accountService.identity().subscribe(account => (this.account = account)); + + //caso semplificato con contesti solo stringhe + this.stringCtxs = this.getContexts(); + console.debug("***stringCtxs..."+this.stringCtxs); + this.filteredContextsStr = this.chooseContextForm.get('namefield').valueChanges.pipe( + startWith(''), + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + map(ctx => (ctx ? this.filterContexts(ctx) : this.stringCtxs.slice())) + ); + + + /* + this.resLoader.getResourcesByContext().subscribe(res => { + this.nestedDataSource.data = res; + }); + + // per la form dei contesti + this.ctxLoader.getData().subscribe(res => { + this.contexts = res; + console.log('*******numero contesti...', res.length); + }); + + this.filteredContexts = this.chooseContextForm.get('namefield').valueChanges.pipe( + startWith(''), + map(ctx => (ctx ? this.filterContexts(ctx) : this.contexts.slice())) + );*/ } + + //mettere ANY come tipo dell'argomento per evitare errore TypeScript nella map!! + /* + filterContexts(name: any): IContextNode[] { + return this.contexts.filter(ctx => ctx.name.toLowerCase().includes(name.toLowerCase())); + }*/ + + //TEMPORANEO: CTX E' TEMPORANEAMENTE UNA STRINGA (NON A REGIME) + filterContexts(name: any): string[] { + return this.stringCtxs.filter(ctx => ctx.toLowerCase().includes(name.toLowerCase())); + } + + + //PER VALIDAZIONE FORM + checkForErrorsIn(formControl: AbstractControl): string { + if (formControl.hasError('required')) { + return 'Value is required!'; + } + return ''; + } + + /* + displayFn(ctx: IContextNode): string { + return ctx.name ? ctx.name + ' | ' + ctx.id : ''; + } +*/ + + displayFn(ctx: string): string { + const tmp = ctx ? ctx + ' (poi ci va id) ': ''; + console.log("***"+tmp); + return tmp; + } + getContexts(): string[] { if (this.account != null && this.account.resourceAccessDTO != null) { @@ -27,10 +121,9 @@ export class HomeComponent implements OnInit { var sc=this.account.resourceAccessDTO.resourceAccess; var contexts=Array.from(Object.keys(sc)); contexts=contexts.filter(element=> - element!==null&&element.startsWith("%2F")); + element!==null&&element.startsWith("%2F")); contexts=contexts.sort(); // eslint-disable-next-line no-console - console.log("*****contexts..."+contexts); return contexts; } else { @@ -38,6 +131,16 @@ export class HomeComponent implements OnInit { } } + copyUid(val: any): void { + if (val instanceof FormControl) { + this.clipboard.copy(val.getRawValue().id); + } else { + //this.clipboard.copy('invalid value'); + this.clipboard.copy('invalid value'); + } + } + + login(): void { this.loginService.login(); } diff --git a/src/main/webapp/app/home/home.module.ts b/src/main/webapp/app/home/home.module.ts index 9ba518f..11c9646 100644 --- a/src/main/webapp/app/home/home.module.ts +++ b/src/main/webapp/app/home/home.module.ts @@ -8,9 +8,21 @@ import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; import { TableNodesModule } from 'app/table-nodes/table-nodes.module'; import { RscTreeModule } from 'app/rsc-tree/rsc-tree.module'; 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'; @NgModule({ - imports: [SharedModule, RouterModule.forChild([HOME_ROUTE]),NgbDropdownModule, TableNodesModule, RscTreeModule,RawjsonPaneComponent], + imports: [SharedModule, + RouterModule.forChild([HOME_ROUTE]), + NgbDropdownModule, + TableNodesModule, + RscTreeModule, + RawjsonPaneComponent, + ClipboardModule, + MatTabsModule, + BrowserAnimationsModule + ], declarations: [HomeComponent], schemas:[CUSTOM_ELEMENTS_SCHEMA] }) diff --git a/src/main/webapp/app/rsc-tree/rsc-tree.component.html b/src/main/webapp/app/rsc-tree/rsc-tree.component.html index 9a6da39..04b4148 100644 --- a/src/main/webapp/app/rsc-tree/rsc-tree.component.html +++ b/src/main/webapp/app/rsc-tree/rsc-tree.component.html @@ -1,4 +1,3 @@ -

Available Resources