Refactor: remove dup code
This commit is contained in:
parent
edcdbd671b
commit
97a9c2293a
4 changed files with 22 additions and 38 deletions
|
@ -1,24 +1,22 @@
|
|||
class RefsController < ProjectResourceController
|
||||
include ExtractsPath
|
||||
|
||||
# Authorize
|
||||
before_filter :authorize_read_project!
|
||||
before_filter :authorize_code_access!
|
||||
before_filter :require_non_empty_project
|
||||
|
||||
before_filter :ref
|
||||
before_filter :define_tree_vars, only: [:blob, :logs_tree]
|
||||
|
||||
def switch
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
new_path = if params[:destination] == "tree"
|
||||
project_tree_path(@project, (@ref + "/" + params[:path]))
|
||||
project_tree_path(@project, (@id))
|
||||
elsif params[:destination] == "blob"
|
||||
project_blob_path(@project, (@ref + "/" + params[:path]))
|
||||
project_blob_path(@project, (@id))
|
||||
elsif params[:destination] == "graph"
|
||||
project_graph_path(@project, @ref)
|
||||
project_graph_path(@project, @id)
|
||||
else
|
||||
project_commits_path(@project, @ref)
|
||||
project_commits_path(@project, @id)
|
||||
end
|
||||
|
||||
redirect_to new_path
|
||||
|
@ -42,27 +40,4 @@ class RefsController < ProjectResourceController
|
|||
}
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def define_tree_vars
|
||||
params[:path] = nil if params[:path].blank?
|
||||
|
||||
@repo = project.repository
|
||||
@commit = @repo.commit(@ref)
|
||||
@tree = Tree.new(@repo, @commit.id, @ref, params[:path])
|
||||
@hex_path = Digest::SHA1.hexdigest(params[:path] || "")
|
||||
|
||||
if params[:path]
|
||||
@logs_path = logs_file_project_ref_path(@project, @ref, params[:path])
|
||||
else
|
||||
@logs_path = logs_tree_project_ref_path(@project, @ref)
|
||||
end
|
||||
rescue
|
||||
return render_404
|
||||
end
|
||||
|
||||
def ref
|
||||
@ref = params[:id] || params[:ref]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,9 +8,6 @@ class TreeController < ProjectResourceController
|
|||
before_filter :require_non_empty_project
|
||||
|
||||
def show
|
||||
@hex_path = Digest::SHA1.hexdigest(@path)
|
||||
@logs_path = logs_file_project_ref_path(@project, @ref, @path)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
# Disable cache so browser history works
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
.clearfix
|
||||
.pull-left
|
||||
= render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path}
|
||||
= render partial: 'shared/ref_switcher', locals: {destination: 'graph'}
|
||||
|
||||
.search.pull-right
|
||||
= form_tag project_graph_path(@project, params[:id]), method: :get do |f|
|
||||
= form_tag project_graph_path(@project, @id), method: :get do |f|
|
||||
.control-group
|
||||
= label_tag :search , "Looking for commit:", class: 'control-label light'
|
||||
.controls
|
||||
|
|
|
@ -94,16 +94,28 @@ module ExtractsPath
|
|||
# Automatically renders `not_found!` if a valid tree path could not be
|
||||
# resolved (e.g., when a user inserts an invalid path or ref).
|
||||
def assign_ref_vars
|
||||
@id = params[:id]
|
||||
@id = get_id
|
||||
|
||||
@ref, @path = extract_ref(@id)
|
||||
|
||||
@commit = @project.repository.commit(@ref)
|
||||
@repo = @project.repository
|
||||
|
||||
@tree = Tree.new(@project.repository, @commit.id, @ref, @path)
|
||||
@commit = @repo.commit(@ref)
|
||||
|
||||
@tree = Tree.new(@repo, @commit.id, @ref, @path)
|
||||
@hex_path = Digest::SHA1.hexdigest(@path)
|
||||
@logs_path = logs_file_project_ref_path(@project, @ref, @path)
|
||||
|
||||
raise InvalidPathError unless @tree.exists?
|
||||
rescue RuntimeError, NoMethodError, InvalidPathError
|
||||
not_found!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_id
|
||||
id = params[:id] || params[:ref]
|
||||
id += "/" + params[:path] unless params[:path].blank?
|
||||
id
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue