Search in sources :

Example 6 with ViewComponent

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

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

the class GraphicalViewEditHandler method handleRequest.

@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception {
    GraphicalView view;
    User user = Common.getUser(request);
    // Fresh hit. Get the id.
    String viewIdStr = request.getParameter("viewId");
    if (viewIdStr != null) {
        // An existing view.
        view = new GraphicalViewDao().getView(Integer.parseInt(viewIdStr));
        if (view == null)
            // Doesn't exist. Redirect back to the views page.
            return new RedirectView("/views.shtm");
        GraphicalViewsCommon.ensureViewEditPermission(user, view);
        if ("true".equals(request.getParameter("copy"))) {
            // Make a copy
            GraphicalView copy = new GraphicalView();
            copy.setId(Common.NEW_ID);
            copy.setUserId(user.getId());
            copy.setXid(new GraphicalViewDao().generateUniqueXid());
            copy.setName(StringUtils.abbreviate(TranslatableMessage.translate(ControllerUtils.getTranslations(request), "common.copyPrefix", view.getName()), 100));
            copy.setBackgroundFilename(GraphicalViewsCommon.copyImage(view.getBackgroundFilename()));
            for (ViewComponent vc : view.getViewComponents()) copy.addViewComponent(vc);
            view = copy;
        }
    } else {
        // A new view.
        GraphicalViewsCommon.ensureCanCreate(user);
        view = new GraphicalView();
        view.setId(Common.NEW_ID);
        view.setUserId(user.getId());
        view.setXid(new GraphicalViewDao().generateUniqueXid());
    }
    GraphicalViewsCommon.setUserEditView(user, view);
    view.validateViewComponents(false);
    model.put("imageSets", Common.imageSets);
    model.put("dynamicImages", Common.dynamicImages);
    model.put("view", view);
    return null;
}
Also used : User(com.serotonin.m2m2.vo.User) GraphicalView(com.serotonin.m2m2.gviews.GraphicalView) GraphicalViewDao(com.serotonin.m2m2.gviews.GraphicalViewDao) RedirectView(org.springframework.web.servlet.view.RedirectView) ViewComponent(com.serotonin.m2m2.gviews.component.ViewComponent)

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