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">
|
<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 Layout::NotificationItemComponent.new(user) %>
|
||||||
<%= render "devise/menu/login_items", current_user: user %>
|
<%= render Layout::LoginItemsComponent.new(user) %>
|
||||||
</ul>
|
</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
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<% if current_user %>
|
<% if user %>
|
||||||
<li>
|
<li>
|
||||||
<%= layout_menu_link_to t("layouts.header.my_activity_link"),
|
<%= layout_menu_link_to t("layouts.header.my_activity_link"),
|
||||||
user_path(current_user),
|
user_path(user),
|
||||||
controller_name == "users",
|
controller_name == "users",
|
||||||
rel: "nofollow",
|
rel: "nofollow",
|
||||||
title: t("shared.go_to_page") +
|
title: t("shared.go_to_page") +
|
||||||
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
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<% if show_admin_menu?(current_user) %>
|
|
||||||
<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 current_user.administrator? %>
|
|
||||||
<li>
|
|
||||||
<%= link_to t("layouts.header.administration"), admin_root_path %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if current_user.administrator? || current_user.moderator? %>
|
|
||||||
<li>
|
|
||||||
<%= link_to t("layouts.header.moderation"), moderation_root_path %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if feature?(:budgets) &&
|
|
||||||
(current_user.administrator? || current_user.valuator?) %>
|
|
||||||
<li>
|
|
||||||
<%= link_to t("layouts.header.valuation"), valuation_root_path %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if current_user.administrator? || current_user.manager? %>
|
|
||||||
<li>
|
|
||||||
<%= link_to t("layouts.header.management"), management_sign_in_path %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if current_user.poll_officer? && Poll.current.any? %>
|
|
||||||
<li>
|
|
||||||
<%= link_to t("layouts.header.officing"), officing_root_path %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if feature?(:sdg) && (current_user.administrator? || current_user.sdg_manager?) %>
|
|
||||||
<li>
|
|
||||||
<%= link_to t("sdg_management.header.title"), sdg_management_root_path %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
Reference in New Issue
Block a user