Fully resource agnostic jsonschemas interpreter
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user