Explorar o código

remove loading template as it is specific to the Trend page and make progress template more generic

Daniel Sheffield hai 1 ano
pai
achega
8ae59aa7fd

+ 1 - 0
app/rest/templates/done.tpl

@@ -0,0 +1 @@
+<div class="done"/>

+ 0 - 61
app/rest/templates/loading.tpl

@@ -1,61 +0,0 @@
-% setdefault("start", False)
-% setdefault("end", False)
-% setdefault("progress", dict())
-% setdefault("done", False)
-% if start:
-<html>
-  <head>
-    <title>{{title}}</title>
-    <meta name="viewport" content="width=device-width, initial-scale=1"/>
-    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@2.1.0/build/pure-min.css" integrity="sha384-yHIFVG6ClnONEA5yB5DJXfW2/KC173DIQrYoZMEtBvGzmf0PKiGyNEqe9N6BNDBH" crossorigin="anonymous"/>
-    <link rel="stylesheet" href="https://shandan.one/css/grids-responsive-min.css"/>
-    <link rel="stylesheet" href="https://shandan.one/css/responsive-visibility-collapse.css"/>
-    <link rel="stylesheet" href="/grocery/static/cloud-gears.css"/>
-    <style>
-html {
-  --scrollbarBG: #333333;
-  --thumbBG: #080808;
-}
-svg {
-  max-height: min(100vh, calc(100vw * 9 / 16));
-  max-width: calc(100vw - 2em);
-}
-body {
-  background-color: #080808;
-  color: #cccccc;
-  text-align: center;
-}
-.loader-container {
-  position: absolute;
-  left: 45vw;
-  top: 45vh;
-}
-.loader-container:has(+ .done) {
-  display: none;
-}
-div.progress {
-  display:grid;
-  grid-template-columns: max-content max-content;
-  grid-gap:5px;
-}
-div.progress label {
-  text-align:left;
-}
-div.progress label:after {
-  content: "...";
-}
-div.progress:has(+ .done) {
-  display: none;
-}
-div.progress:has(+ .done) label:after {
-  content: "";
-}
-    </style>
-  </head>
-  <body align="center">
-    <div class="loader-container">
-% end
-% include('progress', **progress, done=done)
-% if end:
-    </div>
-    <div class="done"/>

+ 1 - 6
app/rest/templates/progress.tpl

@@ -1,6 +1 @@
-% setdefault("done", False)
-% if not done:
-<div class="progress"><label for="loading-{{stage}}">{{stage}}</label><progress id="loading-{{stage}}" value="{{percent}}" max="100"/></div>
-% else:
-<div class="done"/>
-% end
+<div class="progress"><label for="loading-{{stage}}">{{stage}}</label><progress id="loading-{{stage}}" value="{{percent}}" max="100"/></div>

+ 59 - 1
app/rest/templates/trend.tpl

@@ -1,4 +1,62 @@
+% setdefault("start", False)
+% setdefault("end", False)
+% if start:
+<html>
+  <head>
+    <title>Trend</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1"/>
+    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@2.1.0/build/pure-min.css" integrity="sha384-yHIFVG6ClnONEA5yB5DJXfW2/KC173DIQrYoZMEtBvGzmf0PKiGyNEqe9N6BNDBH" crossorigin="anonymous"/>
+    <link rel="stylesheet" href="https://shandan.one/css/grids-responsive-min.css"/>
+    <link rel="stylesheet" href="https://shandan.one/css/responsive-visibility-collapse.css"/>
+    <link rel="stylesheet" href="/grocery/static/cloud-gears.css"/>
+    <style>
+html {
+  --scrollbarBG: #333333;
+  --thumbBG: #080808;
+}
+svg {
+  max-height: min(100vh, calc(100vw * 9 / 16));
+  max-width: calc(100vw - 2em);
+}
+body {
+  background-color: #080808;
+  color: #cccccc;
+  text-align: center;
+}
+.loader-container {
+  position: absolute;
+  left: 45vw;
+  top: 45vh;
+}
+.loader-container:has(+ .done) {
+  display: none;
+}
+div.progress {
+  display:grid;
+  grid-template-columns: max-content max-content;
+  grid-gap:5px;
+}
+div.progress label {
+  text-align:left;
+}
+div.progress label:after {
+  content: "...";
+}
+div.progress:has(+ .done) {
+  display: none;
+}
+div.progress:has(+ .done) label:after {
+  content: "";
+}
+    </style>
+  </head>
+  <body align="center">
+    <div class="loader-container">
+% end
+% if end:
+    </div>
+    <div class="done"/>
 {{!form}}
 {{!svg}}
     </body>
-</html>
+</html>

+ 5 - 6
app/rest/trend.py

@@ -47,7 +47,6 @@ def trend_internal(conn: Connection[TupleRow], path: str, query: FormsDict):
     progress = {
         'stage': None,
         'percent': None,
-        'complete': False,
     }
     try:
         with conn.cursor() as cur:
@@ -64,7 +63,7 @@ def trend_internal(conn: Connection[TupleRow], path: str, query: FormsDict):
                 return
 
             progress.update({ "stage": "Querying database", "percent": "10"})
-            yield template("loading", start=True, progress=progress)
+            yield template("trend", start=True) + template("progress", **progress)
             data = get_data(query_manager, **fields)
             
             if data.empty:
@@ -72,7 +71,7 @@ def trend_internal(conn: Connection[TupleRow], path: str, query: FormsDict):
                 return
             
             progress.update({ "stage": "Preparing data", "percent": "30"})
-            yield template("loading", done=True) + template("loading", progress=progress)
+            yield template("done") + template("progress", **progress)
             
             in_chart = data['$/unit'].apply(lambda x: (x or False) and True)
             data = data[in_chart]
@@ -118,18 +117,18 @@ def trend_internal(conn: Connection[TupleRow], path: str, query: FormsDict):
                 spine.set_color('#ffffff')
             
             progress.update({ "stage": "Rendering chart", "percent": "50"})
-            yield template("loading", done=True) + template("loading", progress=progress)
+            yield template("done") + template("progress", **progress)
             
             f = StringIO()
             plt.savefig(f, format='svg')
             progress.update({ "stage": "Done", "percent": "100" })
-            yield template("loading", done=True) + template("loading", end=True, progress=progress)
+            yield template("done") + template("progress", **progress)
             
             organic = BOOLEAN.get(query.organic, None)
             action = path.split('/')[-1]
             form = get_form(action, 'post', _filter, organic, data)
             
-            yield template("trend", form=form, svg=f.getvalue())
+            yield template("trend", end=True, form=form, svg=f.getvalue())
 
     except:
         yield abort(500, f"Failed to render page")