Skip to content

Commit b074c3c

Browse files
authored
Merge pull request #958 from amatsuda/more_navs
More header nav activations
2 parents 8dbfc75 + 6e4911a commit b074c3c

File tree

6 files changed

+71
-63
lines changed

6 files changed

+71
-63
lines changed

app/assets/stylesheets/modules/navbar.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.dropdown-toggle.gravatar-container {
2-
margin-bottom: -5px;
2+
display: flex;
3+
align-items: center;
34
}
45

56
.navbar-nav {

app/helpers/navbar_helper.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ def path_for(*args)
3535
event_website: {
3636
event_website_configuration: ->(p) { p.start_with?(path_for(current_event, :staff, :website)) },
3737
event_pages: ->(p) { p == path_for(current_event, :staff, Page) }
38-
}
38+
},
39+
admin: {
40+
admin_users: ->(p) { p == path_for(:admin, User) },
41+
admin_events: ->(p) { p == path_for(:admin, Event) }
42+
},
43+
notifications: ->(p) { p == path_for(Notification) },
44+
user: {
45+
edit_profile: ->(p) { p == path_for(:edit, :profile) },
46+
merge_profile: ->(p) { p == path_for(:merge, :profile) },
47+
admin_events: ->(p) { p == path_for(:notifications, :profile) }
48+
},
3949
}.freeze
4050

4151
private
@@ -45,10 +55,10 @@ def nav_item_class(key)
4555
NAV_ITEM_MAP.find do |nav_key, nav_val|
4656
case nav_val
4757
when Proc
48-
@active_nav_key = nav_key if instance_exec(request.path, &nav_val)
58+
@active_nav_key = nav_key if instance_exec(request.path, &nav_val) rescue nil
4959
when Hash
5060
nav_val.find do |subnav_key, subnav_val|
51-
@active_nav_key, @active_subnav_key = nav_key, subnav_key if instance_exec(request.path, &subnav_val)
61+
@active_nav_key, @active_subnav_key = nav_key, subnav_key if instance_exec(request.path, &subnav_val) rescue nil
5262
end
5363
end
5464
end

app/views/layouts/_navbar.html.haml

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,62 @@
4747
%sup Beta
4848
4949
- if admin_nav?
50-
= render partial: "layouts/nav/admin_nav"
51-
52-
= render partial: "layouts/nav/notifications_list"
53-
54-
= render partial: "layouts/nav/user_dropdown"
50+
%li.nav-item.dropdown{class: nav_item_class(:admin)}
51+
%a.nav-link.dropdown-toggle{title: 'Admin Toggle', href: '#', role: 'button', data: {bs_toggle: 'dropdown'}, aria: {expanded: 'false'}}
52+
Admin
53+
%ul.dropdown-menu.dropdown-menu-end
54+
%li
55+
= link_to admin_users_path, class: "dropdown-item #{'active' if request.path == admin_users_path}" do
56+
%i.bi.bi-people-fill
57+
%span Users
58+
%li
59+
= link_to admin_events_path, class: "dropdown-item #{'active' if request.path == admin_events_path}" do
60+
%i.bi.bi-calendar
61+
%span Events
62+
63+
%li.nav-item.dropdown{class: nav_item_class(:notifications)}
64+
- unread_notifications = current_user.notifications.recent_unread.records
65+
%a.nav-link.dropdown-toggle{title: 'Notifications Toggle', href: '#', role: 'button', data: {bs_toggle: 'dropdown'}, aria: {expanded: 'false'}}
66+
%i.bi.bi-envelope-fill
67+
%span.badge.bg-secondary= unread_notifications.length if unread_notifications.any?
68+
69+
%ul.dropdown-menu.dropdown-menu-end
70+
- if unread_notifications.any?
71+
- unread_notifications.each do |notification|
72+
%li
73+
= link_to notification_path(notification), class: 'dropdown-item' do
74+
%i.bi.bi-exclamation
75+
%span= notification.short_message
76+
%li
77+
%hr.dropdown-divider
78+
%li
79+
= link_to mark_all_as_read_notifications_path, data: {turbo: true, turbo_method: :post}, class: 'dropdown-item text-primary' do
80+
%i.bi.bi-check
81+
Mark all as read
82+
%li
83+
= link_to notifications_path, class: 'dropdown-item' do
84+
%i.bi.bi-eye
85+
%span
86+
= (more_unread_count = current_user.notifications.more_unread_count) > 0 ? "#{more_unread_count} More Unread" : "View all notifications"
87+
88+
%li.nav-item.dropdown{class: nav_item_class(:user)}
89+
%a.nav-link.dropdown-toggle.gravatar-container{href: '#', role: 'button', data: {bs_toggle: 'dropdown'}, aria: {expanded: 'false'}}
90+
= image_tag("https://www.gravatar.com/avatar/#{current_user.gravatar_hash}?s=25", class: 'user-dropdown-gravatar', alt: '')
91+
  #{current_user.name}
92+
%ul.dropdown-menu.dropdown-menu-end
93+
%li
94+
= link_to edit_profile_path, class: 'dropdown-item' do
95+
%i.bi.bi-person-fill
96+
%span My Profile
97+
- if current_user.teammates.loaded? ? current_user.teammates.any? : current_user.teammates.exists?
98+
%li
99+
= link_to notifications_profile_path, class: 'dropdown-item' do
100+
%i.bi.bi-bell-fill
101+
%span Notifications
102+
%li
103+
= link_to destroy_user_session_path, data: {turbo: true, turbo_method: :delete}, class: 'dropdown-item' do
104+
%i.bi.bi-box-arrow-right
105+
%span Sign Out
55106

56107
- else
57108
%ul.navbar-nav.ms-auto

app/views/layouts/nav/_admin_nav.html.haml

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/views/layouts/nav/_notifications_list.html.haml

Lines changed: 0 additions & 24 deletions
This file was deleted.

app/views/layouts/nav/_user_dropdown.html.haml

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)