c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainenmodule ApplicationHelper
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def admin?
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen current_user.try(:admin?)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def context_pane
920b9f0fdfa5a5d7763e05736601a31bcb291a53Timo Sirainen if params[:controller] == 'home'
920b9f0fdfa5a5d7763e05736601a31bcb291a53Timo Sirainen 'shared/user_repositories'
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen elsif params[:controller] == 'categories' && params[:action] == 'show'
763f83d3cc47bce05cbc396419c4db2b71dd8e68Timo Sirainen 'shared/user_ontologies'
3f5b0dcbdc4f804a99935b648b34540bd2dc9c08Timo Sirainen elsif params[:action] != 'index'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen false
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen elsif %w(categories logics mappings ontologies).include? params[:controller]
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen 'shared/user_ontologies' unless in_repository?
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen elsif params[:controller] == 'repositories'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen 'shared/user_repositories'
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen else
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen false
920b9f0fdfa5a5d7763e05736601a31bcb291a53Timo Sirainen end
811f2e26d9782d9cb99fdf82e18ffa0a77564fe2Timo Sirainen end
920b9f0fdfa5a5d7763e05736601a31bcb291a53Timo Sirainen
920b9f0fdfa5a5d7763e05736601a31bcb291a53Timo Sirainen def cover_visible?
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen params[:controller] == 'home' && !user_signed_in?
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def in_repository?
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen params[:repository_id].present? || params[:controller] == 'repositories'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen def resource_chain
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen return @resource_chain if @resource_chain
289064eb21595d3e4460439eccdc48232d13f5e1Timo Sirainen
f0ff961282e618945dfe997dc45ff95d656e5790Timo Sirainen if params[:logic_id]
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen @resource_chain = []
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return @resource_chain
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if !params[:repository_id] && !(params[:controller] == 'repositories' && params[:id])
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen @resource_chain = []
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return @resource_chain
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen @resource_chain = [ Repository.find_by_path!( controller_name=='repositories' ? params[:id] : params[:repository_id] )]
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if id = params[:commit_reference_id]
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen @resource_chain << CommitReference.new(id)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if id = (controller_name=='ontologies' ? params[:id] : params[:ontology_id])
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen @resource_chain << Ontology.find(id)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen @resource_chain
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def display_commit?
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen !! Settings.display_head_commit
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen end
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen def display_commit
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen # try to read the HEAD from the Git repository
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen $commit_oid ||= begin
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen path = Rails.root.join(".git")
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen Subprocess.run(*%w(git rev-parse --short HEAD), GIT_DIR: path.to_s).strip if path.exist?
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen end
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen # try to read the revision from file
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen $commit_oid ||= begin
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen path = Rails.root.join("REVISION")
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen path.read.strip if path.exist?
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen $commit_oid ||= 'unknown'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen def to_name(sym)
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen sym.to_s.gsub('_', ' ')
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen end
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen
9a583c7a827f7a4d89ee43774f2d51ea6a214543Timo Sirainen def determine_label_type(state)
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen State::STATE_LABEL[state.to_sym]
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen end
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainenend
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen