use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty 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;
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty in project convertigo by convertigo.
the class UIDynamicElement method getFormatedLabel.
protected String getFormatedLabel() {
if (ionBean != null) {
String source = ionBean.getDisplayFormat();
if (!source.isEmpty()) {
String sourceName = "displayFormat", message = null;
Context javascriptContext = org.mozilla.javascript.Context.enter();
Scriptable scope = javascriptContext.initStandardObjects(null);
for (IonProperty property : ionBean.getProperties().values()) {
String p_name = property.getName();
// Object p_value = property.getValue();
String smartValue = property.getSmartType().getLabel().replace("{{", "").replace("}}", "").replace("?.", ".");
Scriptable jsObject = ((smartValue == null) ? null : org.mozilla.javascript.Context.toObject(smartValue, scope));
scope.put(p_name, scope, jsObject);
}
try {
Object ob = RhinoUtils.evalInterpretedJavascript(javascriptContext, scope, source, sourceName, 1, null);
if (ob instanceof Function) {
Object returnedValue = ((Function) ob).call(javascriptContext, scope, scope, new Object[] {});
return returnedValue.toString();
}
} catch (EcmaError e) {
message = "Unable to evaluate code for '" + sourceName + "'.\n" + "UIDynamicElement: \"" + getName() + "\"\n" + "A Javascript runtime error has occured at line " + e.lineNumber() + ", column " + e.columnNumber() + ": " + e.getMessage() + " \n" + e.lineSource();
} catch (EvaluatorException e) {
message = "Unable to evaluate code for '" + sourceName + "'.\n" + "UIDynamicElement: \"" + getName() + "\"\n" + "A Javascript evaluation error has occured: " + e.getMessage();
} catch (JavaScriptException e) {
message = "Unable to evaluate code for '" + sourceName + "'.\n" + "UIDynamicElement: \"" + getName() + "\"\n" + "A Javascript error has occured: " + e.getMessage();
} finally {
if (javascriptContext != null) {
org.mozilla.javascript.Context.exit();
}
if (message != null) {
System.out.println(message);
Engine.logBeans.warn(message);
}
}
}
}
return null;
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty 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>();
}
};
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty 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();
}
Aggregations