summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-11 15:14:50 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-11 15:14:50 +0200
commitd2d8037b1abdbcc9bd6c23745479be60ebb57151 (patch)
treedb37235f1c7ed335f4833b57aa1e3637555e2a03
parent644b6ba993ce033369bc50642caed69f3bed7f8a (diff)
downloadgitlab-ce-d2d8037b1abdbcc9bd6c23745479be60ebb57151.tar.gz
Refactor merge request widget step 2
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/assets/javascripts/merge_request.js.coffee27
-rw-r--r--app/assets/stylesheets/pages/merge_requests.scss2
-rw-r--r--app/controllers/projects/merge_requests_controller.rb10
-rw-r--r--app/views/projects/merge_requests/automerge.js.haml8
-rw-r--r--app/views/projects/merge_requests/widget/_closed.html.haml2
-rw-r--r--app/views/projects/merge_requests/widget/_heading.html.haml4
-rw-r--r--app/views/projects/merge_requests/widget/_locked.html.haml2
-rw-r--r--app/views/projects/merge_requests/widget/_merged.html.haml2
-rw-r--r--app/views/projects/merge_requests/widget/_mr_accept.html.haml20
-rw-r--r--app/views/projects/merge_requests/widget/_open.html.haml2
-rw-r--r--app/views/projects/merge_requests/widget/open/_accept.html.haml6
-rw-r--r--app/views/projects/merge_requests/widget/open/_check.html.haml4
-rw-r--r--app/views/projects/merge_requests/widget/open/_conflict.html.haml5
-rw-r--r--app/views/projects/merge_requests/widget/open/_conflicts.html.haml9
-rw-r--r--app/views/projects/merge_requests/widget/open/_not_allowed.html.haml11
-rw-r--r--app/views/projects/merge_requests/widget/open/_reload.html.haml1
-rw-r--r--app/views/projects/merge_requests/widget/open/_wip.html.haml20
17 files changed, 60 insertions, 75 deletions
diff --git a/app/assets/javascripts/merge_request.js.coffee b/app/assets/javascripts/merge_request.js.coffee
index b8f916b5223..5e440f3b1d1 100644
--- a/app/assets/javascripts/merge_request.js.coffee
+++ b/app/assets/javascripts/merge_request.js.coffee
@@ -27,14 +27,11 @@ class @MergeRequest
this.bindEvents()
this.activateTabFromPath()
- this.initMergeWidget()
this.$('.show-all-commits').on 'click', =>
this.showAllCommits()
modal = $('#modal_merge_info').modal(show: false)
- disableButtonIfEmptyField '#commit_message', '.accept_merge_request'
-
# Prevent duplicate event bindings
@disableTaskList()
@@ -63,14 +60,11 @@ class @MergeRequest
$(".context .inline-update").on "change", "#merge_request_assignee_id", ->
$(this).submit()
- initMergeWidget: ->
- this.showState( @opts.current_status )
-
- if this.$('.automerge_widget').length and @opts.check_enable
- $.get @opts.url_to_automerge_check, (data) =>
- this.showState( data.merge_status )
- , 'json'
+ getMergeStatus: ->
+ $.get @opts.url_to_automerge_check, (data) ->
+ $('.mr-state-widget').replaceWith(data)
+ getCiStatus: ->
if @opts.ci_enable
$.get @opts.url_to_ci_check, (data) =>
this.showCiState data.status
@@ -92,10 +86,6 @@ class @MergeRequest
unless @opts.action == 'new'
@setCurrentAction(tab_action)
- this.$('.accept_merge_request').on 'click', ->
- $('.automerge_widget.can_be_merged').hide()
- $('.merge-in-progress').show()
-
this.$('.remove_source_branch').on 'click', ->
$('.remove_source_branch_widget').hide()
$('.remove_source_branch_in_progress').show()
@@ -157,10 +147,6 @@ class @MergeRequest
# See https://github.com/rails/turbolinks/issues/363
history.replaceState {turbolinks: true, url: new_state}, '', new_state
- showState: (state) ->
- $('.automerge_widget').hide()
- $('.automerge_widget.' + state).show()
-
showCiState: (state) ->
$('.ci_widget').hide()
allowed_states = ["failed", "canceled", "running", "pending", "success"]
@@ -198,11 +184,6 @@ class @MergeRequest
this.$('.first-commits').remove()
this.$('.all-commits').removeClass 'hide'
- alreadyOrCannotBeMerged: ->
- this.$('.automerge_widget').hide()
- this.$('.merge-in-progress').hide()
- this.$('.automerge_widget.already_cannot_be_merged').show()
-
setMergeButtonClass: (css_class) ->
$('.accept_merge_request').removeClass("btn-create").addClass(css_class)
diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss
index f5ac7bd8805..61071320973 100644
--- a/app/assets/stylesheets/pages/merge_requests.scss
+++ b/app/assets/stylesheets/pages/merge_requests.scss
@@ -3,7 +3,7 @@
* MR -> show: Automerge widget
*
*/
-.automerge_widget {
+.mr-state-widget {
form {
margin-bottom: 0;
.clearfix {
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 71d3051ab88..a7dfedf7f70 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -139,7 +139,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request.check_if_can_be_merged
end
- render json: { merge_status: @merge_request.automerge_status }
+ @allowed_to_merge = allowed_to_merge?
+ closes_issues
+
+ render partial: "projects/merge_requests/widget/show.html.haml",
+ layout: false
end
def automerge
@@ -151,6 +155,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
else
@status = false
end
+
+ respond_to do |format|
+ format.js
+ end
end
def branch_from
diff --git a/app/views/projects/merge_requests/automerge.js.haml b/app/views/projects/merge_requests/automerge.js.haml
index a53cbb150a4..26db408a576 100644
--- a/app/views/projects/merge_requests/automerge.js.haml
+++ b/app/views/projects/merge_requests/automerge.js.haml
@@ -1,6 +1,6 @@
--if @status
+- if @status
:plain
- merge_request.mergeInProgress();
--else
+ merge_request.getMergeStatus();
+- else
:plain
- merge_request.alreadyOrCannotBeMerged()
+ $('.mr-widget-body').html("#{escape_javascript(render('projects/merge_requests/widget/open/reload'))}");
diff --git a/app/views/projects/merge_requests/widget/_closed.html.haml b/app/views/projects/merge_requests/widget/_closed.html.haml
index 3561eae0324..18164ba771f 100644
--- a/app/views/projects/merge_requests/widget/_closed.html.haml
+++ b/app/views/projects/merge_requests/widget/_closed.html.haml
@@ -1,5 +1,5 @@
.mr-state-widget
- = render 'heading'
+ = render 'projects/merge_requests/widget/heading'
.mr-widget-body
%h4
Rejected
diff --git a/app/views/projects/merge_requests/widget/_heading.html.haml b/app/views/projects/merge_requests/widget/_heading.html.haml
index a1707821334..0cbd88157ca 100644
--- a/app/views/projects/merge_requests/widget/_heading.html.haml
+++ b/app/views/projects/merge_requests/widget/_heading.html.haml
@@ -32,3 +32,7 @@
.ci_widget.ci-error{style: "display:none"}
= icon("times")
%span Cannot connect to the CI server. Please check your settings and try again.
+
+ :coffeescript
+ $ ->
+ merge_request.getCiStatus()
diff --git a/app/views/projects/merge_requests/widget/_locked.html.haml b/app/views/projects/merge_requests/widget/_locked.html.haml
index 67f841db520..13ec278847b 100644
--- a/app/views/projects/merge_requests/widget/_locked.html.haml
+++ b/app/views/projects/merge_requests/widget/_locked.html.haml
@@ -1,5 +1,5 @@
.mr-state-widget
- = render 'heading'
+ = render 'projects/merge_requests/widget/heading'
.mr-widget-body
%h4
Merge in progress...
diff --git a/app/views/projects/merge_requests/widget/_merged.html.haml b/app/views/projects/merge_requests/widget/_merged.html.haml
index bd1bc660b9b..7fdeb3a96a3 100644
--- a/app/views/projects/merge_requests/widget/_merged.html.haml
+++ b/app/views/projects/merge_requests/widget/_merged.html.haml
@@ -1,5 +1,5 @@
.mr-state-widget
- = render 'heading'
+ = render 'projects/merge_requests/widget/heading'
.mr-widget-body
%h4
Accepted
diff --git a/app/views/projects/merge_requests/widget/_mr_accept.html.haml b/app/views/projects/merge_requests/widget/_mr_accept.html.haml
deleted file mode 100644
index d3f7a09144e..00000000000
--- a/app/views/projects/merge_requests/widget/_mr_accept.html.haml
+++ /dev/null
@@ -1,20 +0,0 @@
-- if @show_merge_controls
- .automerge_widget.can_be_merged.hide
- .clearfix
-
- .automerge_widget.cannot_be_merged.hide
-
- %p
- %button.btn.disabled{:type => 'button'}
- %i.fa.fa-warning
- Accept Merge Request
- &nbsp;
- This happens when Git is not able to automatically resolve conflicts between branches.
-
-
- .automerge_widget.unchecked
-
- .automerge_widget.already_cannot_be_merged.hide
- %p
- %strong This merge request cannot be merged. Try to reload the page.
-
diff --git a/app/views/projects/merge_requests/widget/_open.html.haml b/app/views/projects/merge_requests/widget/_open.html.haml
index 645ad6e9e49..a9d8e3084ce 100644
--- a/app/views/projects/merge_requests/widget/_open.html.haml
+++ b/app/views/projects/merge_requests/widget/_open.html.haml
@@ -5,7 +5,7 @@
= render 'projects/merge_requests/widget/open/archived'
- elsif !@project.satellite.exists?
= render 'projects/merge_requests/widget/open/no_satellite'
- - elsif @commits.blank?
+ - elsif @merge_request.commits.blank?
= render 'projects/merge_requests/widget/open/nothing'
- elsif @merge_request.branch_missing?
= render 'projects/merge_requests/widget/open/missing_branch'
diff --git a/app/views/projects/merge_requests/widget/open/_accept.html.haml b/app/views/projects/merge_requests/widget/open/_accept.html.haml
index aa14b0cf21e..b2ea57126ee 100644
--- a/app/views/projects/merge_requests/widget/open/_accept.html.haml
+++ b/app/views/projects/merge_requests/widget/open/_accept.html.haml
@@ -1,4 +1,5 @@
= form_for [:automerge, @project.namespace.becomes(Namespace), @project, @merge_request], remote: true, method: :post do |f|
+ = hidden_field_tag :authenticity_token, form_authenticity_token
.accept-merge-holder.clearfix.js-toggle-container
.accept-action
= f.submit "Accept Merge Request", class: "btn btn-create accept_merge_request"
@@ -22,3 +23,8 @@
%strong
= link_to "command line", "#modal_merge_info", class: "how_to_merge_link vlink", title: "How To Merge", "data-toggle" => "modal"
+ :coffeescript
+ disableButtonIfEmptyField '#commit_message', '.accept_merge_request'
+
+ $('.accept_merge_request').on 'click', ->
+ $('.mr-widget-body').html("#{escape_javascript(render('projects/merge_requests/widget/open/mip'))}")
diff --git a/app/views/projects/merge_requests/widget/open/_check.html.haml b/app/views/projects/merge_requests/widget/open/_check.html.haml
index 95a5bcd03c3..0ca54f3941e 100644
--- a/app/views/projects/merge_requests/widget/open/_check.html.haml
+++ b/app/views/projects/merge_requests/widget/open/_check.html.haml
@@ -2,3 +2,7 @@
%strong
%i.fa.fa-spinner.fa-spin
Checking automatic mergeā€¦
+
+:coffeescript
+ $ ->
+ merge_request.getMergeStatus()
diff --git a/app/views/projects/merge_requests/widget/open/_conflict.html.haml b/app/views/projects/merge_requests/widget/open/_conflict.html.haml
deleted file mode 100644
index 3fc294bc0b5..00000000000
--- a/app/views/projects/merge_requests/widget/open/_conflict.html.haml
+++ /dev/null
@@ -1,5 +0,0 @@
-%h4
- This merge request contains merge conflicts that must be resolved.
- You can try it manually on the
- %strong
- = link_to "command line", "#modal_merge_info", class: "how_to_merge_link vlink", title: "How To Merge", "data-toggle" => "modal"
diff --git a/app/views/projects/merge_requests/widget/open/_conflicts.html.haml b/app/views/projects/merge_requests/widget/open/_conflicts.html.haml
new file mode 100644
index 00000000000..9e0c8a9e06f
--- /dev/null
+++ b/app/views/projects/merge_requests/widget/open/_conflicts.html.haml
@@ -0,0 +1,9 @@
+- if @allowed_to_merge
+ %h4
+ This merge request contains merge conflicts that must be resolved.
+ You can try it manually on the
+ %strong
+ = link_to "command line", "#modal_merge_info", class: "how_to_merge_link vlink", title: "How To Merge", "data-toggle" => "modal"
+- else
+ %strong This merge request contains merge conflicts that must be resolved.
+ Only those with write access to this repository can merge merge requests.
diff --git a/app/views/projects/merge_requests/widget/open/_not_allowed.html.haml b/app/views/projects/merge_requests/widget/open/_not_allowed.html.haml
index 3989009c36e..82f6ffd8fcb 100644
--- a/app/views/projects/merge_requests/widget/open/_not_allowed.html.haml
+++ b/app/views/projects/merge_requests/widget/open/_not_allowed.html.haml
@@ -1,9 +1,2 @@
-.automerge_widget.cannot_be_merged.hide
- %strong This merge request contains merge conflicts that must be resolved.
- Only those with write access to this repository can merge merge requests.
-.automerge_widget.work_in_progress.hide
- %strong This merge request is marked as Work In Progress.
- Only those with write access to this repository can merge merge requests.
-.automerge_widget.can_be_merged.hide
- %strong This request can be merged automatically.
- Only those with write access to this repository can merge merge requests.
+%strong This request can be merged automatically.
+Only those with write access to this repository can merge merge requests.
diff --git a/app/views/projects/merge_requests/widget/open/_reload.html.haml b/app/views/projects/merge_requests/widget/open/_reload.html.haml
new file mode 100644
index 00000000000..5787f6efea4
--- /dev/null
+++ b/app/views/projects/merge_requests/widget/open/_reload.html.haml
@@ -0,0 +1 @@
+This merge request cannot be merged. Try to reload the page.
diff --git a/app/views/projects/merge_requests/widget/open/_wip.html.haml b/app/views/projects/merge_requests/widget/open/_wip.html.haml
index 9268d68ba34..30482bce750 100644
--- a/app/views/projects/merge_requests/widget/open/_wip.html.haml
+++ b/app/views/projects/merge_requests/widget/open/_wip.html.haml
@@ -1,9 +1,13 @@
-%h4
- This merge request cannot be accepted because it is marked as Work In Progress.
+- if @allowed_to_merge
+ %h4
+ This merge request cannot be accepted because it is marked as Work In Progress.
-%p
- %button.btn.disabled{:type => 'button'}
- %i.fa.fa-warning
- Accept Merge Request
- &nbsp;
- When the merge request is ready, remove the "WIP" prefix from the title to allow it to be accepted.
+ %p
+ %button.btn.disabled{:type => 'button'}
+ %i.fa.fa-warning
+ Accept Merge Request
+ &nbsp;
+ When the merge request is ready, remove the "WIP" prefix from the title to allow it to be accepted.
+- else
+ %strong This merge request is marked as Work In Progress.
+ Only those with write access to this repository can merge merge requests.