Search in sources :

Example 1 with PointComponent

use of com.serotonin.m2m2.gviews.component.PointComponent in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method setPointComponentSettings.

@DwrPermission(user = true)
public ProcessResult setPointComponentSettings(String pointComponentId, int dataPointId, String name, boolean settable, String bkgdColorOverride, int updatePeriodType, int updatePeriods, boolean displayControls, int x, int y) {
    ProcessResult response = new ProcessResult();
    PointComponent pc = (PointComponent) getViewComponent(pointComponentId);
    User user = Common.getUser();
    DataPointVO dp = DataPointDao.instance.getDataPoint(dataPointId);
    if (dp == null || !Permissions.hasDataPointReadPermission(user, dp))
        response.addContextualMessage("settingsPointInfo", "validate.required");
    if (!Common.TIME_PERIOD_CODES.isValidId(updatePeriodType))
        response.addContextualMessage("settingsUpdatePeriodType", "validate.invalidValue");
    if (updatePeriods < 0)
        response.addContextualMessage("settingsUpdatePeriods", "validate.cannotBeNegative");
    if (x < 0)
        response.addContextualMessage("settingsX", "validate.cannotBeNegative");
    if (y < 0)
        response.addContextualMessage("settingsY", "validate.cannotBeNegative");
    if (!response.getHasMessages()) {
        pc.tsetDataPoint(dp);
        pc.setNameOverride(name);
        pc.setSettableOverride(settable && Permissions.hasDataPointSetPermission(user, dp));
        pc.setBkgdColorOverride(bkgdColorOverride);
        pc.setUpdatePeriodType(updatePeriodType);
        pc.setUpdatePeriods(updatePeriods);
        pc.setDisplayControls(displayControls);
        pc.setLocation(x, y);
        pc.validateDataPoint(user, false);
        response.addData("x", x);
        response.addData("y", y);
    }
    return response;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User) PointComponent(com.serotonin.m2m2.gviews.component.PointComponent) SimplePointComponent(com.serotonin.m2m2.gviews.component.SimplePointComponent) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with PointComponent

use of com.serotonin.m2m2.gviews.component.PointComponent in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method getViewPointData.

