use of com.serotonin.m2m2.gviews.component.PointComponent in project ma-modules-public by infiniteautomation.
the class ScriptComponent method addDataToModel.
@Override
public void addDataToModel(Map<String, Object> model, PointValueTime value) {
String result;
if (value == null)
result = "--";
else {
// Create the script engine.
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
DataPointVO point = tgetDataPoint();
// Put the values into the engine scope.
engine.put("value", value.getValue().getObjectValue());
engine.put("htmlText", Functions.getHtmlText(point, value));
engine.put("renderedText", Functions.getRenderedText(point, value));
engine.put("time", value.getTime());
engine.put("pointComponent", this);
engine.put("point", point);
// Copy properties from the model into the engine scope.
engine.put(BaseDwr.MODEL_ATTR_EVENTS, model.get(BaseDwr.MODEL_ATTR_EVENTS));
engine.put(BaseDwr.MODEL_ATTR_HAS_UNACKED_EVENT, model.get(BaseDwr.MODEL_ATTR_HAS_UNACKED_EVENT));
engine.put(BaseDwr.MODEL_ATTR_TRANSLATIONS, model.get(BaseDwr.MODEL_ATTR_TRANSLATIONS));
// Create the script.
String evalScript = SCRIPT_PREFIX + script + SCRIPT_SUFFIX;
// Execute.
try {
Object o = engine.eval(evalScript);
if (o == null)
result = null;
else
result = o.toString();
} catch (ScriptException e) {
e = ScriptExecutor.prettyScriptMessage(e);
result = e.getMessage();
}
}
model.put("scriptContent", result);
}
use of com.serotonin.m2m2.gviews.component.PointComponent in project ma-modules-public by infiniteautomation.
the class ViewComponent method jsonReadDataPoint.
protected void jsonReadDataPoint(JsonValue jsonXid, PointComponent comp) throws JsonException {
if (jsonXid != null) {
String xid = jsonXid.toString();
DataPointVO dataPoint = DataPointDao.instance.getDataPoint(xid);
if (dataPoint == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
if (!comp.definition().supports(dataPoint.getPointLocator().getDataTypeId()))
throw new TranslatableJsonException("emport.error.component.incompatibleDataType", xid, definition().getExportName());
comp.tsetDataPoint(dataPoint);
}
}
Aggregations