Search in sources :

Example 11 with GraphicalView

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

the class GraphicalViewDwr method getViewPointData.

/**
 * Retrieves point state for all points on a given view. This is the monitoring version of the method. See below for
 * the view editing version.
 *
 * @param viewId
 * @return
 */
public List<ViewComponentState> getViewPointData(boolean edit) {
    User user = Common.getUser();
    GraphicalView view;
    if (edit)
        view = GraphicalViewsCommon.getUserEditView(user);
    else
        view = GraphicalViewsCommon.getUserView(user);
    return getViewPointData(user, view, edit);
}
Also used : ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User)

Example 12 with GraphicalView

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

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

the class GraphicalViewEmportDefinition method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
    JsonObject viewJson = jsonValue.toJsonObject();
    String xid = viewJson.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = graphicalViewDao.generateUniqueXid();
    ensureDao();
    GraphicalView view = graphicalViewDao.getViewByXid(xid);
    if (view == null) {
        view = new GraphicalView();
        view.setXid(xid);
    }
    try {
        importContext.getReader().readInto(view, viewJson);
        // Now validate it. Use a new response object so we can distinguish errors in this view from other
        // errors.
        ProcessResult viewResponse = new ProcessResult();
        view.validate(viewResponse);
        if (viewResponse.getHasMessages())
            // Too bad. Copy the errors into the actual response.
            importContext.copyValidationMessages(viewResponse, "emport.view.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = view.isNew();
            graphicalViewDao.saveView(view);
            importContext.addSuccessMessage(isnew, "emport.view.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.view.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.view.prefix", xid, importContext.getJsonExceptionMessage(e));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 14 with GraphicalView

use of com.serotonin.m2m2.gviews.GraphicalView 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)

Example 15 with GraphicalView

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

the class ImageUploadServlet method doPost.

@SuppressWarnings("unchecked")
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (ServletFileUpload.isMultipartContent(request)) {
        User user = Common.getUser(request);
        GraphicalView view = GraphicalViewsCommon.getUserEditView(user);
        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
        // Fail if we don't have permissions for this
        if (!Permissions.hasPermission(user, SystemSettingsDao.getValue(GraphicalViewUploadPermissionDefinition.PERMISSION))) {
            // The GraphicalViewDwr.clearBackground() method will notify the user of a failure so we can ignore them here
            return;
        }
        List<FileItem> items;
        try {
            items = upload.parseRequest(request);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        for (FileItem item : items) {
            if ("backgroundImage".equals(item.getFieldName())) {
                final DiskFileItem diskItem = (DiskFileItem) item;
                try {
                    // will throw IOException if not supported or null if not an image
                    if (ImageIO.read(diskItem.getInputStream()) != null) {
                        // Create the path to the upload directory.
                        File dir = GraphicalViewsCommon.getUploadDir();
                        // Create the image file name.
                        String filename = GraphicalViewsCommon.getNextImageFilename(dir, diskItem.getName());
                        // Save the file.
                        FileOutputStream fos = new FileOutputStream(new File(dir, filename));
                        StreamUtils.transfer(diskItem.getInputStream(), fos);
                        fos.close();
                        view.setBackgroundFilename(ImageUploadServletDefinition.IMAGE_DIR + "/" + filename);
                    } else {
                    // Unsupported File Type
                    }
                } catch (Exception e) {
                // Unsupported Image Type
                }
            }
        }
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) DiskFileItem(org.apache.commons.fileupload.disk.DiskFileItem) User(com.serotonin.m2m2.vo.User) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) GraphicalView(com.serotonin.m2m2.gviews.GraphicalView) FileOutputStream(java.io.FileOutputStream) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) File(java.io.File) IOException(java.io.IOException) DiskFileItem(org.apache.commons.fileupload.disk.DiskFileItem)

Aggregations

User (com.serotonin.m2m2.vo.User)9 ShareUser (com.serotonin.m2m2.view.ShareUser)6 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)6 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)6 ViewComponent (com.serotonin.m2m2.gviews.component.ViewComponent)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 GraphicalView (com.serotonin.m2m2.gviews.GraphicalView)2 PointComponent (com.serotonin.m2m2.gviews.component.PointComponent)2 SimplePointComponent (com.serotonin.m2m2.gviews.component.SimplePointComponent)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)2 ArrayList (java.util.ArrayList)2 IntStringPair (com.serotonin.db.pair.IntStringPair)1 JsonException (com.serotonin.json.JsonException)1 JsonObject (com.serotonin.json.type.JsonObject)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