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
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)
......
......@@ -3,7 +3,7 @@
* MR -> show: Automerge widget
*
*/
.automerge_widget {
.mr-state-widget {
form {
margin-bottom: 0;
.clearfix {
......
......@@ -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
......
-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'))}");
.mr-state-widget
= render 'heading'
= render 'projects/merge_requests/widget/heading'
.mr-widget-body
%h4
Rejected
......
......@@ -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()
.mr-state-widget
= render 'heading'
= render 'projects/merge_requests/widget/heading'
.mr-widget-body
%h4
Merge in progress...
......
.mr-state-widget
= render 'heading'
= render 'projects/merge_requests/widget/heading'
.mr-widget-body
%h4
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 @@
= 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'
......
= 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'))}")
......@@ -2,3 +2,7 @@
%strong
%i.fa.fa-spinner.fa-spin
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 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.
This merge request cannot be merged. Try to reload the page.
%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.
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