Skip to content

Commit 2e920a2

Browse files
authored
Control the order of navigation links (#282)
- adds ability to select and sort order of static and dynamic pages to appear in the navigation using selectize - removes Page#hide_navigation for controlling page nav visibility - simplifies Website#footer_categories by using selectize with select to create an array instead of string - adds published boolean view to pages#index view - fixes hover color for header nav links [Control the order of navigation links](https://miro.com/app/board/uXjVO6C1LxA=/?moveToWidget=3458764523892494933&cot=14)
1 parent 809b964 commit 2e920a2

File tree

21 files changed

+91
-61
lines changed

21 files changed

+91
-61
lines changed

app/assets/javascripts/base.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ $(document).ready(function() {
66
$(".alert").not('.alert-confirm, .scheduling-error').alert('close');
77
}, 5000);
88

9-
$(".selectize-tags").selectize({
10-
delimiter: ",",
9+
$(".selectize-sortable").selectize({
10+
plugins: ["drag_drop"],
11+
});
12+
13+
$(".selectize-create").selectize({
14+
plugins: ["drag_drop"],
1115
persist: false,
1216
create: function (input) {
1317
return {

app/assets/stylesheets/modules/_code-mirror.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.CodeMirror {
22
/* Bootstrap Settings */
3+
min-height: 60vh;
34
box-sizing: border-box;
45
margin: 0;
56
font: inherit;

app/assets/stylesheets/themes/default/application.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
--body_background_color: white;
1111
--nav_background_color: black;
1212
--nav_text_color: white;
13-
--nav_link_hover: black;
13+
--nav_link_hover: white;
1414
--main_content_background: white;
1515
--sans-serif-font: 'Rubik';
1616
}

app/assets/stylesheets/themes/default/footer.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
footer {
22
color: white;
33
.overlay {
4-
background-color: black !important;
5-
opacity: 0.9 !important;
4+
background-color: black;
5+
opacity: 0.9;
66
padding: 20px 30px 35px;
77
}
88
.footer-header {

app/controllers/staff/pages_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def page_params
9191
:template,
9292
:name,
9393
:slug,
94-
:hide_navigation,
9594
:hide_page,
9695
:hide_header,
9796
:hide_footer,

app/controllers/staff/websites_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def update
2424
private
2525

2626
def set_website
27-
@website = current_event.website || current_event.build_website
27+
@website = (current_event.website || current_event.build_website).decorate
2828
end
2929

3030
def authorize_website
@@ -47,7 +47,8 @@ def website_params
4747
:twitter_handle,
4848
:facebook_url,
4949
:instagram_url,
50-
:footer_categories,
50+
footer_categories: [],
51+
navigation_links: [],
5152
)
5253
end
5354
end

app/decorators/website_decorator.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
class WebsiteDecorator < ApplicationDecorator
22
delegate_all
33

4+
DEFAULT_LINKS = {
5+
'Schedule' => 'schedule',
6+
'Program' => 'program',
7+
'Sponsors' => 'sponsors',
8+
}.freeze
9+
410
def name
511
event.name
612
end
@@ -13,7 +19,7 @@ def event
1319
@event ||= object.event.decorate
1420
end
1521

16-
def location
22+
def formatted_location
1723
h.simple_format(object.location)
1824
end
1925

@@ -33,15 +39,11 @@ def sponsors_in_footer
3339
event.sponsors.published.with_footer_image.order_by_tier
3440
end
3541

36-
def navigation_page_names_and_slugs
37-
pages.navigatable.pluck(:name, :slug)
38-
end
39-
4042
def categorized_footer_pages
4143
pages.in_footer
4244
.select(:footer_category, :name, :slug)
4345
.group_by(&:footer_category)
44-
.sort_by { |category, _| footer_categories.index(category) }
46+
.sort_by { |category, _| footer_categories.index(category) || 1_000 }
4547
end
4648

4749
def twitter_url
@@ -57,4 +59,11 @@ def background_style
5759

5860
{ style: "background-image: url('#{h.url_for(background)}');" }
5961
end
62+
63+
def link_options
64+
@link_options ||= pages.published.pluck(:name, :slug)
65+
.each_with_object(DEFAULT_LINKS.dup) do |(name, slug), memo|
66+
memo[name] = slug
67+
end
68+
end
6069
end

app/models/page.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class Page < ApplicationRecord
77
belongs_to :website
88

99
scope :published, -> { where.not(published_body: nil).where(hide_page: false) }
10-
scope :navigatable, -> { published.where(hide_navigation: false) }
1110
scope :in_footer, -> { published.where.not(footer_category: [nil, ""]) }
1211

1312
validates :name, :slug, presence: true
@@ -16,6 +15,10 @@ class Page < ApplicationRecord
1615

1716
BLANK_SLUG = "0"
1817

18+
def published?
19+
published_body.present? && !hide_page
20+
end
21+
1922
def to_param
2023
persisted? ? slug : BLANK_SLUG
2124
end
@@ -48,7 +51,7 @@ def self.from_template(key, attrs)
4851
# hide_header :boolean default(FALSE), not null
4952
# hide_footer :boolean default(FALSE), not null
5053
# hide_page :boolean default(FALSE), not null
51-
# hide_navigation :boolean default(FALSE), not null
54+
# footer_category :string
5255
#
5356
# Indexes
5457
#

app/models/website.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ class Website < ApplicationRecord
77

88
DEFAULT = 'default'.freeze
99

10-
def footer_categories=(values)
11-
categories = values.is_a?(String) ? values.split(',') : values
12-
self[:footer_categories] = categories
13-
end
14-
1510
def self.domain_match(domain)
1611
where(arel_table[:domains].matches("%#{(domain)}"))
1712
end
@@ -21,18 +16,23 @@ def self.domain_match(domain)
2116
#
2217
# Table name: websites
2318
#
24-
# id :bigint(8) not null, primary key
25-
# event_id :bigint(8)
26-
# created_at :datetime not null
27-
# updated_at :datetime not null
28-
# theme :string default("default")
29-
# domains :string
30-
# city :string
31-
# location :text
32-
# prospectus_link :string
33-
# twitter_handle :string
34-
# directions :string
35-
# footer_categories :string is an Array
19+
# id :bigint(8) not null, primary key
20+
# event_id :bigint(8)
21+
# created_at :datetime not null
22+
# updated_at :datetime not null
23+
# theme :string default("default")
24+
# domains :string
25+
# city :string
26+
# location :text
27+
# prospectus_link :string
28+
# twitter_handle :string
29+
# directions :string
30+
# footer_categories :string default([]), is an Array
31+
# footer_about_content :text
32+
# footer_copyright :string
33+
# facebook_url :string
34+
# instagram_url :string
35+
# navigation_links :string default([]), is an Array
3636
#
3737
# Indexes
3838
#

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
.location-section
1313
.location-details
1414
.date #{current_website.date_range}
15-
.location #{simple_format(current_website.location)}
15+
.location #{current_website.formatted_location}
1616
.register
1717
- if current_website.register_page
1818
= link_to 'Register',

0 commit comments

Comments
 (0)