navigation_helper.rb revision 1cf649be9ed81eb8c96d13284ffa7992d816adce
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrinmodule NavigationHelper
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin def repository_nav(resource, current_page)
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin pages = [
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin [:overview, resource]
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin ]
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin pages << [:files, [resource, :tree]]
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin pages << [:history, repository_oid_path(resource, oid: 'master', path: nil, action: :history)]
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin pages << [:ontologies, [resource, :ontologies]]
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin pages << [:permissions, [resource, :permissions]] if can? :permissions, resource
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin subnavigation(resource, pages, current_page)
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin end
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin def ontology_nav(ontology, current_page)
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin @entities = ontology.entities.groups_by_kind
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin @active_kind = nil
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin @active_kind = @entities.first.kind if current_page == :entities
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin @active_kind = params[:kind] if params[:kind]
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin pages = []
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin if ontology.distributed?
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin pages << [:children, [ontology, :children]]
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin else
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin pages << [:sentences, [ontology, :sentences]]
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin end
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin actions = []
b45c2b86612fd10c2b08965bb99e66a3c0e43480minfrin
# action link to new version
actions << link_to('New version', [:new, ontology, :ontology_version ]) if can? :edit, ontology
# add counters
pages.each do |row|
counter_key = "#{row[0]}_count"
row << ontology.send(counter_key) if ontology.respond_to?(counter_key)
end
@page_title = ontology.to_s
@page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
render :partial => '/ontologies/info', :locals => {
resource: ontology,
current_page: current_page,
pages: pages,
additional_actions: []
}
end
def subnavigation(resource, pages, current_page, additional_actions = [])
# add counters
pages.each do |row|
counter_key = "#{row[0]}_count"
row << resource.send(counter_key) if resource.respond_to?(counter_key)
end
@page_title = resource.to_s
@page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
render :partial => '/shared/subnavigation', :locals => {
resource: resource,
current_page: current_page,
pages: pages,
additional_actions: additional_actions
}
end
def team_nav(team, current_page)
pages = [
[:overview, team],
[:permissions, [team, :permissions]]
]
pages << [:members, [team, :team_users]] if can? :edit, team
subnavigation(team, pages, current_page)
end
end