From c4360a6ddb920bcb8a9daa10ea0263e927f60ea8 Mon Sep 17 00:00:00 2001 From: mariateresa Date: Wed, 27 Sep 2023 17:17:31 +0200 Subject: [PATCH] adding tabbed view (work in progress)... --- src/main/webapp/app/i-tabbed-entity.ts | 7 +++ .../webapp/app/services/i-context-node.ts | 3 +- .../table-screen/table-screen.component.html | 46 +++++------------- .../table-screen/table-screen.component.ts | 47 +++++++++++++------ 4 files changed, 53 insertions(+), 50 deletions(-) create mode 100644 src/main/webapp/app/i-tabbed-entity.ts 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..e20a5d2 --- /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 + type: number; +} diff --git a/src/main/webapp/app/services/i-context-node.ts b/src/main/webapp/app/services/i-context-node.ts index 3f2eb90..d6dbbc9 100644 --- a/src/main/webapp/app/services/i-context-node.ts +++ b/src/main/webapp/app/services/i-context-node.ts @@ -4,7 +4,7 @@ export interface IContextNode { id: string; children?: IContextNode[]; } - +/* export class ContextNode implements IContextNode { parent: string; name: string; @@ -18,3 +18,4 @@ export class ContextNode implements IContextNode { this.children = children; } } +*/ diff --git a/src/main/webapp/app/table-screen/table-screen.component.html b/src/main/webapp/app/table-screen/table-screen.component.html index 2936c4d..661e314 100644 --- a/src/main/webapp/app/table-screen/table-screen.component.html +++ b/src/main/webapp/app/table-screen/table-screen.component.html @@ -37,17 +37,16 @@ - - - - + Actions + + - + - + No data matching the filter "{{ input.value }}" @@ -56,39 +55,18 @@
- - - + - + + -
{{ tab.name }}
-
- - -
Case 2
-
Case 1
-
Default
-
+ {{ tab.content }}
-
+ diff --git a/src/main/webapp/app/table-screen/table-screen.component.ts b/src/main/webapp/app/table-screen/table-screen.component.ts index 122e4e1..73f88ad 100644 --- a/src/main/webapp/app/table-screen/table-screen.component.ts +++ b/src/main/webapp/app/table-screen/table-screen.component.ts @@ -21,6 +21,7 @@ import { SharedModule } from 'app/shared/shared.module'; import { IContextNode } from 'app/services/i-context-node'; import { MatPaginator, MatPaginatorModule, PageEvent } from '@angular/material/paginator'; import { MatTab, MatTabGroup } from '@angular/material/tabs'; +import { ITabbedEntity } from 'app/i-tabbed-entity'; @Component({ standalone: true, @@ -48,9 +49,9 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges { public tabGroup: MatTabGroup | any; public tabNodes: QueryList | any; public closedTabs = []; - public tabs = ['Main']; + public tabs: ITabbedEntity[] = [{ title: 'JSON View', content: '', type: 0, id: '' }]; selectedIdx = 0; - + chosenIds: string[] = []; ////////// fine tabbed view constructor(private myDataService: ResourcesLoaderService) { @@ -74,8 +75,7 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges { } ngOnChanges(changes: SimpleChanges): void { - // eslint-disable-next-line no-console - console.log('---NELLA ONCHANGES...' + this.myCtx.name); + // console.log('---NELLA ONCHANGES...' + this.myCtx.name); for (const propName in changes) { if (propName === 'myCtx') { const param = changes[propName]; @@ -98,24 +98,41 @@ export class TableScreenComponent implements OnInit, AfterViewInit, OnChanges { } // per tabbed pane (versione con aggiunta dinamica) - /* - - removeTab(index: number):void { + removeTab(index: number): void { this.tabs.splice(index, 1); } - */ - addTab(selectAfterAdding: boolean): void { - console.debug('--------CISIAMO------'); - this.selectedIdx++; - alert('ciao'); - this.tabs.push('New'); - //this.setValue(this.tabs.length - 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.tabNodes.length - 1; + this.tabGroup.selectedIndex = this.tabs.length - 1; + //this.chosenIds.indexOf(); + this.tabs.splice(index, 1); } }