diff --git a/back/app/template/models.py b/back/app/template/models.py
index 8eb9eb5a..034975b9 100644
--- a/back/app/template/models.py
+++ b/back/app/template/models.py
@@ -33,16 +33,22 @@ class ProvisionTemplate(CrudDocument):
class ProvisionReference(BaseModel):
- provision_template_id: str = Field(foreignKey={
- "reference": {
- "resource": "template/provision",
- "schema": "ProvisionTemplate",
- }
- })
+ provision_template_id: str = Field(
+ foreignKey={
+ "reference": {
+ "resource": "template/provision",
+ "schema": "ProvisionTemplate",
+ },
+ },
+ props={"test": "test"}
+ )
class ContractTemplate(CrudDocument):
name: str
parties: List[PartyTemplate] = []
- provisions: List[ProvisionReference] = []
+ provisions: List[ProvisionReference] = Field(
+ default=[],
+ props={"items-per-row": "1"}
+ )
diff --git a/front/app/src/app/views/templates/contract-templates.component.ts b/front/app/src/app/views/templates/contract-templates.component.ts
index b3dd952c..f292d1cf 100644
--- a/front/app/src/app/views/templates/contract-templates.component.ts
+++ b/front/app/src/app/views/templates/contract-templates.component.ts
@@ -1,17 +1,9 @@
import { Component, OnInit, } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
-import { FieldCustomizer } from '@common/crud/card/card.component'
-
-export class Customizer extends FieldCustomizer {
- override customizers = {
- "provisions": { props: { width: "col-sm-12" }},
- }
-}
export class BaseContractTemplateComponent {
protected resource: string = "template/contract";
protected schema: string = "ContractTemplate";
- protected field_customizer: FieldCustomizer = new Customizer();
}
@Component({
@@ -21,13 +13,13 @@ export class ContractTemplateListComponent extends BaseContractTemplateComponent
}
@Component({
- template: ''
+ template: ''
})
export class ContractTemplateNewComponent extends BaseContractTemplateComponent {
}
@Component({
- template: ''
+ template: ''
})
export class ContractTemplateCardComponent extends BaseContractTemplateComponent implements OnInit {
resource_id: string | null = null;
diff --git a/front/app/src/common/crud/card/card.component.ts b/front/app/src/common/crud/card/card.component.ts
index bea5316e..d795d275 100644
--- a/front/app/src/common/crud/card/card.component.ts
+++ b/front/app/src/common/crud/card/card.component.ts
@@ -7,45 +7,6 @@ import { CrudService } from '../crud.service'
import {BehaviorSubject, NotFoundError} from "rxjs";
import { CrudFormlyJsonschemaService } from "../crud-formly-jsonschema.service";
-export class FieldCustomizer {
- protected customizers = {};
-
- applyCustomizers(form: FormlyFieldConfig[]): FormlyFieldConfig[] {
- for (const [property, customizer] of Object.entries(this.customizers)) {
- const f = this.getFieldByPath(form, property);
- this.apply(f, customizer)
- }
- return form
- }
-
- apply(field: FormlyFieldConfig, customizer: any) {
- if (customizer.hasOwnProperty("props")) {
- for (const [property, value] of Object.entries(customizer.props)) {
- field.props![property] = value;
- }
- }
- }
-
- getFieldByPath(form: FormlyFieldConfig[], path: string): FormlyFieldConfig {
- let field = form[0];
- let array = path.split('.');
- for (const k in array) {
- field = this.getFieldByKey(field, array[k])
- }
-
- return field;
- }
-
- getFieldByKey(field: FormlyFieldConfig, key: string): FormlyFieldConfig {
- for (let i=0; i < field.fieldGroup!.length; i++) {
- if (field.fieldGroup![i].key == key) {
- return field.fieldGroup![i]
- }
- }
- throw new NotFoundError(`field ${key} not found in fieldgroup`)
- }
-}
-
@Component({
selector: 'crud-card',
templateUrl: './card.component.html',
@@ -55,7 +16,6 @@ export class CardComponent implements OnInit {
@Input() resource: string | undefined;
@Input() resource_id: string | null = null;
@Input() schema: string | undefined;
- @Input() field_customizer: FieldCustomizer = new FieldCustomizer();
@Input() is_modal: Boolean = false;
@Output() resourceCreated: EventEmitter = new EventEmitter();
@@ -101,7 +61,7 @@ export class CardComponent implements OnInit {
}
fields$.subscribe((fields: any) => {
- this.fields = this.field_customizer.applyCustomizers([fields]);
+ this.fields = [fields];
this._formLoading$.next(false);
});
}
diff --git a/front/app/src/common/crud/crud-formly-jsonschema.service.ts b/front/app/src/common/crud/crud-formly-jsonschema.service.ts
index 7b542d59..06691157 100644
--- a/front/app/src/common/crud/crud-formly-jsonschema.service.ts
+++ b/front/app/src/common/crud/crud-formly-jsonschema.service.ts
@@ -47,6 +47,10 @@ export class CrudFormlyJsonschemaOptions implements FormlyJsonschemaOptions {
field.type = "hidden";
}
+ if (schema.hasOwnProperty('props')) {
+ field.props = {...field.props, ...schema.props}
+ }
+
return field;
}
}
diff --git a/front/app/src/common/crud/types/array.type.ts b/front/app/src/common/crud/types/array.type.ts
index 9777b951..989130a6 100644
--- a/front/app/src/common/crud/types/array.type.ts
+++ b/front/app/src/common/crud/types/array.type.ts
@@ -32,8 +32,8 @@ import { FieldArrayType } from '@ngx-formly/core';
export class ArrayTypeComponent extends FieldArrayType implements OnInit {
colSm: string = "col-sm-6"
ngOnInit() {
- if (this.field.props.hasOwnProperty('width')) {
- this.colSm = this.field.props['width'];
+ if (this.field.props.hasOwnProperty('items-per-row')) {
+ this.colSm = `col-sm-${12 / this.field.props['items-per-row']}`
}
}