changeset 250:141948a400a6

working zoom
author Matt Johnston <matt@ucc.asn.au>
date Wed, 27 May 2015 23:45:03 +0800
parents c490de0cf17e
children b6079cb0c665 3e6f82347eab
files web/templog.py web/templog.wsgi web/views/top.tpl
diffstat 3 files changed, 22 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/web/templog.py	Wed May 27 22:37:43 2015 +0800
+++ b/web/templog.py	Wed May 27 23:45:03 2015 +0800
@@ -66,7 +66,8 @@
 @route('/graph.png')
 def graph():
     response.set_header('Content-Type', 'image/png')
-    return make_graph(request.query.length, request.query.end)
+    minutes, endstr = get_request_zoom()
+    return make_graph(minutes, endstr)
 
 @route('/set/update', method='post')
 def set_update():
@@ -94,9 +95,9 @@
         csrf_blob = secure.get_csrf_blob(),
         allowed = allowed)
 
-@route('/')
-def top():
-
+def get_request_zoom():
+    """ returns (length, end) tuple.
+    length is in minutes, end is a DATE_FORMAT string """
     minutes = int(request.query.get('length', 26*60))
 
     if 'end' in request.query:
@@ -124,14 +125,21 @@
 
     if end > datetime.now():
         end = datetime.now()
-        
+
+    endstr = end.strftime(DATE_FORMAT)
+    return (minutes, endstr)
+
+@route('/')
+def top():
+    minutes, endstr = get_request_zoom()
+
     request.query.replace('length', minutes)
-    request.query.replace('end', end.strftime(DATE_FORMAT))
+    request.query.replace('end', endstr)
 
     urlparams = urllib.urlencode(request.query)
-    graphdata = encode_data(make_graph(request.query.length, request.query.end), 'image/png')
+    graphdata = encode_data(make_graph(minutes, endstr), 'image/png')
     return bottle.template('top', urlparams=urlparams,
-                    end = end.strftime(DATE_FORMAT),
+                    end = endstr,
                     length = minutes,
                     graphwidth = config.GRAPH_WIDTH,
                     graphdata = graphdata)
--- a/web/templog.wsgi	Wed May 27 22:37:43 2015 +0800
+++ b/web/templog.wsgi	Wed May 27 23:45:03 2015 +0800
@@ -1,6 +1,5 @@
 #from gevent import monkey; monkey.patch_all()
 
-
 import os
 import sys
 # Change working directory so relative paths (and template lookup) work again
--- a/web/views/top.tpl	Wed May 27 22:37:43 2015 +0800
+++ b/web/views/top.tpl	Wed May 27 23:45:03 2015 +0800
@@ -26,17 +26,19 @@
 <script type="text/javascript">
 function updatewidth() {
 	var width_input = document.getElementById("scaledwidth");
-	width_input.value = document.getElementById("mainimage").clientWidth;
+	var main_image = document.getElementById("mainimage");
+	width_input.value = main_image.clientWidth;
+	return true;
 }
 
 </script>
 <body>
-<form action="" method="get">
-<span class="no_selection"><input type="image" id="mainimage" src="{{graphdata}}" onclick="updatewidth();"/></span>
+<form action="" method="get" onsubmit="return updatewidth();">
+<span class="no_selection"><input type="image" id="mainimage" src="{{graphdata}}"/></span>
 <input type="hidden" name="length" value="{{length}}"/>
 <input type="hidden" name="end" value="{{end}}"/>
 <input type="hidden" name="zoom" value="yeah"/>
-<input type="hidden" name="scaledwidth" id="scaledwidth" value="-1"/>
+<input type="hidden" name="scaledwidth" id="scaledwidth" value="{{graphwidth}}"/>
 </form>
 <span class="codelink">Click to zoom in, click the left axis to zoom out. <a href="https://secure.ucc.asn.au/hg/templog/file/tip">Source code</a> for the Raspberry Pi controller and this web interface</a>. <a href="set">Adjustments</a> by phone.</span>
 </body>