effective_pages 3.1.1 → 3.2.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: 0f090f6237de5e5aabd329729b2c1d9b2098307bfd46510d4663b95783d5a233
4
- data.tar.gz: c8516b8b3e013e8b41660e03cc14a519eee7f0897a80ab0e1cdc6356fd7ec977
3
+ metadata.gz: '06898ad2ffae38015ec40dbeeefb1a46e468a7df73e933c69c194d06415123cc'
4
+ data.tar.gz: 74916bd3ca8fe11dbac3b6ac6b6085cc73cc9fd381fdf96aacd46fed82a3ba72
5
5
  SHA512:
6
- metadata.gz: fb40c0b8c3f7c86ae0374d183bd3217d737594637f469bffb8b93a91bd506a9b20101eb4439698939e835df00b33a38b6c16faf952aa728db9efbda35289c4aa
7
- data.tar.gz: e9dd9e7c455f3f38be630aac0a2cea2d9fee080bb319dda6337bc8a5f4c90c62b8fd8021bb70795283c53a150c31ec22beae83a8946e6adaa7b3494150baa815
6
+ metadata.gz: 27fc19935dabbad5e6710ad06a9ea883d04a983541ae5308d706c62bc5546c295a922a6143fb9778980fd80ec26817c1d68ea7025b32d6950558da8af09290de
7
+ data.tar.gz: 1789579e269f287c2b4db33748d3039f6bc0b152506a0c597ebcbbbd58c8064f38cb240c2de4f76740bd01b620ffcb64c2dbbbda8eee822a513de5d9ea46c322
@@ -15,8 +15,6 @@ class EffectivePagesDatatable < Effective::Datatable
15
15
  col :updated_at, visible: false
16
16
 
17
17
  col :title
18
- col :menu_title
19
- col :menu_name
20
18
 
21
19
  col :slug do |page|
22
20
  link_to(page.slug, effective_pages.page_path(page), target: '_blank')
@@ -27,6 +25,10 @@ class EffectivePagesDatatable < Effective::Datatable
27
25
  col :layout, visible: false
28
26
  col :tempate, visible: false
29
27
 
28
+ col :menu_name
29
+ col :menu_title
30
+ col :menu_group
31
+
30
32
  col :menu_url, visible: false
31
33
  col :menu_parent, search: { collection: admin_menu_parent_collection(), grouped: true }
32
34
  col :menu_position, visible: false
@@ -16,12 +16,12 @@ class EffectivePagesMenuDatatable < Effective::Datatable
16
16
 
17
17
  # We only support depth 2 and 3.
18
18
  col :menu_children, label: 'Children' do |page|
19
- page.menu_children.map do |child|
19
+ page.menu_children.group_by(&:menu_group).values.flatten.map do |child|
20
20
  content_tag(:div, class: 'col-resource_item') do
21
- link = link_to(child, effective_pages.edit_admin_page_path(child))
21
+ link = link_to(child.admin_menu_label, effective_pages.edit_admin_page_path(child))
22
22
 
23
- list = child.menu_children.map do |child|
24
- content_tag(:li, link_to(child, effective_pages.edit_admin_page_path(child)))
23
+ list = child.menu_children.group_by(&:menu_group).values.flatten.map do |child|
24
+ content_tag(:li, link_to(child.admin_menu_label, effective_pages.edit_admin_page_path(child)))
25
25
  end
26
26
 
27
27
  link + (content_tag(:ul, list.join.html_safe) if list.present?).to_s
@@ -67,7 +67,15 @@ module EffectiveMenusHelper
67
67
  # You can only select root level pages and immediate children
68
68
  pages.map do |page|
69
69
  [[page.to_s, page.id, page.menu_name]] + page.menu_children.map do |child|
70
- [' -- ' + child.to_s, child.id, child.menu_name]
70
+ label = content_tag(:div) do
71
+ arrow = "&rarr;"
72
+ group = content_tag(:span, child.menu_group, class: 'badge badge-info') if child.menu_group.present?
73
+ title = child.menu_to_s
74
+
75
+ [arrow, group, title].compact.join(' ').html_safe
76
+ end
77
+
78
+ [child.to_s, child.to_param, { 'data-html': label }, child.menu_name]
71
79
  end
72
80
  end.flatten(1).group_by(&:last)
73
81
  end
@@ -29,12 +29,13 @@ module Effective
29
29
  slug :string
30
30
 
31
31
  # Menu stuff
32
- menu :boolean
33
- menu_name :string
32
+ menu :boolean # Should this be displayed on the menu at all?
33
+ menu_name :string # When I'm a root level item, this is the menu I render underneath
34
+ menu_group :string # Used for design. Group by menu_group to display full dropdowns.
34
35
 
35
- menu_title :string
36
- menu_url :string
37
- menu_position :integer
36
+ menu_title :string # Displayed on the menu instead of title
37
+ menu_url :string # Redirect to this url instead of the page url
38
+ menu_position :integer # Position in the menu
38
39
 
39
40
  # Access
40
41
  roles_mask :integer
@@ -59,7 +60,10 @@ module Effective
59
60
  validates :layout, presence: true
60
61
  validates :template, presence: true
61
62
 
62
- validates :menu_name, if: -> { menu_root? && EffectivePages.menus.present? }, presence: true
63
+ validates :menu_name, presence: true, if: -> { menu_root? && EffectivePages.menus.present? }
64
+
65
+ # Doesn't make sense for a top level item to have a menu group
66
+ validates :menu_group, absence: true, if: -> { menu_root? && EffectivePages.menus.present? }
63
67
 
64
68
  # validates :menu_position, if: -> { menu? },
65
69
  # presence: true, uniqueness: { scope: [:menu_name, :menu_parent_id] }
@@ -69,6 +73,7 @@ module Effective
69
73
  scope :draft, -> { where(draft: true) }
70
74
  scope :published, -> { where(draft: false) }
71
75
  scope :sorted, -> { order(:title) }
76
+
72
77
  scope :on_menu, -> { where(menu: true) }
73
78
  scope :except_home, -> { where.not(title: 'Home') }
74
79
 
@@ -79,10 +84,23 @@ module Effective
79
84
  scope :for_menu_root, -> (name) { for_menu(name).menu_deep.root_level }
80
85
  scope :root_level, -> { where(menu_parent_id: nil) }
81
86
 
87
+ scope :menu_root_with_children, -> { menu_parents.where(menu_parent_id: nil) }
88
+ scope :menu_roots, -> { where(menu: true).where(menu_parent_id: nil) }
89
+ scope :menu_parents, -> { where(menu: true).where(id: Effective::Page.select('menu_parent_id')) }
90
+ scope :menu_children, -> { where(menu: true).where.not(menu_parent_id: nil) }
91
+
92
+ scope :for_sitemap, -> {
93
+ published.where(menu: false).or(published.where(menu: true).where.not(id: menu_root_with_children))
94
+ }
95
+
82
96
  def to_s
83
97
  title
84
98
  end
85
99
 
100
+ def menu_to_s
101
+ (menu_title.presence || title)
102
+ end
103
+
86
104
  # As per has_many_rich_texts
87
105
  def body
88
106
  rich_text_body
@@ -14,14 +14,15 @@
14
14
  = f.hidden_field :menu_name, value: menus.first
15
15
 
16
16
  = f.show_if :menu_root_level, false do
17
- = f.select :menu_parent_id, admin_menu_parent_collection(f.object), required: true, grouped: true
17
+ = f.select :menu_parent_id, admin_menu_parent_collection(f.object), required: true, grouped: true, hint: 'Displayed on the menu underneath this parent'
18
+ = f.text_field :menu_group, hint: 'Displayed on the menu in this group or column'
18
19
 
19
20
  = f.text_field :menu_title, hint: "Display this title on menus instead of full page title"
20
21
 
21
22
  = f.text_field :menu_url, label: "Redirect to path or url instead of displaying page",
22
23
  hint: "Must start with http(s):// or /"
23
24
 
24
- = f.submit
25
+ = effective_submit(f)
25
26
 
26
27
  - if page.menu_parent.present?
27
28
  .mb-4
@@ -25,21 +25,20 @@
25
25
 
26
26
  = render partial: '/admin/pages/additional_fields', locals: { page: page, form: f, f: f }
27
27
 
