use of com.twinsoft.convertigo.beans.mobile.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 "";
}
use of com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean in project convertigo by convertigo.
the class UIDynamicSwitch method computeActionContent.
protected String computeActionContent() {
if (isEnabled()) {
IonBean ionBean = getIonBean();
if (ionBean != null) {
int numThen = numberOfActions();
String actionName = getActionName();
String inputs = computeActionInputs(false);
StringBuilder sbCase = new StringBuilder();
StringBuilder sbCatch = new StringBuilder();
StringBuilder sbThen = new StringBuilder();
List<String> passthroughCases = new ArrayList<String>();
Iterator<UIComponent> it = getUIComponentList().iterator();
while (it.hasNext()) {
UIComponent component = (UIComponent) it.next();
if (component.isEnabled()) {
String sCase = "", 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 UIActionCaseEvent) {
UIActionCaseEvent caseEvent = (UIActionCaseEvent) component;
String caseFn = caseEvent.getCaseFn();
String caseValue = caseEvent.getCaseValue();
int len = caseValue.length();
char c1 = caseValue.charAt(0);
char c2 = caseValue.charAt(len - 1);
if (c1 == c2 && Character.toString(c1).matches("[\'\"]")) {
caseValue = "'" + escapeStringForTs(caseValue.substring(1, len - 1)) + "'";
} else {
caseValue = escapeStringForTs(caseValue);
caseValue = "'" + caseValue + "'";
}
if (caseEvent.isEnabled()) {
sCase += System.lineSeparator();
sCase += caseEvent.computeEvent();
sCase += "\t\tcases[" + caseValue + "] = cases[" + caseValue + "] || []" + System.lineSeparator();
sCase += "\t\tcases[" + caseValue + "].push(" + caseFn + ")" + System.lineSeparator();
for (String cv : passthroughCases) {
if (!cv.equals(caseValue)) {
sCase += "\t\tcases[" + cv + "].push(" + caseFn + ")" + System.lineSeparator();
}
}
if (caseEvent.isPassThrough()) {
if (!passthroughCases.contains(caseValue)) {
passthroughCases.add(caseValue);
}
} else {
passthroughCases.clear();
}
}
}
if (!sCase.isEmpty()) {
sbCase.append(sCase);
}
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();
tsCode += "\t\t" + "let cases = {};" + System.lineSeparator();
if (sbCase.length() > 0) {
tsCode += sbCase.toString();
} else {
// does nothing
;
}
tsCode += "\t\t" + System.lineSeparator();
tsCode += "\t\tlet self: any = stack[\"" + getName() + "\"] = stack[\"" + priority + "\"] = {};" + System.lineSeparator();
tsCode += "\t\tself.in = " + inputs + ";" + System.lineSeparator();
// "(this, self.in.props, {...stack[\"root\"].in, ...self.in.vars}, cases)"+ System.lineSeparator();
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}, cases)" + 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}, cases)" + 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