Search in sources :

Example 16 with IonBean

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.

the class UIDynamicElement method getCustomScss.

@Override
protected String getCustomScss() {
    IonBean ionBean = getIonBean();
    String scss = "";
    if (ionBean != null) {
        for (String s : ionBean.getScssList()) {
            scss += s + System.lineSeparator();
        }
        if (!scss.isEmpty()) {
            String cartridge = "";
            cartridge += "/**\n";
            cartridge += " * Custom properties (sometimes referred to as CSS variables or cascading variables)\n";
            cartridge += " * are entities defined by CSS authors that contain specific values to be reused throughout a document.\n";
            cartridge += " * They are set using custom property notation, e.g.: --main-color: black;\n";
            cartridge += " * and are accessed using the var() function, e.g.: color: var(--main-color);\n";
            cartridge += " * You can find below your component's properties you can customize within the page.\n";
            cartridge += " * If you'd like to make some customizations for whole app, please see your app Style & Theme components.\n";
            cartridge += " * For more informations see https://ionicframework.com/docs/theming.\n";
            cartridge += "**/\n";
            scss = cartridge + scss;
        }
    }
    return scss;
}
Also used : IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean)

Example 17 with IonBean

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.

the class UIDynamicElement method initAttributes.

@Override
protected StringBuilder initAttributes() {
    StringBuilder attributes = super.initAttributes();
    IonBean ionBean = getIonBean();
    if (ionBean != null) {
        UIForm form = getUIForm();
        boolean underForm = form != null;
        Map<String, String> vm = new HashMap<String, String>();
        for (IonProperty property : ionBean.getProperties().values()) {
            String name = property.getName();
            Object value = property.getValue();
            if (!value.equals(false)) {
                MobileSmartSourceType msst = property.getSmartType();
                String smartValue = msst.getValue();
                if (Mode.PLAIN.equals(msst.getMode())) {
                    if (property.getType().equalsIgnoreCase("string")) {
                        if (!isComposedValue(smartValue)) {
                            smartValue = "\'" + MobileSmartSourceType.escapeStringForTpl(smartValue) + "\'";
                        }
                    }
                }
                vm.put(name, smartValue);
            } else {
                vm.put(name, "null");
            }
        }
        StrSubstitutor sub = new StrSubstitutor(vm, "$[", "]");
        sub.setEnableSubstitutionInVariables(true);
        for (IonProperty property : ionBean.getProperties().values()) {
            String name = property.getName();
            String attr = property.getAttr();
            Object value = property.getValue();
            boolean isComposite = property.isComposite();
            // case value is set
            if (!value.equals(false)) {
                if (attr.equals("class")) {
                    // already handle in initAttrClasses
                    continue;
                }
                if (name.equals("AutoDisable")) {
                    if (underForm) {
                        String formIdentifier = form.getIdentifier();
                        if (!formIdentifier.isBlank()) {
                            attributes.append(" [disabled]=\"").append(formIdentifier).append(".invalid\"");
                        }
                    }
                } else {
                    String smartValue = property.getSmartValue();
                    smartValue = sub.replace(smartValue);
                    if (!isComposite) {
                        attributes.append(" ");
                        if (attr.isEmpty()) {
                            attributes.append(smartValue);
                        } else if (attr.indexOf("%%") != -1) {
                            attributes.append(attr.replaceFirst("%%", smartValue));
                        } else {
                            attributes.append(attr).append("=");
                            attributes.append("\"").append(smartValue).append("\"");
                        }
                    }
                }
            } else // case value is not set
            {
                if (!isComposite) {
                    if (underForm) {
                        if (name.equals("DoubleBinding")) {
                            String defval = null;
                            if (tagName.equals("ion-checkbox") || tagName.equals("ion-toggle")) {
                                defval = vm.get("Checked");
                            } else {
                                defval = vm.get("Value");
                            }
                            if (defval != null && !defval.equals("null")) {
                                attributes.append(" [ngModel]=\"" + defval + "\"");
                            } else {
                                attributes.append(" ngModel");
                            }
                        }
                    }
                }
            }
        }
    }
    return attributes;
}
Also used : StrSubstitutor(org.apache.commons.text.StrSubstitutor) IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) HashMap(java.util.HashMap) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 18 with IonBean

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.

