3c19c971df
* master: (112 commits) small change to make less conflict with EE version Add cop for use of remove_column Resolve merge conflicts with dev.gitlab.org/master after security release add index for doc/administration/operations/ Remove RubySampler#sample_objects for performance as well Bugfix: User can't change the access level of an access requester Add spec for removing issues.assignee_id updated imports Keep track of storage check timings Remove a header level in the new 'Automatic CE->EE merge' doc Improve down step of removing issues.assignee_id column Fix specs after removing assignee_id field Remove issues.assignee_id column Resolve conflicts in app/models/user.rb Fix image view mode Do not raise when downstream pipeline is created Remove the need for destroy and add a comment in the spec Use build instead of create in importer spec Simplify normalizing of paths Remove allocation tracking code from InfluxDB sampler for performance ...
89 lines
2.7 KiB
JavaScript
89 lines
2.7 KiB
JavaScript
/* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, no-var, object-shorthand, consistent-return, no-unused-vars, comma-dangle, vars-on-top, prefer-template, max-len */
|
|
import { localTimeAgo } from './lib/utils/datetime_utility';
|
|
|
|
export default class Compare {
|
|
constructor(opts) {
|
|
this.opts = opts;
|
|
this.source_loading = $(".js-source-loading");
|
|
this.target_loading = $(".js-target-loading");
|
|
$('.js-compare-dropdown').each((function(_this) {
|
|
return function(i, dropdown) {
|
|
var $dropdown;
|
|
$dropdown = $(dropdown);
|
|
return $dropdown.glDropdown({
|
|
selectable: true,
|
|
fieldName: $dropdown.data('field-name'),
|
|
filterable: true,
|
|
id: function(obj, $el) {
|
|
return $el.data('id');
|
|
},
|
|
toggleLabel: function(obj, $el) {
|
|
return $el.text().trim();
|
|
},
|
|
clicked: function(e, el) {
|
|
if ($dropdown.is('.js-target-branch')) {
|
|
return _this.getTargetHtml();
|
|
} else if ($dropdown.is('.js-source-branch')) {
|
|
return _this.getSourceHtml();
|
|
} else if ($dropdown.is('.js-target-project')) {
|
|
return _this.getTargetProject();
|
|
}
|
|
}
|
|
});
|
|
};
|
|
})(this));
|
|
this.initialState();
|
|
}
|
|
|
|
initialState() {
|
|
this.getSourceHtml();
|
|
this.getTargetHtml();
|
|
}
|
|
|
|
getTargetProject() {
|
|
return $.ajax({
|
|
url: this.opts.targetProjectUrl,
|
|
data: {
|
|
target_project_id: $("input[name='merge_request[target_project_id]']").val()
|
|
},
|
|
beforeSend: function() {
|
|
return $('.mr_target_commit').empty();
|
|
},
|
|
success: function(html) {
|
|
return $('.js-target-branch-dropdown .dropdown-content').html(html);
|
|
}
|
|
});
|
|
}
|
|
|
|
getSourceHtml() {
|
|
return this.constructor.sendAjax(this.opts.sourceBranchUrl, this.source_loading, '.mr_source_commit', {
|
|
ref: $("input[name='merge_request[source_branch]']").val()
|
|
});
|
|
}
|
|
|
|
getTargetHtml() {
|
|
return this.constructor.sendAjax(this.opts.targetBranchUrl, this.target_loading, '.mr_target_commit', {
|
|
target_project_id: $("input[name='merge_request[target_project_id]']").val(),
|
|
ref: $("input[name='merge_request[target_branch]']").val()
|
|
});
|
|
}
|
|
|
|
static sendAjax(url, loading, target, data) {
|
|
var $target;
|
|
$target = $(target);
|
|
return $.ajax({
|
|
url: url,
|
|
data: data,
|
|
beforeSend: function() {
|
|
loading.show();
|
|
return $target.empty();
|
|
},
|
|
success: function(html) {
|
|
loading.hide();
|
|
$target.html(html);
|
|
var className = '.' + $target[0].className.replace(' ', '.');
|
|
localTimeAgo($('.js-timeago', className));
|
|
}
|
|
});
|
|
}
|
|
}
|