ソースを参照

add tags page

Daniel Sheffield 9 ヶ月 前
コミット
eae5468b6c
2 ファイル変更60 行追加30 行削除
  1. 7 30
      sqlpage/nav.sql
  2. 53 0
      sqlpage/tags.sql

+ 7 - 30
sqlpage/nav.sql

@@ -94,36 +94,7 @@ WHERE p.name is NULL
     EXISTS (SELECT 1 FROM state WHERE update IS TRUE)
 ;
 
---SELECT
---  'text' AS component,
---  '<style>
---.nav { pointer-events: none }
---.navbar { display: none }
---input[value=Products].form-control,
---input[value=Categories].form-control,
---input[value=Groups].form-control,
---input[value=Transactions].form-control
---{
---    color: var(--tblr-secondary);
---    border-right: unset;
---    border-top: unset;
---    border-left: unset;
---}
---input[value='||CASE
---  WHEN $tab IN ('Products', 'Categories', 'Groups')
---  THEN $tab ELSE 'Transactions'
---END||'].form-control
---{
---    color: var(--tblr-primary);
---    border-right: unset;
---    border-top: unset;
---    border-left: unset;
---    border-bottom-color: var(--tblr-primary);
---    border-bottom-width: 2px;
---}
---</style>' AS html
---;
-  
+ 
 SELECT
   'tab' AS component,
   TRUE AS center
@@ -147,6 +118,12 @@ SELECT
  sqlpage.path() = '/groups.sql' AS active,
  'groups.sql' AS link
 ;
+SELECT
+ 'tags' AS id,
+ 'Tags' AS title,
+ sqlpage.path() = '/tags.sql' AS active,
+ 'tags.sql' AS link
+;
 SELECT
  'transactions' AS id,
  'Transactions' AS title,

+ 53 - 0
sqlpage/tags.sql

@@ -0,0 +1,53 @@
+SELECT
+  'dynamic' as component,
+  sqlpage.run_sql('cookie.sql') AS properties
+;
+
+SELECT
+  'dynamic' as component,
+  sqlpage.run_sql('nav.sql') AS properties
+;
+
+SELECT
+  'table' AS component,
+  TRUE AS search,
+  TRUE AS striped_rows,
+  TRUE AS small,
+  'Notice' AS markdown
+;
+
+DROP TABLE IF EXISTS sqlpage_tags;
+CREATE TEMPORARY TABLE IF NOT EXISTS sqlpage_tags AS (
+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
+	WHERE {where}
+	GROUP BY tg.name
+	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
+JOIN sqlpage_options op ON op.type = 'product' AND p.name = op.name
+JOIN sqlpage_options oc ON oc.type = 'category' AND c.name = oc.name
+JOIN sqlpage_options og ON og.type = 'group' AND g.name = og.name
+WHERE COALESCE(op.selected, oc.selected, og.selected, TRUE)
+AND
+  COALESCE(op.selected, oc.selected, og.selected, TRUE)
+AND
+  op.session = sqlpage.cookie('session')
+AND
+  oc.session = sqlpage.cookie('session')
+AND
+  og.session = sqlpage.cookie('session')
+GROUP BY ROLLUP (g.name, c.name, p.name)
+ORDER BY product, category, "group") q
+WHERE q.category IS NULL
+);
+SELECT * FROM sqlpage_tags;
+
+SELECT 
+  '# No Data' AS "Notice"
+WHERE NOT EXISTS(SELECT * FROM sqlpage_tags LIMIT 1);