the class UIDynamicElement method getContributor.

@Override
protected Contributor getContributor() {
    return new Contributor() {

        @Override
        public Map<String, String> getActionTsFunctions() {
            return new HashMap<String, String>();
        }

        @Override
        public Map<String, String> getActionTsImports() {
            return new HashMap<String, String>();
        }

        @Override
        public Map<String, File> getCompBeanDir() {
            return new HashMap<String, File>();
        }

        @Override
        public Map<String, String> getModuleTsImports() {
            Map<String, String> imports = new HashMap<String, String>();
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                Map<String, List<String>> map = ionBean.getConfig().getModuleTsImports();
                if (map.size() > 0) {
                    for (String from : map.keySet()) {
                        for (String component : map.get(from)) {
                            imports.put(component.trim(), from);
                        }
                    }
                }
            }
            return imports;
        }

        @Override
        public Set<String> getModuleNgImports() {
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                return ionBean.getConfig().getModuleNgImports();
            }
            return new HashSet<String>();
        }

        @Override
        public Set<String> getModuleNgProviders() {
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                return ionBean.getConfig().getModuleNgProviders();
            }
            return new HashSet<String>();
        }

        @Override
        public Set<String> getModuleNgDeclarations() {
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                return ionBean.getConfig().getModuleNgDeclarations();
            }
            return new HashSet<String>();
        }

        @Override
        public Set<String> getModuleNgComponents() {
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                return ionBean.getConfig().getModuleNgComponents();
            }
            return new HashSet<String>();
        }

        @Override
        public Map<String, String> getPackageDependencies() {
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                return ionBean.getConfig().getPackageDependencies();
            }
            return new HashMap<String, String>();
        }

        @Override
        public Map<String, String> getConfigPlugins() {
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                Map<String, String> map = ionBean.getConfig().getConfigPlugins();
                for (String plugin : map.keySet()) {
                    try {
                        JSONObject json = new JSONObject(map.get(plugin));
                        if (json.has("variables")) {
                            boolean hasChanged = false;
                            JSONObject jsonVars = json.getJSONObject("variables");
                            @SuppressWarnings("unchecked") Iterator<String> it = jsonVars.keys();
                            while (it.hasNext()) {
                                String varkey = it.next();
                                String varval = jsonVars.getString(varkey);
                                if (varval.startsWith("@")) {
                                    // value = @propertyName
                                    String propertyName = varval.substring(1);
                                    if (ionBean.hasProperty(propertyName)) {
                                        IonProperty ionProperty = ionBean.getProperty(propertyName);
                                        Object p_value = ionProperty.getValue();
                                        String value = "";
                                        if (!p_value.equals(false)) {
                                            MobileSmartSourceType msst = ionProperty.getSmartType();
                                            String smartValue = msst.getValue();
                                            if (Mode.PLAIN.equals(msst.getMode())) {
                                                value = smartValue;
                                            }
                                        }
                                        jsonVars.put(varkey, value);
                                        hasChanged = true;
                                    }
                                }
                            }
                            if (hasChanged) {
                                json.put("variables", jsonVars);
                                map.put(plugin, json.toString());
                            }
                        }
                    } catch (Exception e) {
                    }
                }
                return map;
            }
            return new HashMap<String, String>();
        }

        @Override
        public Set<String> getModuleNgRoutes(String pageSegment) {
            return new HashSet<String>();
        }
    };
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) HashMap(java.util.HashMap) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) EngineException(com.twinsoft.convertigo.engine.EngineException) JSONObject(org.codehaus.jettison.json.JSONObject) List(java.util.List) JSONObject(org.codehaus.jettison.json.JSONObject) File(java.io.File) HashSet(java.util.HashSet)

