dnet-applications/frontends/dnet-is-application/src/app/contexts/contexts.component.ts

102 lines
2.8 KiB
TypeScript
Raw Normal View History

2023-02-08 15:36:13 +01:00
import { Component, Inject, AfterViewInit, OnInit, ViewChild } from '@angular/core';
2023-02-01 11:51:23 +01:00
import { ISService } from '../common/is.service';
2023-01-27 11:44:30 +01:00
import { MatTableDataSource } from '@angular/material/table';
2023-02-01 09:58:36 +01:00
import { MatSort } from '@angular/material/sort';
2023-02-01 11:51:23 +01:00
import { Context, ContextParam, ContextNode } from '../common/is.model';
2023-01-27 11:44:30 +01:00
import { ActivatedRoute, Params } from '@angular/router';
import { MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
@Component({
2023-02-08 15:36:13 +01:00
selector: 'app-contexts',
templateUrl: './contexts.component.html',
styleUrls: ['./contexts.component.css']
2023-01-27 11:44:30 +01:00
})
2023-02-08 15:36:13 +01:00
export class ContextsComponent implements AfterViewInit, OnInit {
contextsDatasource: MatTableDataSource<Context> = new MatTableDataSource<Context>([]);
2023-01-27 11:44:30 +01:00
2023-02-08 15:36:13 +01:00
colums: string[] = ['id', 'label', 'type', 'buttons'];
2023-01-27 11:44:30 +01:00
2023-02-08 15:36:13 +01:00
@ViewChild(MatSort) sort: MatSort | undefined
2023-01-27 11:44:30 +01:00
2023-02-08 15:36:13 +01:00
constructor(public service: ISService, public route: ActivatedRoute, public dialog: MatDialog) {
}
2023-01-27 11:44:30 +01:00
2023-02-08 15:36:13 +01:00
ngOnInit() {
this.reload();
}
2023-01-27 11:44:30 +01:00
2023-02-08 15:36:13 +01:00
ngAfterViewInit() {
if (this.sort) this.contextsDatasource.sort = this.sort;
}
2023-01-27 11:44:30 +01:00
2023-02-08 15:36:13 +01:00
reload() {
this.service.loadContexts((data: Context[]) => this.contextsDatasource.data = data);
}
2023-01-27 11:44:30 +01:00
2023-02-08 15:36:13 +01:00
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value.trim().toLowerCase();
this.contextsDatasource.filter = filterValue;
}
showParamsDialog(context: Context): void {
const dialogRef = this.dialog.open(ContextParamsDialog, {
data: context.parameters,
width: '80%'
});
}
2023-01-27 11:44:30 +01:00
}
@Component({
2023-02-08 15:36:13 +01:00
selector: 'context-dialog',
templateUrl: 'context-params-dialog.html',
styleUrls: ['./contexts.component.css']
2023-01-27 11:44:30 +01:00
})
2023-01-27 12:43:15 +01:00
export class ContextParamsDialog {
2023-02-08 15:36:13 +01:00
constructor(public dialogRef: MatDialogRef<ContextParamsDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
}
onNoClick(): void {
this.dialogRef.close();
}
2023-01-27 11:44:30 +01:00
}
@Component({
2023-02-08 15:36:13 +01:00
selector: 'app-context-editor',
templateUrl: './context-viewer.component.html',
styleUrls: ['./contexts.component.css']
2023-01-27 11:44:30 +01:00
})
2023-01-27 15:00:41 +01:00
export class ContextViewerComponent implements OnInit {
2023-02-08 15:36:13 +01:00
context?: Context
categories: ContextNode[] = [];
constructor(public service: ISService, public route: ActivatedRoute, public dialog: MatDialog) {
}
ngOnInit() {
this.route.queryParams.subscribe((params) => {
this.service.loadContext(params['id'], (data: Context) => this.context = data);
this.service.loadContextCategories(params['id'], (data: ContextNode[]) => this.categories = data);
});
}
populateNode(level: number, node: ContextNode): void {
this.service.loadContextConcepts(level, node.id, (data: ContextNode[]) => {
node.populated = true;
node.childs = data
});
}
showParamsDialog(params: ContextParam[] | undefined): void {
if (params) {
this.dialog.open(ContextParamsDialog, {
data: params,
width: '80%'
});
}
}
2023-01-27 11:44:30 +01:00
}