Fully resource agnostic jsonschemas interpreter

This commit is contained in:
2023-01-18 16:04:01 +01:00
parent 6ccbb8ac00
commit 15f101eb9f
4 changed files with 114 additions and 31 deletions

View File

@@ -6,6 +6,7 @@ import { Router } from '@angular/router';
import { CrudService } from '../crud.service'
import {BehaviorSubject} from "rxjs";
import {JsonschemasService} from "../jsonschemas.service";
export interface Model {
email: string;
@@ -32,45 +33,44 @@ export class CardComponent implements OnInit {
}
constructor(private crudService: CrudService,
private jsonSchemasService: JsonschemasService,
private formlyJsonschema: FormlyJsonschema,
private router: Router
) { }
ngOnInit(): void {
this._loading$.next(true);
this.crudService.getSchema().subscribe((jsonSchemas: any) => {
this.schemas = jsonSchemas.components.schemas.EntityCreate
this.schemas.components = {
schemas: {
EntityType: jsonSchemas.components.schemas.EntityType
ngOnInit(): void {
this._loading$.next(true);
if (this.isCreateForm()) {
this.jsonSchemasService.getCreateResource(this.resource).subscribe((schemas: any) => {
this.fields = [this.formlyJsonschema.toFieldConfig(schemas)];
})
} else {
this.jsonSchemasService.getUpdateResource(this.resource).subscribe((schemas: any) => {
this.fields = [this.formlyJsonschema.toFieldConfig(schemas)];
})
this.crudService.get(this.resource_id!).subscribe((model: any) => {
this.model = model
this._loading$.next(false);
});
}
};
this.fields = [this.formlyJsonschema.toFieldConfig(this.schemas)];
});
if (this.resource_id !== null) {
this.crudService.get(this.resource_id!).subscribe((model: any) => {
this.model = model
});
this._loading$.next(false);
}
}
onSubmit(model: any) {
this._loading$.next(true);
if (this.resource_id !== null) {
this.crudService.update(model).subscribe((model: any) => {
this.model = model;
this._loading$.next(false);
});
} else {
if (this.isCreateForm()) {
this.crudService.create(model).subscribe((response: any) => {
this._loading$.next(false);
this.router.navigateByUrl('/entities/' + response.id);
});
} else {
this.crudService.update(model).subscribe((model: any) => {
this.model = model;
this._loading$.next(false);
});
}
console.log(model);
}
isCreateForm() {
return this.resource_id === null;
}
}