Move login links to components
We're trying to be consistent; in the past, we had the partials "shared/admin_login_items", "layouts/notification_item" and "devise/menu/login_items". Now we're moving all these partials to components in the `Layout` namespace.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<ul class="menu" data-responsive-menu="medium-dropdown">
|
||||
<%= render "shared/admin_login_items", current_user: user %>
|
||||
<%= render Layout::AdminLoginItemsComponent.new(user) %>
|
||||
<%= render Layout::NotificationItemComponent.new(user) %>
|
||||
<%= render "devise/menu/login_items", current_user: user %>
|
||||
<%= render Layout::LoginItemsComponent.new(user) %>
|
||||
</ul>
|
||||
|
||||
41
app/components/layout/admin_login_items_component.html.erb
Normal file
41
app/components/layout/admin_login_items_component.html.erb
Normal file
@@ -0,0 +1,41 @@
|
||||
<li class="has-submenu">
|
||||
<%= link_to t("layouts.header.administration_menu"), "#", rel: "nofollow", class: "hide-for-small-only" %>
|
||||
<ul class="submenu menu" data-submenu>
|
||||
<% if user.administrator? %>
|
||||
<li>
|
||||
<%= link_to t("layouts.header.administration"), admin_root_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if user.administrator? || user.moderator? %>
|
||||
<li>
|
||||
<%= link_to t("layouts.header.moderation"), moderation_root_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:budgets) &&
|
||||
(user.administrator? || user.valuator?) %>
|
||||
<li>
|
||||
<%= link_to t("layouts.header.valuation"), valuation_root_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if user.administrator? || user.manager? %>
|
||||
<li>
|
||||
<%= link_to t("layouts.header.management"), management_sign_in_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if user.poll_officer? && Poll.current.any? %>
|
||||
<li>
|
||||
<%= link_to t("layouts.header.officing"), officing_root_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:sdg) && (user.administrator? || user.sdg_manager?) %>
|
||||
<li>
|
||||
<%= link_to t("sdg_management.header.title"), sdg_management_root_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</li>
|
||||
12
app/components/layout/admin_login_items_component.rb
Normal file
12
app/components/layout/admin_login_items_component.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class Layout::AdminLoginItemsComponent < ApplicationComponent
|
||||
attr_reader :user
|
||||
delegate :show_admin_menu?, to: :helpers
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def render?
|
||||
show_admin_menu?(user)
|
||||
end
|
||||
end
|
||||
31
app/components/layout/login_items_component.html.erb
Normal file
31
app/components/layout/login_items_component.html.erb
Normal file
@@ -0,0 +1,31 @@
|
||||
<% if user %>
|
||||
<li>
|
||||
<%= layout_menu_link_to t("layouts.header.my_activity_link"),
|
||||
user_path(user),
|
||||
controller_name == "users",
|
||||
rel: "nofollow",
|
||||
title: t("shared.go_to_page") +
|
||||
t("layouts.header.my_activity_link") %>
|
||||
</li>
|
||||
<li>
|
||||
<%= layout_menu_link_to t("layouts.header.my_account_link"),
|
||||
account_path,
|
||||
controller_name == "account",
|
||||
rel: "nofollow",
|
||||
title: t("shared.go_to_page") +
|
||||
t("layouts.header.my_account_link") %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to t("devise_views.menu.login_items.logout"),
|
||||
destroy_user_session_path, rel: "nofollow", method: :delete %>
|
||||
</li>
|
||||
<% else %>
|
||||
<li>
|
||||
<%= link_to t("devise_views.menu.login_items.login"),
|
||||
new_user_session_path, rel: "nofollow" %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to t("devise_views.menu.login_items.signup"),
|
||||
new_user_registration_path, rel: "nofollow", class: "button" %>
|
||||
</li>
|
||||
<% end %>
|
||||
8
app/components/layout/login_items_component.rb
Normal file
8
app/components/layout/login_items_component.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Layout::LoginItemsComponent < ApplicationComponent
|
||||
attr_reader :user
|
||||
delegate :layout_menu_link_to, to: :helpers
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user