Better redirect for edit blod from MergeRequest

If you cancel edit you will be redirected back to merge request
If you submit changes you will be redirected back to merge request

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-02-26 14:06:31 +02:00
parent 5d6e4bd2d8
commit a9280de11f
No known key found for this signature in database
GPG key ID: 627C5F589F467F17
4 changed files with 26 additions and 9 deletions

View file

@ -210,4 +210,8 @@ class ApplicationController < ActionController::Base
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email, :password, :login, :remember_me) } devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email, :password, :login, :remember_me) }
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :name, :password, :password_confirmation) } devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :name, :password, :password_confirmation) }
end end
def hexdigest(string)
Digest::SHA1.hexdigest string
end
end end

View file

@ -2,6 +2,8 @@ class Projects::EditTreeController < Projects::BaseTreeController
before_filter :require_branch_head before_filter :require_branch_head
before_filter :blob before_filter :blob
before_filter :authorize_push! before_filter :authorize_push!
before_filter :from_merge_request
before_filter :after_edit_path
def show def show
@last_commit = Gitlab::Git::Commit.last_for_path(@repository, @ref, @path).sha @last_commit = Gitlab::Git::Commit.last_for_path(@repository, @ref, @path).sha
@ -13,15 +15,11 @@ class Projects::EditTreeController < Projects::BaseTreeController
if result[:status] == :success if result[:status] == :success
flash[:notice] = "Your changes have been successfully committed" flash[:notice] = "Your changes have been successfully committed"
# If blob edit was initiated from merge request page
from_merge_request = MergeRequest.find_by(id: params[:from_merge_request_id])
if from_merge_request if from_merge_request
from_merge_request.reload_code from_merge_request.reload_code
redirect_to diffs_project_merge_request_path(from_merge_request.target_project, from_merge_request)
else
redirect_to project_blob_path(@project, @id)
end end
redirect_to after_edit_path
else else
flash[:alert] = result[:error] flash[:alert] = result[:error]
render :show render :show
@ -33,4 +31,19 @@ class Projects::EditTreeController < Projects::BaseTreeController
def blob def blob
@blob ||= @repository.blob_at(@commit.id, @path) @blob ||= @repository.blob_at(@commit.id, @path)
end end
def after_edit_path
@after_edit_path ||=
if from_merge_request
diffs_project_merge_request_path(from_merge_request.target_project, from_merge_request) +
"#file-path-#{hexdigest(@path)}"
else
project_blob_path(@project, @id)
end
end
def from_merge_request
# If blob edit was initiated from merge request page
@from_merge_request ||= MergeRequest.find_by(id: params[:from_merge_request_id])
end
end end

View file

@ -45,7 +45,7 @@
- file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file - file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file
- next unless file - next unless file
.diff-file{id: "diff-#{i}"} .diff-file{id: "diff-#{i}"}
.diff-header .diff-header{id: "file-path-#{hexdigest(diff.new_path || diff.old_path)}"}
- if diff.deleted_file - if diff.deleted_file
%span= diff.old_path %span= diff.old_path

View file

@ -11,7 +11,7 @@
%strong= @ref %strong= @ref
%span.options %span.options
.btn-group.tree-btn-group .btn-group.tree-btn-group
= link_to "Cancel", project_blob_path(@project, @id), class: "btn btn-tiny btn-cancel", data: { confirm: leave_edit_message } = link_to "Cancel", @after_edit_path, class: "btn btn-tiny btn-cancel", data: { confirm: leave_edit_message }
.file-content.code .file-content.code
%pre#editor= @blob.data %pre#editor= @blob.data
@ -29,7 +29,7 @@
.message .message
to branch to branch
%strong= @ref %strong= @ref
= link_to "Cancel", project_blob_path(@project, @id), class: "btn btn-cancel", data: { confirm: leave_edit_message} = link_to "Cancel", @after_edit_path, class: "btn btn-cancel", data: { confirm: leave_edit_message}
:javascript :javascript
ace.config.set("modePath", gon.relative_url_root + "#{Gitlab::Application.config.assets.prefix}/ace") ace.config.set("modePath", gon.relative_url_root + "#{Gitlab::Application.config.assets.prefix}/ace")