Search in sources :

Example 1 with TableChartRenderer

use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-core-public by infiniteautomation.

the class DefaultDataPointPropertiesTemplateFactory method createDefaultBinaryTemplate.

protected DataPointPropertiesTemplateVO createDefaultBinaryTemplate() {
    DataPointPropertiesTemplateVO defaultBinaryPointTemplate = new DataPointPropertiesTemplateVO();
    defaultBinaryPointTemplate.setXid(BINARY_XID);
    defaultBinaryPointTemplate.setName("Binary");
    defaultBinaryPointTemplate.setDataTypeId(DataTypes.BINARY);
    defaultBinaryPointTemplate.setDefaultTemplate(true);
    defaultBinaryPointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
    defaultBinaryPointTemplate.setChartColour("");
    defaultBinaryPointTemplate.setPlotType(PlotTypes.STEP);
    defaultBinaryPointTemplate.setLoggingType(LoggingTypes.ON_CHANGE);
    defaultBinaryPointTemplate.setDefaultCacheSize(1);
    BinaryTextRenderer binaryRenderer = new BinaryTextRenderer();
    binaryRenderer.setOneColour("black");
    binaryRenderer.setOneLabel("one");
    binaryRenderer.setZeroColour("blue");
    binaryRenderer.setZeroLabel("zero");
    defaultBinaryPointTemplate.setTextRenderer(binaryRenderer);
    TableChartRenderer binaryChartRenderer = new TableChartRenderer();
    binaryChartRenderer.setLimit(10);
    defaultBinaryPointTemplate.setChartRenderer(binaryChartRenderer);
    return defaultBinaryPointTemplate;
}
Also used : TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) BinaryTextRenderer(com.serotonin.m2m2.view.text.BinaryTextRenderer)

Example 2 with TableChartRenderer

use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-core-public by infiniteautomation.

the class DataPointDetailsController method handleRequest.

@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception {
    User user = Common.getHttpUser();
    int id = -1;
    if (user.getEditPoint() != null)
        id = user.getEditPoint().getId();
    DataPointDao dataPointDao = DataPointDao.instance;
    String idStr = request.getParameter("dpid");
    DataPointVO point = null;
    if (StringUtils.equals(idStr, "exception"))
        throw new IOException("testing");
    else if (StringUtils.equals(idStr, "permission-exception"))
        throw new PermissionException(new TranslatableMessage("common.default", "Testing"), user);
    if (StringUtils.isBlank(idStr)) {
        // Check for pedid (point event detector id)
        String pedStr = request.getParameter("pedid");
        if (StringUtils.isBlank(pedStr)) {
            // Check if an XID was provided.
            String xid = request.getParameter("dpxid");
            if (!StringUtils.isBlank(xid)) {
                model.put("currentXid", xid);
                point = dataPointDao.getDataPoint(xid);
                id = point == null ? -2 : point.getId();
            }
        } else {
            int pedid = Integer.parseInt(pedStr);
            id = EventDetectorDao.instance.getSourceId(pedid, EventType.EventTypeNames.DATA_POINT);
        }
    } else
        id = Integer.parseInt(idStr);
    // Find accessible points for the goto list
    List<DataPointSummary> userPoints = ControllerUtils.addPointListDataToModel(user, id, model);
    // Get the point.
    if (point == null && id != -1)
        point = dataPointDao.getDataPoint(id);
    if (point == null && id != -2 && /* -2 means an explicit XID was provided but not found */
    !userPoints.isEmpty()) {
        // Load at least 1 point, there may be many points but some might not actually load if thier data source DNE anymore
        for (DataPointSummary userPoint : userPoints) {
            point = dataPointDao.getDataPoint(userPoint.getId());
            if (point != null)
                break;
        }
    }
    if (point != null) {
        // Check permissions
        Permissions.ensureDataPointReadPermission(user, point);
        // Put the point in the model.
        model.put("point", point);
        // Get the users that have access to this point.
        List<User> allUsers = UserDao.instance.getUsers();
        List<Map<String, Object>> users = new LinkedList<>();
        Map<String, Object> userData;
        int accessType;
        for (User mangoUser : allUsers) {
            accessType = Permissions.getDataPointAccessType(mangoUser, point);
            if (accessType != Permissions.DataPointAccessTypes.NONE) {
                userData = new HashMap<>();
                userData.put("user", mangoUser);
                userData.put("accessType", accessType);
                users.add(userData);
            }
        }
        model.put("users", users);
        // Determine whether the link to edit the point should be displayed
        model.put("pointEditor", Permissions.hasDataSourcePermission(user, point.getDataSourceId()));
        // Put the events in the model.
        model.put("events", EventDao.instance.getEventsForDataPoint(id, user.getId()));
        // Put the default history table count into the model. Default to 10.
        int historyLimit = 10;
        if (point.getChartRenderer() instanceof TableChartRenderer)
            historyLimit = ((TableChartRenderer) point.getChartRenderer()).getLimit();
        else if (point.getChartRenderer() instanceof ImageFlipbookRenderer)
            historyLimit = ((ImageFlipbookRenderer) point.getChartRenderer()).getLimit();
        model.put("historyLimit", historyLimit);
        // Determine our image chart rendering capabilities.
        if (ImageChartRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId())) {
            // This point can render an image chart. Carry on...
            int periodType = Common.TimePeriods.DAYS;
            int periodCount = 1;
            if (point.getChartRenderer() instanceof ImageChartRenderer) {
                ImageChartRenderer r = (ImageChartRenderer) point.getChartRenderer();
                periodType = r.getTimePeriod();
                periodCount = r.getNumberOfPeriods();
            }
            model.put("periodType", periodType);
            model.put("periodCount", periodCount);
        }
        // Determine out flipbook rendering capabilities
        if (ImageFlipbookRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId()))
            model.put("flipbookLimit", 10);
        // Set the point in the session for the dwr.
        user.setEditPoint(point);
        model.put("currentXid", point.getXid());
        model.put("hierPath", CollectionUtils.implode(dataPointDao.getPointHierarchy(true).getPath(id), " &raquo; "));
    }
    return null;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) User(com.serotonin.m2m2.vo.User) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) IOException(java.io.IOException) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer) LinkedList(java.util.LinkedList) ImageFlipbookRenderer(com.serotonin.m2m2.view.chart.ImageFlipbookRenderer) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with TableChartRenderer

use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-modules-public by infiniteautomation.

the class ChartRendererFactory method updateDataPoint.

/**
 * @param data
 * @param renderer
 */
public static void updateDataPoint(DataPointVO vo, BaseChartRendererModel<?> baseRendererModel) {
    if (baseRendererModel == null)
        // Nothing to do
        return;
    if (baseRendererModel.getType().equals(ImageChartRenderer.getDefinition().getName())) {
        ImageChartRendererModel model = (ImageChartRendererModel) baseRendererModel;
        ImageChartRenderer r = new ImageChartRenderer();
        r.setNumberOfPeriods(model.getTimePeriod().getPeriods());
        r.setTimePeriod(Common.TIME_PERIOD_CODES.getId(model.getTimePeriod().getPeriodType()));
        vo.setChartRenderer(r);
    } else if (baseRendererModel.getType().equals(ImageFlipbookRenderer.getDefinition().getName())) {
        ImageFlipbookChartRendererModel model = (ImageFlipbookChartRendererModel) baseRendererModel;
        ImageFlipbookRenderer r = new ImageFlipbookRenderer();
        r.setLimit(model.getLimit());
        vo.setChartRenderer(r);
    } else if (baseRendererModel.getType().equals(StatisticsChartRenderer.getDefinition().getName())) {
        StatisticsChartRendererModel model = (StatisticsChartRendererModel) baseRendererModel;
        StatisticsChartRenderer r = new StatisticsChartRenderer();
        r.setNumberOfPeriods(model.getTimePeriod().getPeriods());
        r.setTimePeriod(Common.TIME_PERIOD_CODES.getId(model.getTimePeriod().getPeriodType()));
        r.setIncludeSum(model.isIncludeSum());
        vo.setChartRenderer(r);
    } else if (baseRendererModel.getType().equals(TableChartRenderer.getDefinition().getName())) {
        TableChartRendererModel model = (TableChartRendererModel) baseRendererModel;
        TableChartRenderer r = new TableChartRenderer();
        r.setLimit(model.getLimit());
        vo.setChartRenderer(r);
    } else {
        throw new ShouldNeverHappenException("Unknown Chart Renderer: " + baseRendererModel.getType());
    }
}
Also used : TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) StatisticsChartRenderer(com.serotonin.m2m2.view.chart.StatisticsChartRenderer) ImageFlipbookRenderer(com.serotonin.m2m2.view.chart.ImageFlipbookRenderer) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer)

Example 4 with TableChartRenderer

use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-modules-public by infiniteautomation.

the class ChartRendererFactory method createModel.

/**
 * @param vo
 * @return
 */
