form view model array objects map edit

This commit is contained in:
IDONTSUDO 2024-04-18 17:03:02 +03:00
parent e85dc14fc8
commit 38ffde1d77

View file

@ -82,7 +82,7 @@ export class FormViewModel {
return; return;
} }
try { try {
return JSON.parse(result.replaceAll("\n", "").replaceAll("\\", "").replaceAll("/", "")) return JSON.parse(result.replaceAll("\n", "").replaceAll("\\", "").replaceAll("/", ""));
} catch (error) { } catch (error) {
console.log("ERROR: FormViewModel json() " + result); console.log("ERROR: FormViewModel json() " + result);
} }
@ -114,27 +114,37 @@ export class FormViewModel {
if (element.totalValue instanceof Array) { if (element.totalValue instanceof Array) {
element.totalValue.forEach((el) => { element.totalValue.forEach((el) => {
const objectUnion = {}; const objectUnion = {};
let objectMapperResult = "";
if (el instanceof Array) if (el instanceof Array)
el.forEach((subElement) => { el.forEach((subElement) => {
let subResult = subElement.totalValue ?? subElement.defaultValue; 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)}"`; subResult = `"${String(subResult)}"`;
} }
if (element.type.isEqual(InputType.NUMBER)) { if (subElement.type.isEqual(InputType.NUMBER)) {
subResult = Number(subResult); subResult = Number(subResult);
} }
// @ts-ignore // @ts-ignore
objectUnion[subElement.name] = subResult; objectUnion[subElement.name] = subResult;
}); });
if (Object.keys(objectUnion).length !== 0) { 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 }); operations.push({ regExp: new RegExp("\\${" + element.name + ".*?}"), result: inputResult });
}); });
@ -146,6 +156,16 @@ export class FormViewModel {
return 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<void, FormViewModel> { static fromString(result: string, context: string): Result<void, FormViewModel> {
try { try {
const enums = new Map<string, string[]>(); const enums = new Map<string, string[]>();