private List<ViewComponentState> getViewPointData(User user, GraphicalView view, boolean edit) {
    WebContext webContext = WebContextFactory.get();
    HttpServletRequest request = webContext.getHttpServletRequest();
    List<ViewComponentState> states = new ArrayList<ViewComponentState>();
    Map<String, Object> model = new HashMap<String, Object>();
    for (ViewComponent viewComponent : view.getViewComponents()) {
        // Are we to update this component
        boolean update = System.currentTimeMillis() >= (viewComponent.getLastUpdated() + Common.getMillis(viewComponent.getUpdatePeriodType(), viewComponent.getUpdatePeriods()));
        if (viewComponent.isCompoundComponent() && (edit || viewComponent.isVisible())) {
            CompoundComponent compoundComponent = (CompoundComponent) viewComponent;
            boolean imageChart = compoundComponent instanceof ImageChartComponent;
            // Add states for each of the children
            for (CompoundChild child : compoundComponent.getChildComponents()) addPointComponentState(child.getViewComponent(), update, Common.runtimeManager, model, request, view, user, states, edit, !imageChart);
            // Add a state for the compound component.
            ViewComponentState state = new ViewComponentState();
            state.setId(compoundComponent.getId());
            model.clear();
            model.put("compoundComponent", compoundComponent);
            List<Map<String, Object>> childData = new ArrayList<Map<String, Object>>();
            for (CompoundChild child : compoundComponent.getChildComponents()) {
                if (child.getViewComponent().isPointComponent()) {
                    DataPointVO point = ((PointComponent) child.getViewComponent()).tgetDataPoint();
                    if (point != null) {
                        Map<String, Object> map = new HashMap<String, Object>();
                        if (imageChart)
                            map.put("name", point.getName());
                        else
                            map.put("name", translate(child.getDescription()));
                        map.put("point", point);
                        map.put("pointValue", point.lastValue());
                        childData.add(map);
                    }
                }
            }
            model.put("childData", childData);
            if (compoundComponent.hasInfo())
                state.setInfo(generateViewContent(compoundComponent, update, request, "compoundInfoContent.jsp", model));
            if (imageChart) {
                state.setContent(((ImageChartComponent) compoundComponent).getImageChartData(getTranslations()));
            } else if (!edit) {
                state.setChart(compoundComponent.getImageChartData(getTranslations()));
            }
            states.add(state);
        } else
            addPointComponentState(viewComponent, update, Common.runtimeManager, model, request, view, user, states, edit, true);
        // Save the last time we updated
        if (update)
            viewComponent.setLastUpdated(System.currentTimeMillis());
    }
    return states;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) WebContext(org.directwebremoting.WebContext) HashMap(java.util.HashMap) PointComponent(com.serotonin.m2m2.gviews.component.PointComponent) SimplePointComponent(com.serotonin.m2m2.gviews.component.SimplePointComponent) ArrayList(java.util.ArrayList) CompoundChild(com.serotonin.m2m2.gviews.component.CompoundChild) SimpleCompoundComponent(com.serotonin.m2m2.gviews.component.SimpleCompoundComponent) CompoundComponent(com.serotonin.m2m2.gviews.component.CompoundComponent) HttpServletRequest(javax.servlet.http.HttpServletRequest) ViewComponent(com.serotonin.m2m2.gviews.component.ViewComponent) ImageChartComponent(com.serotonin.m2m2.gviews.component.ImageChartComponent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PointComponent

use of com.serotonin.m2m2.gviews.component.PointComponent in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method preparePointComponentState.

/**
 * Shared convenience method for creating a populated view component state.
 */
private ViewComponentState preparePointComponentState(PointComponent pointComponent, boolean update, User user, DataPointRT point, Map<String, Object> model, HttpServletRequest request) {
    ViewComponentState state = new ViewComponentState();
    state.setId(pointComponent.getId());
    PointValueTime pointValue = prepareBasePointState(pointComponent.getId(), state, pointComponent.tgetDataPoint(), point, model);
    model.put("pointComponent", pointComponent);
    if (pointComponent.isValid()) {
        if (!update && pointComponent.getCachedContent(MODEL_ATTR_EVENTS) != null)
            model.put(MODEL_ATTR_EVENTS, pointComponent.getCachedContent(MODEL_ATTR_EVENTS));
        else {
            setEvents(pointComponent.tgetDataPoint(), user, model, pointEventsLimit);
            pointComponent.putCachedContent(MODEL_ATTR_EVENTS, model.get(MODEL_ATTR_EVENTS));
        }
    }
    pointComponent.addDataToModel(model, pointValue);
    if (!pointComponent.isValid())
        model.put("invalid", "true");
    else {
        // Add the rendered text as a convenience to the snippets.
        model.put("text", pointComponent.tgetDataPoint().getTextRenderer().getText(pointValue, TextRenderer.HINT_FULL));
        state.setContent(generateViewContent(pointComponent, update, request, pointComponent.snippetName() + ".jsp", model));
        pointComponent.tgetDataPoint().updateLastValue(pointValue);
    }
    state.setInfo(generateViewContent(pointComponent, update, request, "infoContent.jsp", model));
    // TODO Cache this
    setMessages(state, request, getFullSnippetName("warningContent.jsp"), model);
    return state;
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 4 with PointComponent

use of com.serotonin.m2m2.gviews.component.PointComponent in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method addPointComponentState.

private void addPointComponentState(ViewComponent viewComponent, boolean update, RuntimeManager rtm, Map<String, Object> model, HttpServletRequest request, GraphicalView view, User user, List<ViewComponentState> states, boolean edit, boolean add) {
    if (viewComponent.isPointComponent() && (edit || viewComponent.isVisible())) {
        PointComponent pointComponent = (PointComponent) viewComponent;
        DataPointRT dataPointRT = null;
        if (pointComponent.tgetDataPoint() != null)
            dataPointRT = rtm.getDataPoint(pointComponent.tgetDataPoint().getId());
        ViewComponentState state = preparePointComponentState(pointComponent, update, user, dataPointRT, model, request);
        if (!edit) {
            if (pointComponent.isSettable()) {
                if (view.isEditor(user) || view.isSetter(user))
                    setChange(pointComponent.tgetDataPoint(), state, dataPointRT, request, model);
            }
            if (pointComponent.tgetDataPoint() != null)
                setChart(pointComponent.tgetDataPoint(), state, request, model);
        }
        if (add)
            states.add(state);
        model.clear();
    }
}
Also used : PointComponent(com.serotonin.m2m2.gviews.component.PointComponent) SimplePointComponent(com.serotonin.m2m2.gviews.component.SimplePointComponent) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT)

Example 5 with PointComponent

use of com.serotonin.m2m2.gviews.component.PointComponent in project ma-modules-public by infiniteautomation.

the class CompoundComponent method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    JsonObject jsonChildren = jsonObject.getJsonObject("children");
    if (jsonChildren != null) {
        for (Map.Entry<String, JsonValue> jsonChild : jsonChildren.entrySet()) {
            CompoundChild child = getChild(jsonChild.getKey());
            if (child == null || !child.getViewComponent().isPointComponent())
                throw new TranslatableJsonException("emport.error.compound.invalidChildId", jsonChild.getKey(), definition().getId(), getPointComponentChildIds());
            jsonReadDataPoint(jsonChild.getValue(), (PointComponent) child.getViewComponent());
        }
    }
}
Also used : JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) HashMap(java.util.HashMap) Map(java.util.Map)

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