28
- - if f.object.persisted?
29
- - if page.menu_root? && page.menu_parent?
30
- .alert.alert-info.my-3.pl-0
31
- %ul.mb-0
32
- %li This page is a top level menu item with at least one child page
33
- %li It will render on the menu as a dropdown link
34
- %li Users will not be able to click access page via the menu
35
- %li Visiting the page URL directly will return a 404 error
36
- %li If you want this page to be accessible while also being a top level menu item, it needs to have no child pages
37
-
38
- - else
39
- = render '/admin/pages/rich_text_areas', page: page, f: f
28
+ - if f.object.persisted? && f.object.menu_root_with_children?
29
+ .alert.alert-info.my-3.pl-0
30
+ %ul.mb-0
31
+ %li This page is a top level menu item with at least one child page
32
+ %li It will render on the menu as a dropdown link
33
+ %li Users will not be able to click access page via the menu
34
+ %li Visiting the page URL directly will return a 404 error
35
+ %li If you want this page to be accessible while also being a top level menu item, it needs to have no child pages
36
+
37
+ - if f.object.persisted? && !f.object.menu_root_with_children?
38
+ = render '/admin/pages/rich_text_areas', page: page, f: f
40
39
 
41
40
  -# This is for duplicate
42
41
  - if f.object.new_record? && f.object.rich_texts.present?
43
- = render partial: '/admin/pages/rich_text_areas', locals: { page: page, form: f, f: f }
42
+ = render '/admin/pages/rich_text_areas', page: page, f: f
44
43
 
45
44
  = effective_submit(f)
@@ -10,13 +10,15 @@
10
10
  - menu_children = page.menu_children
11
11
 
12
12
  - if menu_children.blank?
13
- = nav_link_to((page.menu_title.presence || page.title), (page.menu_url.presence || effective_pages.page_path(page)))
13
+ = nav_link_to(page.menu_to_s, (page.menu_url.presence || effective_pages.page_path(page)))
14
14
 
15
- - else
16
- = nav_dropdown(page.to_s) do
17
- - menu_children.each do |page|
18
- - next unless EffectiveResources.authorized?(self, :show, page)
19
- - next if (page.authenticate_user || page.roles.present?) && current_user.blank?
20
- - next if page.roles.present? && (current_user.roles & page.roles).blank?
15
+ - if menu_children.present?
16
+ = nav_dropdown(page.menu_to_s, groups: true) do
17
+ - menu_children.group_by(&:menu_group).each do |menu_group, pages|
18
+ = nav_dropdown_group(menu_group) do
19
+ - pages.each do |page|
20
+ - next unless EffectiveResources.authorized?(self, :show, page)
21
+ - next if (page.authenticate_user || page.roles.present?) && current_user.blank?
22
+ - next if page.roles.present? && (current_user.roles & page.roles).blank?
21
23
 
22
- = nav_link_to((page.menu_title.presence || page.title), (page.menu_url.presence || effective_pages.page_path(page)))
24
+ = nav_link_to(page.menu_to_s, (page.menu_url.presence || effective_pages.page_path(page)))
@@ -5,9 +5,13 @@
5
5
  - if menu_children.blank? && page.menu_parent&.menu_children.present?
6
6
  - menu_children = page.menu_parent&.menu_children
7
7
 
8
- - menu_children.each do |page|
9
- - next unless EffectiveResources.authorized?(self, :show, page)
10
- - next if (page.authenticate_user || page.roles.present?) && current_user.blank?
11
- - next if page.roles.present? && (current_user.roles & page.roles).blank?
8
+ - menu_children.group_by(&:menu_group).each do |menu_group, pages|
9
+ - if menu_group.present?
10
+ %h6= menu_group
12
11
 
13
- = nav_link_to((page.menu_title.presence || page.title), (page.menu_url.presence || effective_pages.page_path(page)))
12
+ - pages.each do |page|
13
+ - next unless EffectiveResources.authorized?(self, :show, page)
14
+ - next if (page.authenticate_user || page.roles.present?) && current_user.blank?
15
+ - next if page.roles.present? && (current_user.roles & page.roles).blank?
16
+
17
+ = nav_link_to(page.menu_to_s, (page.menu_url.presence || effective_pages.page_path(page)))
@@ -15,8 +15,12 @@ class CreateEffectivePages < ActiveRecord::Migration[4.2]
15
15
  t.integer :roles_mask, default: 0
16
16
 
17
17
  t.integer :menu_parent_id
18
+
18
19
  t.boolean :menu, default: false
20
+
19
21
  t.string :menu_name
22
+ t.string :menu_group
23
+
20
24
  t.string :menu_title
21
25
  t.string :menu_url
22
26
  t.integer :menu_position
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '3.1.1'.freeze
2
+ VERSION = '3.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-06 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails