application_helper.rb revision 00c175adc24043fbcd4cd5e3769c9d13e31ff831
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchimodule ApplicationHelper
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi def admin?
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi current_user.try(:admin?)
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi def context_pane
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi if params[:controller] == 'home'
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi 'shared/user_repositories'
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi elsif params[:controller] == 'categories' && params[:action] == 'show'
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi 'shared/user_ontologies'
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi elsif params[:action] != 'index'
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi false
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi elsif %w(categories logics mappings ontologies).include? params[:controller]
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi 'shared/user_ontologies' unless in_repository?
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi elsif params[:controller] == 'repositories'
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi 'shared/user_repositories'
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi else
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi false
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi def cover_visible?
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi params[:controller] == 'home' && !user_signed_in?
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi def in_repository?
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi params[:repository_id] || params[:controller] == 'repositories'
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi def resource_chain
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi return @resource_chain if @resource_chain
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi if params[:logic_id]
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi @resource_chain = []
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi return @resource_chain
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi if !params[:repository_id] && !(params[:controller] == 'repositories' && params[:id])
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi @resource_chain = []
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi return @resource_chain
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi @resource_chain = [ Repository.find_by_path!( controller_name=='repositories' ? params[:id] : params[:repository_id] )]
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi if id = params[:commit_reference_id]
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi @resource_chain << CommitReference.new(id)
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi if id = (controller_name=='ontologies' ? params[:id] : params[:ontology_id])
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi @resource_chain << Ontology.find(id)
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi @resource_chain
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi def display_commit?
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi !! Settings.display_head_commit
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi def display_commit
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi # try to read the HEAD from the Git repository
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi $commit_oid ||= begin
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi path = Rails.root.join(".git")
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi Subprocess.run(*%w(git rev-parse --short HEAD), GIT_DIR: path.to_s).strip if path.exist?
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi # try to read the revision from file
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi $commit_oid ||= begin
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi path = Rails.root.join("REVISION")
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi path.read.strip if path.exist?
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi $commit_oid ||= 'unknown'
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi def to_name(sym)
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi sym.to_s.gsub('_', ' ')
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi def determine_label_type(state)
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi State::STATE_LABEL[state.to_sym]
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi end
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchiend
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi