Commit 6c1af645668689f9d0e1b0693ea0db80b62d0bb3
Exists in
spb-stable
and in
3 other branches
Merge branch 'improve/edit_cancel' into 'master'
Better redirect for edit blobs from MergeRequest
Showing
4 changed files
with
26 additions
and
9 deletions
Show diff stats
app/controllers/application_controller.rb
| @@ -210,4 +210,8 @@ class ApplicationController < ActionController::Base | @@ -210,4 +210,8 @@ class ApplicationController < ActionController::Base | ||
| 210 | devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email, :password, :login, :remember_me) } | 210 | devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email, :password, :login, :remember_me) } |
| 211 | devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :name, :password, :password_confirmation) } | 211 | devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :name, :password, :password_confirmation) } |
| 212 | end | 212 | end |
| 213 | + | ||
| 214 | + def hexdigest(string) | ||
| 215 | + Digest::SHA1.hexdigest string | ||
| 216 | + end | ||
| 213 | end | 217 | end |
app/controllers/projects/edit_tree_controller.rb
| @@ -2,6 +2,8 @@ class Projects::EditTreeController < Projects::BaseTreeController | @@ -2,6 +2,8 @@ class Projects::EditTreeController < Projects::BaseTreeController | ||
| 2 | before_filter :require_branch_head | 2 | before_filter :require_branch_head |
| 3 | before_filter :blob | 3 | before_filter :blob |
| 4 | before_filter :authorize_push! | 4 | before_filter :authorize_push! |
| 5 | + before_filter :from_merge_request | ||
| 6 | + before_filter :after_edit_path | ||
| 5 | 7 | ||
| 6 | def show | 8 | def show |
| 7 | @last_commit = Gitlab::Git::Commit.last_for_path(@repository, @ref, @path).sha | 9 | @last_commit = Gitlab::Git::Commit.last_for_path(@repository, @ref, @path).sha |
| @@ -13,15 +15,11 @@ class Projects::EditTreeController < Projects::BaseTreeController | @@ -13,15 +15,11 @@ class Projects::EditTreeController < Projects::BaseTreeController | ||
| 13 | if result[:status] == :success | 15 | if result[:status] == :success |
| 14 | flash[:notice] = "Your changes have been successfully committed" | 16 | flash[:notice] = "Your changes have been successfully committed" |
| 15 | 17 | ||
| 16 | - # If blob edit was initiated from merge request page | ||
| 17 | - from_merge_request = MergeRequest.find_by(id: params[:from_merge_request_id]) | ||
| 18 | - | ||
| 19 | if from_merge_request | 18 | if from_merge_request |
| 20 | from_merge_request.reload_code | 19 | from_merge_request.reload_code |
| 21 | - redirect_to diffs_project_merge_request_path(from_merge_request.target_project, from_merge_request) | ||
| 22 | - else | ||
| 23 | - redirect_to project_blob_path(@project, @id) | ||
| 24 | end | 20 | end |
| 21 | + | ||
| 22 | + redirect_to after_edit_path | ||
| 25 | else | 23 | else |
| 26 | flash[:alert] = result[:error] | 24 | flash[:alert] = result[:error] |
| 27 | render :show | 25 | render :show |
| @@ -33,4 +31,19 @@ class Projects::EditTreeController < Projects::BaseTreeController | @@ -33,4 +31,19 @@ class Projects::EditTreeController < Projects::BaseTreeController | ||
| 33 | def blob | 31 | def blob |
| 34 | @blob ||= @repository.blob_at(@commit.id, @path) | 32 | @blob ||= @repository.blob_at(@commit.id, @path) |
| 35 | end | 33 | end |
| 34 | + | ||
| 35 | + def after_edit_path | ||
| 36 | + @after_edit_path ||= | ||
| 37 | + if from_merge_request | ||
| 38 | + diffs_project_merge_request_path(from_merge_request.target_project, from_merge_request) + | ||
| 39 | + "#file-path-#{hexdigest(@path)}" | ||
| 40 | + else | ||
| 41 | + project_blob_path(@project, @id) | ||
| 42 | + end | ||
| 43 | + end | ||
| 44 | + | ||
| 45 | + def from_merge_request | ||
| 46 | + # If blob edit was initiated from merge request page | ||
| 47 | + @from_merge_request ||= MergeRequest.find_by(id: params[:from_merge_request_id]) | ||
| 48 | + end | ||
| 36 | end | 49 | end |
app/views/projects/commits/_diffs.html.haml
| @@ -45,7 +45,7 @@ | @@ -45,7 +45,7 @@ | ||
| 45 | - file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file | 45 | - file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file |
| 46 | - next unless file | 46 | - next unless file |
| 47 | .diff-file{id: "diff-#{i}"} | 47 | .diff-file{id: "diff-#{i}"} |
| 48 | - .diff-header | 48 | + .diff-header{id: "file-path-#{hexdigest(diff.new_path || diff.old_path)}"} |
| 49 | - if diff.deleted_file | 49 | - if diff.deleted_file |
| 50 | %span= diff.old_path | 50 | %span= diff.old_path |
| 51 | 51 |
app/views/projects/edit_tree/show.html.haml
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | %strong= @ref | 11 | %strong= @ref |
| 12 | %span.options | 12 | %span.options |
| 13 | .btn-group.tree-btn-group | 13 | .btn-group.tree-btn-group |
| 14 | - = link_to "Cancel", project_blob_path(@project, @id), class: "btn btn-tiny btn-cancel", data: { confirm: leave_edit_message } | 14 | + = link_to "Cancel", @after_edit_path, class: "btn btn-tiny btn-cancel", data: { confirm: leave_edit_message } |
| 15 | .file-content.code | 15 | .file-content.code |
| 16 | %pre#editor= @blob.data | 16 | %pre#editor= @blob.data |
| 17 | 17 | ||
| @@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
| 29 | .message | 29 | .message |
| 30 | to branch | 30 | to branch |
| 31 | %strong= @ref | 31 | %strong= @ref |
| 32 | - = link_to "Cancel", project_blob_path(@project, @id), class: "btn btn-cancel", data: { confirm: leave_edit_message} | 32 | + = link_to "Cancel", @after_edit_path, class: "btn btn-cancel", data: { confirm: leave_edit_message} |
| 33 | 33 | ||
| 34 | :javascript | 34 | :javascript |
| 35 | ace.config.set("modePath", gon.relative_url_root + "#{Gitlab::Application.config.assets.prefix}/ace") | 35 | ace.config.set("modePath", gon.relative_url_root + "#{Gitlab::Application.config.assets.prefix}/ace") |