use of com.qcadoo.view.api.components.ganttChart.GanttChartItem in project qcadoo by qcadoo.
the class GanttChartComponentState method renderContent.
@Override
protected JSONObject renderContent() throws JSONException {
JSONObject json = new JSONObject();
json.put("zoomLevel", scale.getZoomLevel().toString());
json.put("dateFromErrorMessage", dateFromErrorMessage);
json.put("dateToErrorMessage", dateToErrorMessage);
if (dateFromErrorMessage == null) {
json.put("dateFrom", DATETYPE.toString(scale.getDateFrom(), getLocale()));
}
if (dateToErrorMessage == null) {
json.put("dateTo", DATETYPE.toString(scale.getDateTo(), getLocale()));
}
json.put("globalErrorMessage", globalErrorMessage);
if (globalErrorMessage == null) {
json.put("scale", scale.getAsJson());
JSONArray rowsArray = new JSONArray();
JSONArray itemsArray = new JSONArray();
for (Map.Entry<String, List<GanttChartItem>> entry : items.entrySet()) {
rowsArray.put(entry.getKey());
for (GanttChartItem item : entry.getValue()) {
if (item != null) {
itemsArray.put(item.getAsJson());
}
}
}
json.put("stripsOrientation", getStripsOrientation().getStringValue());
json.put("itemsBorderColor", itemsBorderColor);
json.put("itemsBorderWidth", itemsBorderWidth);
json.put("rows", rowsArray);
json.put("items", itemsArray);
JSONArray collisionItemsArray = new JSONArray();
for (Map.Entry<String, List<GanttChartItem>> entry : collisionItems.entrySet()) {
for (GanttChartItem item : entry.getValue()) {
if (item != null) {
collisionItemsArray.put(item.getAsJson());
}
}
}
json.put("collisions", collisionItemsArray);
json.put("selectedEntityId", selectedEntityId);
}
return json;
}
use of com.qcadoo.view.api.components.ganttChart.GanttChartItem in project qcadoo by qcadoo.
the class GanttChartConflictItem method getAsJson.
@Override
public JSONObject getAsJson() throws JSONException {
JSONObject json = super.getAsJson();
JSONArray itemsArray = new JSONArray();
for (GanttChartItem item : items) {
itemsArray.put(item.getAsJson());
}
json.put("items", itemsArray);
return json;
}
use of com.qcadoo.view.api.components.ganttChart.GanttChartItem in project mes by qcadoo.
the class OperationsGanttChartItemResolverImpl method resolve.
@Override
public Map<String, List<GanttChartItem>> resolve(final GanttChartScale scale, final JSONObject context, final Locale locale) {
try {
Long orderId = Long.valueOf(context.getString("orderId"));
Entity order = dataDefinitionService.get(ORDERS_MODEL, ORDER_FIELD).get(orderId);
if (order == null) {
LOG.warn("Cannot find order for " + orderId);
return Collections.emptyMap();
}
Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
List<Entity> operations = dataDefinitionService.get(com.qcadoo.mes.technologies.constants.TechnologiesConstants.PLUGIN_IDENTIFIER, com.qcadoo.mes.technologies.constants.TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).find().add(SearchRestrictions.belongsTo(TechnologyOperationComponentFields.TECHNOLOGY, technology)).list().getEntities();
if (operations.isEmpty()) {
LOG.warn("Cannot find operations for " + order);
return Collections.emptyMap();
}
if (scale.getIsDatesSet() != null && scale.getIsDatesSet()) {
Entity orderTimeCalculation = dataDefinitionService.get(TimeNormsConstants.PLUGIN_PRODUCTION_SCHEDULING_IDENTIFIER, TimeNormsConstants.MODEL_ORDER_TIME_CALCULATION).find().add(SearchRestrictions.belongsTo("order", order)).setMaxResults(1).uniqueResult();
if (Objects.nonNull(orderTimeCalculation)) {
scale.setDateFrom(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_FROM));
scale.setDateTo(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_TO));
}
}
Map<String, List<GanttChartItem>> items = new LinkedHashMap<String, List<GanttChartItem>>();
Map<String, Integer> counters = new HashMap<String, Integer>();
List<Entity> sortedOperationFromTree = entityTreeUtilsService.getSortedEntities(order.getBelongsToField(OrderFields.TECHNOLOGY).getTreeField(TechnologyFields.OPERATION_COMPONENTS));
for (Entity operationFromTree : sortedOperationFromTree) {
Entity operation = operations.get(operations.indexOf(operationFromTree));
Entity timeCalculation = operationWorkTimeService.createOrGetOperCompTimeCalculation(order, operation);
Date dateFrom = timeCalculation.getDateField(EFFECTIVE_DATE_FROM_FIELD);
Date dateTo = timeCalculation.getDateField(EFFECTIVE_DATE_TO_FIELD);
if (dateFrom == null || dateTo == null || dateTo.before(scale.getDateFrom())) {
continue;
}
StringBuffer operationName = new StringBuffer(getDescriptionForOperation(operation));
int counter = 0;
if (counters.containsKey(operationName.toString())) {
counter = counters.get(operationName.toString()) + 1;
operationName.append(" (");
operationName.append(counter);
operationName.append(") ");
}
GanttChartItem item = scale.createGanttChartItem(operationName.toString(), operationName.toString(), operation.getId(), dateFrom, dateTo);
if (item != null) {
items.put(operationName.toString(), Collections.singletonList(item));
counters.put(operationName.toString(), counter);
}
}
return items;
} catch (NumberFormatException e) {
throw new IllegalStateException(e.getMessage(), e);
} catch (JSONException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
use of com.qcadoo.view.api.components.ganttChart.GanttChartItem in project mes by qcadoo.
the class ShiftsGanttChartItemResolverImpl method getItemsForShift.
private List<GanttChartItem> getItemsForShift(final Shift shift, final GanttChartScale scale) {
String shiftName = shift.getEntity().getStringField(ShiftFields.NAME);
List<DateTimeRange> timeRanges = shiftsService.getDateTimeRanges(Collections.singletonList(shift), scale.getDateFrom(), scale.getDateTo());
List<GanttChartItem> items = new ArrayList<>();
for (DateTimeRange timeRange : timeRanges) {
items.add(scale.createGanttChartItem(shiftName, shiftName, null, timeRange.getFrom().toDate(), timeRange.getTo().toDate()));
}
return items;
}
Aggregations