Linked form with autocompletion to JHipster REST for fetching Contexts.

Consequently fixed Angular Material CSS.
This commit is contained in:
Maria Teresa Paratore 2023-11-10 19:28:50 +01:00
parent 8c7f66d741
commit 2548bcfd63
5 changed files with 40 additions and 40 deletions

View File

@ -36,30 +36,34 @@
<div> <div>
<div class="d-inline-block my-3" ngbDropdown #myDrop="ngbDropdown" ></div> <div class="d-inline-block my-3" ngbDropdown #myDrop="ngbDropdown" ></div>
<div class="col-md-9 mt-2">
<form [formGroup]="chooseContextForm"> <form [formGroup]="chooseContextForm">
<mat-form-field appearance="outline" class="form-field"> <mat-form-field appearance="outline" class="form-field">
<mat-label for="namefield" class="ml-4 flex-grow-1">Context name</mat-label> <mat-label for="namefield" class="ml-4 ">Context name</mat-label>
<input matInput #contextInput (keyup)="(0)" [matAutocomplete]="auto" placeholder="Name" type="text" [formControl]="namefield" /> <input matInput panel
#contextInput (keyup)="(0)"
[matAutocomplete]="auto"
placeholder="Name" type="text"
[formControl]="namefield" />
<mat-error>{{ checkForErrorsIn(namefield) }}</mat-error> <mat-error>{{ checkForErrorsIn(namefield) }}</mat-error>
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn.bind(this)"> <mat-autocomplete #auto="matAutocomplete" [panelWidth]=400
[displayWith]="displayFn.bind(this)">
<mat-option *ngFor="let fctx of filteredContexts | async" [value]="fctx"> <mat-option *ngFor="let fctx of filteredContexts | async" [value]="fctx">
<!--<span>{{fctx}}</span> -->
<span>{{ fctx.name }}</span> <span>{{ fctx.name }}</span>
<small> | ID: {{ fctx.id }}</small> <small> | ID: {{ fctx.id }}</small>
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</mat-form-field> </mat-form-field>
<mat-form-field appearance="outline" class="form-field"> <mat-form-field id="uidfield" [style.width.px]=327 appearance="outline" class="form-field">
<mat-label for="uidfield">Context UUID</mat-label> <mat-label for="uidfield">Context UUID</mat-label>
<input matInput id="uidfield" type="text" placeholder="UUID" formControlName="uidfield" readonly [value]="namefield.value.id" /> <input matInput class="uid-input" type="text" placeholder="UUID" formControlName="uidfield" readonly [value]="namefield.value.id" />
</mat-form-field> </mat-form-field>
<button mat-button (click)="copyUid(namefield)" color="primary" matTooltip="copy UUID" matTooltipPosition="below"> <button mat-button (click)="copyUid(namefield)" color="primary" matTooltip="copy UUID" matTooltipPosition="below">
<mat-icon class="icon-wide2">content_copy</mat-icon> <mat-icon class="icon-wide2">content_copy</mat-icon>
</button> </button>
</form> </form>
</div>
<div [ngSwitch]="resType"> <div [ngSwitch]="resType">
<div *ngSwitchCase = "'HostingNode'"> <div *ngSwitchCase = "'HostingNode'">
<jhi-table-screen></jhi-table-screen> <jhi-table-screen></jhi-table-screen>

View File

@ -21,3 +21,5 @@ Main page styles
background-size: contain; background-size: contain;
} }
} }

View File

@ -63,12 +63,13 @@ export class HomeComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
//questo identifica l'utente e riempie il campo account //questo identifica l'utente e riempie il campo account
this.accountService.identity().subscribe(account => (this.account = account)); this.accountService.identity().subscribe(account => (this.account = account));
//contexts fetched from User
//this.stringCtxs = this.getContexts(); // per la form dei contesti
//console.debug("***stringCtxs..."+this.stringCtxs); this.ctxLoaderService.fetchAll().subscribe(res => {
//contexts fetched from Service this.allCtxs = res;
this.ctxLoaderService.fetchContexts().subscribe(res => this.allCtxs = res); // console.log('*******numero contesti...', this.allCtxs);
console.debug("+++++allCtxs..."+this.allCtxs); });
console.debug("+++++allCtxs..."+this.allCtxs.toString);
this.filteredContexts = this.chooseContextForm.get('namefield').valueChanges.pipe( this.filteredContexts = this.chooseContextForm.get('namefield').valueChanges.pipe(
startWith(''), startWith(''),
map(ctx => (ctx ? this.filterContexts(ctx) : this.allCtxs.slice())) map(ctx => (ctx ? this.filterContexts(ctx) : this.allCtxs.slice()))
@ -77,20 +78,10 @@ export class HomeComponent implements OnInit {
//mettere ANY come tipo dell'argomento per evitare errore TypeScript nella map!! //mettere ANY come tipo dell'argomento per evitare errore TypeScript nella map!!
filterContexts(name: any): IContextNode[] { filterContexts(name: any): IContextNode[] {
//console.log("in filterContext...(name)..."+name);
return this.allCtxs.filter(ctx => ctx.name.toLowerCase().includes(name.toLowerCase())); return this.allCtxs.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()));
}
*/
/*
this.filteredContexts = this.chooseContextForm.get('namefield').valueChanges.pipe(
startWith(''),
map(ctx => (ctx ? this.filterContexts(ctx) : this.contexts.slice()))
);*/
//PER VALIDAZIONE FORM //PER VALIDAZIONE FORM
checkForErrorsIn(formControl: AbstractControl): string { checkForErrorsIn(formControl: AbstractControl): string {
@ -100,18 +91,20 @@ export class HomeComponent implements OnInit {
return ''; return '';
} }
/*
displayFn(ctx: IContextNode): string {
return ctx.name ? ctx.name + ' | ' + ctx.id : '';
}
*/
displayFn(ctx: IContextNode): string {
//return ctx.name ? ctx.name + ' | ' + ctx.id : '';
return ctx.name;
}
/*
displayFn(ctx: string): string { displayFn(ctx: string): string {
const tmp = ctx ? ctx + ' (poi ci va id) ': ''; const tmp = ctx ? ctx + ' (poi ci va id) ': '';
console.log("***"+tmp); console.log("***"+tmp);
return tmp; return tmp;
} }
*/
getContexts(): string[] { getContexts(): string[] {
if (this.account != null && this.account.resourceAccessDTO != null) { if (this.account != null && this.account.resourceAccessDTO != null) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console

View File

@ -15,7 +15,7 @@ export class ContextsLoaderService {
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
fetchContexts(): Observable<IContextNode[]> { fetchAll(): Observable<IContextNode[]> {
return this.http.get<IContextNode[]>(appProperties.BASEURL_API + 'is/allcontexts'); return this.http.get<IContextNode[]>(appProperties.BASEURL_API + 'is/allcontexts');
} }

View File

@ -19,9 +19,10 @@
*/ */
.mat-mdc-form-field { mat-option {
font-size: 14px; font-size: 14px;
width: 100%; width: 100%;
display:block
} }
th.mat-header-cell, td.mat-cell, td.mat-footer-cell{ th.mat-header-cell, td.mat-cell, td.mat-footer-cell{