2015-05-06 19:31:08 +00:00
|
|
|
#= require jquery
|
|
|
|
#= require bootstrap
|
|
|
|
#= require task_list
|
|
|
|
|
2014-10-20 20:48:07 +00:00
|
|
|
class @MergeRequest
|
2014-02-18 14:22:57 +00:00
|
|
|
constructor: (@opts) ->
|
|
|
|
@initContextWidget()
|
|
|
|
this.$el = $('.merge-request')
|
|
|
|
@diffs_loaded = if @opts.action == 'diffs' then true else false
|
|
|
|
@commits_loaded = false
|
|
|
|
|
|
|
|
this.activateTab(@opts.action)
|
|
|
|
|
|
|
|
this.bindEvents()
|
|
|
|
|
|
|
|
this.initMergeWidget()
|
|
|
|
this.$('.show-all-commits').on 'click', =>
|
|
|
|
this.showAllCommits()
|
|
|
|
|
|
|
|
modal = $('#modal_merge_info').modal(show: false)
|
|
|
|
|
2014-09-26 22:41:17 +00:00
|
|
|
disableButtonIfEmptyField '#commit_message', '.accept_merge_request'
|
2014-02-18 14:22:57 +00:00
|
|
|
|
2015-04-29 21:00:30 +00:00
|
|
|
# Prevent duplicate event bindings
|
|
|
|
@disableTaskList()
|
|
|
|
|
2014-10-07 00:19:12 +00:00
|
|
|
if $("a.btn-close").length
|
2015-04-29 21:00:30 +00:00
|
|
|
@initTaskList()
|
2014-02-18 14:22:57 +00:00
|
|
|
|
2015-02-26 04:00:28 +00:00
|
|
|
$('.merge-request-details').waitForImages ->
|
|
|
|
$('.issuable-affix').affix offset:
|
|
|
|
top: ->
|
2015-03-20 22:33:13 +00:00
|
|
|
@top = ($('.issuable-affix').offset().top - 70)
|
2015-02-26 04:00:28 +00:00
|
|
|
bottom: ->
|
|
|
|
@bottom = $('.footer').outerHeight(true)
|
2015-03-26 21:23:31 +00:00
|
|
|
$('.issuable-affix').on 'affix.bs.affix', ->
|
|
|
|
$(@).width($(@).outerWidth())
|
|
|
|
.on 'affixed-top.bs.affix affixed-bottom.bs.affix', ->
|
|
|
|
$(@).width('')
|
2015-02-18 00:14:49 +00:00
|
|
|
|
2014-02-18 14:22:57 +00:00
|
|
|
# Local jQuery finder
|
|
|
|
$: (selector) ->
|
|
|
|
this.$el.find(selector)
|
|
|
|
|
|
|
|
initContextWidget: ->
|
|
|
|
$('.edit-merge_request.inline-update input[type="submit"]').hide()
|
2014-12-22 14:42:26 +00:00
|
|
|
$(".context .inline-update").on "change", "select", ->
|
2014-02-18 14:22:57 +00:00
|
|
|
$(this).submit()
|
2014-12-22 14:42:26 +00:00
|
|
|
$(".context .inline-update").on "change", "#merge_request_assignee_id", ->
|
2014-02-18 14:22:57 +00:00
|
|
|
$(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'
|
|
|
|
|
|
|
|
if @opts.ci_enable
|
|
|
|
$.get @opts.url_to_ci_check, (data) =>
|
|
|
|
this.showCiState data.status
|
2014-10-02 15:17:47 +00:00
|
|
|
if data.coverage
|
|
|
|
this.showCiCoverage data.coverage
|
2014-02-18 14:22:57 +00:00
|
|
|
, 'json'
|
|
|
|
|
|
|
|
bindEvents: ->
|
2014-05-24 10:06:44 +00:00
|
|
|
this.$('.merge-request-tabs').on 'click', 'li', (event) =>
|
2014-02-18 14:22:57 +00:00
|
|
|
this.activateTab($(event.currentTarget).data('action'))
|
|
|
|
|
|
|
|
this.$('.accept_merge_request').on 'click', ->
|
|
|
|
$('.automerge_widget.can_be_merged').hide()
|
|
|
|
$('.merge-in-progress').show()
|
|
|
|
|
2014-04-06 10:54:54 +00:00
|
|
|
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()
|
|
|
|
|
2014-02-18 14:22:57 +00:00
|
|
|
activateTab: (action) ->
|
2014-05-24 10:06:44 +00:00
|
|
|
this.$('.merge-request-tabs li').removeClass 'active'
|
2014-02-18 14:22:57 +00:00
|
|
|
this.$('.tab-content').hide()
|
|
|
|
switch action
|
|
|
|
when 'diffs'
|
2014-05-24 10:06:44 +00:00
|
|
|
this.$('.merge-request-tabs .diffs-tab').addClass 'active'
|
2014-02-18 14:22:57 +00:00
|
|
|
this.loadDiff() unless @diffs_loaded
|
|
|
|
this.$('.diffs').show()
|
2015-02-26 06:17:46 +00:00
|
|
|
$(".diff-header").trigger("sticky_kit:recalc")
|
2014-12-25 12:32:49 +00:00
|
|
|
when 'commits'
|
|
|
|
this.$('.merge-request-tabs .commits-tab').addClass 'active'
|
|
|
|
this.$('.commits').show()
|
2014-02-18 14:22:57 +00:00
|
|
|
else
|
2014-05-24 10:06:44 +00:00
|
|
|
this.$('.merge-request-tabs .notes-tab').addClass 'active'
|
2014-02-18 14:22:57 +00:00
|
|
|
this.$('.notes').show()
|
|
|
|
|
|
|
|
showState: (state) ->
|
|
|
|
$('.automerge_widget').hide()
|
|
|
|
$('.automerge_widget.' + state).show()
|
|
|
|
|
|
|
|
showCiState: (state) ->
|
|
|
|
$('.ci_widget').hide()
|
2015-03-19 15:13:20 +00:00
|
|
|
allowed_states = ["failed", "canceled", "running", "pending", "success"]
|
2014-04-06 14:10:37 +00:00
|
|
|
if state in allowed_states
|
|
|
|
$('.ci_widget.ci-' + state).show()
|
2015-03-24 23:13:29 +00:00
|
|
|
switch state
|
|
|
|
when "failed", "canceled"
|
|
|
|
@setMergeButtonClass('btn-danger')
|
|
|
|
when "running", "pending"
|
|
|
|
@setMergeButtonClass('btn-warning')
|
2014-04-06 14:10:37 +00:00
|
|
|
else
|
|
|
|
$('.ci_widget.ci-error').show()
|
2015-03-24 23:13:29 +00:00
|
|
|
@setMergeButtonClass('btn-danger')
|
2014-04-06 14:10:37 +00:00
|
|
|
|
2014-10-02 15:17:47 +00:00
|
|
|
showCiCoverage: (coverage) ->
|
|
|
|
cov_html = $('<span>')
|
|
|
|
cov_html.addClass('ci-coverage')
|
|
|
|
cov_html.text('Coverage ' + coverage + '%')
|
|
|
|
$('.ci_widget:visible').append(cov_html)
|
2014-02-18 14:22:57 +00:00
|
|
|
|
|
|
|
loadDiff: (event) ->
|
|
|
|
$.ajax
|
|
|
|
type: 'GET'
|
2015-02-20 11:03:28 +00:00
|
|
|
url: this.$('.merge-request-tabs .diffs-tab a').attr('href') + ".json"
|
2014-02-18 14:22:57 +00:00
|
|
|
beforeSend: =>
|
2014-06-20 09:17:06 +00:00
|
|
|
this.$('.mr-loading-status .loading').show()
|
2014-02-18 14:22:57 +00:00
|
|
|
complete: =>
|
|
|
|
@diffs_loaded = true
|
2014-06-20 09:17:06 +00:00
|
|
|
this.$('.mr-loading-status .loading').hide()
|
2014-02-18 14:22:57 +00:00
|
|
|
success: (data) =>
|
|
|
|
this.$(".diffs").html(data.html)
|
|
|
|
dataType: 'json'
|
|
|
|
|
|
|
|
showAllCommits: ->
|
|
|
|
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()
|
2015-01-10 03:10:01 +00:00
|
|
|
|
2015-03-24 23:13:29 +00:00
|
|
|
setMergeButtonClass: (css_class) ->
|
|
|
|
$('.accept_merge_request').removeClass("btn-create").addClass(css_class)
|
|
|
|
|
2015-01-10 03:10:01 +00:00
|
|
|
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'
|
2015-04-29 21:00:30 +00:00
|
|
|
|
|
|
|
initTaskList: ->
|
|
|
|
$('.merge-request-details .js-task-list-container').taskList('enable')
|
|
|
|
$(document).on 'tasklist:changed', '.merge-request-details .js-task-list-container', @updateTaskList
|
|
|
|
|
|
|
|
disableTaskList: ->
|
|
|
|
$('.merge-request-details .js-task-list-container').taskList('disable')
|
|
|
|
$(document).off 'tasklist:changed', '.merge-request-details .js-task-list-container'
|
|
|
|
|
|
|
|
# TODO (rspeicher): Make the merge request description inline-editable like a
|
|
|
|
# note so that we can re-use its form here
|
|
|
|
updateTaskList: ->
|
|
|
|
patchData = {}
|
|
|
|
patchData['merge_request'] = {'description': $('.js-task-list-field', this).val()}
|
|
|
|
|
|
|
|
$.ajax
|
|
|
|
type: 'PATCH'
|
|
|
|
url: $('form.js-merge-request-update').attr('action')
|
|
|
|
data: patchData
|