navigation_helper.rb revision 6f254ee6d91f5511136472397615afa6568f3ac0
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcanomodule NavigationHelper
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def ontology_nav(ontology, current_page)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @top_level_pages = [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Content', :entities],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Comments', :comments],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Metadata', :metadata],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Versions', :ontology_versions]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @entities = ontology.entities.groups_by_kind
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @metadatas = [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Projects', :projects],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Categories', :categories],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['Tasks', :tasks],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ['License Model', :license_model]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @active_kind = nil
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @active_kind = @entities.first.kind if current_page == :entities
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @active_kind = params[:kind] if params[:kind]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages = []
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano if ontology.distributed?
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:children, [ontology, :children]]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano else
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:sentences, [ontology, :sentences]]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano actions = []
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # action link to new version
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano actions << link_to('New version', [:new, ontology, :ontology_version ]) if can? :edit, ontology
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # add counters
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages.each do |row|
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano counter_key = "#{row[0]}_count"
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano row << ontology.send(counter_key) if ontology.respond_to?(counter_key)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @page_title = ontology.to_s
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
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, additional_actions = [])
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
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)
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @page_title = resource.to_s
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @page_title = "#{current_page.capitalize} · #{@page_title}" if current_page != pages[0][0]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano render :partial => '/shared/subnavigation', :locals => {
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano resource: resource,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano current_page: current_page,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages: pages,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano additional_actions: additional_actions
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano def team_nav(team, current_page)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages = [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano [:overview, team],
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano [:permissions, [team, :permissions]]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano pages << [:members, [team, :team_users]] if can? :edit, team
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano subnavigation(team, pages, current_page)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcanoend
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano