Commit e39f0de8ee73ded91aebed696bba696c8082de31

Authored by Dmitriy Zaporozhets
1 parent 138e2a50

Add edit button to MergeRequest diff

It will redirect you to file edit page.
After submit changes you will be redirected back to merge request.

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/assets/stylesheets/sections/commits.scss
... ... @@ -27,10 +27,14 @@
27 27 line-height: 2;
28 28 }
29 29  
30   - .view-file {
31   - font-weight: bold;
  30 + .diff-btn-group {
32 31 float: right;
33   - background-color: #EEE;
  32 +
  33 + .btn {
  34 + background-color: #EEE;
  35 + color: #666;
  36 + font-weight: bolder;
  37 + }
34 38 }
35 39  
36 40 .commit-short-id {
... ...
app/controllers/projects/edit_tree_controller.rb
... ... @@ -12,7 +12,16 @@ class Projects::EditTreeController &lt; Projects::BaseTreeController
12 12  
13 13 if result[:status] == :success
14 14 flash[:notice] = "Your changes have been successfully committed"
15   - redirect_to project_blob_path(@project, @id)
  15 +
  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
  20 + 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
16 25 else
17 26 flash[:alert] = result[:error]
18 27 render :show
... ...
app/views/projects/commits/_diffs.html.haml
... ... @@ -49,18 +49,26 @@
49 49 - if diff.deleted_file
50 50 %span= diff.old_path
51 51  
52   - - if @commit.parent_ids.present?
53   - = link_to project_blob_path(project, tree_join(@commit.parent_id, diff.new_path)), { class: 'btn btn-small view-file' } do
54   - View file @
55   - %span.commit-short-id= @commit.short_id(6)
  52 + .diff-btn-group
  53 + - if @commit.parent_ids.present?
  54 + = link_to project_blob_path(project, tree_join(@commit.parent_id, diff.new_path)), { class: 'btn btn-small view-file' } do
  55 + View file @
  56 + %span.commit-short-id= @commit.short_id(6)
56 57 - else
57 58 %span= diff.new_path
58 59 - if diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode
59 60 %span.file-mode= "#{diff.a_mode} → #{diff.b_mode}"
60 61  
61   - = link_to project_blob_path(project, tree_join(@commit.id, diff.new_path)), { class: 'btn btn-small view-file' } do
62   - View file @
63   - %span.commit-short-id= @commit.short_id(6)
  62 + .diff-btn-group
  63 + - if @merge_request && @merge_request.source_project
  64 + = link_to project_edit_tree_path(@merge_request.source_project, tree_join(@merge_request.source_branch, diff.new_path), from_merge_request_id: @merge_request.id), { class: 'btn btn-small' } do
  65 + Edit
  66 + &nbsp;
  67 +
  68 + = link_to project_blob_path(project, tree_join(@commit.id, diff.new_path)), { class: 'btn btn-small view-file' } do
  69 + View file @
  70 + %span.commit-short-id= @commit.short_id(6)
  71 +
64 72  
65 73 .content
66 74 -# Skipp all non non-supported blobs
... ...
app/views/projects/edit_tree/show.html.haml
... ... @@ -23,6 +23,7 @@
23 23 .form-actions
24 24 = hidden_field_tag 'last_commit', @last_commit
25 25 = hidden_field_tag 'content', '', id: "file-content"
  26 + = hidden_field_tag 'from_merge_request_id', params[:from_merge_request_id]
26 27 .commit-button-annotation
27 28 = button_tag "Commit changes", class: 'btn commit-btn js-commit-button btn-primary'
28 29 .message
... ...