navigation_helper.rb revision cd3073fbe6dc665dc20e2c65cf1ac33f723408f3
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# encoding: utf-8
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemodule NavigationHelper
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte def ontology_nav(ontology, current_page)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte @groups = ontology.entities.grouped_by_kind
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (current_page == :entities)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte @kind = @groups.first
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte @kind = :symbols
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pages = []
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ontology.distributed?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pages << [:children, [ontology, :children]]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pages << [:symbols, [ontology, :entities]] if @groups.blank?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pages << [:sentences, [ontology, :sentences]]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte actions = []
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte # action link to new version
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte actions << link_to('New version', [:new, ontology, :ontology_version ]) if can? :edit, ontology
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte # add counters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pages.each do |row|
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte counter_key = "#{row[0]}_count"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 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 => '/shared/ontology', :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