navigation_helper.rb revision 3163ca485711745703db7bafed31f9675aafeefe
851N/A# encoding: UTF-8
851N/Amodule NavigationHelper
1408N/A
851N/A def repository_nav(resource, current_page, options = {})
1598N/A pages = [
851N/A [:overview, resource]
851N/A ]
919N/A
919N/A chain = resource_chain.last.is_a?(Ontology) ? resource_chain[0..-2] : resource_chain
919N/A
919N/A pages << [:ontologies, [*chain, :ontologies]]
919N/A pages << [:"File browser", [*chain, :tree]]
919N/A pages << [:history, repository_ref_path(resource, 'master', path: nil, action: :history)]
919N/A pages << [:settings, repository_repository_settings_path(resource)]
919N/A
919N/A subnavigation(resource, pages, current_page, options, [])
919N/A end
919N/A
919N/A def ontology_nav(ontology, current_page)
919N/A @top_level_pages = [
919N/A ['Content', ontology.distributed? ? :children : :entities],
919N/A ['Comments', :comments],
919N/A ['Metadata', :metadata],
919N/A ['Versions', :ontology_versions],
851N/A ['Graphs', :graphs],
851N/A ['Mappings', :links]
851N/A ]
851N/A
851N/A @metadatas = []
851N/A
851N/A if params[:action] != "edit"
1634N/A @metadatas = ontology_nav_metadata
851N/A end
911N/A
1634N/A @entities = ontology.distributed? ? [] : ontology.entities.groups_by_kind.sort_by(&:kind)
1634N/A
1634N/A @active_kind = choose_default_entity_kind(@entities) if current_page == :entities
911N/A @active_kind = params[:kind] if params[:kind]
1281N/A
1425N/A pages = []
1281N/A
851N/A if ontology.distributed?
851N/A pages << [:children, [*resource_chain, :children]]
851N/A else
851N/A pages << [:sentences, [*resource_chain, :sentences]]
851N/A pages << [:theorems, [*resource_chain, :theorems]]
1179N/A end
851N/A
1425N/A actions = []
1425N/A
851N/A pages.map! do |page|
1088N/A method = page.first
1088N/A count = ontology.send(method).count if ontology.respond_to?(method)
1088N/A [*page, count]
1598N/A end
1598N/A
1598N/A @page_title = ontology.to_s
1088N/A @page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
851N/A
1097N/A render :partial => '/ontologies/info', :locals => {
1097N/A resource: ontology,
1097N/A current_page: current_page,
1097N/A pages: pages,
1097N/A additional_actions: []
851N/A }
851N/A end
1088N/A
1088N/A def subnavigation(resource, pages, current_page, options = {}, additional_actions = [], partial: '/shared/subnavigation')
1088N/A # Add counters
1088N/A pages.each do |row|
1088N/A counter_key = "#{row[0]}_count"
1088N/A row << resource.send(counter_key) if resource.respond_to?(counter_key)
1088N/A end
1088N/A
@page_title = current_page
@page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
render :partial => partial, :locals => {
resource: resource,
current_page: current_page,
pages: pages,
additional_actions: additional_actions,
options: options
}
end
def team_nav(team, current_page)
pages = [
[:overview, team],
[:permissions, [team, :permissions]]
]
pages << [:members, [team, :team_users]] if can? :edit, team
subnavigation(team, pages, current_page)
end
def active_navigation(controller)
alternatives = [controller.to_s, controller.to_s.gsub('_', '/')]
if params[:repository_id]
if params[:ontology_id]
'active' if controller == :ontologies
else
'active' if controller == :repositories
end
elsif alternatives.include?(controller_name)
'active'
end
end
def menu_entry(title, controller)
content_tag :li, class: active_navigation(controller) do
link_to title, controller
end
end
# used for activating tabs in ontology view
def in_subcontroller?(page, current_page)
case page
when :entities
%w(classes sentences theorems).include?(controller_name)
when :metadata
in_metadata?
end
end
# used for activating tabs in ontology view
def in_metadata?
ontology_nav_metadata.map { |m| m[1][-1].to_s }.include?(controller_name)
end
protected
def ontology_nav_metadata
[
['Projects', [*resource_chain, :projects]],
['Categories', [*resource_chain, :categories]],
['Tasks', [*resource_chain, :tasks]],
['License Models', [*resource_chain, :license_models]],
['Formality Levels', [*resource_chain, :formality_levels]]
]
end
def repository_settings_nav(repository, current_page)
pages = []
chain = resource_chain.last.is_a?(Ontology) ? resource_chain[0..-2] : resource_chain
current_page = t("repository.#{current_page}")
pages << [t("repository.urlmaps"), repository_url_maps_path(repository)]
pages << [t("repository.errors"), repository_errors_path(repository)]
pages << [t("repository.permissions"), [*chain, :permissions]] if can? :permissions, repository
pages << [t("repository.edit"), edit_repository_path(repository)] if can? :edit, repository
subnavigation(repository, pages, current_page, partial: '/repository_settings/subnav')
end
end