소스 검색

squash migrations as they're redundant anyway and put apply/clear buttons in filter.json

Daniel Sheffield 8 달 전
부모
커밋
5bab62da2f

+ 4 - 19
sqlpage/sqlpage/internal/nav.sql

@@ -28,32 +28,17 @@ SELECT j.name
 , j.multiple
 , COALESCE(c.width, j.width) AS width
 , o.j#>'{options}' AS options
-, COALESCE(v.value#>>'{}', j.value) AS value
+, COALESCE(j.value, v.value) AS value
 , CASE j.type
-    WHEN 'checkbox' THEN (v.value#>>'{}')::bool
+    WHEN 'checkbox' THEN v.value::bool
     ELSE NULL
   END AS checked
+, j.formaction
 FROM json_populate_recordset(null::sqlpage_filter_type, sqlpage.read_file_as_text('sqlpage/json/filters.json')::json) j
 LEFT JOIN json_populate_recordset(null::sqlpage_filter_type, $filter_config::json) c
 USING (name)
 LEFT JOIN json_array_elements($filter_options::json) o(j)
 ON (o.j#>>'{name}') = j.name
-LEFT JOIN json_each(sqlpage.variables()::json) v(key, value)
+LEFT JOIN json_each_text(sqlpage.variables()::json) v(key, value)
 ON v.key = j.name
 ;
-
-SELECT 'Apply' AS value
-, 'apply' AS name
-, '' AS label
-, 'blue' AS color
-, 2 AS width
-, 'submit' AS type
-, '/grocery/internal/apply.sql' AS formaction
-;
-SELECT 'Clear' AS value
-, 'clear' AS name
-, '' AS label
-, 2 AS width
-, 'submit' AS type
-, '/grocery/internal/clear.sql' AS formaction
-;

+ 10 - 2
sqlpage/sqlpage/json/filters.json

@@ -15,11 +15,11 @@
     "type": "select", "dropdown": true, "multiple": true,
     "width": 4
   },
-  { "name": "unit_volume", "label": "Unit (vol.)", "default": "L",
+  { "name": "unit_volume", "label": "Unit (vol.)",
     "type": "select", "multiple": false, "dropdown": true,
     "width": 2
   },
-  { "name": "unit_mass", "label": "Unit (mass)", "default": "kg",
+  { "name": "unit_mass", "label": "Unit (mass)",
     "type": "select", "multiple": false, "dropdown": true,
     "width": 2
   },
@@ -38,5 +38,13 @@
   { "name": "log_scale", "label": "Log Scale", "value": "true",
     "type": "checkbox",
     "width": 2
+  },
+  { "name": "apply", "label": "", "value": "Aply",
+    "type": "submit",  "formaction": "/grocery/internal/apply.sql",
+    "width": 2
+  },
+  { "name": "clear", "label": "", "value": "Clear",
+    "type": "submit", "formaction": "/grocery/internal/clear.sql",
+    "width": 2
   }
 ]

+ 0 - 10
sqlpage/sqlpage/migrations/000_constants.sql

@@ -1,10 +0,0 @@
-CREATE TABLE IF NOT EXISTS sqlpage_pages
-(
-    name text PRIMARY KEY
-);
-INSERT INTO sqlpage_pages
-SELECT UNNEST(ARRAY[
-  'Products', 'Categories', 'Groups',
-  'Tags',
-  'Transactions', 'Trend', 'Volume'
-]);

+ 24 - 0
sqlpage/sqlpage/migrations/000_schema.sql

@@ -0,0 +1,24 @@
+DROP TABLE IF EXISTS sqlpage_pages;
+CREATE TABLE sqlpage_pages
+(
+    name text PRIMARY KEY
+);
+INSERT INTO sqlpage_pages
+SELECT UNNEST(ARRAY[
+  'Products', 'Categories', 'Groups',
+  'Tags',
+  'Transactions', 'Trend', 'Volume'
+]);
+
+DROP TYPE IF EXISTS sqlpage_filter_type;
+CREATE TYPE sqlpage_filter_type AS (
+  name text,
+  label text,
+  value text,
+  "default" text,
+  type text,
+  dropdown bool,
+  multiple bool,
+  formaction text,
+  width int
+);

+ 0 - 10
sqlpage/sqlpage/migrations/001_filter_type.sql

@@ -1,10 +0,0 @@
-CREATE TYPE sqlpage_filter_type AS (
-  name text,
-  label text,
-  value text,
-  "default" text,
-  type text,
-  dropdown bool,
-  multiple bool,
-  width int
-);