IDEMPIERE-5527 Implement asynchronous rendering of dashboard gadget p… (#1641)

* IDEMPIERE-5527 Implement asynchronous rendering of dashboard gadget panel

- Auto refresh in background thread instead of UI thread

* IDEMPIERE-5527 Implement asynchronous rendering of dashboard gadget panel

- status line error reported by Peter Takacs

* IDEMPIERE-5527 Implement asynchronous rendering of dashboard gadget panel

- fix performance goal error reported by Peter Takacs
This commit is contained in:
hengsin 2023-01-18 21:38:10 +08:00 committed by GitHub
parent f2684bad08
commit 0aec0cf450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 8 deletions

View File

@ -20,9 +20,12 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import org.adempiere.util.ContextRunnable;
import org.adempiere.util.ServerContext; import org.adempiere.util.ServerContext;
import org.adempiere.webui.apps.BusyDialog;
import org.adempiere.webui.session.SessionContextListener; import org.adempiere.webui.session.SessionContextListener;
import org.adempiere.webui.util.ServerPushTemplate; import org.adempiere.webui.util.ServerPushTemplate;
import org.compiere.Adempiere;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.zkoss.util.Locales; import org.zkoss.util.Locales;
import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Desktop;
@ -132,7 +135,20 @@ public class DashboardRunnable implements Runnable, Serializable
if (pooling && !dashboardPanels.get(i).isPooling()) if (pooling && !dashboardPanels.get(i).isPooling())
continue; continue;
dashboardPanels.get(i).refresh(template); final DashboardPanel dpanel = dashboardPanels.get(i);
BusyDialog busyDialog = new BusyDialog();
busyDialog.setShadow(false);
dpanel.getParent().insertBefore(busyDialog, dpanel.getParent().getFirstChild());
ContextRunnable cr = new ContextRunnable() {
@Override
protected void doRun() {
dpanel.refresh(template);
template.execute(() -> {
busyDialog.detach();
});
}
};
Adempiere.getThreadPoolExecutor().submit(cr);
} }
} }
finally finally

View File

@ -434,7 +434,7 @@ public class DashboardController implements EventListener<Event> {
private void asyncRenderGadgetPanel(ServerPushTemplate spt, MDashboardContent dashboardContent, Panel panel, IDesktop appDesktop, String contextPath, private void asyncRenderGadgetPanel(ServerPushTemplate spt, MDashboardContent dashboardContent, Panel panel, IDesktop appDesktop, String contextPath,
Panelchildren panelChildren, Component zulComponent) throws Exception { Panelchildren panelChildren, Component zulComponent) throws Exception {
List<Component> components = new ArrayList<>(); List<Component> components = new ArrayList<>();
asyncRenderComponents(dashboardContent, dashboardRunnable, appDesktop, contextPath, panelChildren, components, zulComponent); asyncRenderComponents(dashboardContent, dashboardRunnable, appDesktop, contextPath, panelChildren, components, zulComponent, spt);
if (components.size() > 0) { if (components.size() > 0) {
for(Component c : components) { for(Component c : components) {
if (c.getParent() != panelChildren) { if (c.getParent() != panelChildren) {
@ -686,10 +686,11 @@ public class DashboardController implements EventListener<Event> {
* @param parentComponent * @param parentComponent
* @param components * @param components
* @param zulComponent * @param zulComponent
* @param spt
* @throws Exception * @throws Exception
*/ */
private void asyncRenderComponents(MDashboardContent dashboardContent, DashboardRunnable dashboardRunnable, IDesktop appDesktop, String contextPath, private void asyncRenderComponents(MDashboardContent dashboardContent, DashboardRunnable dashboardRunnable, IDesktop appDesktop, String contextPath,
HtmlBasedComponent parentComponent, List<Component> components, Component zulComponent) throws Exception { HtmlBasedComponent parentComponent, List<Component> components, Component zulComponent, ServerPushTemplate spt) throws Exception {
// HTML content // HTML content
String htmlContent = dashboardContent.get_ID() > 0 ? dashboardContent.get_Translation(MDashboardContent.COLUMNNAME_HTML) : null; String htmlContent = dashboardContent.get_ID() > 0 ? dashboardContent.get_Translation(MDashboardContent.COLUMNNAME_HTML) : null;
if(htmlContent != null) if(htmlContent != null)
@ -810,7 +811,7 @@ public class DashboardController implements EventListener<Event> {
options.colorMap.put(WPerformanceIndicator.DIAL_BACKGROUND, new Color(224, 224, 224, 1)); options.colorMap.put(WPerformanceIndicator.DIAL_BACKGROUND, new Color(224, 224, 224, 1));
WPAWidget paWidget = new WPAWidget(goal, options, dashboardContent.isShowTitle()); WPAWidget paWidget = new WPAWidget(goal, options, dashboardContent.isShowTitle());
components.add(paWidget); components.add(paWidget);
LayoutUtils.addSclass("performance-gadget", parentComponent); spt.executeAsync(() -> LayoutUtils.addSclass("performance-gadget", parentComponent));
} else { } else {
//link to open performance detail //link to open performance detail
Div div = new Div(); Div div = new Div();
@ -896,7 +897,7 @@ public class DashboardController implements EventListener<Event> {
div.appendChild(statusLineHtml); div.appendChild(statusLineHtml);
div.setSclass("statusline-gadget"); div.setSclass("statusline-gadget");
components.add(div); components.add(div);
LayoutUtils.addSclass("statusline-wrapper", ((HtmlBasedComponent) parentComponent.getParent())); spt.executeAsync(() -> LayoutUtils.addSclass("statusline-wrapper", ((HtmlBasedComponent) parentComponent.getParent())));
} }
} }
@ -918,10 +919,11 @@ public class DashboardController implements EventListener<Event> {
throw new AdempiereException(e); throw new AdempiereException(e);
} }
} }
HtmlBasedComponent parentComponent = (HtmlBasedComponent) content;
asyncRenderComponents(dashboardContent, dashboardRunnable, SessionManager.getAppDesktop(), Executions.getCurrent().getContextPath(), parentComponent, components, zulComponent);
boolean empty = components.isEmpty();
ServerPushTemplate spt = new ServerPushTemplate(content.getDesktop()); ServerPushTemplate spt = new ServerPushTemplate(content.getDesktop());
HtmlBasedComponent parentComponent = (HtmlBasedComponent) content;
asyncRenderComponents(dashboardContent, dashboardRunnable, SessionManager.getAppDesktop(), Executions.getCurrent().getContextPath(), parentComponent, components,
zulComponent, spt);
boolean empty = components.isEmpty();
for(Component c : components) { for(Component c : components) {
if (c.getParent() != parentComponent) { if (c.getParent() != parentComponent) {
parentComponent.appendChild(c); parentComponent.appendChild(c);