error server side
This commit is contained in:
parent
8ec682096a
commit
7235e4ad4e
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
|
@ -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' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -58,8 +58,6 @@ export class ISService {
|
||||||
return this.client.post<void>('/ajax/resources/', body, { headers: headers });
|
return this.client.post<void>('/ajax/resources/', body, { headers: headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deleteSimpleResource(res:SimpleResource):Observable<void> {
|
deleteSimpleResource(res:SimpleResource):Observable<void> {
|
||||||
return this.client.delete<void>('/ajax/resources/' + encodeURIComponent(res.id));
|
return this.client.delete<void>('/ajax/resources/' + encodeURIComponent(res.id));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ export interface ResourceType {
|
||||||
export interface KeyValue {
|
export interface KeyValue {
|
||||||
k: string;
|
k: string;
|
||||||
v: string;
|
v: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Module {
|
export interface Module {
|
||||||
group: string;
|
group: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
<div mat-dialog-actions>
|
<div mat-dialog-actions>
|
||||||
<button mat-stroked-button color="primary" type="submit" [disabled]="!contentForm.valid">Submit</button>
|
<button mat-stroked-button color="primary" type="submit" [disabled]="!contentForm.valid">Submit</button>
|
||||||
<button mat-stroked-button color="primary" mat-dialog-close>Close</button>
|
<button mat-stroked-button color="primary" mat-dialog-close>Close</button>
|
||||||
|
<mat-error *ngIf="contentForm.errors?.['serverError']">
|
||||||
|
{{ contentForm.errors?.['serverError'] }}
|
||||||
|
</mat-error>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
<div mat-dialog-actions>
|
<div mat-dialog-actions>
|
||||||
<button mat-stroked-button color="primary" type="submit" [disabled]="!metadataForm.valid">Submit</button>
|
<button mat-stroked-button color="primary" type="submit" [disabled]="!metadataForm.valid">Submit</button>
|
||||||
<button mat-stroked-button color="primary" mat-dialog-close>Close</button>
|
<button mat-stroked-button color="primary" mat-dialog-close>Close</button>
|
||||||
|
<mat-error *ngIf="metadataForm.errors?.['serverError']">
|
||||||
|
{{ metadataForm.errors?.['serverError'] }}
|
||||||
|
</mat-error>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
<div mat-dialog-actions>
|
<div mat-dialog-actions>
|
||||||
<button mat-stroked-button color="primary" type="submit" [disabled]="!newResourceForm.valid">Submit</button>
|
<button mat-stroked-button color="primary" type="submit" [disabled]="!newResourceForm.valid">Submit</button>
|
||||||
<button mat-stroked-button color="primary" mat-dialog-close>Close</button>
|
<button mat-stroked-button color="primary" mat-dialog-close>Close</button>
|
||||||
|
<mat-error *ngIf="newResourceForm.errors?.['serverError']">
|
||||||
|
{{ newResourceForm.errors?.['serverError'] }}
|
||||||
|
</mat-error>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Component, Inject,AfterViewInit, ViewChild, OnInit } from '@angular/core';
|
import { Component, Inject,AfterViewInit, ViewChild, OnInit } from '@angular/core';
|
||||||
import { ISService } from '../is.service';
|
import { ISService } from '../is.service';
|
||||||
|
import { IsUtilsService } from '../is-utils.service';
|
||||||
import { MatTableDataSource } from '@angular/material/table';
|
import { MatTableDataSource } from '@angular/material/table';
|
||||||
import { MatSort, Sort } from '@angular/material/sort';
|
import { MatSort, Sort } from '@angular/material/sort';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
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 {FormControl, FormGroup, FormGroupDirective, NgForm, Validators} from '@angular/forms';
|
||||||
import { ResourceLoader } from '@angular/compiler';
|
import { ResourceLoader } from '@angular/compiler';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-resources',
|
selector: 'app-resources',
|
||||||
templateUrl: './resources.component.html',
|
templateUrl: './resources.component.html',
|
||||||
|
@ -116,7 +116,7 @@ export class ResContentDialog {
|
||||||
content : this.contentFormControl
|
content : this.contentFormControl
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(public dialogRef: MatDialogRef<ResContentDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
|
constructor(public dialogRef: MatDialogRef<ResContentDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService, public utils: IsUtilsService) {
|
||||||
this.contentFormControl.setValue(data.content);
|
this.contentFormControl.setValue(data.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ export class ResContentDialog {
|
||||||
next: (data: void) => {
|
next: (data: void) => {
|
||||||
this.dialogRef.close(1)
|
this.dialogRef.close(1)
|
||||||
},
|
},
|
||||||
error: error => console.log(error),
|
error: error => this.utils.prepareFormError(error, this.contentForm),
|
||||||
complete: () => console.log("Completed")
|
complete: () => console.log("Completed")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ export class ResMetadataDialog {
|
||||||
description : new FormControl('')
|
description : new FormControl('')
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(public dialogRef: MatDialogRef<ResMetadataDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
|
constructor(public dialogRef: MatDialogRef<ResMetadataDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService, public utils: IsUtilsService) {
|
||||||
this.metadataForm.get('name')?.setValue(data.name);
|
this.metadataForm.get('name')?.setValue(data.name);
|
||||||
if (data.description) {
|
if (data.description) {
|
||||||
this.metadataForm.get('description')?.setValue(data.description);
|
this.metadataForm.get('description')?.setValue(data.description);
|
||||||
|
@ -163,7 +163,7 @@ export class ResMetadataDialog {
|
||||||
next: (data: void) => {
|
next: (data: void) => {
|
||||||
this.dialogRef.close(1)
|
this.dialogRef.close(1)
|
||||||
},
|
},
|
||||||
error: error => console.log(error),
|
error: error => this.utils.prepareFormError(error, this.metadataForm),
|
||||||
complete: () => console.log("Completed")
|
complete: () => console.log("Completed")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ export class ResCreateNewDialog {
|
||||||
content : new FormControl('')
|
content : new FormControl('')
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(public dialogRef: MatDialogRef<ResCreateNewDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {}
|
constructor(public dialogRef: MatDialogRef<ResCreateNewDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService, public utils: IsUtilsService) {}
|
||||||
|
|
||||||
onSubmit():void {
|
onSubmit():void {
|
||||||
let name:string = this.newResourceForm.get('name')?.value!;
|
let name:string = this.newResourceForm.get('name')?.value!;
|
||||||
|
@ -197,7 +197,7 @@ export class ResCreateNewDialog {
|
||||||
next: (data: void) => {
|
next: (data: void) => {
|
||||||
this.dialogRef.close(1)
|
this.dialogRef.close(1)
|
||||||
},
|
},
|
||||||
error: error => console.log(error),
|
error: error => this.utils.prepareFormError(error, this.newResourceForm),
|
||||||
complete: () => console.log("Completed")
|
complete: () => console.log("Completed")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,4 +72,10 @@ th, td {
|
||||||
|
|
||||||
.badge-info {
|
.badge-info {
|
||||||
background-color: cornflowerblue
|
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;
|
||||||
}
|
}
|
Loading…
Reference in New Issue