From 68fd974cd167158c48904e15c9e7485c42e5c305 Mon Sep 17 00:00:00 2001
From: Tamas Gal <tgal@km3net.de>
Date: Sun, 6 Oct 2019 23:20:42 +0200
Subject: [PATCH] Define a unique URL for individual plots

---
 app/routes.py            |  6 ++++++
 app/static/css/main.css  |  4 ++++
 app/templates/plot.html  | 22 ++++++++++++++++++++++
 app/templates/plots.html |  2 +-
 4 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 app/templates/plot.html

diff --git a/app/routes.py b/app/routes.py
index 891df29..c54ec7a 100644
--- a/app/routes.py
+++ b/app/routes.py
@@ -102,6 +102,12 @@ def index():
     return render_template('plots.html', plots=expand_wildcards(PLOTS))
 
 
+@app.route('/plot_<plot>.html')
+@requires_auth
+def single_plot(plot):
+    return render_template('plot.html', plot=plot)
+
+
 @app.route('/ahrs.html')
 @requires_auth
 def ahrs():
diff --git a/app/static/css/main.css b/app/static/css/main.css
index e570e9f..7ce85f9 100644
--- a/app/static/css/main.css
+++ b/app/static/css/main.css
@@ -33,3 +33,7 @@ img.plot {
 #logs a {
     margin: 5px;
 }
+
+#plot img {
+    margin: 0 auto
+}
diff --git a/app/templates/plot.html b/app/templates/plot.html
new file mode 100644
index 0000000..fe668dd
--- /dev/null
+++ b/app/templates/plot.html
@@ -0,0 +1,22 @@
+{% extends "base.html" %}
+
+{% block main %}
+
+    <div class="container-fluid" id="plot">
+                <a href="plots/{{ plot }}.png">
+                    <img 
+                         class="img-responsive"
+                         src="plots/{{ plot }}.png"
+                         alt="{{ plot }}"/>
+                </a>
+    </div>
+
+    <script type = "text/javascript">
+        $(document).ready(function(){
+            setInterval(function(){
+                $("#plot").attr("src", "plots/{{ plot }}.png?"+new Date().getTime());
+            }, 45000);
+        });
+    </script>
+
+{% endblock %}
diff --git a/app/templates/plots.html b/app/templates/plots.html
index df86529..8e1e77e 100644
--- a/app/templates/plots.html
+++ b/app/templates/plots.html
@@ -13,7 +13,7 @@
         <div class="row">
             {% for plot in row %}
             <div class="col-md-{{ (12/(row|length))|int }} plot-container">
-                <a href="plots/{{ plot }}.png">
+                <a href="plot_{{ plot }}.html">
                     <img id="{{ plot }}"
                          class="plot img-responsive"
                          src="plots/{{ plot }}.png"
-- 
GitLab