Skip to content

Commit bdf9b10

Browse files
authored
Adds ability to remove page from navigation and/or hide it entirely (#280)
- adds Page#hide_navigation and #hide_page boolean - adds hide_page: false condition to published scope - adds WebsiteDecorator#navigation_page_names_and_slugs for more efficient generation of navigation links with just names and slugs [Unpublish a page/hide link](https://miro.com/app/board/uXjVO6C1LxA=/?moveToWidget=3458764524471808252&cot=14)
1 parent 708180c commit bdf9b10

File tree

8 files changed

+43
-5
lines changed

8 files changed

+43
-5
lines changed

app/controllers/staff/pages_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def page_params
9191
:template,
9292
:name,
9393
:slug,
94+
:hide_navigation,
95+
:hide_page,
9496
:hide_header,
9597
:hide_footer,
9698
:unpublished_body

app/decorators/website_decorator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ def banner_sponsors
3232
def sponsors_in_footer
3333
event.sponsors.published.with_footer_image.order_by_tier
3434
end
35+
36+
def navigation_page_names_and_slugs
37+
pages.navigatable.pluck(:name, :slug)
38+
end
3539
end

app/models/page.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class Page < ApplicationRecord
66

77
belongs_to :website
88

9-
scope :published, -> { where.not(published_body: nil) }
9+
scope :published, -> { where.not(published_body: nil).where(hide_page: false) }
10+
scope :navigatable, -> { published.where.not(hide_navigation: true) }
1011

1112
validates :name, :slug, presence: true
1213
validates :slug, uniqueness: { scope: :website_id }

app/views/layouts/themes/default.html.haml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
%h1
1717
= link_to(current_website.name, landing_path(website_event_slug))
1818
%nav#main-nav
19-
- current_website.pages.published.each do |page|
20-
= link_to page.name, page_path(website_event_slug, page)
19+
- current_website.navigation_page_names_and_slugs.each do |page_name, page_slug|
20+
= link_to page_name, page_path(website_event_slug, page_slug)
2121
= link_to "Schedule", schedule_path(current_website.event)
2222
= link_to "Program", program_path(website_event_slug)
2323
= link_to "Sponsors", sponsors_path(website_event_slug)
@@ -38,7 +38,6 @@
3838
- current_website.pages.published.each do |page|
3939
= link_to page.name, page_path(website_event_slug, page)
4040
= link_to "Schedule", schedule_path(current_website.event)
41-
= link_to "Schedule", schedule_path(current_website.event)
4241
= link_to "Program", program_path(website_event_slug)
4342
= link_to "Sponsors", sponsors_path(website_event_slug)
4443

app/views/staff/pages/_form.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
.inner
88
= f.input :name
99
= f.input :slug
10+
= f.input :hide_navigation, as: :boolean, wrapper: :vertical_radio_and_checkboxes
11+
= f.input :hide_page, as: :boolean, wrapper: :vertical_radio_and_checkboxes
1012
= f.input :hide_header, as: :boolean, wrapper: :vertical_radio_and_checkboxes
1113
= f.input :hide_footer, as: :boolean, wrapper: :vertical_radio_and_checkboxes
1214
%div{ data: { "editor-target": :wysiwyg }, class: 'hidden', disabled: true }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddHidingFieldsToPages < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :pages, :hide_page, :boolean, default: false, null: false
4+
add_column :pages, :hide_navigation, :boolean, default: false, null: false
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2022_04_28_160329) do
13+
ActiveRecord::Schema.define(version: 2022_05_03_085207) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -113,6 +113,8 @@
113113
t.boolean "landing", default: false, null: false
114114
t.boolean "hide_header", default: false, null: false
115115
t.boolean "hide_footer", default: false, null: false
116+
t.boolean "hide_page", default: false, null: false
117+
t.boolean "hide_navigation", default: false, null: false
116118
t.index ["website_id"], name: "index_pages_on_website_id"
117119
end
118120

spec/features/website/page_management_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,26 @@
9696
expect(page).not_to have_css('footer')
9797
end
9898

99+
scenario "Organizer hides navigation to a page and hides a page entirely", :js do
100+
home_page = create(:page, published_body: 'Home Content')
101+
visit page_path(slug: event.slug, page: home_page.slug)
102+
expect(page).to have_content('Home Content')
103+
within('#main-nav') { expect(page).to have_content(home_page.name) }
104+
105+
login_as(organizer)
106+
visit edit_event_staff_page_path(event, home_page)
107+
check("Hide navigation")
108+
click_on("Save")
109+
110+
visit page_path(slug: event.slug, page: home_page.slug)
111+
within('#main-nav') { expect(page).not_to have_content(home_page.name) }
112+
113+
visit edit_event_staff_page_path(event, home_page)
114+
check("Hide page")
115+
click_on("Save")
116+
117+
visit page_path(slug: event.slug, page: home_page.slug)
118+
expect(page).to have_content("Page Not Found")
119+
end
120+
99121
end

0 commit comments

Comments
 (0)