|
@@ -61,98 +61,67 @@ WHERE $apply::bool OR $clear::bool;
|
|
SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/data/units.sql') AS properties
|
|
SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/data/units.sql') AS properties
|
|
WHERE $apply::bool OR $clear::bool;
|
|
WHERE $apply::bool OR $clear::bool;
|
|
|
|
|
|
-SET products_options = (
|
|
|
|
-SELECT
|
|
|
|
- json_agg(json_build_object(
|
|
|
|
- 'label', value,
|
|
|
|
- 'value', value,
|
|
|
|
- 'selected', value IN (SELECT v#>>'{}' FROM json_array_elements($products::json) j(v))
|
|
|
|
- ) ORDER BY value)
|
|
|
|
-FROM (
|
|
|
|
- SELECT v#>>'{}'
|
|
|
|
- FROM json_array_elements($products::json) j(v)
|
|
|
|
- UNION
|
|
|
|
- SELECT product
|
|
|
|
- FROM sqlpage_products
|
|
|
|
-) o(value)
|
|
|
|
-WHERE value IS NOT NULL
|
|
|
|
-);
|
|
|
|
-SET categories_options = (
|
|
|
|
-SELECT
|
|
|
|
- json_agg(json_build_object(
|
|
|
|
- 'label', value,
|
|
|
|
- 'value', value,
|
|
|
|
- 'selected', value IN (SELECT v#>>'{}' FROM json_array_elements($categories::json) j(v))
|
|
|
|
- ) ORDER BY value)
|
|
|
|
-FROM (
|
|
|
|
- SELECT v#>>'{}'
|
|
|
|
- FROM json_array_elements($categories::json) j(v)
|
|
|
|
- UNION
|
|
|
|
- SELECT category
|
|
|
|
- FROM sqlpage_products
|
|
|
|
-) o(value)
|
|
|
|
-WHERE value IS NOT NULL
|
|
|
|
-);
|
|
|
|
-SET groups_options = (
|
|
|
|
-SELECT
|
|
|
|
- json_agg(json_build_object(
|
|
|
|
- 'label', value,
|
|
|
|
- 'value', value,
|
|
|
|
- 'selected', value IN (SELECT v#>>'{}' FROM json_array_elements($groups::json) j(v))
|
|
|
|
- ) ORDER BY value)
|
|
|
|
-FROM (
|
|
|
|
- SELECT v#>>'{}'
|
|
|
|
- FROM json_array_elements($groups::json) j(v)
|
|
|
|
- UNION
|
|
|
|
- SELECT "group"
|
|
|
|
- FROM sqlpage_products
|
|
|
|
-) o(value)
|
|
|
|
-WHERE value IS NOT NULL
|
|
|
|
-);
|
|
|
|
-
|
|
|
|
-SET tags_options = (
|
|
|
|
-SELECT
|
|
|
|
- json_agg(json_build_object(
|
|
|
|
- 'label', value,
|
|
|
|
- 'value', value,
|
|
|
|
- 'selected', value IN (SELECT v#>>'{}' FROM json_array_elements($tags::json) j(v))
|
|
|
|
- ) ORDER BY value)
|
|
|
|
-FROM (
|
|
|
|
- SELECT v#>>'{}'
|
|
|
|
- FROM json_array_elements($tags::json) j(v)
|
|
|
|
- UNION
|
|
|
|
- SELECT "Name"
|
|
|
|
- FROM sqlpage_tags
|
|
|
|
-) o(value)
|
|
|
|
-WHERE value IS NOT NULL
|
|
|
|
-);
|
|
|
|
-
|
|
|
|
-SET unit_volume_options = (
|
|
|
|
-SELECT json_agg(json_build_object(
|
|
|
|
- 'label', o.name,
|
|
|
|
- 'value', o.name,
|
|
|
|
- 'selected', o.name = $unit_volume
|
|
|
|
- ) ORDER BY o.name)
|
|
|
|
-FROM sqlpage_units o
|
|
|
|
-WHERE type = 'Volume'
|
|
|
|
-);
|
|
|
|
-SET unit_mass_options = (
|
|
|
|
-SELECT json_agg(json_build_object(
|
|
|
|
- 'label', o.name,
|
|
|
|
- 'value', o.name,
|
|
|
|
- 'selected', o.name = $unit_mass
|
|
|
|
- ) ORDER BY o.name)
|
|
|
|
-FROM sqlpage_units o
|
|
|
|
-WHERE type = 'Mass'
|
|
|
|
-);
|
|
|
|
-SET unit_count_options = (
|
|
|
|
-SELECT json_agg(json_build_object(
|
|
|
|
- 'label', o.name,
|
|
|
|
- 'value', o.name,
|
|
|
|
- 'selected', o.name IN (SELECT v#>>'{}' FROM json_array_elements($unit_count::json) j(v))
|
|
|
|
- ) ORDER BY o.name)
|
|
|
|
-FROM sqlpage_units o
|
|
|
|
-WHERE type = 'Count'
|
|
|
|
|
|
+SET filter_options = (
|
|
|
|
+ SELECT json_agg(json_build_object('name', k, 'options', o))
|
|
|
|
+ FROM (
|
|
|
|
+ SELECT o.k||'[]', json_agg(
|
|
|
|
+ json_build_object('label', v, 'value', v, 'selected', s)
|
|
|
|
+ ORDER BY v)
|
|
|
|
+ FROM (
|
|
|
|
+ SELECT DISTINCT o.k, CASE o.k
|
|
|
|
+ WHEN 'products' THEN product
|
|
|
|
+ WHEN 'categories' THEN category
|
|
|
|
+ WHEN 'groups' THEN "group"
|
|
|
|
+ END, v.k IS NOT NULL --, v.v
|
|
|
|
+ FROM sqlpage_products
|
|
|
|
+ CROSS JOIN UNNEST(ARRAY['products', 'categories', 'groups']) o(k)
|
|
|
|
+ LEFT JOIN json_each_text(sqlpage.variables()::json) v(k,v)
|
|
|
|
+ ON v.k = o.k
|
|
|
|
+ AND (CASE o.k
|
|
|
|
+ WHEN 'products' THEN product
|
|
|
|
+ WHEN 'categories' THEN category
|
|
|
|
+ WHEN 'groups' THEN "group"
|
|
|
|
+ END) IN (
|
|
|
|
+ SELECT j.v#>>'{}' FROM json_array_elements(v.v::json) j(v)
|
|
|
|
+ )
|
|
|
|
+ ) AS o(k, v, s)
|
|
|
|
+ WHERE v IS NOT NULL
|
|
|
|
+ GROUP BY o.k
|
|
|
|
+ UNION ALL
|
|
|
|
+ SELECT o.k||'[]', json_agg(
|
|
|
|
+ json_build_object('label', v, 'value', v, 'selected', s)
|
|
|
|
+ ORDER BY v)
|
|
|
|
+ FROM (
|
|
|
|
+ SELECT DISTINCT 'tags', "Name", v.k IS NOT NULL
|
|
|
|
+ FROM sqlpage_tags
|
|
|
|
+ LEFT JOIN json_each_text(sqlpage.variables()::json) v(k,v)
|
|
|
|
+ ON v.k = 'tags' AND "Name" IN (
|
|
|
|
+ SELECT j.v#>>'{}' FROM json_array_elements(v.v::json) j(v)
|
|
|
|
+ )
|
|
|
|
+ ) AS o(k, v, s)
|
|
|
|
+ WHERE v IS NOT NULL
|
|
|
|
+ GROUP BY o.k
|
|
|
|
+ UNION ALL
|
|
|
|
+ SELECT CASE o.k
|
|
|
|
+ WHEN 'count' THEN 'unit_'||o.k||'[]'
|
|
|
|
+ ELSE 'unit_'||o.k END, json_agg(
|
|
|
|
+ json_build_object('label', v, 'value', v, 'selected', s)
|
|
|
|
+ ORDER BY v)
|
|
|
|
+ FROM (
|
|
|
|
+ SELECT DISTINCT o.k, name, v.k IS NOT NULL
|
|
|
|
+ FROM sqlpage_units
|
|
|
|
+ CROSS JOIN UNNEST(ARRAY['volume', 'mass', 'count']) o(k)
|
|
|
|
+ LEFT JOIN json_each_text(sqlpage.variables()::json) v(k,v)
|
|
|
|
+ ON v.k = 'unit_'||o.k AND (CASE o.k
|
|
|
|
+ WHEN 'count' THEN name IN (
|
|
|
|
+ SELECT j.v#>>'{}' FROM json_array_elements(v.v::json) j(v)
|
|
|
|
+ )
|
|
|
|
+ ELSE name = v.v END)
|
|
|
|
+ WHERE lower(type) = o.k
|
|
|
|
+ ) AS o(k, v, s)
|
|
|
|
+ WHERE v IS NOT NULL
|
|
|
|
+ GROUP BY o.k
|
|
|
|
+ ) q(k, o)
|
|
);
|
|
);
|
|
|
|
|
|
SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/internal/theme.sql') AS properties;
|
|
SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/internal/theme.sql') AS properties;
|