diff --git a/frontends/dnet-is-application/src/app/is-utils.service.spec.ts b/frontends/dnet-is-application/src/app/is-utils.service.spec.ts new file mode 100644 index 00000000..d2561a49 --- /dev/null +++ b/frontends/dnet-is-application/src/app/is-utils.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { IsUtilsService } from './is-utils.service'; + +describe('IsUtilsService', () => { + let service: IsUtilsService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(IsUtilsService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontends/dnet-is-application/src/app/is-utils.service.ts b/frontends/dnet-is-application/src/app/is-utils.service.ts new file mode 100644 index 00000000..905a2e50 --- /dev/null +++ b/frontends/dnet-is-application/src/app/is-utils.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { FormGroup } from '@angular/forms'; + +@Injectable({ + providedIn: 'root' +}) +export class IsUtilsService { + + constructor() { } + + prepareFormError(error:any, form:FormGroup): void { + if (error.error && error.error.message) { + form.setErrors({ serverError: error.error.message }) + } else if (error.message) { + form.setErrors({ serverError: error.message }) + } else { + form.setErrors({ serverError: 'Generic server side error' }) + } + } + +} diff --git a/frontends/dnet-is-application/src/app/is.service.ts b/frontends/dnet-is-application/src/app/is.service.ts index 4921b206..f792625e 100644 --- a/frontends/dnet-is-application/src/app/is.service.ts +++ b/frontends/dnet-is-application/src/app/is.service.ts @@ -58,8 +58,6 @@ export class ISService { return this.client.post('/ajax/resources/', body, { headers: headers }); } - - deleteSimpleResource(res:SimpleResource):Observable { return this.client.delete('/ajax/resources/' + encodeURIComponent(res.id)); } diff --git a/frontends/dnet-is-application/src/app/model/controller.model.ts b/frontends/dnet-is-application/src/app/model/controller.model.ts index 80a686e4..c9172a49 100644 --- a/frontends/dnet-is-application/src/app/model/controller.model.ts +++ b/frontends/dnet-is-application/src/app/model/controller.model.ts @@ -9,8 +9,8 @@ export interface ResourceType { export interface KeyValue { k: string; v: string; - } - +} + export interface Module { group: string; name: string; diff --git a/frontends/dnet-is-application/src/app/resources/content-dialog.html b/frontends/dnet-is-application/src/app/resources/content-dialog.html index 34484367..dea62e9d 100644 --- a/frontends/dnet-is-application/src/app/resources/content-dialog.html +++ b/frontends/dnet-is-application/src/app/resources/content-dialog.html @@ -19,6 +19,9 @@
+ + {{ contentForm.errors?.['serverError'] }} +
diff --git a/frontends/dnet-is-application/src/app/resources/metadata-dialog.html b/frontends/dnet-is-application/src/app/resources/metadata-dialog.html index 11790198..c5afdd28 100644 --- a/frontends/dnet-is-application/src/app/resources/metadata-dialog.html +++ b/frontends/dnet-is-application/src/app/resources/metadata-dialog.html @@ -28,6 +28,9 @@
+ + {{ metadataForm.errors?.['serverError'] }} +
diff --git a/frontends/dnet-is-application/src/app/resources/new-dialog.html b/frontends/dnet-is-application/src/app/resources/new-dialog.html index 3c5934e9..c8c66a46 100644 --- a/frontends/dnet-is-application/src/app/resources/new-dialog.html +++ b/frontends/dnet-is-application/src/app/resources/new-dialog.html @@ -25,6 +25,9 @@
+ + {{ newResourceForm.errors?.['serverError'] }} +
diff --git a/frontends/dnet-is-application/src/app/resources/resources.component.ts b/frontends/dnet-is-application/src/app/resources/resources.component.ts index 76bdd418..f1fca58e 100644 --- a/frontends/dnet-is-application/src/app/resources/resources.component.ts +++ b/frontends/dnet-is-application/src/app/resources/resources.component.ts @@ -1,5 +1,6 @@ import { Component, Inject,AfterViewInit, ViewChild, OnInit } from '@angular/core'; import { ISService } from '../is.service'; +import { IsUtilsService } from '../is-utils.service'; import { MatTableDataSource } from '@angular/material/table'; import { MatSort, Sort } from '@angular/material/sort'; import { ActivatedRoute } from '@angular/router'; @@ -10,7 +11,6 @@ import { ResourceType, SimpleResource } from '../model/controller.model'; import {FormControl, FormGroup, FormGroupDirective, NgForm, Validators} from '@angular/forms'; import { ResourceLoader } from '@angular/compiler'; - @Component({ selector: 'app-resources', templateUrl: './resources.component.html', @@ -116,7 +116,7 @@ export class ResContentDialog { content : this.contentFormControl }); - constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) { + constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService, public utils: IsUtilsService) { this.contentFormControl.setValue(data.content); } @@ -127,7 +127,7 @@ export class ResContentDialog { next: (data: void) => { this.dialogRef.close(1) }, - error: error => console.log(error), + error: error => this.utils.prepareFormError(error, this.contentForm), complete: () => console.log("Completed") }); } @@ -149,7 +149,7 @@ export class ResMetadataDialog { description : new FormControl('') }); - constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) { + constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService, public utils: IsUtilsService) { this.metadataForm.get('name')?.setValue(data.name); if (data.description) { this.metadataForm.get('description')?.setValue(data.description); @@ -163,7 +163,7 @@ export class ResMetadataDialog { next: (data: void) => { this.dialogRef.close(1) }, - error: error => console.log(error), + error: error => this.utils.prepareFormError(error, this.metadataForm), complete: () => console.log("Completed") }); } @@ -185,7 +185,7 @@ export class ResCreateNewDialog { content : new FormControl('') }); - constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {} + constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService, public utils: IsUtilsService) {} onSubmit():void { let name:string = this.newResourceForm.get('name')?.value!; @@ -197,7 +197,7 @@ export class ResCreateNewDialog { next: (data: void) => { this.dialogRef.close(1) }, - error: error => console.log(error), + error: error => this.utils.prepareFormError(error, this.newResourceForm), complete: () => console.log("Completed") }); } diff --git a/frontends/dnet-is-application/src/styles.css b/frontends/dnet-is-application/src/styles.css index f08e01a5..56a89aba 100644 --- a/frontends/dnet-is-application/src/styles.css +++ b/frontends/dnet-is-application/src/styles.css @@ -72,4 +72,10 @@ th, td { .badge-info { background-color: cornflowerblue +} + +.mat-mdc-dialog-actions .mat-mdc-form-field-error { + margin-left: 2em !important; + margin-right: 2em !important; + font-size: 0.75em !important; } \ No newline at end of file