Fix ordering of sub entries

This commit is contained in:
Jan Kvetina 2022-01-15 18:00:56 +01:00
parent 4bfcd2ea3e
commit a7420a6ff4

View File

@ -8,9 +8,14 @@ WITH x AS (
WHERE u.user_id = app.get_user_id() WHERE u.user_id = app.get_user_id()
), ),
t AS ( t AS (
SELECT
ROWNUM AS r#, -- to keep hierarchy sorted
t.*
FROM (
SELECT SELECT
n.app_id, n.app_id,
n.page_id, n.page_id,
n.order#,
-- --
REPLACE(p.page_name, '&' || 'APP_NAME.', a.application_name) AS page_name, REPLACE(p.page_name, '&' || 'APP_NAME.', a.application_name) AS page_name,
REPLACE(p.page_title, '&' || 'APP_NAME.', a.application_name) AS page_title, REPLACE(p.page_title, '&' || 'APP_NAME.', a.application_name) AS page_title,
@ -37,13 +42,20 @@ t AS (
CONNECT BY n.parent_id = PRIOR n.page_id CONNECT BY n.parent_id = PRIOR n.page_id
AND n.app_id = PRIOR n.app_id AND n.app_id = PRIOR n.app_id
START WITH n.parent_id IS NULL START WITH n.parent_id IS NULL
ORDER SIBLINGS BY n.app_id, n.order#, n.page_id
) t
) )
SELECT SELECT
n.app_id, n.app_id,
n.page_id, n.page_id,
n.parent_id, n.parent_id,
n.order#, n.order#,
t.page_root || ' ' || COALESCE(t.page_group, (SELECT t.page_group FROM t WHERE t.app_id = n.app_id AND t.page_id = n.parent_id)) AS page_group, --
t.page_root || ' ' || COALESCE (
t.page_group,
(SELECT t.page_group FROM t WHERE t.app_id = n.app_id AND t.page_id = n.parent_id)
) AS page_group,
--
t.page_alias, t.page_alias,
-- --
CASE WHEN r.page_id IS NULL CASE WHEN r.page_id IS NULL
@ -79,7 +91,7 @@ SELECT
-- --
'UD' AS allow_changes, -- U = update, D = delete 'UD' AS allow_changes, -- U = update, D = delete
-- --
t.page_root || '.' || t.depth || '.' || NVL(n.order#, n.page_id) AS sort_order, t.page_root || '.' || TO_CHAR(10000 + t.r#) || '.' || NVL(t.order#, t.page_id) AS sort_order,
-- --
CASE CASE
WHEN r.page_id IS NOT NULL WHEN r.page_id IS NOT NULL
@ -97,7 +109,7 @@ JOIN apps a
ON a.app_id = n.app_id ON a.app_id = n.app_id
AND a.is_active = 'Y' AND a.is_active = 'Y'
CROSS JOIN x CROSS JOIN x
LEFT JOIN t LEFT JOIN t ---------- LEFT JOIN ???
ON t.app_id = n.app_id ON t.app_id = n.app_id
AND t.page_id = n.page_id AND t.page_id = n.page_id
LEFT JOIN nav_pages_to_remove r LEFT JOIN nav_pages_to_remove r
@ -149,7 +161,7 @@ SELECT
-- --
NULL AS allow_changes, -- no changes allowed NULL AS allow_changes, -- no changes allowed
-- --
NVL(t.page_root, n.page_id) || '.' || (t.depth + 1) || '.' || NVL(n.order#, n.page_id) AS sort_order, NVL(t.page_root, n.page_id) || '.' || TO_CHAR(10000 + t.r#) || '.' || NVL(n.order#, n.page_id) AS sort_order,
-- --
app.get_icon('fa-plus-square', 'Create record in Navigation table') AS action, app.get_icon('fa-plus-square', 'Create record in Navigation table') AS action,
-- --