diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 19:40:48 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 19:40:48 +0200 |
| commit | 527376039c527eb8f559c5e6da76429bc3f3ee4f (patch) | |
| tree | 283f9b5950cd1c7840c5c48cb8d604cb9cd32dc2 /app | |
| parent | 3dbf522783dfce496884e05559dc962cae4b1e1b (diff) | |
Add tree-position scoping to Page.aggregate
New :children option ("direct" or "all") on the [aggregate] shortcode,
composable with the existing :tags filter - both apply as independent
successive .where clauses, ANDing together automatically, no special
casing needed. content_helper.rb passes the current @page.node through
as :node whenever :children is requested, since Page.aggregate has no
way to resolve "which node" from the shortcode's bare option strings on
its own. Guarded so nothing changes for any existing [aggregate]
shortcode that never uses children= - :node stays nil, the new branch
never fires.
"all" resolves via node.descendants.pluck(:id) rather than embedding the
descendants relation directly as a subquery. Not proven strictly
necessary - extensive debugging this session initially pointed at a
subquery/table-alias collision, but every actual failure traced instead
to accumulated test-node debris left in the dev DB by earlier
interrupted runs, confirmed by re-running against a cleaned database.
Kept anyway as a one-round-trip-cheaper, more defensive default
regardless.
Diffstat (limited to 'app')
| -rw-r--r-- | app/helpers/content_helper.rb | 1 | ||||
| -rw-r--r-- | app/models/page.rb | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 6043089..6bcd437 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb | |||
| @@ -108,6 +108,7 @@ module ContentHelper | |||
| 108 | end | 108 | end |
| 109 | 109 | ||
| 110 | options[:partial] = select_partial(options[:partial]) | 110 | options[:partial] = select_partial(options[:partial]) |
| 111 | options[:node] = @page.node if options[:children].present? | ||
| 111 | 112 | ||
| 112 | sanitize(content.sub(tag, render_collection(options)), :attributes => cccms_attributes) | 113 | sanitize(content.sub(tag, render_collection(options)), :attributes => cccms_attributes) |
| 113 | else | 114 | else |
diff --git a/app/models/page.rb b/app/models/page.rb index 4d1e94a..6fff7d6 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -63,6 +63,12 @@ class Page < ApplicationRecord | |||
| 63 | end | 63 | end |
| 64 | end | 64 | end |
| 65 | 65 | ||
| 66 | if options[:node] && options[:children] == "direct" | ||
| 67 | scope = scope.where(nodes: { parent_id: options[:node].id }) | ||
| 68 | elsif options[:node] && options[:children] == "all" | ||
| 69 | scope = scope.where(nodes: { id: options[:node].descendants.pluck(:id) }) | ||
| 70 | end | ||
| 71 | |||
| 66 | direction = %w[ASC DESC].include?(options[:order_direction]&.upcase) ? options[:order_direction].upcase : "ASC" | 72 | direction = %w[ASC DESC].include?(options[:order_direction]&.upcase) ? options[:order_direction].upcase : "ASC" |
| 67 | 73 | ||
| 68 | if options[:order_by] == "title" | 74 | if options[:order_by] == "title" |
