IDEMPIERE-2640 Performance: Html/Tabular reports size could be reduced / IDEMPIERE-2355 Allow to style the summary rows of HTML report

This commit is contained in:
Carlos Ruiz 2015-12-06 17:22:56 -05:00
parent 045e250a69
commit c47d87d389
4 changed files with 49 additions and 18 deletions

View File

@ -16,9 +16,9 @@
*****************************************************************************/
package org.compiere.print;
import static org.compiere.model.SystemIDs.TABLE_AD_TABLE;
import static org.compiere.model.SystemIDs.PROCESS_RPT_M_INVENTORY;
import static org.compiere.model.SystemIDs.PROCESS_RPT_M_MOVEMENT;
import static org.compiere.model.SystemIDs.TABLE_AD_TABLE;
import java.awt.Color;
import java.awt.Font;
@ -807,14 +807,14 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
if (extension != null && extension.getStyleURL() != null)
{
// maybe cache style content with key is path
String pathStyleFile = extension.getFullPathStyle();
String pathStyleFile = extension.getFullPathStyle(); // creates a temp file - delete below
Path path = Paths.get(pathStyleFile);
List<String> styleLines = Files.readAllLines(path, Ini.getCharset());
Files.delete(path); // delete temp file
StringBuilder styleBuild = new StringBuilder();
for (String styleLine : styleLines){
styleBuild.append(styleLine);
styleBuild.append(styleLine); //.append("\n");
}
appendInlineCss (doc, styleBuild);
}
if (extension != null && extension.getScriptURL() != null && !isExport)
@ -2092,4 +2092,5 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
return String.format(CSS_SELECTOR_TEMPLATE, index + 1);
}
}
} // ReportEngine

View File

@ -798,8 +798,7 @@ public class DashboardController implements EventListener<Event> {
Iframe iframe = new Iframe();
iframe.setSclass("dashboard-report-iframe");
File file = File.createTempFile(re.getName(), ".html");
re.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(Executions.getCurrent().getDesktop().getWebApp().getRealPath("/"),
Executions.getCurrent().getContextPath(), "rp",
re.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(Executions.getCurrent().getContextPath(), "rp",
SessionManager.getAppDesktop().getComponent().getUuid()));
AMedia media = new AMedia(re.getName(), "html", "text/html", file, false);
iframe.setContent(media);

View File

@ -13,6 +13,13 @@
*****************************************************************************/
package org.adempiere.webui.report;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.theme.ThemeManager;
import org.apache.ecs.ConcreteElement;
@ -36,9 +43,8 @@ public class HTMLExtension implements IHTMLExtension {
private String componentId;
private String scriptURL;
private String styleURL;
private String contextFullPath;
public HTMLExtension(String contextFullPath, String contextPath, String classPrefix, String componentId) {
public HTMLExtension(String contextPath, String classPrefix, String componentId) {
String theme = MSysConfig.getValue(MSysConfig.HTML_REPORT_THEME, "/", Env.getAD_Client_ID(Env.getCtx()));
@ -51,7 +57,6 @@ public class HTMLExtension implements IHTMLExtension {
this.componentId = componentId;
this.scriptURL = contextPath + theme + "js/report.js";
this.styleURL = contextPath + theme + "css/report.css";
this.contextFullPath = contextFullPath;
}
public void extendIDColumn(int row, ConcreteElement columnElement, a href,
@ -96,13 +101,42 @@ public class HTMLExtension implements IHTMLExtension {
public String getFullPathStyle() {
String theme = MSysConfig.getValue(MSysConfig.HTML_REPORT_THEME, "/", Env.getAD_Client_ID(Env.getCtx()));
if (! theme.startsWith("/"))
theme = "/" + theme;
if (! theme.endsWith("/"))
theme = theme + "/";
String resFile = theme + "css/report.css";
return contextFullPath + theme + "css/report.css";
URL urlFile = this.getClass().getResource(resFile);
if (urlFile == null) {
resFile = "/css/report.css"; // default
urlFile = this.getClass().getResource(resFile);
}
if (urlFile != null) {
FileOutputStream cssStream = null;
File cssFile = null;
try {
// copy the resource to a temporary file to process it with 2pack
InputStream stream = urlFile.openStream();
cssFile = File.createTempFile("report", ".css");
cssStream = new FileOutputStream(cssFile);
byte[] buffer = new byte[1024];
int read;
while((read = stream.read(buffer)) != -1){
cssStream.write(buffer, 0, read);
}
} catch (IOException e) {
throw new AdempiereException(e);
} finally{
if (cssStream != null) {
try {
cssStream.close();
} catch (Exception e2) {}
}
}
return cssFile.getAbsolutePath();
} else {
return null;
}
}
}

View File

@ -1043,8 +1043,7 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
{
StringWriter sw = new StringWriter();
String contextPath = Executions.getCurrent().getContextPath();
String contextFullPath = Executions.getCurrent().getDesktop().getWebApp().getRealPath("/");
m_reportEngine.createHTML(sw, false, m_reportEngine.getPrintFormat().getLanguage(), new HTMLExtension(contextFullPath, contextPath, "rp", this.getUuid()), true);
m_reportEngine.createHTML(sw, false, m_reportEngine.getPrintFormat().getLanguage(), new HTMLExtension(contextPath, "rp", this.getUuid()), true);
data = sw.getBuffer().toString().getBytes();
}
else if (ext.equals("xls"))
@ -1424,13 +1423,11 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
private ZkReportViewer viewer;
private String contextPath;
private String contextFullPath;
public HTMLRendererRunnable(ZkReportViewer viewer) {
super();
this.viewer = viewer;
contextPath = Executions.getCurrent().getContextPath();
contextFullPath = Executions.getCurrent().getDesktop().getWebApp().getRealPath("/");
}
@Override
@ -1445,7 +1442,7 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
}
File file = File.createTempFile(prefix, ".html", new File(path));
viewer.m_reportEngine.createHTML(file, false, viewer.m_reportEngine.getPrintFormat().getLanguage(), new HTMLExtension(contextFullPath, contextPath, "rp", viewer.getUuid()));
viewer.m_reportEngine.createHTML(file, false, viewer.m_reportEngine.getPrintFormat().getLanguage(), new HTMLExtension(contextPath, "rp", viewer.getUuid()));
viewer.media = new AMedia(file.getName(), "html", "text/html", file, false);
} catch (Exception e) {
if (e instanceof RuntimeException)