debian-mirror-gitlab/app/assets/javascripts/merge_request.js.coffee

167 lines
5.2 KiB
CoffeeScript
Raw Normal View History

2015-04-26 12:48:37 +05:30
class @MergeRequest
2014-09-02 18:07:02 +05:30
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)
2015-04-26 12:48:37 +05:30
disableButtonIfEmptyField '#commit_message', '.accept_merge_request'
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
if $("a.btn-close").length
$("li.task-list-item input:checkbox").prop("disabled", false)
$('.merge-request-details').waitForImages ->
$('.issuable-affix').affix offset:
top: ->
@top = ($('.issuable-affix').offset().top - 70)
bottom: ->
@bottom = $('.footer').outerHeight(true)
$('.issuable-affix').on 'affix.bs.affix', ->
$(@).width($(@).outerWidth())
.on 'affixed-top.bs.affix affixed-bottom.bs.affix', ->
$(@).width('')
2014-09-02 18:07:02 +05:30
# Local jQuery finder
$: (selector) ->
this.$el.find(selector)
initContextWidget: ->
$('.edit-merge_request.inline-update input[type="submit"]').hide()
2015-04-26 12:48:37 +05:30
$(".context .inline-update").on "change", "select", ->
2014-09-02 18:07:02 +05:30
$(this).submit()
2015-04-26 12:48:37 +05:30
$(".context .inline-update").on "change", "#merge_request_assignee_id", ->
2014-09-02 18:07:02 +05:30
$(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
2015-04-26 12:48:37 +05:30
if data.coverage
this.showCiCoverage data.coverage
2014-09-02 18:07:02 +05:30
, 'json'
bindEvents: ->
this.$('.merge-request-tabs').on 'click', 'a', (event) =>
a = $(event.currentTarget)
href = a.attr('href')
History.replaceState {path: href}, document.title, href
event.preventDefault()
this.$('.merge-request-tabs').on 'click', 'li', (event) =>
this.activateTab($(event.currentTarget).data('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()
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()
2015-04-26 12:48:37 +05:30
$('.task-list-item input:checkbox').off('change')
$('.task-list-item input:checkbox').change('merge_request', updateTaskState)
2014-09-02 18:07:02 +05:30
activateTab: (action) ->
this.$('.merge-request-tabs li').removeClass 'active'
this.$('.tab-content').hide()
switch action
when 'diffs'
this.$('.merge-request-tabs .diffs-tab').addClass 'active'
this.loadDiff() unless @diffs_loaded
this.$('.diffs').show()
2015-04-26 12:48:37 +05:30
$(".diff-header").trigger("sticky_kit:recalc")
when 'commits'
this.$('.merge-request-tabs .commits-tab').addClass 'active'
this.$('.commits').show()
2014-09-02 18:07:02 +05:30
else
this.$('.merge-request-tabs .notes-tab').addClass 'active'
this.$('.notes').show()
showState: (state) ->
$('.automerge_widget').hide()
$('.automerge_widget.' + state).show()
showCiState: (state) ->
$('.ci_widget').hide()
2015-04-26 12:48:37 +05:30
allowed_states = ["failed", "canceled", "running", "pending", "success"]
2014-09-02 18:07:02 +05:30
if state in allowed_states
$('.ci_widget.ci-' + state).show()
2015-04-26 12:48:37 +05:30
switch state
when "failed", "canceled"
@setMergeButtonClass('btn-danger')
when "running", "pending"
@setMergeButtonClass('btn-warning')
2014-09-02 18:07:02 +05:30
else
$('.ci_widget.ci-error').show()
2015-04-26 12:48:37 +05:30
@setMergeButtonClass('btn-danger')
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
showCiCoverage: (coverage) ->
cov_html = $('<span>')
cov_html.addClass('ci-coverage')
cov_html.text('Coverage ' + coverage + '%')
$('.ci_widget:visible').append(cov_html)
2014-09-02 18:07:02 +05:30
loadDiff: (event) ->
$.ajax
type: 'GET'
2015-04-26 12:48:37 +05:30
url: this.$('.merge-request-tabs .diffs-tab a').attr('href') + ".json"
2014-09-02 18:07:02 +05:30
beforeSend: =>
this.$('.mr-loading-status .loading').show()
complete: =>
@diffs_loaded = true
this.$('.mr-loading-status .loading').hide()
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-04-26 12:48:37 +05:30
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'