Search in sources :

Example 1 with ViewComponent

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

the class GraphicalView method addViewComponent.

public void addViewComponent(ViewComponent viewComponent) {
    // Determine an index for the component.
    int min = 0;
    for (ViewComponent vc : viewComponents) {
        if (min < vc.getIndex())
            min = vc.getIndex();
    }
    viewComponent.setIndex(min + 1);
    viewComponents.add(viewComponent);
}
Also used : ViewComponent(com.serotonin.m2m2.gviews.component.ViewComponent)

Example 2 with ViewComponent

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

the class GraphicalView method validate.

public void validate(ProcessResult response) {
    if (StringUtils.isBlank(name))
        response.addMessage("name", new TranslatableMessage("validate.required"));
    else if (StringValidation.isLengthGreaterThan(name, 100))
        response.addMessage("name", new TranslatableMessage("validate.notLongerThan", 100));
    if (StringUtils.isBlank(xid))
        response.addMessage("xid", new TranslatableMessage("validate.required"));
    else if (StringValidation.isLengthGreaterThan(xid, 50))
        response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
    else if (!new GraphicalViewDao().isXidUnique(xid, id))
        response.addMessage("xid", new TranslatableMessage("validate.xidUsed"));
    for (ViewComponent vc : viewComponents) vc.validate(response);
    // Validate the permissions
    User user = Common.getUser();
    GraphicalView existingView = null;
    if (this.id != Common.NEW_ID) {
        existingView = new GraphicalViewDao().getView(id);
    }
    if (existingView == null) {
        Permissions.validateAddedPermissions(this.readPermission, user, response, "readPermission");
        Permissions.validateAddedPermissions(this.setPermission, user, response, "setPermission");
        Permissions.validateAddedPermissions(this.editPermission, user, response, "editPermission");
    } else {
        // We are updating a view so only validate the new permissions, allow existing ones to remain and don't let
        // the user remove permissions they do not have
        this.readPermission = trimPermission(this.readPermission);
        validateUpdatedPermissions(existingView.readPermission, this.readPermission, user, response, "readPermission");
        this.setPermission = trimPermission(this.setPermission);
        validateUpdatedPermissions(existingView.setPermission, this.setPermission, user, response, "setPermission");
        this.editPermission = trimPermission(this.editPermission);
        validateUpdatedPermissions(existingView.editPermission, this.editPermission, user, response, "editPermission");
    }
}
Also used : ShareUser(com.serotonin.m2m2.view.ShareUser) User(com.serotonin.m2m2.vo.User) ViewComponent(com.serotonin.m2m2.gviews.component.ViewComponent) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 3 with ViewComponent

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

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

the class GraphicalViewDwr method getViewComponentIds.

@DwrPermission(user = true)
public List<String> getViewComponentIds() {
    User user = Common.getUser();
    List<String> result = new ArrayList<String>();
    for (ViewComponent vc : GraphicalViewsCommon.getUserEditView(user).getViewComponents()) result.add(vc.getId());
    return result;
}
Also used : ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User) ArrayList(java.util.ArrayList) ViewComponent(com.serotonin.m2m2.gviews.component.ViewComponent) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 5 with ViewComponent

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

the class GraphicalViewDwr method addComponent.

@DwrPermission(user = true)
public ViewComponent addComponent(String componentName) {
    ViewComponent viewComponent = ViewComponent.newInstance(componentName);
    User user = Common.getUser();
    GraphicalView view = GraphicalViewsCommon.getUserEditView(user);
    view.addViewComponent(viewComponent);
    viewComponent.validateDataPoint(user, false);
    return viewComponent;
}
Also used : ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User) ViewComponent(com.serotonin.m2m2.gviews.component.ViewComponent) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

ViewComponent (com.serotonin.m2m2.gviews.component.ViewComponent)6 User (com.serotonin.m2m2.vo.User)4 ShareUser (com.serotonin.m2m2.view.ShareUser)3 PointComponent (com.serotonin.m2m2.gviews.component.PointComponent)2 SimplePointComponent (com.serotonin.m2m2.gviews.component.SimplePointComponent)2 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 ArrayList (java.util.ArrayList)2 GraphicalView (com.serotonin.m2m2.gviews.GraphicalView)1 GraphicalViewDao (com.serotonin.m2m2.gviews.GraphicalViewDao)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 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1