progress
This commit is contained in:
parent
f11dfa7e57
commit
e85dc14fc8
5 changed files with 22 additions and 13 deletions
|
@ -24,7 +24,7 @@ export const FormBuilder = observer((props: IFormBuilder) => {
|
|||
props.formBuilder.context,
|
||||
props.formBuilder.result
|
||||
);
|
||||
console.log(props.formBuilder.form.map((el) => InputBuilderViewModel.fromJSON(el)));
|
||||
props.formBuilder.form.map((el) => InputBuilderViewModel.fromJSON(el));
|
||||
}
|
||||
store.changerForm.on((event) => {
|
||||
if (event) props.onChange(event);
|
||||
|
|
|
@ -10,6 +10,11 @@ export enum InputType {
|
|||
ENUM = "Enum",
|
||||
}
|
||||
|
||||
interface IOperation {
|
||||
regExp: RegExp;
|
||||
result: any;
|
||||
}
|
||||
|
||||
export class InputBuilderViewModel {
|
||||
id: string;
|
||||
constructor(
|
||||
|
@ -44,8 +49,6 @@ export class InputBuilderViewModel {
|
|||
}
|
||||
public toJson(): string {
|
||||
try {
|
||||
console.log(this.id);
|
||||
console.log(this.totalValue);
|
||||
return JSON.stringify(this);
|
||||
} catch (error) {
|
||||
console.log("InputBuilderViewModel.toJson(): " + this.id);
|
||||
|
@ -74,10 +77,14 @@ export class FormViewModel {
|
|||
}
|
||||
public json() {
|
||||
const result = this.toResult();
|
||||
if (result.isEmpty()) {
|
||||
console.log("result is Empty error");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(result).replaceAll("\n", "").replaceAll("\\", "").replaceAll("/", "");
|
||||
return JSON.parse(result.replaceAll("\n", "").replaceAll("\\", "").replaceAll("/", ""))
|
||||
} catch (error) {
|
||||
console.log(result);
|
||||
console.log("ERROR: FormViewModel json() " + result);
|
||||
}
|
||||
}
|
||||
public fromFormBuilderValidationModel() {
|
||||
|
@ -89,7 +96,7 @@ export class FormViewModel {
|
|||
);
|
||||
}
|
||||
public toResult(): string {
|
||||
let result = "";
|
||||
const operations: IOperation[] = [];
|
||||
|
||||
this.inputs.forEach((element) => {
|
||||
let inputResult = element.totalValue ?? element.defaultValue;
|
||||
|
@ -127,7 +134,14 @@ export class FormViewModel {
|
|||
}
|
||||
}
|
||||
if (inputResult instanceof Array) inputResult = JSON.stringify(inputResult);
|
||||
result = result.replace(new RegExp("\\${" + element.name + ".*?}"), inputResult);
|
||||
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue