2016-03-15 10:43:40 -04:00
|
|
|
class @Compare
|
|
|
|
constructor: (@opts) ->
|
|
|
|
@source_loading = $ ".js-source-loading"
|
|
|
|
@target_loading = $ ".js-target-loading"
|
|
|
|
|
2016-03-29 06:11:16 -04:00
|
|
|
$('.js-compare-dropdown').each (i, dropdown) =>
|
|
|
|
$dropdown = $(dropdown)
|
2016-03-15 10:43:40 -04:00
|
|
|
|
2016-03-29 06:11:16 -04:00
|
|
|
$dropdown.glDropdown(
|
|
|
|
selectable: true
|
|
|
|
fieldName: $dropdown.data 'field-name'
|
2016-03-29 06:51:13 -04:00
|
|
|
filterable: true
|
2016-03-29 06:11:16 -04:00
|
|
|
id: (obj, $el) ->
|
|
|
|
$el.data 'id'
|
|
|
|
toggleLabel: (obj, $el) ->
|
|
|
|
$el.text().trim()
|
|
|
|
clicked: (e, el) =>
|
|
|
|
if $dropdown.is '.js-target-branch'
|
|
|
|
@getTargetHtml()
|
|
|
|
else if $dropdown.is '.js-source-branch'
|
|
|
|
@getSourceHtml()
|
|
|
|
else if $dropdown.is '.js-target-project'
|
|
|
|
@getTargetProject()
|
|
|
|
)
|
2016-03-15 10:43:40 -04:00
|
|
|
|
2016-03-29 06:11:16 -04:00
|
|
|
@initialState()
|
2016-03-15 10:43:40 -04:00
|
|
|
|
|
|
|
initialState: ->
|
|
|
|
@getSourceHtml()
|
|
|
|
@getTargetHtml()
|
|
|
|
|
|
|
|
getTargetProject: ->
|
2016-03-29 07:43:33 -04:00
|
|
|
$.ajax(
|
|
|
|
url: @opts.targetProjectUrl
|
|
|
|
data:
|
|
|
|
target_project_id: $("input[name='merge_request[target_project_id]']").val()
|
|
|
|
beforeSend: ->
|
|
|
|
$('.mr_target_commit').empty()
|
|
|
|
success: (html) ->
|
|
|
|
$('.js-target-branch-dropdown .dropdown-content').html html
|
|
|
|
)
|
2016-03-15 10:43:40 -04:00
|
|
|
|
|
|
|
getSourceHtml: ->
|
2016-03-29 07:43:33 -04:00
|
|
|
@sendAjax(@opts.sourceBranchUrl, @source_loading, '.mr_source_commit',
|
|
|
|
ref: $("input[name='merge_request[source_branch]']").val()
|
2016-03-15 10:43:40 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
getTargetHtml: ->
|
2016-03-29 07:43:33 -04:00
|
|
|
@sendAjax(@opts.targetBranchUrl, @target_loading, '.mr_target_commit',
|
|
|
|
target_project_id: $("input[name='merge_request[target_project_id]']").val()
|
|
|
|
ref: $("input[name='merge_request[target_branch]']").val()
|
|
|
|
)
|
|
|
|
|
|
|
|
sendAjax: (url, loading, target, data) ->
|
|
|
|
$target = $(target)
|
|
|
|
|
2016-03-15 10:43:40 -04:00
|
|
|
$.ajax(
|
2016-03-29 07:43:33 -04:00
|
|
|
url: url
|
|
|
|
data: data
|
|
|
|
beforeSend: ->
|
|
|
|
loading.show()
|
|
|
|
$target.empty()
|
|
|
|
success: (html) ->
|
|
|
|
loading.hide()
|
|
|
|
$target.html html
|
|
|
|
$('.js-timeago', $target).timeago()
|
2016-03-15 10:43:40 -04:00
|
|
|
)
|