This class provides a method which shows whether a certain process is
enabled.
Even if it uses a helper, this class is inside the models folder because
the helper it uses actually only uses model methods. We might eventually
remove/simplify this helper and cache inside the model, like we did with
I18n content translations in commit 41dba842a.
43 lines
1017 B
Ruby
43 lines
1017 B
Ruby
class SDGManagement::MenuComponent < ApplicationComponent
|
|
include LinkListHelper
|
|
|
|
private
|
|
|
|
def links
|
|
[goals_link, *relatable_links]
|
|
end
|
|
|
|
def goals_link
|
|
[t("sdg_management.menu.sdg_content"), sdg_management_goals_path, sdg?, class: "goals-link"]
|
|
end
|
|
|
|
def relatable_links
|
|
SDG::Related::RELATABLE_TYPES.map do |type|
|
|
next unless SDG::ProcessEnabled.new(type).enabled?
|
|
|
|
[
|
|
t("sdg_management.menu.#{table_name(type)}"),
|
|
relatable_type_path(type),
|
|
controller_name == "relations" && params[:relatable_type] == type.tableize,
|
|
class: "#{table_name(type).tr("_", "-")}-link"
|
|
]
|
|
end
|
|
end
|
|
|
|
def sdg?
|
|
%w[goals targets local_targets].include?(controller_name)
|
|
end
|
|
|
|
def relatable_type_path(type)
|
|
{
|
|
controller: "sdg_management/relations",
|
|
action: :index,
|
|
relatable_type: type.tableize
|
|
}
|
|
end
|
|
|
|
def table_name(type)
|
|
type.constantize.table_name
|
|
end
|
|
end
|