|
@@ -1,5 +1,7 @@
|
|
|
SET title = 'Categories';
|
|
|
SET products = COALESCE($products, sqlpage.cookie('products'));
|
|
|
+SET categories = COALESCE($categories, sqlpage.cookie('categories'));
|
|
|
+SET groups = COALESCE($groups, sqlpage.cookie('groups'));
|
|
|
|
|
|
DROP TABLE IF EXISTS sqlpage_categories;
|
|
|
CREATE TEMPORARY TABLE IF NOT EXISTS sqlpage_categories AS (
|
|
@@ -38,6 +40,38 @@ FROM (
|
|
|
) o(value)
|
|
|
WHERE value IS NOT NULL
|
|
|
);
|
|
|
+SET category_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_categories
|
|
|
+) o(value)
|
|
|
+WHERE value IS NOT NULL
|
|
|
+);
|
|
|
+SET group_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_categories
|
|
|
+) o(value)
|
|
|
+WHERE value IS NOT NULL
|
|
|
+);
|
|
|
|
|
|
SELECT 'dynamic' AS component, sqlpage.run_sql('cookie.sql') AS properties;
|
|
|
SELECT 'dynamic' AS component, sqlpage.run_sql('theme.sql') AS properties;
|