form view model array objects map edit
This commit is contained in:
parent
e85dc14fc8
commit
38ffde1d77
1 changed files with 28 additions and 8 deletions
|
@ -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<void, FormViewModel> {
|
||||
try {
|
||||
const enums = new Map<string, string[]>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue