use of com.serotonin.m2m2.gviews.component.ImageChartComponent in project ma-modules-public by infiniteautomation.
the class GraphicalViewDwr method saveImageChartComponent.
@DwrPermission(user = true)
public ProcessResult saveImageChartComponent(String viewComponentId, String name, int width, int height, int durationType, int durationPeriods, int updatePeriodType, int updatePeriods, List<StringStringPair> childPointIds) {
ProcessResult response = new ProcessResult();
validateCompoundComponent(response, name);
if (width < 1)
response.addContextualMessage("imageChartWidth", "validate.greaterThanZero");
if (height < 1)
response.addContextualMessage("imageChartHeight", "validate.greaterThanZero");
if (!Common.TIME_PERIOD_CODES.isValidId(durationType))
response.addContextualMessage("imageChartDurationType", "validate.invalidValue");
if (durationPeriods <= 0)
response.addContextualMessage("imageChartDurationPeriods", "validate.greaterThanZero");
if (!Common.TIME_PERIOD_CODES.isValidId(updatePeriodType))
response.addContextualMessage("imageChartUpdatePeriodType", "validate.invalidValue");
if (updatePeriods < 0)
response.addContextualMessage("imageChartUpdatePeriods", "validate.cannotBeNegative");
if (!response.getHasMessages()) {
ImageChartComponent c = (ImageChartComponent) getViewComponent(viewComponentId);
c.setName(name);
c.setWidth(width);
c.setHeight(height);
c.setDurationType(durationType);
c.setDurationPeriods(durationPeriods);
c.setUpdatePeriodType(updatePeriodType);
c.setUpdatePeriods(updatePeriods);
saveCompoundPoints(c, childPointIds);
}
return response;
}
use of com.serotonin.m2m2.gviews.component.ImageChartComponent 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;
}
Aggregations