This commit is contained in:
Michele Artini 2023-01-27 11:44:30 +01:00
parent 448bcb4e86
commit 1cb603a83c
20 changed files with 345 additions and 30 deletions

View File

@ -4,12 +4,18 @@ import { InfoComponent } from './info/info.component';
import { ProtocolsComponent } from './protocols/protocols.component';
import { WfHistoryComponent } from './wf-history/wf-history.component';
import { ResourcesComponent } from './resources/resources.component';
import { VocabulariesComponent, VocabularyEditorComponent } from './vocabularies/vocabularies.component';
import { ContextEditorComponent, ContextsComponent } from './contexts/contexts.component';
const routes: Routes = [
{ path:"info" , component:InfoComponent},
{ path:"adv_resources/protocol" , component:ProtocolsComponent},
{ path:"wf_history" , component:WfHistoryComponent},
{ path:"resources/:type" , component:ResourcesComponent}
{ path:"info" , component:InfoComponent },
{ path:"resources/:type" , component:ResourcesComponent },
{ path:"adv_resources/context" , component:ContextsComponent },
{ path:"adv_resources/vocabulary", component:VocabulariesComponent },
{ path:"adv_resources/protocol" , component:ProtocolsComponent },
{ path:"wf_history" , component:WfHistoryComponent },
{ path:"ctx_editor" , component:ContextEditorComponent },
{ path:"voc_editor" , component:VocabularyEditorComponent },
];
@NgModule({

View File

@ -28,6 +28,8 @@ import { MatDialogModule } from '@angular/material/dialog';
import { MatSortModule } from '@angular/material/sort';
import { ResourcesComponent, ResContentDialog, ResCreateNewDialog, ResMetadataDialog } from './resources/resources.component'
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { ContextsComponent, ContextEditorComponent, ContextDialog } from './contexts/contexts.component';
import { VocabulariesComponent, VocabularyEditorComponent } from './vocabularies/vocabularies.component';
@NgModule({
declarations: [
@ -42,7 +44,12 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
ResourcesComponent,
ResContentDialog,
ResCreateNewDialog,
ResMetadataDialog
ResMetadataDialog,
ContextsComponent,
ContextEditorComponent,
ContextDialog,
VocabulariesComponent,
VocabulariesComponent
],
imports: [
BrowserModule,

View File

@ -0,0 +1,35 @@
<form [formGroup]="contextForm" (ngSubmit)="onSubmit()">
<h1 mat-dialog-title *ngIf="mode == 'new'">New context</h1>
<h1 mat-dialog-title *ngIf="mode != 'new'">Edit context</h1>
<div mat-dialog-content>
<mat-form-field appearance="fill" style="width: 100%;">
<mat-label>ID</mat-label>
<input matInput formControlName="id" required [readonly]="mode != 'new'" />
<mat-error *ngIf="contextForm.get('id')?.invalid">This field is <strong>required</strong></mat-error>
</mat-form-field>
<mat-form-field appearance="fill" style="width: 100%;">
<mat-label>Label</mat-label>
<input matInput formControlName="label" required />
<mat-error *ngIf="contextForm.get('label')?.invalid">This field is <strong>required</strong></mat-error>
</mat-form-field>
<mat-form-field appearance="fill" style="width: 100%;">
<mat-label>Type</mat-label>
<input matInput formControlName="type" required />
<mat-error *ngIf="contextForm.get('type')?.invalid">This field is <strong>required</strong></mat-error>
</mat-form-field>
</div>
<div mat-dialog-actions>
<button mat-stroked-button color="primary" type="submit" [disabled]="!contextForm.valid">Submit</button>
<button mat-stroked-button color="primary" mat-dialog-close>Close</button>
<mat-error *ngIf="contextForm.errors?.['serverError']">
{{ contextForm.errors?.['serverError'] }}
</mat-error>
</div>
</form>

View File

@ -0,0 +1 @@
CONTEXT EDITOR

View File

@ -0,0 +1,6 @@
.table-buttons { text-align: right; }
.table-buttons button {
font-size: 0.8em;
padding: 0 !important;
height: 2.5em !important;
}

View File

@ -0,0 +1,45 @@
<h2>Contexts</h2>
<button mat-stroked-button color="primary" (click)="openNewDialog()">create a new context</button>
<mat-form-field style="width: 100%; margin-top: 10px;">
<mat-label>Filter</mat-label>
<input matInput (keyup)="applyFilter($event)" placeholder="Filter..." #input />
</mat-form-field>
<table mat-table [dataSource]="contextsDatasource" matSort class="mat-elevation-z8">
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef style="width: 20%;" mat-sort-header sortActionDescription="Sort by Context ID"> Id </th>
<td mat-cell *matCellDef="let element">
<a [routerLink]="['/ctx_editor']" [queryParams]="{id: element.id}">{{element.id}}</a>
</td>
</ng-container>
<ng-container matColumnDef="label">
<th mat-header-cell *matHeaderCellDef style="width: 40%;" mat-sort-header sortActionDescription="Sort by Context Label"> Label </th>
<td mat-cell *matCellDef="let element"> {{element.label}} </td>
</ng-container>
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef style="width: 10%;" mat-sort-header sortActionDescription="Sort by Context Type"> Type </th>
<td mat-cell *matCellDef="let element"> {{element.type}} </td>
</ng-container>
<ng-container matColumnDef="buttons">
<th mat-header-cell *matHeaderCellDef style="width: 30%;"></th>
<td mat-cell *matCellDef="let element" class="table-buttons">
<button mat-stroked-button color="primary" (click)="openEditDialog(element)">edit</button>
<button mat-stroked-button color="warn" (click)="deleteContext(element)">delete</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="colums"></tr>
<tr mat-row *matRowDef="let row; columns: colums;"></tr>
<!-- Row shown when there is no matching data. -->
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" colspan="4" style="padding: 0 16px;">No data matching the filter "{{input.value}}"</td>
</tr>
</table>

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ContextsComponent } from './contexts.component';
describe('ContextsComponent', () => {
let component: ContextsComponent;
let fixture: ComponentFixture<ContextsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ContextsComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(ContextsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,116 @@
import { Component, Inject,AfterViewInit, OnInit, ViewChild } from '@angular/core';
import { ISService } from '../is.service';
import { MatTableDataSource } from '@angular/material/table';
import { MatSort, Sort } from '@angular/material/sort';
import { Context, WfHistoryEntry } from '../model/controller.model';
import { ActivatedRoute, Params } from '@angular/router';
import { Observable, combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
import { MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { KeyValue } from '../model/controller.model';
import { FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms';
@Component({
selector: 'app-contexts',
templateUrl: './contexts.component.html',
styleUrls: ['./contexts.component.css']
})
export class ContextsComponent implements AfterViewInit ,OnInit {
contextsDatasource: MatTableDataSource<Context> = new MatTableDataSource<Context>([]);
colums: string[] = ['id', 'label', 'type', 'buttons'];
@ViewChild(MatSort) sort: MatSort | undefined
constructor(public service: ISService, public route: ActivatedRoute, public contextDialog: MatDialog) {
}
ngOnInit() {
this.reload();
}
ngAfterViewInit() {
if(this.sort) this.contextsDatasource.sort = this.sort;
}
reload() {
this.service.loadContexts((data: Context[]) => this.contextsDatasource.data = data);
}
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value.trim().toLowerCase();
this.contextsDatasource.filter = filterValue;
}
openNewDialog(): void {
const dialogRef = this.contextDialog.open(ContextDialog, {
data: {},
width: '80%'
});
dialogRef.afterClosed().subscribe(result => {
if (result) this.reload();
});
}
openEditDialog(context: Context): void {
const dialogRef = this.contextDialog.open(ContextDialog, {
data: context,
width: '80%'
});
dialogRef.afterClosed().subscribe(result => {
if (result) this.reload();
});
}
deleteContext(ctx:Context) {
if (confirm('Are you sure?')) {
this.service.deleteContext(ctx.id, (data: void) => this.reload());
}
}
}
@Component({
selector: 'context-dialog',
templateUrl: 'context-dialog.html',
styleUrls: ['./contexts.component.css']
})
export class ContextDialog {
mode:string = 'new';
contextForm = new FormGroup({
id: new FormControl(''),
label: new FormControl(''),
type: new FormControl(''),
});
constructor(public dialogRef: MatDialogRef<ContextDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
if (data && data.id) {
this.mode = 'update';
this.contextForm.get('id')?.setValue(data.id);
this.contextForm.get('label')?.setValue(data.label);
this.contextForm.get('type')?.setValue(data.type);
}
}
onSubmit():void {
const res = Object.assign({}, this.data, this.contextForm.value);
this.service.addContext(res, (data: void) => this.dialogRef.close(1), this.contextForm);
}
onNoClick(): void {
this.dialogRef.close();
}
}
@Component({
selector: 'app-context-editor',
templateUrl: './context-editor.component.html',
styleUrls: ['./contexts.component.css']
})
export class ContextEditorComponent {
}

View File

@ -24,7 +24,7 @@
<!-- Row shown when there is no matching data. -->
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" colspan="2">No data matching the filter "{{input.value}}"</td>
<td class="mat-cell" colspan="2" style="padding: 0 16px;">No data matching the filter "{{input.value}}"</td>
</tr>
</table>
</div>
@ -60,7 +60,7 @@
<!-- Row shown when there is no matching data. -->
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" colspan="4">No data matching the filter "{{input.value}}"</td>
<td class="mat-cell" colspan="4" style="padding: 0 16px;">No data matching the filter "{{input.value}}"</td>
</tr>
</table>
</div>

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { ResourceType,Protocol,WfHistoryEntry,SimpleResource } from './model/controller.model';
import { ResourceType, Protocol, WfHistoryEntry, SimpleResource, Context } from './model/controller.model';
import { Observable, Observer } from 'rxjs';
import { FormGroup } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
@ -10,7 +10,7 @@ import { MatSnackBar } from '@angular/material/snack-bar';
})
export class ISService {
constructor(public client:HttpClient, public snackBar: MatSnackBar) { }
constructor(public client: HttpClient, public snackBar: MatSnackBar) { }
loadResourceTypes(onSuccess: Function): void {
this.client.get<ResourceType[]>("/ajax/resourceTypes").subscribe({
@ -19,7 +19,7 @@ export class ISService {
});
}
loadResourceType(id:string, onSuccess: Function): void {
loadResourceType(id: string, onSuccess: Function): void {
this.client.get<ResourceType>("/ajax/resourceTypes/" + encodeURIComponent(id)).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error)
@ -40,14 +40,14 @@ export class ISService {
});
}
loadSimpleResources(type:string, onSuccess: Function): void {
loadSimpleResources(type: string, onSuccess: Function): void {
this.client.get<SimpleResource[]>("/ajax/resources/" + encodeURIComponent(type)).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error)
});
}
loadSimpleResourceContent(id:any, onSuccess: Function): void {
loadSimpleResourceContent(id: any, onSuccess: Function): void {
const headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
this.client.get<string>("/ajax/resources/" + encodeURIComponent(id) + '/content', {
headers, responseType: 'text' as 'json'
@ -57,14 +57,14 @@ export class ISService {
});
}
saveSimpleResourceMedatata(res:SimpleResource, onSuccess: Function, relatedForm?:FormGroup): void {
saveSimpleResourceMedatata(res: SimpleResource, onSuccess: Function, relatedForm?: FormGroup): void {
this.client.post<void>('/ajax/resources/' + encodeURIComponent(res.id) + '/metadata', res).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error, relatedForm)
});
}
saveSimpleResourceContent(id:string, content:string, onSuccess: Function, relatedForm?:FormGroup): void {
saveSimpleResourceContent(id: string, content: string, onSuccess: Function, relatedForm?: FormGroup): void {
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
let body = new HttpParams().set('content', content);
this.client.post<void>('/ajax/resources/' + encodeURIComponent(id) + '/content', body, { headers: headers }).subscribe({
@ -73,7 +73,7 @@ export class ISService {
});
}
addSimpleResource(name:string, type:string, description:string, content:string, onSuccess: Function, relatedForm?:FormGroup): void {
addSimpleResource(name: string, type: string, description: string, content: string, onSuccess: Function, relatedForm?: FormGroup): void {
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
let body = new HttpParams()
.set('name', name)
@ -82,30 +82,51 @@ export class ISService {
.set('content', content);
this.client.post<void>('/ajax/resources/', body, { headers: headers }).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error, relatedForm)
error: error => this.showError(error, relatedForm)
});
}
deleteSimpleResource(res:SimpleResource, onSuccess: Function): void {
this.client.delete<void>('/ajax/resources/' + encodeURIComponent(res.id)).subscribe({
deleteSimpleResource(resourceId: string, onSuccess: Function): void {
this.client.delete<void>('/ajax/resources/' + encodeURIComponent(resourceId)).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error)
});
}
loadWfHistory(total:number, from:number, to:number, onSuccess: Function): void {
loadWfHistory(total: number, from: number, to: number, onSuccess: Function): void {
let params = new HttpParams();
if (total && total > 0) { params = params.append('total', total); }
if (from && from > 0) { params = params.append('from', from); }
if (to && to > 0) { params = params.append('to', to); }
this.client.get<WfHistoryEntry[]>('/ajax/wfs/', {params: params}).subscribe({
if (from && from > 0) { params = params.append('from', from); }
if (to && to > 0) { params = params.append('to', to); }
this.client.get<WfHistoryEntry[]>('/ajax/wfs/', { params: params }).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error)
});
}
}
private showError(error:any, form?:FormGroup) {
loadContexts(onSuccess: Function): void {
this.client.get<Context[]>('./ajax/contexts/').subscribe({
next: data => onSuccess(data),
error: error => this.showError(error)
});
}
addContext(context: Context, onSuccess: Function, relatedForm?: FormGroup): void {
this.client.post<void>('/ajax/contexts/', context).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error, relatedForm)
});
}
deleteContext(contextId: string, onSuccess: Function): void {
this.client.delete<void>('/ajax/contexts/' + encodeURIComponent(contextId)).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error)
});
}
private showError(error: any, form?: FormGroup) {
const msg = this.errorMessage(error);
if (form) {
form.setErrors({ serverError: msg })
@ -118,7 +139,7 @@ export class ISService {
}
}
private errorMessage(error:any) {
private errorMessage(error: any) {
if (error.error && error.error.message) {
return error.error.message;
} else if (error.message) {

View File

@ -52,3 +52,16 @@ export interface SimpleResource {
creationDate?: string,
modificationDate?: string
}
export interface ContextParam {
name: string,
value: string
}
export interface Context {
id: string,
label: string,
parameters: ContextParam[],
nChilds: number,
type: string
}

View File

@ -78,7 +78,7 @@ export class ResourcesComponent implements OnInit {
deleteResource(r:SimpleResource) {
if (confirm('Are you sure?')) {
this.service.deleteSimpleResource(r, (data: void) => this.reload());
this.service.deleteSimpleResource(r.id, (data: void) => this.reload());
}
}
}

View File

@ -0,0 +1 @@
<p>vocabularies works!</p>

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { VocabulariesComponent } from './vocabularies.component';
describe('VocabulariesComponent', () => {
let component: VocabulariesComponent;
let fixture: ComponentFixture<VocabulariesComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ VocabulariesComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(VocabulariesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,19 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-vocabularies',
templateUrl: './vocabularies.component.html',
styleUrls: ['./vocabularies.component.css']
})
export class VocabulariesComponent {
}
@Component({
selector: 'app-vocabulary-editor',
templateUrl: './vocabulary-editor.component.html',
styleUrls: ['./vocabularies.component.css']
})
export class VocabularyEditorComponent {
}

View File

@ -29,7 +29,7 @@
<!-- Row shown when there is no matching data. -->
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" colspan="2">No data matching the filter "{{filterParams.value}}"</td>
<td class="mat-cell" colspan="2" style="padding: 0 16px;">No data matching the filter "{{filterParams.value}}"</td>
</tr>
</table>

View File

@ -61,6 +61,6 @@
<!-- Row shown when there is no matching data. -->
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" colspan="4">No data matching the filter "{{input.value}}"</td>
<td class="mat-cell" colspan="4" style="padding: 0 16px;">No data matching the filter "{{input.value}}"</td>
</tr>
</table>

View File

@ -50,7 +50,6 @@ export class WfHistoryComponent implements AfterViewInit , OnInit{
if(this.sort) this.historyDatasource.sort = this.sort;
}
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value.trim().toLowerCase();
this.historyDatasource.filter = filterValue;