navigation_helper.rb revision b17c7a521e12ece55af76387a9668acb5f830d43
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch# encoding: UTF-8
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainenmodule NavigationHelper
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen def repository_nav(resource, current_page, options = {})
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages = [
1f366614aaafcc9496ff85b25988f19c3254ab7cTimo Sirainen [:overview, resource]
1f366614aaafcc9496ff85b25988f19c3254ab7cTimo Sirainen ]
39ea5717264668e2c7f9f7986eb821d21785f47fTimo Sirainen
97943a36e08923d625898f5ca8ffd38325a3986dTimo Sirainen chain = resource_chain.last.is_a?(Ontology) ? resource_chain[0..-2] : resource_chain
3bc62efe513ebc7450cffe9a4e8f0b07424bf190Timo Sirainen
f739c92a9237db03327dc82e3792e39c160a1e4dTimo Sirainen pages << [:ontologies, [*chain, :ontologies]]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:"File browser", [*chain, :tree]]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:"URL catalog", repository_url_maps_path(resource)]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:history, repository_ref_path(resource, 'master', path: nil, action: :history)]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:errors, repository_errors_path(resource)]
8bf42ce5ef783b96a2ded67524173e95e9b45adaTimo Sirainen pages << [:permissions, [*chain, :permissions]] if can? :permissions, resource
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen subnavigation(resource, pages, current_page, [], options)
f739c92a9237db03327dc82e3792e39c160a1e4dTimo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen def ontology_nav(ontology, current_page)
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen @top_level_pages = [
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Content', ontology.distributed? ? :children : :entities],
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Comments', :comments],
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Metadata', :metadata],
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Versions', :ontology_versions],
f739c92a9237db03327dc82e3792e39c160a1e4dTimo Sirainen ['Graphs', :graphs],
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Links', :links]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ]
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen @metadatas = []
f739c92a9237db03327dc82e3792e39c160a1e4dTimo Sirainen
f739c92a9237db03327dc82e3792e39c160a1e4dTimo Sirainen if params[:action] != "edit"
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen @metadatas = ontology_nav_metadata
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
9c7f6dbf65ca01026e5f9c8c8b67c7e629c0b5e7Timo Sirainen
9c7f6dbf65ca01026e5f9c8c8b67c7e629c0b5e7Timo Sirainen @entities = ontology.distributed? ? [] : ontology.entities.groups_by_kind
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen
9c7f6dbf65ca01026e5f9c8c8b67c7e629c0b5e7Timo Sirainen @active_kind = @entities.first.kind if current_page == :entities
9c7f6dbf65ca01026e5f9c8c8b67c7e629c0b5e7Timo Sirainen @active_kind = params[:kind] if params[:kind]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages = []
9c7f6dbf65ca01026e5f9c8c8b67c7e629c0b5e7Timo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen if ontology.distributed?
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:children, [*resource_chain, :children]]
9c7f6dbf65ca01026e5f9c8c8b67c7e629c0b5e7Timo Sirainen else
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:sentences, [*resource_chain, :sentences]]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
055389c58fa3915e12fb4e72ec86782ce77c5c72Timo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen actions = []
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen # Add counters
f323e3f0de9841f399aba5919e3f25652a88fa65Timo Sirainen pages.each do |row|
f323e3f0de9841f399aba5919e3f25652a88fa65Timo Sirainen counter_key = "#{row[0]}_count"
f323e3f0de9841f399aba5919e3f25652a88fa65Timo Sirainen row << ontology.send(counter_key) if ontology.respond_to?(counter_key)
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
10399559650f552a23949772be79eb6a80198c5aTimo Sirainen @page_title = ontology.to_s
10399559650f552a23949772be79eb6a80198c5aTimo Sirainen @page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
a6a6ad107e509cf8952a28f740eb2023284497b9Timo Sirainen
39ea5717264668e2c7f9f7986eb821d21785f47fTimo Sirainen render :partial => '/ontologies/info', :locals => {
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen resource: ontology,
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen current_page: current_page,
a6a6ad107e509cf8952a28f740eb2023284497b9Timo Sirainen pages: pages,
f739c92a9237db03327dc82e3792e39c160a1e4dTimo Sirainen additional_actions: []
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen }
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen end
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen def subnavigation(resource, pages, current_page, additional_actions = [], options = {})
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen # Add counters
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen pages.each do |row|
a6a6ad107e509cf8952a28f740eb2023284497b9Timo Sirainen counter_key = "#{row[0]}_count"
f739c92a9237db03327dc82e3792e39c160a1e4dTimo Sirainen row << resource.send(counter_key) if resource.respond_to?(counter_key)
a6a6ad107e509cf8952a28f740eb2023284497b9Timo Sirainen end
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen @page_title = current_page
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen @page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen
8f2eb1ee9ec07661bd50275da99b5f351972a49aTimo Sirainen render :partial => '/shared/subnavigation', :locals => {
eca38954bcf972618f6b85932a3690acbd2b673aTimo Sirainen resource: resource,
8f2eb1ee9ec07661bd50275da99b5f351972a49aTimo Sirainen current_page: current_page,
8f2eb1ee9ec07661bd50275da99b5f351972a49aTimo Sirainen pages: pages,
8f2eb1ee9ec07661bd50275da99b5f351972a49aTimo Sirainen additional_actions: additional_actions,
f739c92a9237db03327dc82e3792e39c160a1e4dTimo Sirainen options: options
a6a6ad107e509cf8952a28f740eb2023284497b9Timo Sirainen }
a6a6ad107e509cf8952a28f740eb2023284497b9Timo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen def team_nav(team, current_page)
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen pages = [
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen [:overview, team],
10399559650f552a23949772be79eb6a80198c5aTimo Sirainen [:permissions, [team, :permissions]]
dc599de6096c51e6c922e069bfbbcb7d68c50ffaStephan Bosch ]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:members, [team, :team_users]] if can? :edit, team
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen subnavigation(team, pages, current_page)
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
a943ed0f901e312445fd393249b91932797bba79Josef 'Jeff' Sipek def active_navigation(controller)
3ccab0bac68040f179a7de45c516cec258e28fdbTimo Sirainen if params[:repository_id]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen if params[:ontology_id]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen return 'active' if controller == :ontologies
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen else
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen return 'active' if controller == :repositories
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen else
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen return 'active' if [controller.to_s, controller.to_s.gsub('_', '/')].include? params[:controller]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
37fed1bc1545f7eb1755b61d6a5ac4d083a693b3Timo Sirainen
37fed1bc1545f7eb1755b61d6a5ac4d083a693b3Timo Sirainen def menu_entry(title, controller)
37fed1bc1545f7eb1755b61d6a5ac4d083a693b3Timo Sirainen content_tag :li, class: active_navigation(controller) do
37fed1bc1545f7eb1755b61d6a5ac4d083a693b3Timo Sirainen link_to title, controller
37fed1bc1545f7eb1755b61d6a5ac4d083a693b3Timo Sirainen end
37fed1bc1545f7eb1755b61d6a5ac4d083a693b3Timo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen # used for activating tabs in ontology view
62ff6002b1e37a42303c2c0107f324860232e204Timo Sirainen def in_subcontroller?(page, current_page)
62ff6002b1e37a42303c2c0107f324860232e204Timo Sirainen case page
62ff6002b1e37a42303c2c0107f324860232e204Timo Sirainen when :entities
62ff6002b1e37a42303c2c0107f324860232e204Timo Sirainen %w(classes sentences).include? controller_name
62ff6002b1e37a42303c2c0107f324860232e204Timo Sirainen when :metadata
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen in_metadata?
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen # used for activating tabs in ontology view
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen def in_metadata?
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ontology_nav_metadata.map{ |m| m[1][-1].to_s }.include? controller_name
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen protected
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen def ontology_nav_metadata
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen [
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Projects', [*resource_chain, :projects]],
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Categories', [*resource_chain, :categories]],
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Tasks', [*resource_chain, :tasks]],
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['License Model', [*resource_chain, :license_models]],
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Formality Levels', [*resource_chain, :formality_levels]]
b5052fbfdbc2678cc8f12899afe55c998f43b740Timo Sirainen ]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen end
f739c92a9237db03327dc82e3792e39c160a1e4dTimo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainenend
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen