Search in sources :

Example 6 with PointComponent

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);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ScriptException(javax.script.ScriptException) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine)

Example 7 with PointComponent

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);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Aggregations

DataPointVO (com.serotonin.m2m2.vo.DataPointVO)4 PointComponent (com.serotonin.m2m2.gviews.component.PointComponent)3 SimplePointComponent (com.serotonin.m2m2.gviews.component.SimplePointComponent)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JsonObject (com.serotonin.json.type.JsonObject)1 JsonValue (com.serotonin.json.type.JsonValue)1 CompoundChild (com.serotonin.m2m2.gviews.component.CompoundChild)1 CompoundComponent (com.serotonin.m2m2.gviews.component.CompoundComponent)1 ImageChartComponent (com.serotonin.m2m2.gviews.component.ImageChartComponent)1 SimpleCompoundComponent (com.serotonin.m2m2.gviews.component.SimpleCompoundComponent)1 ViewComponent (com.serotonin.m2m2.gviews.component.ViewComponent)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1 ShareUser (com.serotonin.m2m2.view.ShareUser)1 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)1 User (com.serotonin.m2m2.vo.User)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1