summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-11 18:27:03 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-11 18:27:03 +0200
commit00600a592b006024ff102499fc3c9412f26e993e (patch)
tree289bd38d2061ac83524ea26bf43fe31cf284d9c3
parentd2d8037b1abdbcc9bd6c23745479be60ebb57151 (diff)
downloadgitlab-ce-00600a592b006024ff102499fc3c9412f26e993e.tar.gz
Extract merge request widget JS to separate class
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/assets/javascripts/merge_request.js.coffee66
-rw-r--r--app/assets/javascripts/merge_request_widget.js.coffee58
-rw-r--r--app/controllers/projects/merge_requests_controller.rb4
-rw-r--r--app/views/projects/merge_requests/_show.html.haml5
-rw-r--r--app/views/projects/merge_requests/automerge.js.haml2
-rw-r--r--app/views/projects/merge_requests/widget/_heading.html.haml2
-rw-r--r--app/views/projects/merge_requests/widget/_merged.html.haml15
-rw-r--r--app/views/projects/merge_requests/widget/_show.html.haml12
-rw-r--r--app/views/projects/merge_requests/widget/open/_accept.html.haml12
-rw-r--r--app/views/projects/merge_requests/widget/open/_check.html.haml2
-rw-r--r--app/views/projects/merge_requests/widget/open/_mip.html.haml5
11 files changed, 96 insertions, 87 deletions
diff --git a/app/assets/javascripts/merge_request.js.coffee b/app/assets/javascripts/merge_request.js.coffee
index 5e440f3b1d1..25a7815dba2 100644
--- a/app/assets/javascripts/merge_request.js.coffee
+++ b/app/assets/javascripts/merge_request.js.coffee
@@ -11,12 +11,6 @@ class @MergeRequest
# commits_loaded - Boolean, have commits been pre-rendered server-side?
# (default: false)
#
- # check_enable - Boolean, whether to check automerge status
- # url_to_automerge_check - String, URL to use to check automerge status
- # current_status - String, current automerge status
- # ci_enable - Boolean, whether a CI service is enabled
- # url_to_ci_check - String, URL to use to check CI status
- #
constructor: (@opts) ->
@initContextWidget()
this.$el = $('.merge-request')
@@ -30,8 +24,6 @@ class @MergeRequest
this.$('.show-all-commits').on 'click', =>
this.showAllCommits()
- modal = $('#modal_merge_info').modal(show: false)
-
# Prevent duplicate event bindings
@disableTaskList()
@@ -60,17 +52,6 @@ class @MergeRequest
$(".context .inline-update").on "change", "#merge_request_assignee_id", ->
$(this).submit()
- 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
- if data.coverage
- this.showCiCoverage data.coverage
- , 'json'
bindEvents: ->
this.$('.merge-request-tabs a[data-toggle="tab"]').on 'shown.bs.tab', (e) =>
@@ -86,18 +67,6 @@ class @MergeRequest
unless @opts.action == 'new'
@setCurrentAction(tab_action)
- this.$('.remove_source_branch').on 'click', ->
- $('.remove_source_branch_widget').hide()
- $('.remove_source_branch_in_progress').show()
-
- this.$(".remove_source_branch").on "ajax:success", (e, data, status, xhr) ->
- location.reload()
-
- this.$(".remove_source_branch").on "ajax:error", (e, data, status, xhr) =>
- this.$('.remove_source_branch_widget').hide()
- this.$('.remove_source_branch_in_progress').hide()
- this.$('.remove_source_branch_widget.failed').show()
-
# Activate a tab based on the current URL path
#
# If the current action is 'show' or 'new' (i.e., initial page load),
@@ -147,26 +116,6 @@ class @MergeRequest
# See https://github.com/rails/turbolinks/issues/363
history.replaceState {turbolinks: true, url: new_state}, '', new_state
- showCiState: (state) ->
- $('.ci_widget').hide()
- allowed_states = ["failed", "canceled", "running", "pending", "success"]
- if state in allowed_states
- $('.ci_widget.ci-' + state).show()
- switch state
- when "failed", "canceled"
- @setMergeButtonClass('btn-danger')
- when "running", "pending"
- @setMergeButtonClass('btn-warning')
- else
- $('.ci_widget.ci-error').show()
- @setMergeButtonClass('btn-danger')
-
- showCiCoverage: (coverage) ->
- cov_html = $('<span>')
- cov_html.addClass('ci-coverage')
- cov_html.text('Coverage ' + coverage + '%')
- $('.ci_widget:visible').append(cov_html)
-
loadDiff: (event) ->
$.ajax
type: 'GET'
@@ -184,21 +133,6 @@ class @MergeRequest
this.$('.first-commits').remove()
this.$('.all-commits').removeClass 'hide'
- setMergeButtonClass: (css_class) ->
- $('.accept_merge_request').removeClass("btn-create").addClass(css_class)
-
- mergeInProgress: ->
- $.ajax
- type: 'GET'
- url: $('.merge-request').data('url')
- success: (data) =>
- switch data.state
- when 'merged'
- location.reload()
- else
- setTimeout(merge_request.mergeInProgress, 3000)
- dataType: 'json'
-
initTaskList: ->
$('.merge-request-details .js-task-list-container').taskList('enable')
$(document).on 'tasklist:changed', '.merge-request-details .js-task-list-container', @updateTaskList
diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee
new file mode 100644
index 00000000000..3ba38766ae5
--- /dev/null
+++ b/app/assets/javascripts/merge_request_widget.js.coffee
@@ -0,0 +1,58 @@
+class @MergeRequestWidget
+ # Initialize MergeRequestWidget behavior
+ #
+ # check_enable - Boolean, whether to check automerge status
+ # url_to_automerge_check - String, URL to use to check automerge status
+ # current_status - String, current automerge status
+ # ci_enable - Boolean, whether a CI service is enabled
+ # url_to_ci_check - String, URL to use to check CI status
+ #
+ constructor: (@opts) ->
+ modal = $('#modal_merge_info').modal(show: false)
+
+ mergeInProgress: ->
+ $.ajax
+ type: 'GET'
+ url: $('.merge-request').data('url')
+ success: (data) =>
+ switch data.state
+ when 'merged'
+ location.reload()
+ else
+ setTimeout(merge_request.mergeInProgress, 3000)
+ dataType: '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
+ if data.coverage
+ this.showCiCoverage data.coverage
+ , 'json'
+
+ showCiState: (state) ->
+ $('.ci_widget').hide()
+ allowed_states = ["failed", "canceled", "running", "pending", "success"]
+ if state in allowed_states
+ $('.ci_widget.ci-' + state).show()
+ switch state
+ when "failed", "canceled"
+ @setMergeButtonClass('btn-danger')
+ when "running", "pending"
+ @setMergeButtonClass('btn-warning')
+ else
+ $('.ci_widget.ci-error').show()
+ @setMergeButtonClass('btn-danger')
+
+ showCiCoverage: (coverage) ->
+ cov_html = $('<span>')
+ cov_html.addClass('ci-coverage')
+ cov_html.text('Coverage ' + coverage + '%')
+ $('.ci_widget:visible').append(cov_html)
+
+ setMergeButtonClass: (css_class) ->
+ $('.accept_merge_request').removeClass("btn-create").addClass(css_class)
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index a7dfedf7f70..277a2ade2e3 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -155,10 +155,6 @@ 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/_show.html.haml b/app/views/projects/merge_requests/_show.html.haml
index 02a9a53d9c8..5d7e73f2b28 100644
--- a/app/views/projects/merge_requests/_show.html.haml
+++ b/app/views/projects/merge_requests/_show.html.haml
@@ -69,10 +69,5 @@
var merge_request;
merge_request = new MergeRequest({
- url_to_automerge_check: "#{automerge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
- check_enable: #{@merge_request.unchecked? ? "true" : "false"},
- url_to_ci_check: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
- ci_enable: #{@project.ci_service ? "true" : "false"},
- current_status: "#{@merge_request.automerge_status}",
action: "#{controller.action_name}"
});
diff --git a/app/views/projects/merge_requests/automerge.js.haml b/app/views/projects/merge_requests/automerge.js.haml
index 26db408a576..33321651e32 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
:plain
- merge_request.getMergeStatus();
+ merge_request_widget.mergeInProgress();
- else
:plain
$('.mr-widget-body').html("#{escape_javascript(render('projects/merge_requests/widget/open/reload'))}");
diff --git a/app/views/projects/merge_requests/widget/_heading.html.haml b/app/views/projects/merge_requests/widget/_heading.html.haml
index 0cbd88157ca..107c61477e3 100644
--- a/app/views/projects/merge_requests/widget/_heading.html.haml
+++ b/app/views/projects/merge_requests/widget/_heading.html.haml
@@ -35,4 +35,4 @@
:coffeescript
$ ->
- merge_request.getCiStatus()
+ merge_request_widget.getCiStatus()
diff --git a/app/views/projects/merge_requests/widget/_merged.html.haml b/app/views/projects/merge_requests/widget/_merged.html.haml
index 7fdeb3a96a3..17c3fdacda8 100644
--- a/app/views/projects/merge_requests/widget/_merged.html.haml
+++ b/app/views/projects/merge_requests/widget/_merged.html.haml
@@ -24,3 +24,18 @@
%i.fa.fa-spinner.fa-spin
&nbsp;
Removing source branch '#{@merge_request.source_branch}'. Please wait. Page will be automatically reloaded. &nbsp;
+
+ :coffeescript
+ $('.remove_source_branch').on 'click', ->
+ $('.remove_source_branch_widget').hide()
+ $('.remove_source_branch_in_progress').show()
+
+ $(".remove_source_branch").on "ajax:success", (e, data, status, xhr) ->
+ location.reload()
+
+ $(".remove_source_branch").on "ajax:error", (e, data, status, xhr) ->
+ $('.remove_source_branch_widget').hide()
+ $('.remove_source_branch_in_progress').hide()
+ $('.remove_source_branch_widget.failed').show()
+
+
diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml
index da936a54aa6..263cab7a9e8 100644
--- a/app/views/projects/merge_requests/widget/_show.html.haml
+++ b/app/views/projects/merge_requests/widget/_show.html.haml
@@ -6,3 +6,15 @@
= render 'projects/merge_requests/widget/closed'
- elsif @merge_request.locked?
= render 'projects/merge_requests/widget/locked'
+
+:javascript
+ var merge_request_widget;
+
+ merge_request_widget = new MergeRequestWidget({
+ url_to_automerge_check: "#{automerge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
+ check_enable: #{@merge_request.unchecked? ? "true" : "false"},
+ url_to_ci_check: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
+ ci_enable: #{@project.ci_service ? "true" : "false"},
+ current_status: "#{@merge_request.automerge_status}",
+ });
+
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 b2ea57126ee..41aa66dd76b 100644
--- a/app/views/projects/merge_requests/widget/open/_accept.html.haml
+++ b/app/views/projects/merge_requests/widget/open/_accept.html.haml
@@ -1,8 +1,9 @@
-= 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, html: { class: 'accept-mr-form' } 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"
+ = f.button class: "btn btn-create accept_merge_request" do
+ Accept Merge Request
- if can_remove_branch?(@merge_request.source_project, @merge_request.source_branch) && !@merge_request.for_fork?
.accept-control.checkbox
= label_tag :should_remove_source_branch, class: "remove_source_checkbox" do
@@ -26,5 +27,8 @@
: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'))}")
+ $('.accept-mr-form').on 'ajax:before', ->
+ btn = $('.accept_merge_request')
+ btn.disable()
+ btn.html("<i class='fa fa-spinner fa-spin'></i> Merge in progress")
+
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 0ca54f3941e..5ca2d37a979 100644
--- a/app/views/projects/merge_requests/widget/open/_check.html.haml
+++ b/app/views/projects/merge_requests/widget/open/_check.html.haml
@@ -5,4 +5,4 @@
:coffeescript
$ ->
- merge_request.getMergeStatus()
+ merge_request_widget.getMergeStatus()
diff --git a/app/views/projects/merge_requests/widget/open/_mip.html.haml b/app/views/projects/merge_requests/widget/open/_mip.html.haml
deleted file mode 100644
index d86aaff3507..00000000000
--- a/app/views/projects/merge_requests/widget/open/_mip.html.haml
+++ /dev/null
@@ -1,5 +0,0 @@
-.merge-in-progress
- %p
- %i.fa.fa-spinner.fa-spin
- &nbsp;
- Merge is in progress. Please wait… Page will be reloaded automatically. &nbsp;