navigation_helper.rb revision 827e98b08be3acd813ab859061f7e6318b7f8abd
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch# encoding: UTF-8
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainenmodule NavigationHelper
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen def repository_nav(resource, current_page)
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages = [
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen [:overview, resource]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen ]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
056e7cd4029d460afabff2dc27c269096d8661c1Timo Sirainen chain = resource_chain.last.is_a?(Ontology) ? resource_chain[0..-2] : resource_chain
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages << [:ontologies, [*chain, :ontologies]]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages << [:"Ontology files", [*chain, :tree]]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages << [:"Ontology urls", repository_url_maps_path(resource)]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages << [:history, repository_ref_path(resource, 'master', path: nil, action: :history)]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages << [:permissions, [*chain, :permissions]] if can? :permissions, resource
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen subnavigation(resource, pages, current_page)
54b88816e47ceeccf953751c90e64d86195d5c2dTimo Sirainen end
1a883718249b8db128a105ee7f03293873f1f9c5Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen def ontology_nav(ontology, current_page)
cbe49ba128638e63395aedaa2144087c89835633Timo Sirainen @top_level_pages = [
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen ['Content', ontology.distributed? ? :children : :entities],
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen ['Comments', :comments],
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen ['Metadata', :metadata],
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen ['Versions', :ontology_versions],
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen ['Graphs', :graphs],
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch ['Links', :links]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen ]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen @entities = ontology.distributed? ? [] : ontology.entities.groups_by_kind
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen @active_kind = @entities.first.kind if current_page == :entities
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen @active_kind = params[:kind] if params[:kind]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages = []
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
8e1491e4924e3f9fc474a99438b6297b8d1ce1f3Timo Sirainen if ontology.distributed?
8e1491e4924e3f9fc474a99438b6297b8d1ce1f3Timo Sirainen pages << [:children, [*resource_chain, :children]]
8e1491e4924e3f9fc474a99438b6297b8d1ce1f3Timo Sirainen else
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages << [:sentences, [*resource_chain, :sentences]]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen end
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen actions = []
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen # Add counters
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages.each do |row|
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen counter_key = "#{row[0]}_count"
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen row << ontology.send(counter_key) if ontology.respond_to?(counter_key)
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch end
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch @page_title = ontology.to_s
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch @page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen render :partial => '/ontologies/info', :locals => {
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen resource: ontology,
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen current_page: current_page,
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages: pages,
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen additional_actions: [],
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen files: ontology.repository.paths_starting_with(ontology.basepath)
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen }
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen end
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen def subnavigation(resource, pages, current_page, additional_actions = [])
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen # Add counters
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages.each do |row|
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen counter_key = "#{row[0]}_count"
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen row << resource.send(counter_key) if resource.respond_to?(counter_key)
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen end
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen @page_title = current_page
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen @page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen render :partial => '/shared/subnavigation', :locals => {
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen resource: resource,
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen current_page: current_page,
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages: pages,
20e04227229970d148801c507946666e2a9bd838Timo Sirainen additional_actions: additional_actions
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen }
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen end
eca38954bcf972618f6b85932a3690acbd2b673aTimo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen def team_nav(team, current_page)
c7fd0af4fddec4a5a6d87d105a429e32429ae17dAki Tuomi pages = [
c7fd0af4fddec4a5a6d87d105a429e32429ae17dAki Tuomi [:overview, team],
c7fd0af4fddec4a5a6d87d105a429e32429ae17dAki Tuomi [:permissions, [team, :permissions]]
c7fd0af4fddec4a5a6d87d105a429e32429ae17dAki Tuomi ]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen pages << [:members, [team, :team_users]] if can? :edit, team
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen subnavigation(team, pages, current_page)
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen end
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen def active_navigation(controller)
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen if params[:repository_id]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen if params[:ontology_id]
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen return 'active' if controller == :ontologies
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen else
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen return 'active' if controller == :repositories
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen end
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch else
20e04227229970d148801c507946666e2a9bd838Timo Sirainen return 'active' if [controller.to_s, controller.to_s.gsub('_', '/')].include? params[:controller]
20e04227229970d148801c507946666e2a9bd838Timo Sirainen end
20e04227229970d148801c507946666e2a9bd838Timo Sirainen end
20e04227229970d148801c507946666e2a9bd838Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen def menu_entry(title, controller)
eca38954bcf972618f6b85932a3690acbd2b673aTimo Sirainen content_tag :li, class: active_navigation(controller) do
eca38954bcf972618f6b85932a3690acbd2b673aTimo Sirainen link_to title, controller
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen end
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen end
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainenend
1ea214b620715aa8b213c5686383b821e720fe42Timo Sirainen