]> git.ipfire.org Git - people/ms/westferry.git/commitdiff
analytics: Add graph thumbnails
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Dec 2015 21:55:33 +0000 (22:55 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Dec 2015 21:55:33 +0000 (22:55 +0100)
Thumbnails of graphs are very handy for the user to
see certain events in the graph at one sight.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/modules/graphs/preview.html
src/templates/modules/graphs/thumbnail-bar.html [new file with mode: 0644]
src/templates/modules/graphs/thumbnail.html [new file with mode: 0644]
src/westferry/handlers/analytics.py
src/westferry/ui/graphs.py

index 292b076e81545c43da0dcccee3be6490d8586e13..70993a1bd4691595e299b8b1e7cb2b8b4a287448 100644 (file)
@@ -138,7 +138,9 @@ templates_modules_graphsdir = $(templates_modulesdir)/graphs
 
 dist_templates_modules_graphs_DATA = \
        src/templates/modules/graphs/box.html \
-       src/templates/modules/graphs/preview.html
+       src/templates/modules/graphs/preview.html \
+       src/templates/modules/graphs/thumbnail.html \
+       src/templates/modules/graphs/thumbnail-bar.html
 
 templates_modules_menudir = $(templates_modulesdir)/menu
 
index 21b957e2fed961c6a9a511fc5bb280c9286ec353..8706901f988a3ffdcc769754141355b2015c5fb3 100644 (file)
@@ -4,6 +4,8 @@
        </h3>
 </div>
 
+{% module GraphThumbnailBar(graph) %}
+
 <a href="{{ graph.make_url(interval="week") }}">
        <img class="img-responsive img-thumbnail" src="{{ graph.make_image_url() }}"
                alt="{{ graph.title }}">
diff --git a/src/templates/modules/graphs/thumbnail-bar.html b/src/templates/modules/graphs/thumbnail-bar.html
new file mode 100644 (file)
index 0000000..02eccd2
--- /dev/null
@@ -0,0 +1,7 @@
+<div class="row">
+       {% for interval in ("1h", "12h", "1d", "week", "month", "year") %}
+               <div class="col-md-2">
+                       {% module GraphThumbnail(graph, interval=interval) %}
+               </div>
+       {% end %}
+</div>
diff --git a/src/templates/modules/graphs/thumbnail.html b/src/templates/modules/graphs/thumbnail.html
new file mode 100644 (file)
index 0000000..e84b861
--- /dev/null
@@ -0,0 +1,2 @@
+<img class="img-responsive img-thumbnail"
+       src="{{ graph.make_thumbnail_url(**args) }}" alt="{{ graph.title }}">
index 3b412656d0a983b39b20eb88f65518ea5c1a919f..6346fa8d5ecdc3c978084c21084b5e432f439794 100644 (file)
@@ -319,9 +319,9 @@ class GraphExportHandler(base.BaseHandler):
 
        SUPPORTED_FORMATS = ("pdf", "png", "svg")
 
-       url = r"/graph/([\w\-]+)(?:/([\w\d\.]+))?\.(%s)" % "|".join(SUPPORTED_FORMATS)
+       url = r"/graph(/thumbnail)?/([\w\-]+)(?:/([\w\d\.]+))?\.(%s)" % "|".join(SUPPORTED_FORMATS)
 
-       def get(self, template_name, object_id, format):
+       def get(self, thumbnail, template_name, object_id, format):
                # Get the requested dimensions of the image
                height = self.get_argument_int("height", None)
                width  = self.get_argument_int("width", None)
@@ -340,6 +340,7 @@ class GraphExportHandler(base.BaseHandler):
                        "interval"   : interval,
                        "height"     : height,
                        "width"      : width,
+                       "thumbnail"  : bool(thumbnail),
 
                        # Include the title in the PDF exports
                        "with_title" : format == "pdf",
index 1098c742bba6cadf79abe6870f511ac77bf68e89..ab9b09e7c21bd8fd6cdea8a0a17b38047751ba02 100644 (file)
@@ -118,6 +118,14 @@ class Graph(object):
 
                return self._make_url(url, **kwargs)
 
+       def make_thumbnail_url(self, **kwargs):
+               if self.object_id:
+                       url = "/graph/thumbnail/%(template)s/%(object_id)s.%(format)s"
+               else:
+                       url = "/graph/thumbnail/%(template)s.%(format)s"
+
+               return self._make_url(url, **kwargs)
+
        def make_url(self, **kwargs):
                if self.object_id:
                        url = "/graph/%(template)s/%(object_id)s"
@@ -139,3 +147,13 @@ class GraphBoxModule(base.BaseUIModule):
 class GraphBoxPreviewModule(base.BaseUIModule):
        def render(self, graph):
                return self.render_string("modules/graphs/preview.html", graph=graph)
+
+
+class GraphThumbnailModule(base.BaseUIModule):
+       def render(self, graph, **kwargs):
+               return self.render_string("modules/graphs/thumbnail.html", graph=graph, args=kwargs)
+
+
+class GraphThumbnailBarModule(base.BaseUIModule):
+       def render(self, graph):
+               return self.render_string("modules/graphs/thumbnail-bar.html", graph=graph)