Fully generic CRUD pages

This commit is contained in:
2023-01-18 19:43:13 +01:00
parent 15f101eb9f
commit ddb3706e44
9 changed files with 84 additions and 62 deletions

View File

@@ -18,11 +18,11 @@ export interface Model {
styleUrls: ['./card.component.css']
})
export class CardComponent implements OnInit {
@Input() resource: string | undefined;
@Input() resource_id: string | null = null;
form = new FormGroup({});
model = {};
fields: FormlyFieldConfig[] = [];
resource: string = "Entity";
schemas = JSON.parse(`{}`);
@@ -41,14 +41,14 @@ export class CardComponent implements OnInit {
ngOnInit(): void {
this._loading$.next(true);
if (this.isCreateForm()) {
this.jsonSchemasService.getCreateResource(this.resource).subscribe((schemas: any) => {
this.jsonSchemasService.getCreateResource(this.resource!).subscribe((schemas: any) => {
this.fields = [this.formlyJsonschema.toFieldConfig(schemas)];
})
} else {
this.jsonSchemasService.getUpdateResource(this.resource).subscribe((schemas: any) => {
this.jsonSchemasService.getUpdateResource(this.resource!).subscribe((schemas: any) => {
this.fields = [this.formlyJsonschema.toFieldConfig(schemas)];
})
this.crudService.get(this.resource_id!).subscribe((model: any) => {
this.crudService.get(this.resource!, this.resource_id!).subscribe((model: any) => {
this.model = model
this._loading$.next(false);
});
@@ -58,12 +58,12 @@ export class CardComponent implements OnInit {
onSubmit(model: any) {
this._loading$.next(true);
if (this.isCreateForm()) {
this.crudService.create(model).subscribe((response: any) => {
this.crudService.create(this.resource!, model).subscribe((response: any) => {
this._loading$.next(false);
this.router.navigateByUrl('/entities/' + response.id);
this.router.navigateByUrl(response.id);
});
} else {
this.crudService.update(model).subscribe((model: any) => {
this.crudService.update(this.resource!, model).subscribe((model: any) => {
this.model = model;
this._loading$.next(false);
});