work in progress...

This commit is contained in:
Maria Teresa Paratore 2023-10-13 19:40:12 +02:00
parent cf12b842b3
commit afcd47eac4
7 changed files with 84 additions and 14 deletions

View File

@ -1,4 +1,4 @@
<h2 class="display-8" id="tree-title"><span>Available contexts</span></h2> <h2 class="display-8" id="tree-title"><span>Available Resources</span></h2>
<mat-tree [dataSource]="nestedDataSource" [treeControl]="nestedTreeControl" class="example-tree"> <mat-tree [dataSource]="nestedDataSource" [treeControl]="nestedTreeControl" class="example-tree">
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle> <mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
<button mat-button (click)="loadTable(node)"> <button mat-button (click)="loadTable(node)">

View File

@ -25,7 +25,7 @@
* This padding sets alignment of the nested nodes. * This padding sets alignment of the nested nodes.
*/ */
.example-tree .mat-nested-tree-node div[role='group'] { .example-tree .mat-nested-tree-node div[role='group'] {
padding-left: 40px; padding-left: 25px;
} }
/* /*
@ -34,5 +34,5 @@
* under the same parent. * under the same parent.
*/ */
.example-tree div[role='group'] > .mat-tree-node { .example-tree div[role='group'] > .mat-tree-node {
padding-left: 40px; padding-left: 25px;
} }

View File

@ -1,33 +1,34 @@
import { Component , OnInit } from '@angular/core'; import { Component , OnInit } from '@angular/core';
import { MatTreeNestedDataSource } from '@angular/material/tree'; import { MatTreeNestedDataSource } from '@angular/material/tree';
import { NestedTreeControl } from '@angular/cdk/tree'; import { NestedTreeControl } from '@angular/cdk/tree';
import { IContextNode } from 'app/services/i-context-node'; //import { IContextNode } from 'app/services/i-context-node';
import { MockCtxloaderService } from 'app/services/mock-ctxloader.service'; import { IResource } from 'app/services/i-resource';
import { ResourcesLoaderService } from 'app/services/resources-loader.service';
@Component({ @Component({
selector: 'jhi-ctx-tree', selector: 'jhi-ctx-tree',
templateUrl: './ctx-tree.component.html', templateUrl: './ctx-tree.component.html',
styleUrls: ['./ctx-tree.component.scss'], styleUrls: ['./ctx-tree.component.scss'],
providers: [MockCtxloaderService], providers: [ResourcesLoaderService],
}) })
export class CtxTreeComponent implements OnInit { export class CtxTreeComponent implements OnInit {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return // eslint-disable-next-line @typescript-eslint/no-unsafe-return
nestedTreeControl = new NestedTreeControl<IContextNode>(node => node.children); nestedTreeControl = new NestedTreeControl<IResource>(node => node.children);
nestedDataSource = new MatTreeNestedDataSource<IContextNode>(); nestedDataSource = new MatTreeNestedDataSource<IResource>();
tmp: IContextNode ; tmp: IResource ;
showTable: boolean; showTable: boolean;
constructor(private myService:MockCtxloaderService) { constructor(private myService:ResourcesLoaderService) {
this.tmp = {} as IContextNode; this.tmp = {} as IResource;
this.showTable = false; this.showTable = false;
} }
hasNestedChild(_: number, node: IContextNode): boolean { hasNestedChild(_: number, node: IResource): boolean {
if (node.children == null) { if (node.children == null) {
return false; return false;
} else { } else {
@ -36,12 +37,12 @@ export class CtxTreeComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.myService.getData().subscribe(res => { this.myService.getResourcesByContext().subscribe(res => {
this.nestedDataSource.data = res; this.nestedDataSource.data = res;
}); });
} }
loadTable(choosenContext:IContextNode):boolean{ loadTable(choosenContext:IResource):boolean{
//TODO: qui va chiamato il componente hnodes-table e conseguentemente visualizzato //TODO: qui va chiamato il componente hnodes-table e conseguentemente visualizzato
this.showTable = true; this.showTable = true;
return this.showTable; return this.showTable;

View File

@ -0,0 +1,4 @@
<h2 *ngIf="chosenId" id="detail-title">Raw JSON for UID: {{ chosenId }}</h2>
<div class="bg-light">
<pre>{{ fetchedRawData | json }}</pre>
</div>

View File

@ -0,0 +1,26 @@
import { CommonModule } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core';
import { ResourcesLoaderService } from 'app/services/resources-loader.service';
@Component({
standalone: true,
imports: [CommonModule],
selector: 'jhi-rawjson-pane',
templateUrl: './rawjson-pane.component.html',
styleUrls: ['./rawjson-pane.component.scss'],
providers: [ResourcesLoaderService],
})
export class RawjsonPaneComponent implements OnInit {
@Input() chosenId: string;
fetchedRawData: string;
constructor(private service: ResourcesLoaderService) {
this.fetchedRawData = '';
this.chosenId = '';
}
ngOnInit(): void {
//TODO: passare al servizio qui sotto: chosenItem.id come parametro rest
this.service.getJsonDetail(this.chosenId).subscribe(res => {
this.fetchedRawData = res;
});
}
}

View File

@ -0,0 +1,39 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { IHostingnode } from './i-hostinngnode';
import { IResource } from './i-resource';
@Injectable({
providedIn: 'root',
})
export class ResourcesLoaderService {
httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
constructor(private http: HttpClient) {}
//TODO: a regime questo metodo prende un parametro nella get
getHostingNodes(): Observable<IHostingnode[]> {
//TODO: pipe per gestione errori
return this.http.get<IHostingnode[]>('http://localhost:3002/is/hostingnodes/all');
}
getResourcesByContext(): Observable<IResource[]> {
//TODO: pipe per gestione errori
return this.http.get<IResource[]>('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<string> {
//TODO: pipe per gestione errori
return this.http.get<string>('http://localhost:3002/is/hostingnodes/detail');
}
getHostingNodeDetail(): Observable<string> {
//TODO: pipe per gestione errori
return this.http.get<string>('http://localhost:3002/is/hostingnodes/detail');
}
}