loading draft from template
This commit is contained in:
@@ -56,6 +56,7 @@ class ProvisionTemplateReference(BaseModel):
|
||||
class ContractTemplate(CrudDocument):
|
||||
name: str
|
||||
title: str
|
||||
label: str = ""
|
||||
parties: List[PartyTemplate] = []
|
||||
provisions: List[ProvisionTemplateReference] = Field(
|
||||
default=[],
|
||||
@@ -65,3 +66,10 @@ class ContractTemplate(CrudDocument):
|
||||
default=[],
|
||||
format="dictionary",
|
||||
)
|
||||
|
||||
@validator("label", always=True)
|
||||
def generate_label(cls, v, values, **kwargs):
|
||||
return "{} - \"{}\"".format(values['name'], unescape(remove_html_tags(values['title'])))
|
||||
|
||||
class Settings(CrudDocument.Settings):
|
||||
fulltext_search = ['name', 'title']
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<crud-card
|
||||
[resource]="this.resource"
|
||||
[schema]="this.schema"
|
||||
[model]="this.model"
|
||||
(resourceCreated)="this.flashService.success('Entity created')"
|
||||
(error)="this.flashService.error($event)">
|
||||
</crud-card>
|
||||
@@ -6,11 +6,11 @@ import {FlashmessagesService} from "../../../layout/flashmessages/flashmessages.
|
||||
templateUrl: 'new.component.html'
|
||||
})
|
||||
export class BaseCrudNewComponent {
|
||||
@Input() resource: string | undefined;
|
||||
@Input() schema: string | undefined;
|
||||
@Input() model = {};
|
||||
@Input() resource: string | undefined;
|
||||
@Input() schema: string | undefined;
|
||||
@Input() model: {} = {};
|
||||
|
||||
constructor(
|
||||
public flashService: FlashmessagesService
|
||||
public flashService: FlashmessagesService
|
||||
) {}
|
||||
}
|
||||
@@ -3,21 +3,32 @@ import { NgModule } from '@angular/core';
|
||||
|
||||
import { BaseViewModule } from "../base-view/base-view.module";
|
||||
import { ContractsRoutingModule } from './contracts-routing.module';
|
||||
import { DraftCardComponent, DraftListComponent, DraftNewComponent } from "./drafts.component";
|
||||
|
||||
import { DraftCardComponent, DraftListComponent, DraftNewComponent, DraftNewFormComponent } from "./drafts.component";
|
||||
import { FormlyModule } from "@ngx-formly/core";
|
||||
import { FormlyBootstrapModule } from "@ngx-formly/bootstrap";
|
||||
import { ForeignkeyTypeComponent } from "@common/crud/types/foreignkey.type";
|
||||
import { CrudService } from "@common/crud/crud.service";
|
||||
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
BaseViewModule,
|
||||
ContractsRoutingModule
|
||||
ContractsRoutingModule,
|
||||
FormlyModule.forRoot({
|
||||
types: [
|
||||
{ name: 'foreign-key', component: ForeignkeyTypeComponent }
|
||||
]
|
||||
}),
|
||||
FormlyBootstrapModule,
|
||||
],
|
||||
declarations: [
|
||||
DraftListComponent,
|
||||
DraftNewComponent,
|
||||
DraftCardComponent,
|
||||
]
|
||||
DraftNewFormComponent
|
||||
],
|
||||
providers: [CrudService]
|
||||
})
|
||||
export class ContractsModule {
|
||||
}
|
||||
|
||||
@@ -1,26 +1,92 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { FormlyFieldConfig } from "@ngx-formly/core";
|
||||
import { FormGroup} from "@angular/forms";
|
||||
import { CrudFormlyJsonschemaService } from "@common/crud/crud-formly-jsonschema.service";
|
||||
import { CrudService } from "@common/crud/crud.service";
|
||||
|
||||
|
||||
export class BaseEntitiesComponent {
|
||||
protected resource: string = "contract-draft";
|
||||
protected schema: string = "ContractDraft";
|
||||
protected resource: string = "contract-draft";
|
||||
protected schema: string = "ContractDraft";
|
||||
}
|
||||
|
||||
@Component({
|
||||
templateUrl: '../base-view/templates/list.template.html'
|
||||
templateUrl: '../base-view/templates/list.template.html'
|
||||
})
|
||||
export class DraftListComponent extends BaseEntitiesComponent {
|
||||
columns = [];
|
||||
columns = [];
|
||||
}
|
||||
|
||||
@Component({
|
||||
templateUrl: '../base-view/templates/new.template.html'
|
||||
selector: 'draft-new-form',
|
||||
template: `<base-new [resource]="this.resource" [schema]="this.schema" [model]="this.value"></base-new>`
|
||||
})
|
||||
export class DraftNewComponent extends BaseEntitiesComponent {
|
||||
export class DraftNewFormComponent extends BaseEntitiesComponent {
|
||||
@Input() value: {} = {};
|
||||
}
|
||||
|
||||
@Component({
|
||||
templateUrl: '../base-view/templates/card.template.html'
|
||||
selector: 'draft-new',
|
||||
template: `
|
||||
<formly-form [fields]="temaplateFormfields" [form]="temaplateForm"></formly-form>
|
||||
<draft-new-form [value]="this.templateModel"></draft-new-form>
|
||||
`
|
||||
})
|
||||
export class DraftNewComponent extends BaseEntitiesComponent implements OnInit {
|
||||
templateModel: {} = {};
|
||||
temaplateFormfields: FormlyFieldConfig[] = [];
|
||||
temaplateForm: FormGroup = new FormGroup({});
|
||||
|
||||
fieldJson = {
|
||||
type: "object",
|
||||
properties: {
|
||||
template_id: {
|
||||
type: "string",
|
||||
title: "Find a template",
|
||||
foreignKey: {
|
||||
reference: {
|
||||
resource: "template/contract",
|
||||
schema: "ContractTemplate"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
constructor(private formlyJsonschema: CrudFormlyJsonschemaService,
|
||||
private crudService: CrudService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
// @ts-ignore
|
||||
this.temaplateFormfields = [this.formlyJsonschema.toFieldConfig(this.fieldJson)];
|
||||
this.temaplateForm.valueChanges.subscribe((values) => {
|
||||
if (values.template_id !== undefined) {
|
||||
this.crudService.get("template/contract", values.template_id).subscribe((templateModel) => {
|
||||
delete templateModel._id;
|
||||
delete templateModel.created_at;
|
||||
delete templateModel.updated_at;
|
||||
delete templateModel.label;
|
||||
const provisions = [];
|
||||
for (const p of templateModel.provisions) {
|
||||
provisions.push({
|
||||
provision: { type: "template", provision_template_id: p.provision_template_id}
|
||||
})
|
||||
}
|
||||
templateModel.provisions = provisions;
|
||||
this.templateModel = templateModel;
|
||||
});
|
||||
} else {
|
||||
this.templateModel = {};
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
templateUrl: '../base-view/templates/card.template.html'
|
||||
})
|
||||
export class DraftCardComponent extends BaseEntitiesComponent{
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user