navigation_helper.rb revision b17c7a521e12ece55af76387a9668acb5f830d43
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch# encoding: UTF-8
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen def repository_nav(resource, current_page, options = {})
97943a36e08923d625898f5ca8ffd38325a3986dTimo Sirainen chain = resource_chain.last.is_a?(Ontology) ? resource_chain[0..-2] : resource_chain
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 subnavigation(resource, pages, current_page, [], options)
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen ['Content', ontology.distributed? ? :children : :entities],
9c7f6dbf65ca01026e5f9c8c8b67c7e629c0b5e7Timo Sirainen @entities = ontology.distributed? ? [] : ontology.entities.groups_by_kind
9c7f6dbf65ca01026e5f9c8c8b67c7e629c0b5e7Timo Sirainen @active_kind = @entities.first.kind if current_page == :entities
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:children, [*resource_chain, :children]]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:sentences, [*resource_chain, :sentences]]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen # Add counters
f323e3f0de9841f399aba5919e3f25652a88fa65Timo Sirainen row << ontology.send(counter_key) if ontology.respond_to?(counter_key)
10399559650f552a23949772be79eb6a80198c5aTimo Sirainen @page_title = ontology.to_s
10399559650f552a23949772be79eb6a80198c5aTimo Sirainen @page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
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: []
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)
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen @page_title = current_page
bdb0f594a5673a0c5a16b92dc49eb2a8a66bdaceTimo Sirainen @page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
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
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen def team_nav(team, current_page)
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen [:overview, team],
10399559650f552a23949772be79eb6a80198c5aTimo Sirainen [:permissions, [team, :permissions]]
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen pages << [:members, [team, :team_users]] if can? :edit, team
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen subnavigation(team, pages, current_page)
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 return 'active' if controller == :repositories
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen return 'active' if [controller.to_s, controller.to_s.gsub('_', '/')].include? params[:controller]
37fed1bc1545f7eb1755b61d6a5ac4d083a693b3Timo Sirainen def menu_entry(title, controller)
37fed1bc1545f7eb1755b61d6a5ac4d083a693b3Timo Sirainen content_tag :li, class: active_navigation(controller) do
37fed1bc1545f7eb1755b61d6a5ac4d083a693b3Timo Sirainen link_to title, controller
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen # used for activating tabs in ontology view
62ff6002b1e37a42303c2c0107f324860232e204Timo Sirainen def in_subcontroller?(page, current_page)
62ff6002b1e37a42303c2c0107f324860232e204Timo Sirainen when :entities
62ff6002b1e37a42303c2c0107f324860232e204Timo Sirainen %w(classes sentences).include? controller_name
62ff6002b1e37a42303c2c0107f324860232e204Timo Sirainen when :metadata
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 def ontology_nav_metadata
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]]