Files
cht-lawfirm/front/app/src/common/crud/card/card.component.ts

72 lines
1.8 KiB
TypeScript

import {Component, Input, OnInit} from '@angular/core';
import { FormGroup } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core'
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
import { CrudService } from '../crud.service'
import {ParamMap} from "@angular/router";
import {BehaviorSubject} from "rxjs";
export interface Model {
email: string;
}
@Component({
selector: 'crud-card',
templateUrl: './card.component.html',
styleUrls: ['./card.component.css']
})
export class CardComponent implements OnInit {
@Input() resource_id: string | null = null;
form = new FormGroup({});
model = {};
fields: FormlyFieldConfig[] = [];
resource: string = "Entity";
schemas = JSON.parse(`{}`);
private _loading$ = new BehaviorSubject<boolean>(true);
get loading$() {
return this._loading$.asObservable();
}
constructor(private crudService: CrudService,
private formlyJsonschema: FormlyJsonschema
) {
}
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
}
};
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);
this.crudService.update(model).subscribe((model: any) => {
this.model = model
this._loading$.next(false);
})
console.log(model);
}
}