public static BaseChartRendererModel<?> createModel(DataPointVO vo) {
    ChartRenderer renderer = vo.getChartRenderer();
    if (renderer == null)
        return null;
    if (renderer.getTypeName().equals(ImageChartRenderer.getDefinition().getName())) {
        ImageChartRenderer r = (ImageChartRenderer) renderer;
        TimePeriodModel tp = new TimePeriodModel(r.getNumberOfPeriods(), r.getTimePeriod());
        ImageChartRendererModel model = new ImageChartRendererModel(tp);
        return model;
    } else if (renderer.getTypeName().equals(ImageFlipbookRenderer.getDefinition().getName())) {
        ImageFlipbookRenderer r = (ImageFlipbookRenderer) renderer;
        ImageFlipbookChartRendererModel model = new ImageFlipbookChartRendererModel(r.getLimit());
        return model;
    } else if (renderer.getTypeName().equals(StatisticsChartRenderer.getDefinition().getName())) {
        StatisticsChartRenderer r = (StatisticsChartRenderer) renderer;
        TimePeriodModel tp = new TimePeriodModel(r.getNumberOfPeriods(), r.getTimePeriod());
        StatisticsChartRendererModel model = new StatisticsChartRendererModel(tp, r.isIncludeSum());
        return model;
    } else if (renderer.getTypeName().equals(TableChartRenderer.getDefinition().getName())) {
        TableChartRenderer r = (TableChartRenderer) renderer;
        TableChartRendererModel model = new TableChartRendererModel(r.getLimit());
        return model;
    } else {
        throw new ShouldNeverHappenException("Unknown Chart Renderer: " + renderer.getDef().getName());
    }
}
Also used : TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) StatisticsChartRenderer(com.serotonin.m2m2.view.chart.StatisticsChartRenderer) ImageFlipbookRenderer(com.serotonin.m2m2.view.chart.ImageFlipbookRenderer) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer) TimePeriodModel(com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.TimePeriodModel) StatisticsChartRenderer(com.serotonin.m2m2.view.chart.StatisticsChartRenderer) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer) ChartRenderer(com.serotonin.m2m2.view.chart.ChartRenderer) TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer)

Example 5 with TableChartRenderer

use of com.serotonin.m2m2.view.chart.TableChartRenderer in project ma-core-public by infiniteautomation.

the class DefaultDataPointPropertiesTemplateFactory method createDefaultAlphanumericTemplate.

protected DataPointPropertiesTemplateVO createDefaultAlphanumericTemplate() {
    DataPointPropertiesTemplateVO defaultAlphanumericPointTemplate = new DataPointPropertiesTemplateVO();
    defaultAlphanumericPointTemplate.setXid(ALPHANUMERIC_XID);
    defaultAlphanumericPointTemplate.setName("Alphanumeric");
    defaultAlphanumericPointTemplate.setDataTypeId(DataTypes.ALPHANUMERIC);
    defaultAlphanumericPointTemplate.setDefaultTemplate(true);
    defaultAlphanumericPointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
    defaultAlphanumericPointTemplate.setChartColour("");
    defaultAlphanumericPointTemplate.setPlotType(PlotTypes.STEP);
    defaultAlphanumericPointTemplate.setLoggingType(LoggingTypes.ON_CHANGE);
    defaultAlphanumericPointTemplate.setDefaultCacheSize(1);
    defaultAlphanumericPointTemplate.setTextRenderer(new PlainRenderer());
    TableChartRenderer alphaChartRenderer = new TableChartRenderer();
    alphaChartRenderer.setLimit(10);
    defaultAlphanumericPointTemplate.setChartRenderer(alphaChartRenderer);
    return defaultAlphanumericPointTemplate;
}
Also used : TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) PlainRenderer(com.serotonin.m2m2.view.text.PlainRenderer)

Aggregations

TableChartRenderer (com.serotonin.m2m2.view.chart.TableChartRenderer)6 ImageChartRenderer (com.serotonin.m2m2.view.chart.ImageChartRenderer)3 ImageFlipbookRenderer (com.serotonin.m2m2.view.chart.ImageFlipbookRenderer)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 StatisticsChartRenderer (com.serotonin.m2m2.view.chart.StatisticsChartRenderer)2 PlainRenderer (com.serotonin.m2m2.view.text.PlainRenderer)2 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 ChartRenderer (com.serotonin.m2m2.view.chart.ChartRenderer)1 BinaryTextRenderer (com.serotonin.m2m2.view.text.BinaryTextRenderer)1 DataPointSummary (com.serotonin.m2m2.vo.DataPointSummary)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 User (com.serotonin.m2m2.vo.User)1 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)1 TimePeriodModel (com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.TimePeriodModel)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1