Example 19 with IonBean

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.

the class UIDynamicIf method computeActionContent.

protected String computeActionContent() {
    if (isEnabled()) {
        IonBean ionBean = getIonBean();
        if (ionBean != null) {
            int numThen = numberOfActions();
            String actionName = getActionName();
            String inputs = computeActionInputs(false);
            StringBuilder sbElse = 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 sElse = "", 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 UIActionElseEvent) {
                        sElse = ((UIActionElseEvent) component).computeEvent();
                    }
                    if (!sElse.isEmpty()) {
                        sbElse.append(sElse);
                    }
                    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\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})" + 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();
            tsCode += "\t\tif (res == true) {" + 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} else if (res == false) {" + System.lineSeparator();
            if (sbElse.toString().isEmpty()) {
                tsCode += "\t\tthis.c8o.log.debug(\"For '" + getName() + "' condition is not verified. No Else handler, skipping and resolve false\");" + System.lineSeparator();
                tsCode += "\t\tresolve(false)" + System.lineSeparator();
            } else {
                tsCode += "\t\t" + sbElse.toString().replaceFirst("\t\t", "");
            }
            tsCode += "\t\t}" + System.lineSeparator();
            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();
            tsCode += "\t\t.then((res:any) => {resolve(res)}).catch((error:any) => {reject(error)})" + System.lineSeparator();
            tsCode += "\t\t})" + System.lineSeparator();
            return tsCode;
        }
    }
    return "";
}
Also used : IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean)

Example 20 with IonBean

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.

the class UIDynamicAction method computeJsonModel.

@Override
public String computeJsonModel() {
    JSONObject jsonModel = new JSONObject();
    // if (isEnabled()) {
    try {
        jsonModel.put("in", new JSONObject().put("props", new JSONObject()).put("vars", new JSONObject())).put("out", new JSONObject());
        IonBean ionBean = getIonBean();
        if (ionBean != null) {
            JSONObject jsonProps = jsonModel.getJSONObject("in").getJSONObject("props");
            jsonProps.put("tplVersion", "");
            jsonProps.put("actionName", "");
            jsonProps.put("actionFunction", "");
            for (IonProperty property : ionBean.getProperties().values()) {
                jsonProps.put(property.getName(), "");
            }
        }
        JSONObject jsonVars = jsonModel.getJSONObject("in").getJSONObject("vars");
        Iterator<UIComponent> it = getUIComponentList().iterator();
        while (it.hasNext()) {
            UIComponent component = (UIComponent) it.next();
            if (component instanceof UIControlVariable) {
                UIControlVariable var = (UIControlVariable) component;
                jsonVars.put(var.getVarName(), "");
            }
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // }
    return jsonModel.toString();
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) JSONObject(org.codehaus.jettison.json.JSONObject) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) JSONException(org.codehaus.jettison.json.JSONException)

Aggregations

IonBean (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean)23 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 EngineException (com.twinsoft.convertigo.engine.EngineException)9 IonProperty (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty)8 JSONObject (org.codehaus.jettison.json.JSONObject)8 JSONException (org.codehaus.jettison.json.JSONException)6 UIDynamicAction (com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction)4 HashMap (java.util.HashMap)4 UIActionStack (com.twinsoft.convertigo.beans.ngx.components.UIActionStack)3 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)3 UIUseShared (com.twinsoft.convertigo.beans.ngx.components.UIUseShared)3 File (java.io.File)3 Project (com.twinsoft.convertigo.beans.core.Project)2 ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)2 MobileSmartSourceType (com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType)2 UICompVariable (com.twinsoft.convertigo.beans.ngx.components.UICompVariable)2 UIControlVariable (com.twinsoft.convertigo.beans.ngx.components.UIControlVariable)2 UIDynamicElement (com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement)2 UIDynamicInvoke (com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke)2 UIStackVariable (com.twinsoft.convertigo.beans.ngx.components.UIStackVariable)2