Search in sources :

Example 1 with CompoundComponent

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

the class GraphicalViewDwr method saveCompoundPoints.

private void saveCompoundPoints(CompoundComponent c, List<StringStringPair> childPointIds) {
    User user = Common.getUser();
    for (StringStringPair kvp : childPointIds) {
        int dataPointId = -1;
        try {
            dataPointId = Integer.parseInt(kvp.getValue());
        } catch (NumberFormatException e) {
        // no op
        }
        DataPointVO dp = DataPointDao.instance.getDataPoint(dataPointId);
        if (dp == null || !Permissions.hasDataPointReadPermission(user, dp))
            c.setDataPoint(kvp.getKey(), null);
        else
            c.setDataPoint(kvp.getKey(), dp);
        c.getChildComponent(kvp.getKey()).validateDataPoint(user, false);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) StringStringPair(com.serotonin.db.pair.StringStringPair) ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User)

Example 2 with CompoundComponent

use of com.serotonin.m2m2.gviews.component.CompoundComponent 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 CompoundComponent

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

the class GraphicalViewDwr method saveCompoundComponent.

@DwrPermission(user = true)
public ProcessResult saveCompoundComponent(String viewComponentId, String name, List<StringStringPair> childPointIds) {
    ProcessResult response = new ProcessResult();
    validateCompoundComponent(response, name);
    if (!response.getHasMessages()) {
        CompoundComponent c = (CompoundComponent) getViewComponent(viewComponentId);
        c.setName(name);
        saveCompoundPoints(c, childPointIds);
    }
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) SimpleCompoundComponent(com.serotonin.m2m2.gviews.component.SimpleCompoundComponent) CompoundComponent(com.serotonin.m2m2.gviews.component.CompoundComponent) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

CompoundComponent (com.serotonin.m2m2.gviews.component.CompoundComponent)2 SimpleCompoundComponent (com.serotonin.m2m2.gviews.component.SimpleCompoundComponent)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 StringStringPair (com.serotonin.db.pair.StringStringPair)1 CompoundChild (com.serotonin.m2m2.gviews.component.CompoundChild)1 ImageChartComponent (com.serotonin.m2m2.gviews.component.ImageChartComponent)1 PointComponent (com.serotonin.m2m2.gviews.component.PointComponent)1 SimplePointComponent (com.serotonin.m2m2.gviews.component.SimplePointComponent)1 ViewComponent (com.serotonin.m2m2.gviews.component.ViewComponent)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 WebContext (org.directwebremoting.WebContext)1