use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class UIDynamicAction method computeActionContent.
protected String computeActionContent() {
if (isEnabled()) {
IonBean ionBean = getIonBean();
if (ionBean != null) {
int numThen = numberOfActions();
String actionName = getActionName();
String inputs = computeActionInputs(false);
StringBuilder sbCatch = new StringBuilder();
StringBuilder sbThen = new StringBuilder();
Iterator<UIComponent> it = getUIComponentList().iterator();
while (it.hasNext()) {
UIComponent component = (UIComponent) it.next();
if (component.isEnabled()) {
String sCatch = "", sThen = "";
if (component instanceof UIDynamicAction) {
sThen = ((UIDynamicAction) component).computeActionContent();
}
if (component instanceof UICustomAction) {
sThen = ((UICustomAction) component).computeActionContent();
}
if (component instanceof UIActionFailureEvent) {
sCatch = ((UIActionFailureEvent) component).computeEvent();
}
if (!sCatch.isEmpty()) {
sbCatch.append(sCatch);
}
if (!sThen.isEmpty()) {
sbThen.append(sbThen.length() > 0 && numThen > 1 ? "\t\t," + System.lineSeparator() : "").append(sThen);
}
}
}
String tsCode = "";
tsCode += "\t\tnew Promise((resolve, reject) => {" + System.lineSeparator();
// tsCode += "\t\tlet self: any = stack[\""+ getName() +"\"] = {};"+ System.lineSeparator();
tsCode += "\t\tlet self: any = stack[\"" + getName() + "\"] = stack[\"" + priority + "\"] = {};" + System.lineSeparator();
tsCode += "\t\tself.in = " + inputs + ";" + System.lineSeparator();
if ("InvokeAction".equals(ionBean.getName())) {
if (isBroken()) {
tsCode += "\t\treturn this.actionBeans." + actionName + "(this, {...self.in.props, ...{message: 'Invoke source is broken'}}, " + "{...stack[\"root\"].in, ...self.in.vars})" + System.lineSeparator();
} else {
if (getSharedAction() != null) {
tsCode += "\t\treturn this.actionBeans." + actionName + "(this, {...{stack: stack, parent: parent, out: out}, ...self.in.props}, " + "{...stack[\"root\"].in, ...params, ...self.in.vars}, event)" + System.lineSeparator();
} else {
tsCode += "\t\treturn this.actionBeans." + actionName + "(this, {...{stack: stack, parent: parent, out: out}, ...self.in.props}, " + "{...stack[\"root\"].in, ...self.in.vars}, event)" + System.lineSeparator();
}
}
} else {
tsCode += "\t\treturn this.actionBeans." + actionName + "(this, self.in.props, {...stack[\"root\"].in, ...self.in.vars})" + System.lineSeparator();
}
tsCode += "\t\t.catch((error:any) => {" + System.lineSeparator();
tsCode += "\t\tparent = self;" + System.lineSeparator();
tsCode += "\t\tparent.out = error;" + System.lineSeparator();
tsCode += "\t\tout = parent.out;" + System.lineSeparator();
if (sbCatch.length() > 0) {
tsCode += "\t\t" + sbCatch.toString();
} else {
tsCode += "\t\treturn Promise.reject(error);" + System.lineSeparator();
}
tsCode += "\t\t})" + System.lineSeparator();
tsCode += "\t\t.then((res:any) => {" + System.lineSeparator();
tsCode += "\t\tparent = self;" + System.lineSeparator();
tsCode += "\t\tparent.out = res;" + System.lineSeparator();
tsCode += "\t\tout = parent.out;" + System.lineSeparator();
if (sbThen.length() > 0) {
if (numThen > 1) {
tsCode += "\t\treturn Promise.all([" + System.lineSeparator();
tsCode += sbThen.toString();
tsCode += "\t\t])" + System.lineSeparator();
} else {
tsCode += "\t\treturn " + sbThen.toString().replaceFirst("\t\t", "");
}
} else {
tsCode += "\t\treturn Promise.resolve(res);" + System.lineSeparator();
}
if ("IfAction".equals(ionBean.getName())) {
tsCode += "\t\t}, (error: any) => {if (\"c8oSkipError\" === error.message) {resolve(false);} else {this.c8o.log.debug(\"[MB] " + actionName + " : \", error.message);throw new Error(error);}})" + System.lineSeparator();
} else {
tsCode += "\t\t}, (error: any) => {this.c8o.log.debug(\"[MB] " + actionName + " : \", error.message);throw new Error(error);})" + System.lineSeparator();
}
tsCode += "\t\t.then((res:any) => {resolve(res)}).catch((error:any) => {reject(error)})" + System.lineSeparator();
tsCode += "\t\t})" + System.lineSeparator();
return tsCode;
}
}
return "";
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class UIDynamicAction method computeTemplate.
@Override
public String computeTemplate() {
if (isEnabled()) {
String formIdentifier = null;
if (underSubmitEvent()) {
UIForm uiForm = getUIForm();
if (uiForm != null) {
if (!uiForm.getIdentifier().isBlank()) {
formIdentifier = uiForm.getIdentifier();
}
}
}
String scope = getScope();
String in = formIdentifier == null ? "{}" : "merge({}," + formIdentifier + ".value)";
if (isStacked()) {
return getFunctionName() + "({root: {scope:" + scope + ", in:" + in + ", out:$event}})";
} else {
IonBean ionBean = getIonBean();
if (ionBean != null) {
String actionName = getActionName();
String props = "{}", vars = "{}";
String inputs = computeActionInputs(true);
Pattern pattern = Pattern.compile("\\{props:(\\{.*\\}), vars:(\\{.*\\})\\}");
Matcher matcher = pattern.matcher(inputs);
if (matcher.matches()) {
props = matcher.group(1);
vars = matcher.group(2);
}
if (formIdentifier != null) {
vars = "merge(merge({}," + formIdentifier + ".value), " + vars + ")";
}
String stack = "{stack:{root: {scope:" + scope + ", in:" + in + ", out:$event}}}";
props = "merge(merge({}," + props + "), " + stack + ")";
if (compareToTplVersion("1.0.91") >= 0) {
return "resolveError(actionBeans." + actionName + "(this," + props + "," + vars + ", $event))";
} else {
return "actionBeans." + actionName + "(this," + props + "," + vars + ", $event)";
}
}
}
}
return "";
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class UIDynamicIterate method computeActionContent.
protected String computeActionContent() {
if (isEnabled()) {
IonBean ionBean = getIonBean();
if (ionBean != null) {
int numThen = numberOfActions();
String actionName = getActionName();
String inputs = computeActionInputs(false);
StringBuilder sbLoop = new StringBuilder();
StringBuilder sbCatch = new StringBuilder();
StringBuilder sbThen = new StringBuilder();
Iterator<UIComponent> it = getUIComponentList().iterator();
while (it.hasNext()) {
UIComponent component = (UIComponent) it.next();
if (component.isEnabled()) {
String sLoop = "", sCatch = "", sThen = "";
if (component instanceof UIDynamicAction) {
sThen = ((UIDynamicAction) component).computeActionContent();
}
if (component instanceof UICustomAction) {
sThen = ((UICustomAction) component).computeActionContent();
}
if (component instanceof UIActionFailureEvent) {
sCatch = ((UIActionFailureEvent) component).computeEvent();
}
if (component instanceof UIActionLoopEvent) {
sLoop = ((UIActionLoopEvent) component).computeEvent();
}
if (!sLoop.isEmpty()) {
sbLoop.append(sLoop);
}
if (!sCatch.isEmpty()) {
sbCatch.append(sCatch);
}
if (!sThen.isEmpty()) {
sbThen.append(sbThen.length() > 0 && numThen > 1 ? "\t\t," + System.lineSeparator() : "").append(sThen);
}
}
}
String tsCode = "";
tsCode += "\t\tnew Promise((resolve, reject) => {" + System.lineSeparator();
tsCode += "\t\t" + System.lineSeparator();
if (sbLoop.length() > 0) {
tsCode += sbLoop.toString();
} else {
tsCode += "\t\tconst doLoop = (c8oPage : C8oPageBase, item : any, index : number) : Promise<any> => {" + System.lineSeparator();
tsCode += "\t\treturn Promise.reject('no loop handler');" + System.lineSeparator();
tsCode += "\t\t}" + System.lineSeparator();
}
tsCode += "\t\t" + System.lineSeparator();
// tsCode += "\t\tlet self: any = stack[\""+ getName() +"\"] = {};"+ System.lineSeparator();
tsCode += "\t\tlet self: any = stack[\"" + getName() + "\"] = stack[\"" + priority + "\"] = {};" + System.lineSeparator();
tsCode += "\t\tself.in = " + inputs + ";" + System.lineSeparator();
tsCode += "\t\treturn this.actionBeans." + actionName + "(this, self.in.props, {...stack[\"root\"].in, ...self.in.vars}, doLoop)" + System.lineSeparator();
tsCode += "\t\t.catch((error:any) => {" + System.lineSeparator();
tsCode += "\t\tparent = self;" + System.lineSeparator();
tsCode += "\t\tparent.out = error;" + System.lineSeparator();
tsCode += "\t\tout = parent.out;" + System.lineSeparator();
if (sbCatch.length() > 0) {
tsCode += "\t\t" + sbCatch.toString();
} else {
tsCode += "\t\treturn Promise.reject(error);" + System.lineSeparator();
}
tsCode += "\t\t})" + System.lineSeparator();
tsCode += "\t\t.then((res:any) => {" + System.lineSeparator();
tsCode += "\t\tparent = self;" + System.lineSeparator();
tsCode += "\t\tparent.out = res;" + System.lineSeparator();
tsCode += "\t\tout = parent.out;" + System.lineSeparator();
if (sbThen.length() > 0) {
if (numThen > 1) {
tsCode += "\t\treturn Promise.all([" + System.lineSeparator();
tsCode += sbThen.toString();
tsCode += "\t\t])" + System.lineSeparator();
} else {
tsCode += "\t\treturn " + sbThen.toString().replaceFirst("\t\t", "");
}
} else {
tsCode += "\t\treturn Promise.resolve(res);" + System.lineSeparator();
}
tsCode += "\t\t}, (error: any) => {this.c8o.log.debug(\"[MB] " + actionName + " : \", error.message);throw new Error(error);})" + System.lineSeparator();
tsCode += "\t\t.then((res:any) => {resolve(res)}).catch((error:any) => {reject(error)})" + System.lineSeparator();
tsCode += "\t\t})" + System.lineSeparator();
return tsCode;
}
}
return "";
}
Aggregations