effective_pages 3.8.4 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab2014d3e00b7e610f9e4bbb783dc853d5eeb5a5c51215266d37c42d6435d453
4
- data.tar.gz: 59c5957db1af495169511e34bd2b77b9da60574d16d8fabcde374738429c55eb
3
+ metadata.gz: de13a6ce9afb0cee9e8401e076c3416a159f9a64f4a5fb7cf70c890de442263f
4
+ data.tar.gz: dfa2b67769948a6e25c5c20e3b1520260f494d0722165cfd5a78eeff1aeb3ce8
5
5
  SHA512:
6
- metadata.gz: 71d6ef9905b0426c44b791e6422b6784e395bd776d3a346fee1609931769b5e9e2f2b5f63b5240e643d763394d6624ebf8089f5d59bb45d7f25f85071a1c74a7
7
- data.tar.gz: 8d07252b5ba59072c8f078f394260da1ab6bd5b874f1ec9543f247c66528760b729a22c7cab542b66dbee7a402f64db929fc08ebf5baebfbe15deb1caa8f2eaa
6
+ metadata.gz: 11295b2af4904ad5469948123e4e910302fa4e3d7c29a79b55bd4500b7456f458e31f5f389c587725a7d534a21c4e138daff27b525fae74d874c8344948cd1d7
7
+ data.tar.gz: 5e2bbcef490e3b25c6ba565fd64fab7ee4a7091377fef64ca664a4be1edfa54d64b0810c2b5005a7e33e63c04e54ff65f2955c5e705f5ec9e03bb39ff513c654
data/README.md CHANGED
@@ -6,6 +6,33 @@ Create content pages ontop of one or more templates -- just regular Rails views
6
6
 
7
7
  Use this gem to create a fully-functional CMS that provides full or restricted editing for your end users.
8
8
 
9
+ ## Upgrading to 3.9.0
10
+
11
+ Add a migration
12
+
13
+ ```
14
+ class UpgradeEffectivePagesThreeNine < ActiveRecord::Migration[7.0]
15
+ def change
16
+ # Add a counter cache
17
+ add_column :pages, :menu_children_count, :integer, default: 0
18
+ end
19
+ end
20
+ ```
21
+
22
+ Run a one time script
23
+
24
+ ```
25
+ # rake upgrade_effective_pages_to_three_nine
26
+ task upgrade_effective_pages_to_three_nine: :environment do
27
+ puts "Starting effective pages 3.9.0 upgrade"
28
+
29
+ Effective::Page.where(menu_children_count: 0).find_each do |page|
30
+ Effective::Page.reset_counters(page.slug, :menu_children)
31
+ end
32
+
33
+ puts 'All done'
34
+ end
35
+ ```
9
36
 
10
37
  ## effective_pages 3.0
11
38
 
@@ -14,6 +14,8 @@ class EffectivePagesMenuDatatable < Effective::Datatable
14
14
  col :menu_url, label: 'Redirect Url'
15
15
  col :menu_position, label: 'Position', visible: false
16
16
 
17
+ col :menu_children_count, label: 'Children Count', visible: false
18
+
17
19
  # We only support depth 2 and 3.
18
20
  col :menu_children, label: 'Children' do |page|
19
21
  page.menu_children.group_by { |child| child.menu_group.presence }.values.flatten.map do |child|
