Files
nairobi/app/helpers/admin_helper.rb
Javi Martín 4a5d4b3c0b Group investment search form methods together
We had helper methods all over the place which were only used in one
view. Since we're going to change some of them to use the budget as a
parameter, they don't belong in those helpers anymore.

Note the method `budget_heading_select_options` is used in more places,
so we're keeping it where it was.
2020-09-08 18:35:16 +02:00

113 lines
3.0 KiB
Ruby

module AdminHelper
def side_menu
if namespace == "moderation/budgets"
render "/moderation/menu"
else
render "/#{namespace}/menu"
end
end
def namespaced_root_path
"/#{namespace}"
end
def namespaced_header_title
if namespace == "moderation/budgets"
t("moderation.header.title")
else
t("#{namespace}.header.title")
end
end
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
def official_level_options
options = [["", 0]]
(1..5).each do |i|
options << [[t("admin.officials.level_#{i}"), setting["official_level_#{i}_name"]].compact.join(": "), i]
end
options
end
def admin_submit_action(resource)
resource.persisted? ? "edit" : "new"
end
def user_roles(user)
roles = []
roles << :admin if user.administrator?
roles << :moderator if user.moderator?
roles << :valuator if user.valuator?
roles << :manager if user.manager?
roles << :poll_officer if user.poll_officer?
roles << :official if user.official?
roles << :organization if user.organization?
roles
end
def display_user_roles(user)
user_roles(user).join(", ")
end
private
def namespace
controller.class.name.downcase.split("::").first
end
end