Skip to content

Commit

Permalink
Include all not displayed fields in Record
Browse files Browse the repository at this point in the history
  • Loading branch information
mpuyosa91 committed Nov 16, 2023
1 parent 957b2eb commit c1c0d6e
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 82 deletions.
9 changes: 5 additions & 4 deletions core/app/common/src/lib/metadata/metadata.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {BehaviorSubject, Observable} from 'rxjs';

export interface ViewFieldDefinition {
name?: string;
vardefBased?: boolean;
label?: string;
labelKey?: string;
dynamicLabelKey?: string;
Expand Down Expand Up @@ -63,7 +64,7 @@ export interface PanelCell extends ViewFieldDefinition {
}

export interface ViewFieldDefinitionMap {
[key: string]: ViewFieldDefinition
[key: string]: ViewFieldDefinition;
}

export interface TabDefinitions {
Expand All @@ -86,12 +87,12 @@ export interface LogicDefinition {
modes: Array<string>;
params: {
activeOnFields?: {
[key:string]: LogicRuleValues[];
}
[key: string]: LogicRuleValues[];
};
displayState?: boolean;
fieldDependencies: Array<string>;
asyncProcessHandler?: string;
}
};
}

export interface LogicRuleValues{
Expand Down
65 changes: 53 additions & 12 deletions core/app/core/src/lib/services/record/field/field.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,18 @@ export class FieldManager {

/**
* Build line item and add to record
* @param {object} itemDefinition
* @param {object }item
* @param {object} parentRecord
* @param {object} parentField
*
* @param {FieldDefinition} itemDefinition Item Definition
* @param {Record} parentRecord Parent Record
* @param {Field} parentField Parent Field
* @param {Record | null} item Item
*/
public addLineItem(
itemDefinition: FieldDefinition,
parentRecord: Record,
parentField: Field,
item: Record = null
) {
): void {
if (!item) {
item = {
id: '',
Expand All @@ -183,10 +184,11 @@ export class FieldManager {

/**
* Remove line item
* @param {object} parentField
* @param index
*
* @param {Field} parentField Parent Field
* @param {number} index Index
*/
public removeLineItem(parentField: Field, index: number) {
public removeLineItem(parentField: Field, index: number): void {
const item = parentField.items[index];

if (!item) {
Expand All @@ -204,13 +206,13 @@ export class FieldManager {

parentField.itemFormArray.clear();

parentField.items.forEach(item => {
const deleted = item && item.attributes && item.attributes.deleted;
if (!item || deleted) {
parentField.items.forEach(parentItem => {
const deleted = parentItem && parentItem.attributes && parentItem.attributes.deleted;
if (!parentItem || deleted) {
return;
}

parentField.itemFormArray.push(item.formGroup);
parentField.itemFormArray.push(parentItem.formGroup);
});

parentField.itemFormArray.updateValueAndValidity();
Expand Down Expand Up @@ -246,6 +248,45 @@ export class FieldManager {
}


/**
* Build and add vardef only field to record
*
* @param {object} record Record
* @param {object} viewField ViewFieldDefinition
* @param {object} language LanguageStore
* @returns {object}Field
*/
public addVardefOnlyField(record: Record, viewField: ViewFieldDefinition, language: LanguageStore = null): Field {

const field = this.fieldBuilder.buildField(record, viewField, language);

this.addVardefOnlyFieldToRecord(record, viewField.name, field);

return field;
}


/**
* Add field to record
*
* @param {object} record Record
* @param {string} name string
* @param {object} field Field
*/
public addVardefOnlyFieldToRecord(record: Record, name: string, field: Field): void {

if (!record || !name || !field) {
return;
}

if (!record.fields) {
record.fields = {};
}

record.fields[name] = field;
}


/**
* Is field initialized in record
*
Expand Down
12 changes: 12 additions & 0 deletions core/app/core/src/lib/services/record/record.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ export class RecordManager {
if (!viewField || !viewField.name) {
return;
}

if(record.fields[viewField.name]) {
return;
}

const isVardefBased = viewField?.vardefBased ?? false;

if (isVardefBased) {
this.fieldManager.addVardefOnlyField(record, viewField, this.language);
return;
}

this.fieldManager.addField(record, viewField, this.language);
});

Expand Down
Loading

0 comments on commit c1c0d6e

Please sign in to comment.