@@ -28,8 +28,6 @@ module EffectiveMenusHelper
28
28
  (
29
29
  [content_tag(:li, link_to(root, root_path, title: root), class: 'breadcrumb-item')] +
30
30
  parents.map do |page|
31
- page.try(:strict_loading!, false)
32
-
33
31
  next if page.menu_root_with_children? # Don't show root pages because they have no content
34
32
 
35
33
  url = (page.menu_url.presence || effective_pages.page_path(page))
@@ -62,7 +60,7 @@ module EffectiveMenusHelper
62
60
  def admin_menu_parent_collection(page = nil)
63
61
  raise('expected a page') if page.present? && !page.kind_of?(Effective::Page)
64
62
 
65
- pages = Effective::Page.deep.menuable.root_level.where.not(id: page)
63
+ pages = Effective::Page.deep_menuable.menuable.root_level.where.not(id: page)
66
64
 
67
65
  if EffectivePages.max_menu_depth == 2
68
66
  # You can only select root level pages
@@ -14,7 +14,7 @@ module Effective
14
14
  belongs_to :page_banner, optional: true
15
15
 
16
16
  # These parent / children are for the menu as well
17
- belongs_to :menu_parent, class_name: 'Effective::Page', optional: true
17
+ belongs_to :menu_parent, class_name: 'Effective::Page', optional: true, touch: true, counter_cache: :menu_children_count
18
18
 
19
19
  has_many :menu_children, -> { Effective::Page.menuable }, class_name: 'Effective::Page',
20
20
  foreign_key: :menu_parent_id, inverse_of: :menu_parent
@@ -47,6 +47,8 @@ module Effective
47
47
  menu_url :string # Redirect to this url instead of the page url
48
48
  menu_position :integer # Position in the menu
49
49
 
50
+ menu_children_count :integer # Counter cache
51
+
50
52
  # Banners
51
53
  banner :boolean # Should we display a banner?
52
54
  banner_random :boolean # Display a random banner
@@ -59,11 +61,14 @@ module Effective
59
61
  end
60
62
 
61
63
  scope :deep, -> {
62
- base = includes(:page_banner, :tags, :rich_texts, :menu_parent, menu_children: [:menu_parent, :menu_children])
64
+ base = includes(:page_banner, :tags, :rich_texts)
65
+ base = base.deep_menuable
63
66
  base = base.includes(:pg_search_document) if defined?(PgSearch)
64
67
  base
65
68
  }
66
69
 
70
+ scope :deep_menuable, -> { includes(:menu_parent, menu_children: [:menu_parent, :menu_children]) }
71
+
67
72
  scope :draft, -> { where(draft: true) }
68
73
  scope :published, -> { where(draft: false) }
69
74
  scope :sorted, -> { order(:title) }
@@ -186,13 +191,21 @@ module Effective
186
191
  end
187
192
 
188
193
  def menu_parent?
189
- menu? && menu_children.to_a.present?
194
+ menu? && menu_children_present?
190
195
  end
191
196
 
192
197
  def menu_child?
193
198
  menu? && menu_parent_id.present?
194
199
  end
195
200
 
201
+ def menu_children_present?
202
+ menu_children_count > 0
203
+ end
204
+
205
+ def menu_children_blank?
206
+ menu_children_count <= 0
207
+ end
208
+
196
209
  end
197
210
 
198
211
  end
@@ -7,14 +7,11 @@
7
7
  - next if (page.authenticate_user || page.roles.present?) && current_user.blank?
8
8
  - next if page.roles.present? && (current_user.roles & page.roles).blank?
9
9
 
10
- - menu_children = page.menu_children
11
-
12
- - if menu_children.blank?
10
+ - if page.menu_children_blank?
13
11
  = nav_link_to(page.menu_to_s, (page.menu_url.presence || effective_pages.page_path(page)))
14
-
15
- - if menu_children.present?
12
+ - else
16
13
  = nav_dropdown(page.menu_to_s, groups: true) do
17
- - menu_children.group_by { |menu| menu.menu_group.presence }.each do |menu_group, pages|
14
+ - page.menu_children.group_by { |menu| menu.menu_group.presence }.each do |menu_group, pages|
18
15
  = nav_dropdown_group(menu_group || '') do
19
16
  - pages.each do |page|
20
17
  - next unless EffectiveResources.authorized?(self, :show, page)
@@ -1,15 +1,15 @@
1
1
  - raise('expected a page') unless page.present?
2
2
 
3
- - children = page.menu_children
3
+ - children = []
4
4
 
5
- - if page.menu_children.present?
5
+ - if page.menu_children_present?
6
+ - children = page.menu_children
6
7
  = nav_link_to(page.menu_to_s, (page.menu_url.presence || effective_pages.page_path(page)))
7
8
 
8
9
  - # if this is a third depth page, show the parent and siblings
9
- - if page.menu_children.blank? && page.menu_parent.try(:menu_parent_id).present?
10
- - page.menu_parent.try(:strict_loading!, false)
11
-
12
- - if page.menu_parent.menu_children.present?
10
+ - if page.menu_children_blank? && page.menu_parent.try(:menu_parent_id).present?
11
+ - if page.menu_parent.menu_children_present?
12
+ - page.menu_parent.try(:strict_loading!, false)
13
13
  - children = page.menu_parent.menu_children
14
14
  = nav_link_to(page.menu_parent.menu_to_s, (page.menu_parent.menu_url.presence || effective_pages.page_path(page.menu_parent)))
15
15
 
@@ -27,6 +27,8 @@ class CreateEffectivePages < ActiveRecord::Migration[6.0]
27
27
  t.string :menu_url
28
28
  t.integer :menu_position
29
29
 
30
+ t.integer :menu_children_count, default: 0
31
+
30
32
  t.boolean :banner, default: false
31
33
  t.boolean :banner_random, default: false
32
34
 
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '3.8.4'.freeze
2
+ VERSION = '3.9.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.4
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect