|
@@ -0,0 +1,169 @@
|
|
|
+SET apply = CASE WHEN (COALESCE($apply, '') = 'Apply') THEN TRUE ELSE FALSE END;
|
|
|
+SET clear = CASE WHEN (COALESCE($clear, '') = 'Clear') THEN TRUE ELSE FALSE END;
|
|
|
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/internal/cookie.sql') AS properties;
|
|
|
+SET products = sqlpage.cookie('products')::json;
|
|
|
+SET categories = sqlpage.cookie('categories')::json;
|
|
|
+SET groups = sqlpage.cookie('groups')::json;
|
|
|
+SET tags = sqlpage.cookie('tags')::json;
|
|
|
+SET start = sqlpage.cookie('start');
|
|
|
+SET end = sqlpage.cookie('end');
|
|
|
+SET unit_volume = sqlpage.cookie('unit_volume');
|
|
|
+SET unit_mass = sqlpage.cookie('unit_mass');
|
|
|
+SET unit_count = sqlpage.cookie('unit_count')::json;
|
|
|
+SET log_scale = sqlpage.cookie('log_scale');
|
|
|
+
|
|
|
+SET unit_volume = (CASE
|
|
|
+ WHEN $unit_volume = '' OR ($unit_volume IS NULL OR $unit_volume = '')
|
|
|
+ THEN 'L'
|
|
|
+ ELSE $unit_volume
|
|
|
+END);
|
|
|
+SET unit_mass = (CASE
|
|
|
+ WHEN $unit_mass = '' OR ($unit_mass IS NULL OR $unit_mass = '')
|
|
|
+ THEN 'kg'
|
|
|
+ ELSE $unit_mass
|
|
|
+END);
|
|
|
+SET start = (CASE
|
|
|
+ WHEN $start = '' OR $start IS NULL
|
|
|
+ THEN to_char(now()-'30 days'::interval, 'YYYY-MM-DD')
|
|
|
+ ELSE $start
|
|
|
+END);
|
|
|
+SET end = CASE
|
|
|
+ WHEN $end = '' OR $end IS NULL
|
|
|
+ THEN to_char(now(), 'YYYY-MM-DD')
|
|
|
+ ELSE $end
|
|
|
+END;
|
|
|
+
|
|
|
+SET page = CASE
|
|
|
+ WHEN $title IN (
|
|
|
+ 'Products', 'Categories', 'Groups', 'Tags', 'Transactions',
|
|
|
+ 'Trend', 'Volume'
|
|
|
+ )
|
|
|
+ THEN $title||'.sql'
|
|
|
+ ELSE NULL
|
|
|
+END;
|
|
|
+
|
|
|
+SELECT 'redirect' AS component
|
|
|
+, '/grocery/internal/404.sql?title='||COALESCE($title, '') AS link
|
|
|
+WHERE ($page IS NULL OR $page = '')
|
|
|
+;
|
|
|
+
|
|
|
+
|
|
|
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/data/tags.sql') AS properties
|
|
|
+WHERE $apply::bool OR $clear::bool;
|
|
|
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/data/transactions.sql') AS properties
|
|
|
+WHERE $apply::bool OR $clear::bool;
|
|
|
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/data/products.sql') AS properties
|
|
|
+WHERE $apply::bool OR $clear::bool;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+SET product_options = (
|
|
|
+SELECT
|
|
|
+ json_agg(json_build_object(
|
|
|
+ 'label', value,
|
|
|
+ 'value', value,
|
|
|
+ 'selected', value IN (SELECT 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 category_options = (
|
|
|
+SELECT
|
|
|
+ json_agg(json_build_object(
|
|
|
+ 'label', value,
|
|
|
+ 'value', value,
|
|
|
+ 'selected', value IN (SELECT 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 group_options = (
|
|
|
+SELECT
|
|
|
+ json_agg(json_build_object(
|
|
|
+ 'label', value,
|
|
|
+ 'value', value,
|
|
|
+ 'selected', value IN (SELECT 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 tag_options = (
|
|
|
+SELECT
|
|
|
+ json_agg(json_build_object(
|
|
|
+ 'label', value,
|
|
|
+ 'value', value,
|
|
|
+ 'selected', value IN (SELECT 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
|
|
|
+);
|
|
|
+
|
|
|
+DROP TABLE IF EXISTS sqlpage_units;
|
|
|
+CREATE TEMPORARY TABLE IF NOT EXISTS sqlpage_units AS
|
|
|
+SELECT u.name, ut.name AS type FROM units u
|
|
|
+JOIN unit_types ut ON ut.id = u.unit_type_id
|
|
|
+;
|
|
|
+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
|
|
|
+ ) ORDER BY o.name)
|
|
|
+FROM sqlpage_units o
|
|
|
+WHERE type = 'Count'
|
|
|
+);
|
|
|
+
|
|
|
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/internal/theme.sql') AS properties;
|
|
|
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/internal/nav.sql') AS properties;
|
|
|
+
|
|
|
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/pages/'||$page) AS properties;
|