Commit d50ef03a authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update controllers and views to export graph as png/pdf file.

parent 2fc1708e
......@@ -2,17 +2,15 @@
"""new_report controllers
"""
import json
import urllib
from gluon.tools import PluginManager
from plugin_dbui import INLINE_ALERT, Selector
from plugin_dbui import INLINE_ALERT
from plugin_event import Graph2, List2, Metric2D2, ReportException
def list():
"""The report is a list rendered by an ``Ext.grid.Panel`` widget.
def grid():
"""The list is rendered such as an ``Ext.grid.Panel`` widget.
Its context menu allows to export the content of the table as a CSV, LaTeX
or PDF format.
......@@ -36,7 +34,7 @@ def list():
def metric2d():
"""The report contains a table rendered by an ``Ext.grid.Panel`` widget
"""The metric 2D is a 2D table rendered by an ``Ext.grid.Panel`` widget
and a graph rendered as an image. The context menu associated to the grid
allows to export the content of the table as a CSV, LaTeX or PDF format.
The context menu associated to the image allow to export in PNG or PDF
......@@ -48,18 +46,33 @@ def metric2d():
the graph.
"""
extension = request.extension
try:
report = Metric2D2(request.vars.id_metric2d)
store = report.get_store_configuration()
grid = report.get_grid_configuration()
title = report.get_title()
graph = Graph2(report)
img = graph.to_svg()
img = urllib.quote(img)
title = report.get_title()
if extension == "html":
store = report.get_store_configuration()
grid = report.get_grid_configuration()
img = graph.to_svg()
img = urllib.quote(img)
response.view = "plugin_event/grid_and_graph.html"
return dict(cfg_store=store, grid=grid, img=img, title=title)
elif extension == "pdf":
data = graph.to_pdf()
response.view = "plugin_event/graph_mpl.pdf"
return dict(data=data, title=title)
elif extension == "png":
data = graph.to_png()
response.view = "plugin_event/graph_mpl.png"
return dict(data=data, title=title)
except (IndexError, ReportException, TypeError, ValueError) as e:
return INLINE_ALERT % ("REPORT Error...", e)
response.view = "plugin_event/grid_and_graph.html"
return dict(cfg_store=store, grid=grid, img=img, title=title)
......@@ -274,7 +274,7 @@ class ViewportUi(object):
for row in db(db.lists2.id > 0).select(orderby=db.lists2.name):
panel = selector_panel
panel.baseUrl = URL("new_report", "list")
panel.baseUrl = URL("new_report", "grid")
panel.baseParams = {"id_list": row.id}
add_child(row.name, panel)
......
......@@ -39,8 +39,8 @@
myapp = request.application
myvars = urllib.urlencode(request.vars)
url_pdf = "/%s/plugin_event/graph_mpl.pdf?%s" % (myapp, myvars)
url_png = "/%s/plugin_event/graph_mpl.png?%s" % (myapp, myvars)
url_pdf = "/%s/new_report/metric2d.pdf?%s" % (myapp, myvars)
url_png = "/%s/new_report/metric2d.png?%s" % (myapp, myvars)
#
# translate
......@@ -103,6 +103,7 @@
cfgPanelImg = {
border: false,
html: '<img src="data:image/svg+xml;utf8,{{=img}}" height=400></img>',
itemId: "graphPanel"
};
/**
......@@ -131,7 +132,7 @@
}]
});
panel.body.on("contextmenu", function(event) {
panel.getComponent('graphPanel').body.on("contextmenu", function(event) {
event.stopEvent();
menu.showAt(event.getXY());
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment