Merge branch 'mergerequest-to-coffee' of https://github.com/koenpunt/gitlabhq into koenpunt-mergerequest-to-coffee
This commit is contained in:
commit
eaa8cd28d0
13 changed files with 142 additions and 183 deletions
|
@ -1,132 +0,0 @@
|
|||
var MergeRequest = {
|
||||
diffs_loaded: false,
|
||||
commits_loaded: false,
|
||||
opts: false,
|
||||
|
||||
init:
|
||||
function(opts) {
|
||||
var self = this;
|
||||
self.opts = opts;
|
||||
|
||||
self.initTabs();
|
||||
self.initMergeWidget();
|
||||
|
||||
$(".mr_show_all_commits").bind("click", function() {
|
||||
self.showAllCommits();
|
||||
});
|
||||
},
|
||||
|
||||
initMergeWidget:
|
||||
function() {
|
||||
var self = this;
|
||||
self.showState(self.opts.current_state);
|
||||
|
||||
if($(".automerge_widget").length && self.opts.check_enable){
|
||||
$.get(self.opts.url_to_automerge_check, function(data){
|
||||
self.showState(data.state);
|
||||
}, "json");
|
||||
}
|
||||
|
||||
if(self.opts.ci_enable){
|
||||
$.get(self.opts.url_to_ci_check, function(data){
|
||||
self.showCiState(data.status);
|
||||
}, "json");
|
||||
}
|
||||
},
|
||||
|
||||
initTabs:
|
||||
function() {
|
||||
$(".mr_nav_tabs a").live("click", function() {
|
||||
$(".mr_nav_tabs a").parent().removeClass("active");
|
||||
$(this).parent().addClass("active");
|
||||
});
|
||||
|
||||
var current_tab;
|
||||
if(this.opts.action == "diffs") {
|
||||
current_tab = $(".mr_nav_tabs .merge-diffs-tab");
|
||||
} else {
|
||||
current_tab = $(".mr_nav_tabs .merge-notes-tab");
|
||||
}
|
||||
current_tab.parent().addClass("active");
|
||||
|
||||
this.initNotesTab();
|
||||
this.initDiffTab();
|
||||
},
|
||||
|
||||
initNotesTab:
|
||||
function() {
|
||||
$(".mr_nav_tabs a.merge-notes-tab").live("click", function(e) {
|
||||
$(".merge-request-diffs").hide();
|
||||
$(".merge_request_notes").show();
|
||||
var mr_path = $(".merge-notes-tab").attr("data-url");
|
||||
history.pushState({ path: mr_path }, '', mr_path);
|
||||
e.preventDefault();
|
||||
});
|
||||
},
|
||||
|
||||
initDiffTab:
|
||||
function() {
|
||||
$(".mr_nav_tabs a.merge-diffs-tab").live("click", function(e) {
|
||||
if(!MergeRequest.diffs_loaded) {
|
||||
MergeRequest.loadDiff();
|
||||
}
|
||||
$(".merge_request_notes").hide();
|
||||
$(".merge-request-diffs").show();
|
||||
var mr_diff_path = $(".merge-diffs-tab").attr("data-url");
|
||||
history.pushState({ path: mr_diff_path }, '', mr_diff_path);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
showState:
|
||||
function(state){
|
||||
$(".automerge_widget").hide();
|
||||
$(".automerge_widget." + state).show();
|
||||
},
|
||||
|
||||
showCiState:
|
||||
function(state){
|
||||
$(".ci_widget").hide();
|
||||
$(".ci_widget.ci-" + state).show();
|
||||
},
|
||||
|
||||
loadDiff:
|
||||
function() {
|
||||
$(".dashboard-loader").show();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: $(".merge-diffs-tab").attr("data-url"),
|
||||
beforeSend: function(){ $('.status').addClass("loading")},
|
||||
complete: function(){
|
||||
MergeRequest.diffs_loaded = true;
|
||||
$(".merge_request_notes").hide();
|
||||
$('.status').removeClass("loading");
|
||||
},
|
||||
dataType: "script"});
|
||||
},
|
||||
|
||||
showAllCommits:
|
||||
function() {
|
||||
$(".first_mr_commits").remove();
|
||||
$(".all_mr_commits").removeClass("hide");
|
||||
},
|
||||
|
||||
already_cannot_be_merged:
|
||||
function(){
|
||||
$(".automerge_widget").hide();
|
||||
$(".merge_in_progress").hide();
|
||||
$(".automerge_widget.already_cannot_be_merged").show();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Filter merge requests
|
||||
*/
|
||||
function merge_requestsPage() {
|
||||
$("#assignee_id").chosen();
|
||||
$("#milestone_id").chosen();
|
||||
$("#milestone_id, #assignee_id").on("change", function(){
|
||||
$(this).closest("form").submit();
|
||||
});
|
||||
}
|
97
app/assets/javascripts/merge_requests.js.coffee
Normal file
97
app/assets/javascripts/merge_requests.js.coffee
Normal file
|
@ -0,0 +1,97 @@
|
|||
#
|
||||
# * Filter merge requests
|
||||
#
|
||||
@merge_requestsPage = ->
|
||||
$('#assignee_id').chosen()
|
||||
$('#milestone_id').chosen()
|
||||
$('#milestone_id, #assignee_id').on 'change', ->
|
||||
$(this).closest('form').submit()
|
||||
|
||||
class MergeRequest
|
||||
|
||||
constructor: (@opts) ->
|
||||
this.$el = $('.merge-request')
|
||||
@diffs_loaded = false
|
||||
@commits_loaded = false
|
||||
|
||||
this.activateTab(@opts.action)
|
||||
|
||||
this.bindEvents()
|
||||
|
||||
this.initMergeWidget()
|
||||
this.$('.show-all-commits').on 'click', =>
|
||||
this.showAllCommits()
|
||||
|
||||
# Local jQuery finder
|
||||
$: (selector) ->
|
||||
this.$el.find(selector)
|
||||
|
||||
initMergeWidget: ->
|
||||
this.showState( @opts.current_state )
|
||||
|
||||
if this.$('.automerge_widget').length and @opts.check_enable
|
||||
$.get @opts.url_to_automerge_check, (data) =>
|
||||
this.showState( data.state )
|
||||
, 'json'
|
||||
|
||||
if @opts.ci_enable
|
||||
$.get self.opts.url_to_ci_check, (data) =>
|
||||
this.showCiState data.status
|
||||
, 'json'
|
||||
|
||||
bindEvents: ->
|
||||
this.$('.nav-tabs').on 'click', 'a', (event) =>
|
||||
a = $(event.currentTarget)
|
||||
|
||||
href = a.attr('href')
|
||||
History.replaceState {path: href}, document.title, href
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
this.$('.nav-tabs').on 'click', 'li', (event) =>
|
||||
this.activateTab($(event.currentTarget).data('action'))
|
||||
|
||||
activateTab: (action) ->
|
||||
this.$('.nav-tabs li').removeClass 'active'
|
||||
this.$('.tab-content').hide()
|
||||
switch action
|
||||
when 'diffs'
|
||||
this.$('.nav-tabs .diffs-tab').addClass 'active'
|
||||
this.loadDiff() unless @diffs_loaded
|
||||
this.$('.diffs').show()
|
||||
else
|
||||
this.$('.nav-tabs .notes-tab').addClass 'active'
|
||||
this.$('.notes').show()
|
||||
|
||||
showState: (state) ->
|
||||
$('.automerge_widget').hide()
|
||||
$('.automerge_widget.' + state).show()
|
||||
|
||||
showCiState: (state) ->
|
||||
$('.ci_widget').hide()
|
||||
$('.ci_widget.ci-' + state).show()
|
||||
|
||||
loadDiff: (event) ->
|
||||
$('.dashboard-loader').show()
|
||||
$.ajax
|
||||
type: 'GET'
|
||||
url: this.$('.nav-tabs .diffs-tab a').attr('href')
|
||||
beforeSend: =>
|
||||
this.$('.status').addClass 'loading'
|
||||
|
||||
complete: =>
|
||||
@diffs_loaded = true
|
||||
this.$('.status').removeClass 'loading'
|
||||
|
||||
dataType: 'script'
|
||||
|
||||
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()
|
||||
|
||||
this.MergeRequest = MergeRequest
|
Loading…
Add table
Add a link
Reference in a new issue