navigation_helper.rb revision f3f213d0921bfa18271c737598361fb7cd9851f3
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber# encoding: UTF-8
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def repository_nav(resource, current_page, options = {})
9afe19d634946d50eab30e3b90cb5cebcde39eeaDaniel Lezcano chain = resource_chain.last.is_a?(Ontology) ? resource_chain[0..-2] : resource_chain
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:history, repository_ref_path(resource, 'master', path: nil, action: :history)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:settings, repository_repository_settings_path(resource)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano subnavigation(resource, pages, current_page, options, [])
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano content_page = ontology.distributed? ? :children : :symbols
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand ['Versions', locid_for(resource, :ontology_versions),
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano choose_default_symbol_kind(@symbols) if current_page == :symbols
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:children, locid_for(resource_chain.last, :children)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:axioms, locid_for(resource_chain.last, :axioms)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:theorems, locid_for(resource_chain.last, :theorems)]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @page_title = "#{current_page.capitalize} · #{@page_title}"
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def subnavigation(resource, pages, current_page, options = {},
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano additional_actions = [], partial: '/shared/subnavigation')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # Add counters
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano row << resource.send(counter_key) if resource.respond_to?(counter_key)
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano @page_title = current_page
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano if current_page != pages[0][0]
bb787bc51f0a272f6574fe359f0749302e67c550Matthias Brugger @page_title = "#{current_page.capitalize} · #{@page_title}"
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
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi def team_nav(team, current_page)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano [:overview, team],
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi [:permissions, [team, :permissions]]
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi pages << [:members, [team, :team_users]] if can? :edit, team
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi subnavigation(team, pages, current_page)
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 'active' if controller == :repositories
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano elsif alternatives.include?(controller_name)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def menu_entry(title, controller)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano content_tag :li, class: active_navigation(controller) do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano link_to title, controller
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano # used for activating tabs in ontology view
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano def in_subcontroller?(page, current_page)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano when :symbols
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano %w(classes axioms theorems proof_attempts prover_outputs).include?(controller_name)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano when :metadata
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano in_metadata?
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 def ontology_nav_metadata
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano resource = resource_chain.last
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano ['Projects', locid_for(resource, :projects),
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano ['Categories', locid_for(resource, :categories),
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano :categories],
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano ['Tasks', locid_for(resource, :tasks),
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano ['License Models', locid_for(resource, :license_models),
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano :license_models],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Formality Levels', locid_for(resource, :formality_levels),
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano :formality_levels],
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand def repository_settings_nav(repository, current_page)
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand if resource_chain.last.is_a?(Ontology)
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand resource_chain[0..-2]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano resource_chain
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 if can? :edit, repository
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano pages << [t('repository.edit'), edit_repository_path(repository)]
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano subnavigation(repository, pages, current_page,
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano partial: '/repository_settings/subnav')