Commit d2d8037b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor merge request widget step 2

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 644b6ba9
...@@ -27,14 +27,11 @@ class @MergeRequest ...@@ -27,14 +27,11 @@ class @MergeRequest
this.bindEvents() this.bindEvents()
this.activateTabFromPath() this.activateTabFromPath()
this.initMergeWidget()
this.$('.show-all-commits').on 'click', => this.$('.show-all-commits').on 'click', =>
this.showAllCommits() this.showAllCommits()
modal = $('#modal_merge_info').modal(show: false) modal = $('#modal_merge_info').modal(show: false)
disableButtonIfEmptyField '#commit_message', '.accept_merge_request'
# Prevent duplicate event bindings # Prevent duplicate event bindings
@disableTaskList() @disableTaskList()
...@@ -63,14 +60,11 @@ class @MergeRequest ...@@ -63,14 +60,11 @@ class @MergeRequest
$(".context .inline-update").on "change", "#merge_request_assignee_id", -> $(".context .inline-update").on "change", "#merge_request_assignee_id", ->
$(this).submit() $(this).submit()
initMergeWidget: -> getMergeStatus: ->
this.showState( @opts.current_status ) $.get @opts.url_to_automerge_check, (data) ->
$('.mr-state-widget').replaceWith(data)
if this.$('.automerge_widget').length and @opts.check_enable
$.get @opts.url_to_automerge_check, (data) =>
this.showState( data.merge_status )
, 'json'
getCiStatus: ->
if @opts.ci_enable if @opts.ci_enable
$.get @opts.url_to_ci_check, (data) => $.get @opts.url_to_ci_check, (data) =>
this.showCiState data.status this.showCiState data.status
...@@ -92,10 +86,6 @@ class @MergeRequest ...@@ -92,10 +86,6 @@ class @MergeRequest
unless @opts.action == 'new' unless @opts.action == 'new'
@setCurrentAction(tab_action) @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', -> this.$('.remove_source_branch').on 'click', ->
$('.remove_source_branch_widget').hide() $('.remove_source_branch_widget').hide()
$('.remove_source_branch_in_progress').show() $('.remove_source_branch_in_progress').show()
...@@ -157,10 +147,6 @@ class @MergeRequest ...@@ -157,10 +147,6 @@ class @MergeRequest
# See https://github.com/rails/turbolinks/issues/363 # See https://github.com/rails/turbolinks/issues/363
history.replaceState {turbolinks: true, url: new_state}, '', new_state history.replaceState {turbolinks: true, url: new_state}, '', new_state
showState: (state) ->
$('.automerge_widget').hide()
$('.automerge_widget.' + state).show()
showCiState: (state) -> showCiState: (state) ->
$('.ci_widget').hide() $('.ci_widget').hide()
allowed_states = ["failed", "canceled", "running", "pending", "success"] allowed_states = ["failed", "canceled", "running", "pending", "success"]
...@@ -198,11 +184,6 @@ class @MergeRequest ...@@ -198,11 +184,6 @@ class @MergeRequest
this.$('.first-commits').remove() this.$('.first-commits').remove()
this.$('.all-commits').removeClass 'hide' 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) -> setMergeButtonClass: (css_class) ->
$('.accept_merge_request').removeClass("btn-create").addClass(css_class) $('.accept_merge_request').removeClass("btn-create").addClass(css_class)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* MR -> show: Automerge widget * MR -> show: Automerge widget
* *
*/ */
.automerge_widget { .mr-state-widget {
form { form {
margin-bottom: 0; margin-bottom: 0;
.clearfix { .clearfix {
......
...@@ -139,7 +139,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -139,7 +139,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request.check_if_can_be_merged @merge_request.check_if_can_be_merged
end 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 end
def automerge def automerge
...@@ -151,6 +155,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -151,6 +155,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
else else
@status = false @status = false
end end
respond_to do |format|
format.js
end
end end
def branch_from def branch_from
......
-if @status - if @status
:plain :plain
merge_request.mergeInProgress(); merge_request.getMergeStatus();
-else - else
:plain :plain
merge_request.alreadyOrCannotBeMerged() $('.mr-widget-body').html("#{escape_javascript(render('projects/merge_requests/widget/open/reload'))}");
.mr-state-widget .mr-state-widget
= render 'heading' = render 'projects/merge_requests/widget/heading'
.mr-widget-body .mr-widget-body
%h4 %h4
Rejected Rejected
......
...@@ -32,3 +32,7 @@ ...@@ -32,3 +32,7 @@
.ci_widget.ci-error{style: "display:none"} .ci_widget.ci-error{style: "display:none"}
= icon("times") = icon("times")
%span Cannot connect to the CI server. Please check your settings and try again. %span Cannot connect to the CI server. Please check your settings and try again.
:coffeescript
$ ->
merge_request.getCiStatus()
.mr-state-widget .mr-state-widget
= render 'heading' = render 'projects/merge_requests/widget/heading'
.mr-widget-body .mr-widget-body
%h4 %h4
Merge in progress... Merge in progress...
......
.mr-state-widget .mr-state-widget
= render 'heading' = render 'projects/merge_requests/widget/heading'
.mr-widget-body .mr-widget-body
%h4 %h4
Accepted Accepted
......
- 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.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
= render 'projects/merge_requests/widget/open/archived' = render 'projects/merge_requests/widget/open/archived'
- elsif !@project.satellite.exists? - elsif !@project.satellite.exists?
= render 'projects/merge_requests/widget/open/no_satellite' = render 'projects/merge_requests/widget/open/no_satellite'
- elsif @commits.blank? - elsif @merge_request.commits.blank?
= render 'projects/merge_requests/widget/open/nothing' = render 'projects/merge_requests/widget/open/nothing'
- elsif @merge_request.branch_missing? - elsif @merge_request.branch_missing?
= render 'projects/merge_requests/widget/open/missing_branch' = render 'projects/merge_requests/widget/open/missing_branch'
......
= form_for [:automerge, @project.namespace.becomes(Namespace), @project, @merge_request], remote: true, method: :post do |f| = 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-merge-holder.clearfix.js-toggle-container
.accept-action .accept-action
= f.submit "Accept Merge Request", class: "btn btn-create accept_merge_request" = f.submit "Accept Merge Request", class: "btn btn-create accept_merge_request"
...@@ -22,3 +23,8 @@ ...@@ -22,3 +23,8 @@
%strong %strong
= link_to "command line", "#modal_merge_info", class: "how_to_merge_link vlink", title: "How To Merge", "data-toggle" => "modal" = 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'))}")
...@@ -2,3 +2,7 @@ ...@@ -2,3 +2,7 @@
%strong %strong
%i.fa.fa-spinner.fa-spin %i.fa.fa-spinner.fa-spin
Checking automatic merge… Checking automatic merge…
:coffeescript
$ ->
merge_request.getMergeStatus()
%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"
- 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.
.automerge_widget.cannot_be_merged.hide %strong This request can be merged automatically.
%strong This merge request contains merge conflicts that must be resolved. Only those with write access to this repository can merge merge requests.
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.
This merge request cannot be merged. Try to reload the page.
%h4 - if @allowed_to_merge
%h4
This merge request cannot be accepted because it is marked as Work In Progress. This merge request cannot be accepted because it is marked as Work In Progress.
%p %p
%button.btn.disabled{:type => 'button'} %button.btn.disabled{:type => 'button'}
%i.fa.fa-warning %i.fa.fa-warning
Accept Merge Request Accept Merge Request
&nbsp; &nbsp;
When the merge request is ready, remove the "WIP" prefix from the title to allow it to be accepted. 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.
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