navigation_helper.rb revision fe90e1e1ecaa3e8916cdb1bac8cadb8daf9631c3
4070N/Amodule NavigationHelper
4070N/A
4070N/A def repository_nav(resource, current_page)
4070N/A pages = [
4070N/A [:overview, resource]
4070N/A ]
4070N/A
4070N/A chain = resource_chain.last.is_a?(Ontology) ? resource_chain[0..-2] : resource_chain
4070N/A pages << [:ontologies, [*chain, :ontologies]]
4070N/A pages << [:files, [*chain, :tree]]
4070N/A pages << [:history, repository_ref_path(resource, 'master', path: nil, action: :history)]
4070N/A pages << [:permissions, [*chain, :permissions]] if can? :permissions, resource
4070N/A
4070N/A subnavigation(resource, pages, current_page)
4070N/A end
4070N/A
4070N/A def ontology_nav(ontology, current_page)
4070N/A @top_level_pages = [
4070N/A ['Content', ontology.distributed? ? :children : :entities],
4070N/A ['Comments', :comments],
4070N/A ['Metadata', :metadata],
4070N/A ['Versions', :ontology_versions],
4070N/A ['Graphs', :graphs],
4070N/A ['Links', :links]
4070N/A ]
4070N/A
4070N/A @entities = ontology.distributed? ? [] : ontology.entities.groups_by_kind
4070N/A
4070N/A @active_kind = @entities.first.kind if current_page == :entities
4070N/A @active_kind = params[:kind] if params[:kind]
4070N/A
4070N/A pages = []
4070N/A
4070N/A if ontology.distributed?
4070N/A pages << [:children, [*resource_chain, :children]]
4070N/A else
4070N/A pages << [:sentences, [*resource_chain, :sentences]]
4070N/A end
4070N/A
4070N/A actions = []
4070N/A
4070N/A # Add counters
4070N/A pages.each do |row|
4070N/A counter_key = "#{row[0]}_count"
4070N/A row << ontology.send(counter_key) if ontology.respond_to?(counter_key)
4070N/A end
4070N/A
4070N/A @page_title = ontology.to_s
4070N/A @page_title = "#{current_page.capitalize} ยท #{@page_title}" if current_page != pages[0][0]
4070N/A
4070N/A render :partial => '/ontologies/info', :locals => {
4070N/A resource: ontology,
4070N/A current_page: current_page,
4070N/A pages: pages,
additional_actions: []
}
end
def subnavigation(resource, pages, current_page, additional_actions = [])
# Add counters
pages.each do |row|
counter_key = "#{row[0]}_count"
row << resource.send(counter_key) if resource.respond_to?(counter_key)
end
@page_title = resource.to_s
@page_title = "#{current_page.capitalize} ยท #{@page_title}" if current_page != pages[0][0]
render :partial => '/shared/subnavigation', :locals => {
resource: resource,
current_page: current_page,
pages: pages,
additional_actions: additional_actions
}
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)
if params[:repository_id]
if params[:ontology_id]
return 'active' if controller == :ontologies
else
return 'active' if controller == :repositories
end
else
return 'active' if [controller.to_s, controller.to_s.gsub('_', '/')].include? params[:controller]
end
end
def menu_entry(title, controller)
content_tag :li, class: active_navigation(controller) do
link_to title, controller
end
end
end