navigation_helper.rb revision f3f213d0921bfa18271c737598361fb7cd9851f3
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber# encoding: UTF-8
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcanomodule NavigationHelper
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def repository_nav(resource, current_page, options = {})
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages = [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano [:overview, resource]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
9afe19d634946d50eab30e3b90cb5cebcde39eeaDaniel Lezcano chain = resource_chain.last.is_a?(Ontology) ? resource_chain[0..-2] : resource_chain
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:ontologies, [*chain, :ontologies]]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:"File browser", [*chain, :tree]]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:history, repository_ref_path(resource, 'master', path: nil, action: :history)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:settings, repository_repository_settings_path(resource)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano subnavigation(resource, pages, current_page, options, [])
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def ontology_nav(ontology, current_page)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano resource = resource_chain.last
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano content_page = ontology.distributed? ? :children : :symbols
250b1eec71b074acdff1c5f6b5a1f0d7d2c20b77Stéphane Graber @top_level_pages = [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Content', locid_for(resource, content_page),
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano :symbols],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Comments', locid_for(resource, :comments),
7f95145833bb24f54e037f73ecc37444d6635697Dwight Engen :comments],
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand ['Metadata', locid_for(resource, :metadata),
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand :metadata],
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand ['Versions', locid_for(resource, :ontology_versions),
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano :ontology_versions],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Graphs', locid_for(resource, :graphs),
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano :graphs],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Mappings', locid_for(resource, :mappings),
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano :mappings],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @metadatas = []
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano if params[:action] != "edit"
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @metadatas = ontology_nav_metadata
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
d5cf438682963ac84c3617941032ba623d4ac9b2Michel Normand
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @symbols =
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano if ontology.distributed?
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano []
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano else
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ontology.symbols.groups_by_kind.sort_by(&:kind)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @active_kind =
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano choose_default_symbol_kind(@symbols) if current_page == :symbols
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @active_kind = params[:kind] if params[:kind]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages = []
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano if ontology.distributed?
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:children, locid_for(resource_chain.last, :children)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano else
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:axioms, locid_for(resource_chain.last, :axioms)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:theorems, locid_for(resource_chain.last, :theorems)]
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano end
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano actions = []
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages.map! do |page|
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano method = page.first
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano count =
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano if %i(axioms theorems).include?(page.first)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ontology.send(method).original.count
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano elsif ontology.respond_to?(method)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ontology.send(method).count
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano [*page, count]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @page_title = ontology.to_s
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano if current_page != pages[0][0]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @page_title = "#{current_page.capitalize} · #{@page_title}"
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano render partial: '/ontologies/info', locals: {
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano resource: ontology,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano current_page: current_page,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages: pages,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano additional_actions: []
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def subnavigation(resource, pages, current_page, options = {},
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano additional_actions = [], partial: '/shared/subnavigation')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # Add counters
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages.each do |row|
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano counter_key = "#{row[0]}_count"
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano row << resource.send(counter_key) if resource.respond_to?(counter_key)
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano @page_title = current_page
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano if current_page != pages[0][0]
bb787bc51f0a272f6574fe359f0749302e67c550Matthias Brugger @page_title = "#{current_page.capitalize} · #{@page_title}"
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano render partial: partial, locals: {
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano resource: resource,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano current_page: current_page,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages: pages,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano additional_actions: additional_actions,
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi options: options
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi end
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi def team_nav(team, current_page)
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi pages = [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano [:overview, team],
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi [:permissions, [team, :permissions]]
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi ]
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi pages << [:members, [team, :team_users]] if can? :edit, team
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi subnavigation(team, pages, current_page)
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi end
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi def active_navigation(controller)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano alternatives = [controller.to_s, controller.to_s.gsub('_', '/')]
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano if params[:repository_id]
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano if params[:ontology_id]
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano 'active' if controller == :ontologies
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano else
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano 'active' if controller == :repositories
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano end
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano elsif alternatives.include?(controller_name)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano 'active'
ac30d6a43245e0c50aad9e2ebfb88d80aaeea691Filippo Giunchedi end
ac30d6a43245e0c50aad9e2ebfb88d80aaeea691Filippo Giunchedi end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def menu_entry(title, controller)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano content_tag :li, class: active_navigation(controller) do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano link_to title, controller
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano # used for activating tabs in ontology view
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano def in_subcontroller?(page, current_page)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano case page
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano when :symbols
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano %w(classes axioms theorems proof_attempts prover_outputs).include?(controller_name)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano when :metadata
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano in_metadata?
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano # used for activating tabs in ontology view
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def in_metadata?
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano ontology_nav_metadata.map { |m| m.last.to_s }.
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano include?(controller_name)
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano end
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano protected
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano def ontology_nav_metadata
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano resource = resource_chain.last
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano [
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano ['Projects', locid_for(resource, :projects),
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano :projects],
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano ['Categories', locid_for(resource, :categories),
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano :categories],
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano ['Tasks', locid_for(resource, :tasks),
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano :tasks],
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano ['License Models', locid_for(resource, :license_models),
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano :license_models],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Formality Levels', locid_for(resource, :formality_levels),
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano :formality_levels],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand def repository_settings_nav(repository, current_page)
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand pages = []
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand chain =
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand if resource_chain.last.is_a?(Ontology)
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand resource_chain[0..-2]
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand else
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano resource_chain
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano current_page = t("repository.#{current_page}")
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [t('repository.urlmaps'), repository_url_maps_path(repository)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [t('repository.errors'), repository_errors_path(repository)]
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano if can? :permissions, repository
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano pages << [t('repository.permissions'), [*chain, :permissions]]
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano end
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano if can? :edit, repository
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano pages << [t('repository.edit'), edit_repository_path(repository)]
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano end
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano subnavigation(repository, pages, current_page,
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano partial: '/repository_settings/subnav')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcanoend
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano