Kaynağa Gözat

share filters on tables pages too and make table thems dark too

Daniel Sheffield 1 yıl önce
ebeveyn
işleme
49299fa64f

+ 24 - 14
app/rest/pyapi.py

@@ -169,7 +169,6 @@ def get_form(action, method, filter_data, data):
         'category': 1,
         'group': 2,
     }[x])
-    in_chart = data['$/unit'].apply(lambda x: (x or False) and True)
     return template('form', action=action, method=method,
         **{
             k: {
@@ -283,7 +282,7 @@ def trend_internal(path, query):
 
             f = StringIO()
             plt.savefig(f, format='svg')
-            form = get_form(path, 'get', get_filter(request.query, allow=PARAMS), data)
+            form = get_form(path.split('/')[-1], 'get', get_filter(request.query, allow=PARAMS), data)
             
             progress[-1]["status"] = "done"
             yield template("loading", progress=progress)
@@ -299,16 +298,13 @@ def trend_internal(path, query):
      
     yield from iter(resp, lambda started=time(): time() - started > 600)
 
-@route('/grocery/xslt')
-def table():
-    title = request.query['title'] if 'title' in request.query.keys() else None
-    foot = request.query['foot'] == 'True' and "last()" if 'foot' in request.query.keys() else "-1"
-    response.content_type = 'application/xhtml+xml; charset=utf-8'
-    return template("query-to-xml-xslt", title=title, foot=foot)
 
 @route('/grocery/groups')
 def groups():
     filters = get_filter(request.query, allow=('group', 'category', 'product'))
+    form = template('form-nav', action='groups', method='get', params=[
+        {'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
+    ])
     try:
         with conn.cursor() as cur:
             inner = get_product_rollup_statement(
@@ -327,11 +323,14 @@ FROM (
     finally:
         conn.commit()
     response.content_type = 'application/xhtml+xml; charset=utf-8'
-    return template("query-to-xml", title="Groups", foot=True, xml=xml)
+    return template("query-to-xml", title="Groups", xml=xml, form=form)
 
 @route('/grocery/categories')
 def categories():
     filters = get_filter(request.query, allow=('group', 'category', 'product'))
+    form = template('form-nav', action='categories', method='get', params=[
+        {'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
+    ])
     try:
         with conn.cursor() as cur:
             inner = get_product_rollup_statement(
@@ -350,11 +349,14 @@ FROM (
     finally:
         conn.commit()
     response.content_type = 'application/xhtml+xml; charset=utf-8'
-    return template("query-to-xml", title="Categories", foot=True, xml=xml)
+    return template("query-to-xml", title="Categories", xml=xml, form=form)
 
 @route('/grocery/products')
 def products():
     filters = get_filter(request.query, allow=('group', 'category', 'product'))
+    form = template('form-nav', action='products', method='get', params=[
+        {'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
+    ])
     try:
         with conn.cursor() as cur:
             inner = get_product_rollup_statement(
@@ -374,19 +376,27 @@ FROM (
     finally:
         conn.commit()
     response.content_type = 'application/xhtml+xml; charset=utf-8'
-    return template("query-to-xml", title="Products", foot=True, xml=xml)
+    return template("query-to-xml", title="Products", xml=xml, form=form)
 
 @route('/grocery/tags')
 def tags():
+    form = template('form-nav', action='tags', method='get', params=[
+        {'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
+    ])
     try:
         with conn.cursor() as cur:
             inner = SQL('\n').join([SQL("""
-SELECT count(DISTINCT txn.id) AS "Uses", tg.name AS "Name"
+SELECT * FROM (SELECT count(DISTINCT txn.id) AS "Uses", tg.name AS "Name"
 FROM tags tg
 JOIN tags_map tm ON tg.id = tm.tag_id
 JOIN transactions txn ON txn.id = tm.transaction_id
 GROUP BY tg.name
-ORDER BY 1 DESC, 2
+ORDER BY 1 DESC, 2) q
+UNION ALL
+SELECT count(DISTINCT txn.id) AS "Uses", count(DISTINCT tg.name)||'' AS "Name"
+FROM tags tg
+JOIN tags_map tm ON tg.id = tm.tag_id
+JOIN transactions txn ON txn.id = tm.transaction_id
 """)]).as_string(cur)
             xml = cur.execute(SQL("""
 SELECT query_to_xml_and_xmlschema({inner}, false, false, ''::text)
@@ -394,6 +404,6 @@ SELECT query_to_xml_and_xmlschema({inner}, false, false, ''::text)
     finally:
         conn.commit()
     response.content_type = 'application/xhtml+xml; charset=utf-8'
-    return template("query-to-xml", title="Tags", foot="false", xml=xml)
+    return template("query-to-xml", title="Tags", xml=xml, form=form)
 
 run(host='0.0.0.0', port=6772, server='gunicorn')

+ 10 - 15
app/rest/templates/query-to-xml-xslt.tpl → app/rest/static/query-to-xml-xslt.xml

@@ -8,24 +8,21 @@
       doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
       doctype-public="-//W3C/DTD XHTML 1.0 Strict//EN"
       indent="yes"/>
-
-  <xsl:template match="/*">
+  <!-- This is an identity template - it copies everything
+        that doesn't match another template -->
+  <xsl:template match="@* | node()">
+      <xsl:copy>
+          <xsl:apply-templates select="@* | node()"/>
+      </xsl:copy>
+  </xsl:template>
+  <xsl:template match="/html/body/xml/*">
     <xsl:variable name="schema" select="//xsd:schema"/>
     <xsl:variable name="tabletypename"
                   select="$schema/xsd:element[@name=name(current())]/@type"/>
     <xsl:variable name="rowtypename"
                   select="$schema/xsd:complexType[@name=$tabletypename]/xsd:sequence/xsd:element[@name='row']/@type"/>
     <xsl:variable name="tablename" select="$schema/xsd:complexType[@name=$rowtypename]/xsd:sequence/xsd:element[1]/@name"/>
-
-    <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"/>
-      </head>
-      <body>
+     
         <table class="pure-table pure-table-bordered pure-table-striped">
           <thead>
           <tr>
@@ -37,7 +34,7 @@
 
           <xsl:for-each select="row">
             <xsl:choose>
-              <xsl:when test="position() = {{foot}}">
+              <xsl:when test="position() = last()">
                 <tfoot>
                   <tr>
                     <xsl:for-each select="*">
@@ -56,8 +53,6 @@
             </xsl:choose>
           </xsl:for-each>
         </table>
-      </body>
-    </html>
   </xsl:template>
 
 </xsl:stylesheet>

+ 9 - 11
app/rest/templates/filter-set.tpl

@@ -1,11 +1,9 @@
-<div class="pure-g">
-  <%
-    for filter in (product, category, group):
-      include('include-exclude', **filter)
-    end
-  %>
-  <%
-    include('include-exclude', **tags)
-    include('select-one', **units)
-  %>
-</div>
+<%
+  for filter in (product, category, group):
+    include('include-exclude', **filter)
+  end
+%>
+<%
+  include('include-exclude', **tags)
+  include('select-one', **units)
+%>

+ 17 - 0
app/rest/templates/form-nav.tpl

@@ -0,0 +1,17 @@
+<form id="filter" method="{{ method }}" action="{{ action }}">
+  <div class="pure-g">
+    <div class="pure-u-1-5 pure-u-lg-11-12">
+    % for param in params:
+    %   include('hidden-input', **param)
+    % end
+    </div>
+    <div class="pure-u-1-5 pure-u-lg-1-12">
+      <button class="pure-button" type="submit" style="width: 80%"> Apply </button>
+      % for target in ("trend", "products", "categories", "groups", "tags"):
+      %   if target != action:
+      <button class="pure-button" type="submit" formaction="{{target}}" style="width: 80%"> {{target.title()}} </button>
+      %   end
+      % end
+    </div>
+  </div>
+</form>

+ 9 - 2
app/rest/templates/form.tpl

@@ -1,10 +1,17 @@
 <form id="filter" style="display: inline-flex"  method="{{ method }}" action="{{ action }}">
+  <div class="pure-g">
     <%
     include('filter-set',
       product=product, category=category, group=group,
       tags=tags, units=units)
     %>
-    <div>
-    <button type="submit"> Apply </button>
+    <div class="pure-u-1-5 pure-u-lg-1-12">
+      <button class="pure-button" type="submit" style="width: 80%"> Apply </button>
+      % for target in ("trend", "products", "categories", "groups", "tags"):
+      %   if target != action:
+      <button class="pure-button" type="submit" formaction="{{target}}" style="width: 80%"> {{target.title()}} </button>
+      %   end
+      % end
     </div>
+  </div>
 </form>

+ 1 - 0
app/rest/templates/hidden-input.tpl

@@ -0,0 +1 @@
+<input type="text" name="{{name}}" value="{{value}}" hidden="true"></input>

+ 22 - 22
app/rest/templates/include-exclude.tpl

@@ -1,26 +1,26 @@
-<div class="pure-u-1-3 pure-u-lg-{{"1-4" if name != "tag" else "1-8"}}">
-<div class="pure-g">
-  <div class="pure-u-1">
-    <div class="l-box">
-      <h3>{{name.title()}}</h3>
+<div class="pure-u-{{"1-3" if name != "tag" else "2-5"}} pure-u-lg-{{"5-24" if name != "tag" else "1-6"}}">
+  <div class="pure-g">
+    <div class="pure-u-1">
+      <div class="l-box">
+        <h3>{{name.title()}}</h3>
+      </div>
     </div>
-  </div>
-  <%
-    include('select', id=f"{name}-include", name=name,
-      children=_include["option_groups"] if "option_groups" in _include else [{
-        "options": _include["options"]
-      }],
-      hint="Include", multiple=True)
-  %>
+    <%
+      include('select', id=f"{name}-include", name=name,
+        children=_include["option_groups"] if "option_groups" in _include else [{
+          "options": _include["options"]
+        }],
+        hint="Include", multiple=True)
+    %>
 
-  <%
-  if defined("_exclude"):
-    include('select', id=f"{name}-exclude", name=name,
-      children=_exclude["option_groups"] if "option_groups" in _exclude else [{
-        "options": _exclude["options"]
-      }], hint="Exclude", multiple=True)
-  end
-  %>
+    <%
+    if defined("_exclude"):
+      include('select', id=f"{name}-exclude", name=name,
+        children=_exclude["option_groups"] if "option_groups" in _exclude else [{
+          "options": _exclude["options"]
+        }], hint="Exclude", multiple=True)
+    end
+    %>
 
-</div>
+  </div>
 </div>

+ 38 - 2
app/rest/templates/query-to-xml.tpl

@@ -1,3 +1,39 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<?xml-stylesheet type="text/xsl" href="/grocery/xslt?title={{title}}&amp;foot={{foot}}"?>
-{{!xml}}
+<?xml-stylesheet type="text/xsl" href="/grocery/static/query-to-xml-xslt.xml"?>
+<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"/>
+    <style>
+body {
+  background-color: #080808;
+  color: #a0a0a0a0;
+}
+.pure-table thead{
+  background-color:#a0a0a0;
+  color:#000;
+  text-align:left;
+  vertical-align:bottom;
+}
+.pure-table td{
+  background-color:transparent;
+}
+.pure-table-odd td{
+  background-color:#181818;
+}
+.pure-table-striped tr:nth-child(2n-1) td{
+  background-color:#181818;
+}
+    </style>
+  </head>
+  <body>
+{{!form}}
+<xml>
+{{!xml}}
+</xml>
+  </body>
+</html>
+

+ 1 - 1
app/rest/templates/select-one.tpl

@@ -1,4 +1,4 @@
-<div class="pure-u-1-3 pure-u-lg-1-8">
+<div class="pure-u-2-5 pure-u-lg-1-8">
 <div class="pure-g">
   <div class="pure-u-1">
     <div class="l-box">

+ 1 - 1
app/rest/templates/select.tpl

@@ -5,7 +5,7 @@
 %    include('label', id=id, label=label)
 %  end
 
-<select id="{{id}}" name="{{name}}" size=10 {{multiple}} style="width: 98%; margin: 1em">
+<select id="{{id}}" name="{{name}}" size=10 {{multiple}} style="width: 95%; margin: 1em">
 %  if defined("hint"):
 %    include('option', value=hint, disabled=True)
 %  end