Extract admin menu to a component
This way adding new methods will be easier.
This commit is contained in:
279
app/components/admin/menu_component.html.erb
Normal file
279
app/components/admin/menu_component.html.erb
Normal file
@@ -0,0 +1,279 @@
|
||||
<ul id="admin_menu" data-accordion-menu data-multi-open="true">
|
||||
<% if feature?(:proposals) %>
|
||||
<li class="section-title">
|
||||
<%= link_to admin_proposals_path do %>
|
||||
<span class="icon-proposals"></span>
|
||||
<strong><%= t("admin.menu.proposals") %></strong>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:debates) %>
|
||||
<li class="section-title <%= "is-active" if controller_name == "debates" %>">
|
||||
<%= link_to admin_debates_path do %>
|
||||
<span class="icon-debates"></span>
|
||||
<strong><%= t("admin.menu.debates") %></strong>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<li class="section-title <%= "is-active" if controller_name == "comments" %>">
|
||||
<%= link_to admin_comments_path do %>
|
||||
<span class="icon-comments"></span>
|
||||
<strong><%= t("admin.menu.comments") %></strong>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<% if feature?(:polls) %>
|
||||
<li class="section-title <%= "is-active" if menu_polls? %>">
|
||||
<%= link_to admin_polls_path do %>
|
||||
<span class="icon-checkmark-circle"></span>
|
||||
<strong><%= t("admin.menu.polls") %></strong>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:legislation) %>
|
||||
<li class="section-title <%= "is-active" if controller.class.parent == Admin::Legislation %>">
|
||||
<%= link_to admin_legislation_processes_path do %>
|
||||
<span class="icon-file-text"></span>
|
||||
<strong><%= t("admin.menu.legislation") %></strong>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:budgets) %>
|
||||
<li class="section-title <%= "is-active" if menu_budgets? %>">
|
||||
<%= link_to admin_budgets_path do %>
|
||||
<span class="icon-budget"></span>
|
||||
<strong><%= t("admin.menu.budgets") %></strong>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<li class="section-title">
|
||||
<a href="#">
|
||||
<span class="icon-box"></span>
|
||||
<strong><%= t("admin.menu.title_booths") %></strong>
|
||||
</a>
|
||||
<ul id="booths_menu" <%= "class=is-active" if menu_booths? %>>
|
||||
<li <%= "class=is-active" if %w[officers officer_assignments].include?(controller_name) %>>
|
||||
<%= link_to t("admin.menu.poll_officers"), admin_officers_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "booths" &&
|
||||
action_name != "available" %>>
|
||||
<%= link_to t("admin.menu.poll_booths"), admin_booths_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if (controller_name == "polls" &&
|
||||
action_name == "booth_assignments") ||
|
||||
controller_name == "booth_assignments" &&
|
||||
action_name == "manage" %>>
|
||||
<%= link_to t("admin.menu.poll_booth_assignments"), booth_assignments_admin_polls_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if %w[shifts booths].include?(controller_name) &&
|
||||
%w[available new].include?(action_name) %>>
|
||||
<%= link_to t("admin.menu.poll_shifts"), available_admin_booths_path %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<% if feature?(:signature_sheets) %>
|
||||
<li class="section-title <%= "is-active" if controller_name == "signature_sheets" %>">
|
||||
<%= link_to admin_signature_sheets_path do %>
|
||||
<span class="icon-file-text-o"></span>
|
||||
<strong><%= t("admin.menu.signature_sheets") %></strong>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% messages_sections = %w[newsletters emails_download admin_notifications system_emails] %>
|
||||
<% messages_menu_active = messages_sections.include?(controller_name) %>
|
||||
<li class="section-title" <%= "class=is-active" if messages_menu_active %>>
|
||||
<a href="#">
|
||||
<span class="icon-zip"></span>
|
||||
<strong><%= t("admin.menu.messaging_users") %></strong>
|
||||
</a>
|
||||
<ul id="messaging_users_menu" <%= "class=is-active" if messages_menu_active %>>
|
||||
<li <%= "class=is-active" if controller_name == "newsletters" %>>
|
||||
<%= link_to t("admin.menu.newsletters"), admin_newsletters_path %>
|
||||
</li>
|
||||
<li <%= "class=is-active" if controller_name == "admin_notifications" %>>
|
||||
<%= link_to t("admin.menu.admin_notifications"), admin_admin_notifications_path %>
|
||||
</li>
|
||||
<li <%= "class=is-active" if controller_name == "system_emails" %>>
|
||||
<%= link_to t("admin.menu.system_emails"), admin_system_emails_path %>
|
||||
</li>
|
||||
<li <%= "class=is-active" if controller_name == "emails_download" %>>
|
||||
<%= link_to t("admin.menu.emails_download"), admin_emails_download_index_path %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="section-title">
|
||||
<a href="#">
|
||||
<span class="icon-edit"></span>
|
||||
<strong><%= t("admin.menu.title_site_customization") %></strong>
|
||||
</a>
|
||||
<ul <%= "class=is-active" if menu_customization? &&
|
||||
controller.class.parent != Admin::Poll::Questions::Answers %>>
|
||||
|
||||
<li <%= "class=is-active" if menu_homepage? %>>
|
||||
<%= link_to t("admin.menu.site_customization.homepage"), admin_homepage_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if menu_pages? || controller_name == "pages" %>>
|
||||
<%= link_to t("admin.menu.site_customization.pages"), admin_site_customization_pages_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "banners" %>>
|
||||
<%= link_to t("admin.menu.banner"), admin_banners_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "information_texts" %>>
|
||||
<%= link_to t("admin.menu.site_customization.information_texts"), admin_site_customization_information_texts_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "documents" %>>
|
||||
<%= link_to t("admin.menu.site_customization.documents"),
|
||||
admin_site_customization_documents_path %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="section-title">
|
||||
<a href="#">
|
||||
<span class="icon-eye"></span>
|
||||
<strong><%= t("admin.menu.title_moderated_content") %></strong>
|
||||
</a>
|
||||
<ul <%= "class=is-active" if menu_moderated_content? %>>
|
||||
<% if feature?(:proposals) %>
|
||||
<li <%= "class=is-active" if controller_name == "hidden_proposals" %>>
|
||||
<%= link_to t("admin.menu.hidden_proposals"), admin_hidden_proposals_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:debates) %>
|
||||
<li <%= "class=is-active" if controller_name == "hidden_debates" %>>
|
||||
<%= link_to t("admin.menu.hidden_debates"), admin_hidden_debates_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:budgets) %>
|
||||
<li <%= "class=is-active" if controller_name == "hidden_budget_investments" %>>
|
||||
<%= link_to t("admin.menu.hidden_budget_investments"), admin_hidden_budget_investments_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "hidden_comments" %>>
|
||||
<%= link_to t("admin.menu.hidden_comments"), admin_hidden_comments_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "hidden_proposal_notifications" %>>
|
||||
<%= link_to t("admin.menu.hidden_proposal_notifications"), admin_hidden_proposal_notifications_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "hidden_users" %>>
|
||||
<%= link_to t("admin.menu.hidden_users"), admin_hidden_users_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "activity" %>>
|
||||
<%= link_to t("admin.menu.activity"), admin_activity_path %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="section-title">
|
||||
<a href="#">
|
||||
<span class="icon-organizations"></span>
|
||||
<strong><%= t("admin.menu.title_profiles") %></strong>
|
||||
</a>
|
||||
<ul <%= "class=is-active" if menu_profiles? %>>
|
||||
<li <%= "class=is-active" if controller_name == "administrators" %>>
|
||||
<%= link_to t("admin.menu.administrators"), admin_administrators_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "organizations" %>>
|
||||
<%= link_to t("admin.menu.organizations"), admin_organizations_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "officials" %>>
|
||||
<%= link_to t("admin.menu.officials"), admin_officials_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "moderators" %>>
|
||||
<%= link_to t("admin.menu.moderators"), admin_moderators_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "valuators" %>>
|
||||
<%= link_to t("admin.menu.valuators"), admin_valuators_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "managers" %>>
|
||||
<%= link_to t("admin.menu.managers"), admin_managers_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "users" %>>
|
||||
<%= link_to t("admin.menu.users"), admin_users_path %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="section-title" <%= "class=is-active" if controller_name == "stats" %>>
|
||||
<%= link_to admin_stats_path do %>
|
||||
<span class="icon-stats"></span><%= t("admin.menu.stats") %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li class="section-title">
|
||||
<a href="#">
|
||||
<span class="icon-settings"></span>
|
||||
<strong><%= t("admin.menu.title_settings") %></strong>
|
||||
</a>
|
||||
<ul <%= "class=is-active" if menu_settings? %>>
|
||||
<li <%= "class=is-active" if controller_name == "settings" %>>
|
||||
<%= link_to t("admin.menu.settings"), admin_settings_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "tags" %>>
|
||||
<%= link_to t("admin.menu.proposals_topics"), admin_tags_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "geozones" %>>
|
||||
<%= link_to t("admin.menu.geozones"), admin_geozones_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "images" &&
|
||||
controller.class.parent != Admin::Poll::Questions::Answers %>>
|
||||
<%= link_to t("admin.menu.site_customization.images"), admin_site_customization_images_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "content_blocks" %>>
|
||||
<%= link_to t("admin.menu.site_customization.content_blocks"), admin_site_customization_content_blocks_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if submenu_local_census_records? %>>
|
||||
<%= link_to t("admin.menu.local_census_records"), admin_local_census_records_path %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="section-title">
|
||||
<a href="#">
|
||||
<span class="icon-check"></span>
|
||||
<strong><%= t("admin.menu.dashboard") %></strong>
|
||||
</a>
|
||||
<ul <%= "class=is-active" if menu_dashboard? %>>
|
||||
<li <%= "class=is-active" if controller_name == "actions" %>>
|
||||
<%= link_to t("admin.menu.dashboard_actions"), admin_dashboard_actions_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=is-active" if controller_name == "administrator_tasks" %>>
|
||||
<%= link_to admin_dashboard_administrator_tasks_path do %>
|
||||
<%= t("admin.menu.administrator_tasks") %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
60
app/components/admin/menu_component.rb
Normal file
60
app/components/admin/menu_component.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
class Admin::MenuComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def menu_moderated_content?
|
||||
moderated_sections.include?(controller_name) && controller.class.parent != Admin::Legislation
|
||||
end
|
||||
|
||||
def moderated_sections
|
||||
["hidden_proposals", "hidden_debates", "hidden_comments", "hidden_users", "activity",
|
||||
"hidden_budget_investments", "hidden_proposal_notifications"]
|
||||
end
|
||||
|
||||
def menu_budgets?
|
||||
controller_name.starts_with?("budget")
|
||||
end
|
||||
|
||||
def menu_polls?
|
||||
controller.class.parent == Admin::Poll::Questions::Answers ||
|
||||
%w[polls active_polls recounts results questions answers].include?(controller_name) &&
|
||||
action_name != "booth_assignments"
|
||||
end
|
||||
|
||||
def menu_booths?
|
||||
%w[officers booths shifts booth_assignments officer_assignments].include?(controller_name) ||
|
||||
controller_name == "polls" && action_name == "booth_assignments"
|
||||
end
|
||||
|
||||
def menu_profiles?
|
||||
%w[administrators organizations officials moderators valuators managers users].include?(controller_name)
|
||||
end
|
||||
|
||||
def menu_settings?
|
||||
controllers_names = ["settings", "tags", "geozones", "images", "content_blocks",
|
||||
"local_census_records", "imports"]
|
||||
controllers_names.include?(controller_name) &&
|
||||
controller.class.parent != Admin::Poll::Questions::Answers
|
||||
end
|
||||
|
||||
def menu_customization?
|
||||
["pages", "banners", "information_texts", "documents"].include?(controller_name) ||
|
||||
menu_homepage? || menu_pages?
|
||||
end
|
||||
|
||||
def menu_homepage?
|
||||
["homepage", "cards"].include?(controller_name) && params[:page_id].nil?
|
||||
end
|
||||
|
||||
def menu_pages?
|
||||
["pages", "cards"].include?(controller_name) && params[:page_id].present?
|
||||
end
|
||||
|
||||
def menu_dashboard?
|
||||
["actions", "administrator_tasks"].include?(controller_name)
|
||||
end
|
||||
|
||||
def submenu_local_census_records?
|
||||
controller_name == "local_census_records" ||
|
||||
(controller_name == "imports" && controller.class.parent == Admin::LocalCensusRecords)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user