diff --git a/ui/src/core/ui/form_builder/form_view_model.ts b/ui/src/core/ui/form_builder/form_view_model.ts index 73b495e..951ba20 100644 --- a/ui/src/core/ui/form_builder/form_view_model.ts +++ b/ui/src/core/ui/form_builder/form_view_model.ts @@ -82,7 +82,7 @@ export class FormViewModel { return; } try { - return JSON.parse(result.replaceAll("\n", "").replaceAll("\\", "").replaceAll("/", "")) + return JSON.parse(result.replaceAll("\n", "").replaceAll("\\", "").replaceAll("/", "")); } catch (error) { console.log("ERROR: FormViewModel json() " + result); } @@ -114,38 +114,58 @@ export class FormViewModel { if (element.totalValue instanceof Array) { element.totalValue.forEach((el) => { const objectUnion = {}; + let objectMapperResult = ""; if (el instanceof Array) el.forEach((subElement) => { let subResult = subElement.totalValue ?? subElement.defaultValue; - if (element.type.isEqualMany([InputType.STRING, InputType.ENUM])) { + console.log(subResult); + if (subElement.type.isEqualMany([InputType.STRING, InputType.ENUM])) { + console.log(201) subResult = `"${String(subResult)}"`; } - if (element.type.isEqual(InputType.NUMBER)) { + if (subElement.type.isEqual(InputType.NUMBER)) { subResult = Number(subResult); } + // @ts-ignore objectUnion[subElement.name] = subResult; }); if (Object.keys(objectUnion).length !== 0) { - inputResult.push(objectUnion); + if (element.subType) { + objectMapperResult = this.getTypeBody(element.subType); + Object.entries(objectUnion).forEach(([key, value]) => { + objectMapperResult = objectMapperResult.replace(new RegExp("\\${" + key + ".*?}"), value as any); + }); + } + + inputResult.push(objectMapperResult.replaceAll("\n", "").replaceAll("\\", "").replaceAll("/", "").replaceAll(';','')) } }); } } } - if (inputResult instanceof Array) inputResult = JSON.stringify(inputResult); - + if (inputResult instanceof Array) inputResult = JSON.stringify(inputResult.map((el) => JSON.parse(el))); operations.push({ regExp: new RegExp("\\${" + element.name + ".*?}"), result: inputResult }); }); let result = this.result; - + operations.forEach((el) => { result = result.replace(el.regExp, el.result); }); - + return result; } + getTypeBody(subType: string): string { + let result; + this.context.match(typeParse)?.forEach((type) => { + const matchTypeName = type.match(typeNameParse)?.at(0)?.split(" ").at(1); + if (matchTypeName?.isEqual(subType)) { + result = type.match(typeBodyParse)?.at(0); + } + }); + return result as unknown as string; + } static fromString(result: string, context: string): Result { try { const enums = new Map();