提交 fca53b57 编写于 作者: J Joram Barrez

ACT-1593: save report functionality

上级 534614c4
......@@ -285,6 +285,7 @@ public interface Messages {
String REPORTING_MENU_SAVED_REPORTS = "reporting.menu.saved.reports";
String REPORTING_SAVE_POPUP_CAPTION = "reporting.save.popup.caption";
String REPORTING_SAVE_POPUP_NAME = "reporting.save.popup.name";
String REPORTING_SAVE_POPUP_NAME_EMPTY = "reporting.save.popup.name.empty";
String REPORTING_SAVE_POPUP_NAME_EXISTS = "reporting.save.popup.name.exists";
String REPORTING_SAVE_POPUP_NAME_TOO_LONG = "reporting.save.popup..name.too.long";
......
......@@ -21,10 +21,12 @@ import org.dussan.vaadin.dcharts.DCharts;
import org.dussan.vaadin.dcharts.base.elements.XYaxis;
import org.dussan.vaadin.dcharts.data.DataSeries;
import org.dussan.vaadin.dcharts.data.Ticks;
import org.dussan.vaadin.dcharts.metadata.LegendPlacements;
import org.dussan.vaadin.dcharts.metadata.renderers.AxisRenderers;
import org.dussan.vaadin.dcharts.metadata.renderers.SeriesRenderers;
import org.dussan.vaadin.dcharts.options.Axes;
import org.dussan.vaadin.dcharts.options.Highlighter;
import org.dussan.vaadin.dcharts.options.Legend;
import org.dussan.vaadin.dcharts.options.Options;
import org.dussan.vaadin.dcharts.options.SeriesDefaults;
......@@ -65,9 +67,11 @@ public class ChartGenerator {
SeriesDefaults seriesDefaults = new SeriesDefaults().setRenderer(SeriesRenderers.BAR);
Axes axes = new Axes().addAxis(new XYaxis().setRenderer(AxisRenderers.CATEGORY).setTicks(new Ticks().add((Object[]) names)));
Highlighter highlighter = new Highlighter().setShow(false);
Options options = new Options().setSeriesDefaults(seriesDefaults).setAxes(axes).setHighlighter(highlighter);
options.setAnimate(true);
options.setAnimateReplot(true);
chart = new DCharts().setDataSeries(dataSeries).setOptions(options);
} else if(CHART_TYPE_PIE_CHART.equals(type)) {
......@@ -77,13 +81,20 @@ public class ChartGenerator {
dataSeries.add(names[i], values[i]);
}
SeriesDefaults seriesDefaults = new SeriesDefaults().setRenderer(SeriesRenderers.PIE);
Options options = new Options().setSeriesDefaults(seriesDefaults);
options.setAnimate(true);
options.setAnimateReplot(true);
Legend legend = new Legend().setShow(true).setPlacement(LegendPlacements.INSIDE);
options.setLegend(legend);
Highlighter highlighter = new Highlighter().setShow(true);
options.setHighlighter(highlighter);
chart = new DCharts().setDataSeries(dataSeries).setOptions(options);
}
return new ChartComponent(description, chart);
}
......
......@@ -12,6 +12,8 @@
*/
package org.activiti.explorer.ui.reports;
import java.util.Map;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.form.StartFormData;
......@@ -28,7 +30,6 @@ import org.activiti.explorer.ui.form.FormPropertiesEventListener;
import org.activiti.explorer.ui.form.FormPropertiesForm;
import org.activiti.explorer.ui.form.FormPropertiesForm.FormPropertiesEvent;
import org.activiti.explorer.ui.mainlayout.ExplorerLayout;
import org.activiti.explorer.ui.management.processdefinition.ChangeProcessSuspensionStatePopupWindow;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
......@@ -56,6 +57,8 @@ public class ReportDetailPanel extends DetailPanel {
protected HorizontalLayout detailContainer;
protected FormPropertiesForm processDefinitionStartForm;
protected Map<String, String> savedFormProperties;
public ReportDetailPanel(String processDefinitionId, AbstractPage parentPage) {
this.parentPage = parentPage;
this.i18nManager = ExplorerApp.get().getI18nManager();
......@@ -117,15 +120,17 @@ public class ReportDetailPanel extends DetailPanel {
}
protected void initActions() {
Button saveButton = new Button(i18nManager.getMessage(Messages.BUTTON_SAVE));
final Button saveButton = new Button(i18nManager.getMessage(Messages.BUTTON_SAVE));
saveButton.addListener(new ClickListener() {
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
ChangeProcessSuspensionStatePopupWindow popupWindow =
new ChangeProcessSuspensionStatePopupWindow(processDefinition.getId(), parentPage, false);
ExplorerApp.get().getViewManager().showPopupWindow(popupWindow);
SaveReportPopupWindow saveReportPopupWindow = new SaveReportPopupWindow();
saveReportPopupWindow.setProcessDefinitionId(processDefinition.getId());
saveReportPopupWindow.setOriginalFormProperties(savedFormProperties);
saveReportPopupWindow.setComponentToDisableOnClose(saveButton);
ExplorerApp.get().getViewManager().showPopupWindow(saveReportPopupWindow);
}
});
......@@ -153,11 +158,10 @@ public class ReportDetailPanel extends DetailPanel {
private static final long serialVersionUID = 1L;
protected void handleFormSubmit(FormPropertiesEvent event) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// Report is generated by a process
ProcessInstance processInstance = processEngine.getFormService()
.submitStartFormData(processDefinition.getId(), event.getFormProperties());
// Report is generated by running a process and storing the dataset in the history tablkes
savedFormProperties = event.getFormProperties();
ProcessInstance processInstance = startProcessInstanceWithFormProperties(processDefinition.getId(), event.getFormProperties());
generateReport(processInstance);
}
......@@ -170,11 +174,20 @@ public class ReportDetailPanel extends DetailPanel {
} else {
// Just start the process-instance since it has no form.
ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinition.getId());
ProcessInstance processInstance = startProcessInstance(processDefinition.getId());
generateReport(processInstance);
}
}
protected ProcessInstance startProcessInstanceWithFormProperties(String processDefinitonId, Map<String, String> formProperties) {
return ProcessEngines.getDefaultProcessEngine().getFormService()
.submitStartFormData(processDefinitonId, formProperties);
}
protected ProcessInstance startProcessInstance(String processDefinitionId) {
return ProcessEngines.getDefaultProcessEngine().getRuntimeService().startProcessInstanceById(processDefinitionId);
}
protected void generateReport(ProcessInstance processInstance) {
// Report dataset is stored as historical variable as json
HistoricVariableInstance historicVariableInstance = ProcessEngines.getDefaultProcessEngine()
......@@ -196,6 +209,10 @@ public class ReportDetailPanel extends DetailPanel {
processDefinitionStartForm = null;
}
detailContainer.addComponent(chart);
// The historic process instance can now be removed from the system
// Only when save is clicked, the report will be regenerated
ProcessEngines.getDefaultProcessEngine().getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
}
protected String getReportDisplayName() {
......
......@@ -12,11 +12,26 @@
*/
package org.activiti.explorer.ui.reports;
import java.util.Map;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.explorer.ExplorerApp;
import org.activiti.explorer.I18nManager;
import org.activiti.explorer.Messages;
import org.activiti.explorer.ui.custom.PopupWindow;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.Reindeer;
/**
* @author Joram Barrez
......@@ -24,10 +39,120 @@ import org.activiti.explorer.ui.custom.PopupWindow;
public class SaveReportPopupWindow extends PopupWindow {
private static final long serialVersionUID = 1L;
protected String processDefinitionId;
protected Map<String, String> originalFormProperties;
protected Component componentToDisableOnClose;
protected TextField nameField;
public SaveReportPopupWindow() {
I18nManager i18nManager = ExplorerApp.get().getI18nManager();
setCaption(i18nManager.getMessage(Messages.REPORTING_SAVE_POPUP_CAPTION));
VerticalLayout layout = new VerticalLayout();
addComponent(layout);
createNameTextField(i18nManager, layout);
createSaveButton(i18nManager, layout);
setModal(true);
center();
setResizable(false);
setWidth(400, UNITS_PIXELS);
setHeight(150, UNITS_PIXELS);
addStyleName(Reindeer.WINDOW_LIGHT);
}
protected void createNameTextField(I18nManager i18nManager, VerticalLayout layout) {
HorizontalLayout fieldLayout = new HorizontalLayout();
fieldLayout.setWidth(100, UNITS_PERCENTAGE);
layout.addComponent(fieldLayout);
fieldLayout.addComponent(new Label(i18nManager.getMessage(Messages.REPORTING_SAVE_POPUP_NAME)));
nameField = new TextField();
nameField.setWidth(250, UNITS_PIXELS);
fieldLayout.addComponent(nameField);
}
protected void createSaveButton(final I18nManager i18nManager, final VerticalLayout layout) {
layout.addComponent(new Label("&nbsp", Label.CONTENT_XHTML));
Button saveButton = new Button(i18nManager.getMessage(Messages.BUTTON_SAVE));
layout.addComponent(saveButton);
layout.setComponentAlignment(saveButton, Alignment.MIDDLE_CENTER);
saveButton.addListener(new ClickListener() {
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
String reportName = null;
// Validate
String error = null;
if (nameField.getValue() == null || ((String) nameField.getValue()).length() == 0) {
error = i18nManager.getMessage(Messages.REPORTING_SAVE_POPUP_NAME_EMPTY);
} else {
reportName = ExplorerApp.get().getLoggedInUser().getId() + "_" + nameField.getValue();
if (reportName.length() > 255) {
error = i18nManager.getMessage(Messages.REPORTING_SAVE_POPUP_NAME_TOO_LONG);
} else {
boolean nameUsed = ProcessEngines.getDefaultProcessEngine().getHistoryService()
.createHistoricProcessInstanceQuery().processInstanceBusinessKey(reportName).count() != 0;
if (nameUsed) {
error = i18nManager.getMessage(Messages.REPORTING_SAVE_POPUP_NAME_EXISTS);
}
}
}
// Re-run reports to store the data for good now (the previous process instance was deleted)
if (originalFormProperties != null) {
startProcessInstanceWithFormProperties(reportName);
} else {
startProcessInstance(reportName);
}
// Remove the popup
if (componentToDisableOnClose != null) {
componentToDisableOnClose.setEnabled(false);
}
close();
}
});
}
protected ProcessInstance startProcessInstanceWithFormProperties(String businessKey) {
return ProcessEngines.getDefaultProcessEngine().getFormService()
.submitStartFormData(processDefinitionId, businessKey, originalFormProperties);
}
protected ProcessInstance startProcessInstance(String businessKey) {
return ProcessEngines.getDefaultProcessEngine().getRuntimeService().startProcessInstanceById(processDefinitionId, businessKey);
}
public String getProcessDefinitionId() {
return processDefinitionId;
}
public void setProcessDefinitionId(String processDefinitionId) {
this.processDefinitionId = processDefinitionId;
}
public Map<String, String> getOriginalFormProperties() {
return originalFormProperties;
}
public void setOriginalFormProperties(Map<String, String> originalFormProperties) {
this.originalFormProperties = originalFormProperties;
}
public Component getComponentToDisableOnClose() {
return componentToDisableOnClose;
}
public void setComponentToDisableOnClose(Component componentToDisableOnClose) {
this.componentToDisableOnClose = componentToDisableOnClose;
}
}
......@@ -266,8 +266,9 @@ reporting.menu.run.reports = Run reports
reporting.menu.saved.reports = Saved reports
reporting.save.popup.caption = Save this report
reporting.save.popup.name = Name
reporting.save.popup.name.exists = Invalid name: A report with this name already exists.
reporting.save.popup.name.too.long = Invalid name: too long.
reporting.save.popup.name.exists = Invalid name: a report with this name already exists
reporting.save.popup.name.too.long = Invalid name: name is too long
reporting.save.popup.name.empty = Name must be provided
# Management menu
management.menu.database = Database
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册