|
@@ -1,5 +1,4 @@
|
|
|
SET input_log_scale = COALESCE($input_log_scale, 'checkbox');
|
|
|
---SET input_log_scale = 'hidden'; -- log scale now working yet
|
|
|
SET input_start = COALESCE($input_start, 'date');
|
|
|
SET input_end = COALESCE($input_end, 'date');
|
|
|
SET input_unit_mass = COALESCE($input_unit_mass, 'select');
|
|
@@ -26,71 +25,29 @@ SELECT 'hidden' AS type
|
|
|
, 'title' AS name
|
|
|
, $title AS value
|
|
|
;
|
|
|
-SELECT 'Product' AS label
|
|
|
-, 'products[]' AS name
|
|
|
-, 4 AS width
|
|
|
-, 'select' AS type
|
|
|
-, TRUE AS dropdown
|
|
|
-, TRUE AS multiple
|
|
|
-, $product_options AS options
|
|
|
-;
|
|
|
-SELECT 'Categories' AS label
|
|
|
-, 'categories[]' AS name
|
|
|
-, 4 AS width
|
|
|
-, 'select' AS type
|
|
|
-, TRUE AS dropdown
|
|
|
-, TRUE AS multiple
|
|
|
-, $category_options AS options
|
|
|
-;
|
|
|
-SELECT 'Groups' AS label
|
|
|
-, 'groups[]' AS name
|
|
|
-, 4 AS width
|
|
|
-, 'select' AS type
|
|
|
-, TRUE AS dropdown
|
|
|
-, TRUE AS multiple
|
|
|
-, $group_options AS options
|
|
|
-;
|
|
|
-SELECT 'Unit (vol.)' AS label
|
|
|
-, 'unit_volume' AS name
|
|
|
-, 2 AS width
|
|
|
-, $input_unit_volume AS type
|
|
|
-, $unit_volume_options AS options
|
|
|
-;
|
|
|
-SELECT 'Unit (mass)' AS label
|
|
|
-, 'unit_mass' AS name
|
|
|
-, 2 AS width
|
|
|
-, $input_unit_mass AS type
|
|
|
-, $unit_mass AS value
|
|
|
-, $unit_mass_options AS options
|
|
|
-;
|
|
|
-SELECT 'Unit (count)' AS label
|
|
|
-, 'unit_count[]' AS name
|
|
|
-, 4 AS width
|
|
|
-, $input_unit_count AS type
|
|
|
-, TRUE AS multiple
|
|
|
-, TRUE AS dropdown
|
|
|
-, '' AS value
|
|
|
-, $unit_count_options AS options
|
|
|
-;
|
|
|
-SELECT 'Tags' AS label
|
|
|
-, 'tags[]' AS name
|
|
|
-, 4 AS width
|
|
|
-, 'select' AS "type"
|
|
|
-, TRUE AS dropdown
|
|
|
-, TRUE AS multiple
|
|
|
-, $tag_options AS options
|
|
|
-;
|
|
|
-SELECT 'From' AS label
|
|
|
-, 'start' AS name
|
|
|
-, 2 AS width
|
|
|
-, $start AS value
|
|
|
-, $input_start AS type
|
|
|
-;
|
|
|
-SELECT 'To' AS label
|
|
|
-, 'end' AS name
|
|
|
-, 2 AS width
|
|
|
-, $end AS value
|
|
|
-, $input_end AS type
|
|
|
+
|
|
|
+SELECT v#>>'{name}' AS name
|
|
|
+, v#>>'{label}' AS label
|
|
|
+, COALESCE(c.value#>>'{type}', v#>>'{type}') AS type
|
|
|
+, v#>>'{dropdown}' AS dropdown
|
|
|
+, v#>>'{multiple}' AS multiple
|
|
|
+, v#>>'{width}' AS width
|
|
|
+, o.value AS options
|
|
|
+, CASE v#>>'{type}'
|
|
|
+ WHEN 'checkbox' THEN 'true'
|
|
|
+ ELSE v.value#>>'{}'
|
|
|
+ END AS value
|
|
|
+, CASE v#>>'{type}'
|
|
|
+ WHEN 'checkbox' THEN (v.value#>>'{}')::bool
|
|
|
+ ELSE NULL
|
|
|
+END AS checked
|
|
|
+FROM json_array_elements(sqlpage.read_file_as_text('sqlpage/json/filters.json')::json) j(v)
|
|
|
+LEFT JOIN json_each($filter_config::json) c(k,value)
|
|
|
+ON c.k = (v#>>'{name}')
|
|
|
+LEFT JOIN json_each(sqlpage.variables()::json) o(key, value)
|
|
|
+ON o.key = replace(v#>>'{name}', '[]', '')||'_options'
|
|
|
+LEFT JOIN json_each(sqlpage.variables()::json) v(key, value)
|
|
|
+ON v.key = (v#>>'{name}')
|
|
|
;
|
|
|
|
|
|
SELECT 'Apply' AS value
|
|
@@ -108,12 +65,3 @@ SELECT 'Clear' AS value
|
|
|
, 'submit' AS type
|
|
|
, '/grocery/internal/clear.sql' AS formaction
|
|
|
;
|
|
|
-
|
|
|
-SELECT 'Log Scale' AS label
|
|
|
-, 'log_scale' AS name
|
|
|
-, $input_log_scale AS type
|
|
|
-, TRUE AS disabled
|
|
|
-, 2 AS width
|
|
|
-, lower($log_scale) = 'true' AS checked
|
|
|
-, TRUE AS value
|
|
|
-;
|