Commit 97a9c229 authored by Sato Hiroyuki's avatar Sato Hiroyuki

Refactor: remove dup code

parent edcdbd67
class RefsController < ProjectResourceController class RefsController < ProjectResourceController
include ExtractsPath
# Authorize # Authorize
before_filter :authorize_read_project! before_filter :authorize_read_project!
before_filter :authorize_code_access! before_filter :authorize_code_access!
before_filter :require_non_empty_project before_filter :require_non_empty_project
before_filter :ref
before_filter :define_tree_vars, only: [:blob, :logs_tree]
def switch def switch
respond_to do |format| respond_to do |format|
format.html do format.html do
new_path = if params[:destination] == "tree" new_path = if params[:destination] == "tree"
project_tree_path(@project, (@ref + "/" + params[:path])) project_tree_path(@project, (@id))
elsif params[:destination] == "blob" elsif params[:destination] == "blob"
project_blob_path(@project, (@ref + "/" + params[:path])) project_blob_path(@project, (@id))
elsif params[:destination] == "graph" elsif params[:destination] == "graph"
project_graph_path(@project, @ref) project_graph_path(@project, @id)
else else
project_commits_path(@project, @ref) project_commits_path(@project, @id)
end end
redirect_to new_path redirect_to new_path
...@@ -42,27 +40,4 @@ class RefsController < ProjectResourceController ...@@ -42,27 +40,4 @@ class RefsController < ProjectResourceController
} }
end end
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 end
...@@ -8,9 +8,6 @@ class TreeController < ProjectResourceController ...@@ -8,9 +8,6 @@ class TreeController < ProjectResourceController
before_filter :require_non_empty_project before_filter :require_non_empty_project
def show def show
@hex_path = Digest::SHA1.hexdigest(@path)
@logs_path = logs_file_project_ref_path(@project, @ref, @path)
respond_to do |format| respond_to do |format|
format.html format.html
# Disable cache so browser history works # Disable cache so browser history works
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
.clearfix .clearfix
.pull-left .pull-left
= render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} = render partial: 'shared/ref_switcher', locals: {destination: 'graph'}
.search.pull-right .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 .control-group
= label_tag :search , "Looking for commit:", class: 'control-label light' = label_tag :search , "Looking for commit:", class: 'control-label light'
.controls .controls
......
...@@ -94,16 +94,28 @@ module ExtractsPath ...@@ -94,16 +94,28 @@ module ExtractsPath
# Automatically renders `not_found!` if a valid tree path could not be # Automatically renders `not_found!` if a valid tree path could not be
# resolved (e.g., when a user inserts an invalid path or ref). # resolved (e.g., when a user inserts an invalid path or ref).
def assign_ref_vars def assign_ref_vars
@id = params[:id] @id = get_id
@ref, @path = extract_ref(@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? raise InvalidPathError unless @tree.exists?
rescue RuntimeError, NoMethodError, InvalidPathError rescue RuntimeError, NoMethodError, InvalidPathError
not_found! not_found!
end end
private
def get_id
id = params[:id] || params[:ref]
id += "/" + params[:path] unless params[:path].blank?
id
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment