loading draft from template

This commit is contained in:
2023-02-12 20:12:19 +01:00
parent 57a282b004
commit 7c34c2ba91
7 changed files with 130 additions and 23 deletions

View File

@@ -17,9 +17,22 @@ export class CardComponent implements OnInit {
@Input() resource: string | undefined;
@Input() resource_id: string | null = null;
@Input() schema: string | undefined;
@Input() model = {};
@Input() is_modal: Boolean = false;
private _model: {} = {};
@Input() set model(value: any) {
this._model = value;
if (Object.keys(this.form.controls).length) {
delete value._id;
this.form.patchValue(value);
}
}
get model(): any {
return this._model;
}
@Output() resourceCreated: EventEmitter<string> = new EventEmitter();
@Output() resourceUpdated: EventEmitter<string> = new EventEmitter();
@Output() resourceDeleted: EventEmitter<string> = new EventEmitter();
@@ -91,6 +104,7 @@ export class CardComponent implements OnInit {
error: (err) => this.error.emit("Error creating the entity:" + err)
});
} else {
model._id = this.resource_id;
this.crudService.update(this.resource!, model).subscribe( {
next: (model: any) => {
this.model = model;

View File

@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import {FieldType, FieldTypeConfig, FormlyFieldConfig, FormlyFormOptions} from '@ngx-formly/core';
import {FormControl, FormGroup, FormArray} from "@angular/forms";
import { FieldType, FieldTypeConfig, FormlyFieldConfig } from '@ngx-formly/core';
import { FormGroup } from "@angular/forms";
import {DictionaryService} from "./dictionary.service";
import {JSONSchema7} from "json-schema";
import {FormlyJsonschema} from "@ngx-formly/core/json-schema";
@@ -58,7 +58,10 @@ export class DictionaryTypeComponent extends FieldType<FieldTypeConfig> implemen
this.parameterFields = [this.formlyJsonschema.toFieldConfig(
this.getFormSchema(parameters)
)];
this.parameterForm.setValue(this.parameterModel, {emitEvent: false});
if (Object.keys(this.parameterForm.controls).length) {
this.parameterForm.setValue(this.parameterModel, {emitEvent: false});
}
});
this.parameterForm.valueChanges.subscribe((values) => {
@@ -70,6 +73,12 @@ export class DictionaryTypeComponent extends FieldType<FieldTypeConfig> implemen
}
this.formControl.setValue(formValue)
})
this.formControl.valueChanges.subscribe((values) => {
for (const entry of values) {
this.parameterModel[entry.key] = entry.value;
}
})
}
getFormSchema(properties: string[]) {
@@ -92,6 +101,4 @@ export class DictionaryTypeComponent extends FieldType<FieldTypeConfig> implemen
return schema
}
}