Commit 030de8b3 authored by Filipa Lacerda's avatar Filipa Lacerda

Export code as ES6 modules

parent 2b594daf
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, no-var, quotes, vars-on-top, no-unused-vars, no-new, max-len */ /* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, no-var, quotes, vars-on-top, no-unused-vars, no-new, max-len */
/* global EditBlob */ /* global EditBlob */
/* global NewCommitForm */ import NewCommitForm from '../new_commit_form';
import EditBlob from './edit_blob'; import EditBlob from './edit_blob';
import BlobFileDropzone from '../blob/blob_file_dropzone'; import BlobFileDropzone from '../blob/blob_file_dropzone';
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
import { s__ } from './locale'; import { s__ } from './locale';
import projectSelect from './project_select'; import projectSelect from './project_select';
import IssuableIndex from './issuable_index'; import IssuableIndex from './issuable_index';
/* global Milestone */ import Milestone from './milestone';
import IssuableForm from './issuable_form'; import IssuableForm from './issuable_form';
import LabelsSelect from './labels_select'; import LabelsSelect from './labels_select';
/* global MilestoneSelect */ /* global MilestoneSelect */
/* global NewBranchForm */ import NewBranchForm from './new_branch_form';
/* global NotificationsForm */ /* global NotificationsForm */
/* global NotificationsDropdown */ /* global NotificationsDropdown */
import groupAvatar from './group_avatar'; import groupAvatar from './group_avatar';
...@@ -18,8 +18,7 @@ import groupsSelect from './groups_select'; ...@@ -18,8 +18,7 @@ import groupsSelect from './groups_select';
/* global Search */ /* global Search */
/* global Admin */ /* global Admin */
import NamespaceSelect from './namespace_select'; import NamespaceSelect from './namespace_select';
/* global NewCommitForm */ import NewCommitForm from './new_commit_form';
/* global NewBranchForm */
import Project from './project'; import Project from './project';
import projectAvatar from './project_avatar'; import projectAvatar from './project_avatar';
/* global MergeRequest */ /* global MergeRequest */
......
/* eslint-disable no-new */ /* eslint-disable no-new */
import LabelsSelect from './labels_select'; import LabelsSelect from './labels_select';
/* global MilestoneSelect */ /* global MilestoneSelect */
/* global SubscriptionSelect */ import subscriptionSelect from './subscription_select';
import UsersSelect from './users_select'; import UsersSelect from './users_select';
import issueStatusSelect from './issue_status_select'; import issueStatusSelect from './issue_status_select';
...@@ -11,5 +10,5 @@ export default () => { ...@@ -11,5 +10,5 @@ export default () => {
new LabelsSelect(); new LabelsSelect();
new MilestoneSelect(); new MilestoneSelect();
issueStatusSelect(); issueStatusSelect();
new SubscriptionSelect(); subscriptionSelect();
}; };
/* eslint-disable class-methods-use-this, no-new */ /* eslint-disable class-methods-use-this, no-new */
/* global MilestoneSelect */ /* global MilestoneSelect */
/* global SubscriptionSelect */
import IssuableBulkUpdateActions from './issuable_bulk_update_actions'; import IssuableBulkUpdateActions from './issuable_bulk_update_actions';
import './milestone_select'; import './milestone_select';
import issueStatusSelect from './issue_status_select'; import issueStatusSelect from './issue_status_select';
import './subscription_select'; import subscriptionSelect from './subscription_select';
import LabelsSelect from './labels_select'; import LabelsSelect from './labels_select';
const HIDDEN_CLASS = 'hidden'; const HIDDEN_CLASS = 'hidden';
...@@ -48,7 +47,7 @@ export default class IssuableBulkUpdateSidebar { ...@@ -48,7 +47,7 @@ export default class IssuableBulkUpdateSidebar {
new LabelsSelect(); new LabelsSelect();
new MilestoneSelect(); new MilestoneSelect();
issueStatusSelect(); issueStatusSelect();
new SubscriptionSelect(); subscriptionSelect();
} }
setupBulkUpdateActions() { setupBulkUpdateActions() {
......
...@@ -58,11 +58,7 @@ import './line_highlighter'; ...@@ -58,11 +58,7 @@ import './line_highlighter';
import initLogoAnimation from './logo'; import initLogoAnimation from './logo';
import './merge_request'; import './merge_request';
import './merge_request_tabs'; import './merge_request_tabs';
import './milestone';
import './milestone_select'; import './milestone_select';
import './namespace_select';
import './new_branch_form';
import './new_commit_form';
import './notes'; import './notes';
import './notifications_dropdown'; import './notifications_dropdown';
import './notifications_form'; import './notifications_form';
...@@ -78,8 +74,6 @@ import './render_gfm'; ...@@ -78,8 +74,6 @@ import './render_gfm';
import './right_sidebar'; import './right_sidebar';
import './search'; import './search';
import './search_autocomplete'; import './search_autocomplete';
import './smart_interval';
import './subscription_select';
import initBreadcrumbs from './breadcrumb'; import initBreadcrumbs from './breadcrumb';
import './dispatcher'; import './dispatcher';
......
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-use-before-define, camelcase, quotes, object-shorthand, no-shadow, no-unused-vars, comma-dangle, no-var, prefer-template, no-underscore-dangle, consistent-return, one-var, one-var-declaration-per-line, default-case, prefer-arrow-callback, max-len */
/* global Sortable */ /* global Sortable */
import Flash from './flash'; import Flash from './flash';
(function() { export default class Milestone {
this.Milestone = (function() { constructor() {
function Milestone() { this.bindTabsSwitching();
this.bindTabsSwitching();
// Load merge request tab if it is active // Load merge request tab if it is active
// merge request tab is active based on different conditions in the backend // merge request tab is active based on different conditions in the backend
this.loadTab($('.js-milestone-tabs .active a')); this.loadTab($('.js-milestone-tabs .active a'));
this.loadInitialTab(); this.loadInitialTab();
} }
bindTabsSwitching() {
return $('a[data-toggle="tab"]').on('show.bs.tab', (e) => {
const $target = $(e.target);
Milestone.prototype.bindTabsSwitching = function() { location.hash = $target.attr('href');
return $('a[data-toggle="tab"]').on('show.bs.tab', (e) => { this.loadTab($target);
const $target = $(e.target); });
}
// eslint-disable-next-line class-methods-use-this
loadInitialTab() {
const $target = $(`.js-milestone-tabs a[href="${location.hash}"]`);
location.hash = $target.attr('href'); if ($target.length) {
this.loadTab($target); $target.tab('show');
}
}
// eslint-disable-next-line class-methods-use-this
loadTab($target) {
const endpoint = $target.data('endpoint');
const tabElId = $target.attr('href');
if (endpoint && !$target.hasClass('is-loaded')) {
$.ajax({
url: endpoint,
dataType: 'JSON',
})
.fail(() => new Flash('Error loading milestone tab'))
.done((data) => {
$(tabElId).html(data.html);
$target.addClass('is-loaded');
}); });
}; }
}
Milestone.prototype.loadInitialTab = function() { }
const $target = $(`.js-milestone-tabs a[href="${location.hash}"]`);
if ($target.length) {
$target.tab('show');
}
};
Milestone.prototype.loadTab = function($target) {
const endpoint = $target.data('endpoint');
const tabElId = $target.attr('href');
if (endpoint && !$target.hasClass('is-loaded')) {
$.ajax({
url: endpoint,
dataType: 'JSON',
})
.fail(() => new Flash('Error loading milestone tab'))
.done((data) => {
$(tabElId).html(data.html);
$target.addClass('is-loaded');
});
}
};
return Milestone;
})();
}).call(window);
/* eslint-disable func-names, space-before-function-paren, no-var, one-var, prefer-rest-params, max-len, vars-on-top, wrap-iife, consistent-return, comma-dangle, one-var-declaration-per-line, quotes, no-return-assign, prefer-arrow-callback, prefer-template, no-shadow, no-else-return, max-len, object-shorthand */ /* eslint-disable func-names, space-before-function-paren, no-var, one-var, prefer-rest-params, max-len, vars-on-top, wrap-iife, consistent-return, comma-dangle, one-var-declaration-per-line, quotes, no-return-assign, prefer-arrow-callback, prefer-template, no-shadow, no-else-return, max-len, object-shorthand */
import RefSelectDropdown from '~/ref_select_dropdown'; import RefSelectDropdown from './ref_select_dropdown';
(function() { export default class NewBranchForm {
this.NewBranchForm = (function() { constructor(form, availableRefs) {
function NewBranchForm(form, availableRefs) { this.validate = this.validate.bind(this);
this.validate = this.validate.bind(this); this.branchNameError = form.find('.js-branch-name-error');
this.branchNameError = form.find('.js-branch-name-error'); this.name = form.find('.js-branch-name');
this.name = form.find('.js-branch-name'); this.ref = form.find('#ref');
this.ref = form.find('#ref'); new RefSelectDropdown($('.js-branch-select'), availableRefs); // eslint-disable-line no-new
new RefSelectDropdown($('.js-branch-select'), availableRefs); // eslint-disable-line no-new this.setupRestrictions();
this.setupRestrictions(); this.addBinding();
this.addBinding(); this.init();
this.init(); }
addBinding() {
return this.name.on('blur', this.validate);
}
init() {
if (this.name.length && this.name.val().length > 0) {
return this.name.trigger('blur');
} }
}
NewBranchForm.prototype.addBinding = function() { setupRestrictions() {
return this.name.on('blur', this.validate); var endsWith, invalid, single, startsWith;
startsWith = {
pattern: /^(\/|\.)/g,
prefix: "can't start with",
conjunction: "or"
}; };
endsWith = {
NewBranchForm.prototype.init = function() { pattern: /(\/|\.|\.lock)$/g,
if (this.name.length && this.name.val().length > 0) { prefix: "can't end in",
return this.name.trigger('blur'); conjunction: "or"
}
}; };
invalid = {
NewBranchForm.prototype.setupRestrictions = function() { pattern: /(\s|~|\^|:|\?|\*|\[|\\|\.\.|@\{|\/{2,}){1}/g,
var endsWith, invalid, single, startsWith; prefix: "can't contain",
startsWith = { conjunction: ", "
pattern: /^(\/|\.)/g, };
prefix: "can't start with", single = {
conjunction: "or" pattern: /^@+$/g,
}; prefix: "can't be",
endsWith = { conjunction: "or"
pattern: /(\/|\.|\.lock)$/g,
prefix: "can't end in",
conjunction: "or"
};
invalid = {
pattern: /(\s|~|\^|:|\?|\*|\[|\\|\.\.|@\{|\/{2,}){1}/g,
prefix: "can't contain",
conjunction: ", "
};
single = {
pattern: /^@+$/g,
prefix: "can't be",
conjunction: "or"
};
return this.restrictions = [startsWith, invalid, endsWith, single];
}; };
return this.restrictions = [startsWith, invalid, endsWith, single];
}
NewBranchForm.prototype.validate = function() { validate() {
var errorMessage, errors, formatter, unique, validator; var errorMessage, errors, formatter, unique, validator;
const indexOf = [].indexOf; const indexOf = [].indexOf;
this.branchNameError.empty(); this.branchNameError.empty();
unique = function(values, value) { unique = function(values, value) {
if (indexOf.call(values, value) === -1) { if (indexOf.call(values, value) === -1) {
values.push(value); values.push(value);
}
return values;
};
formatter = function(values, restriction) {
var formatted;
formatted = values.map(function(value) {
switch (false) {
case !/\s/.test(value):
return 'spaces';
case !/\/{2,}/g.test(value):
return 'consecutive slashes';
default:
return "'" + value + "'";
}
});
return restriction.prefix + " " + (formatted.join(restriction.conjunction));
};
validator = (function(_this) {
return function(errors, restriction) {
var matched;
matched = _this.name.val().match(restriction.pattern);
if (matched) {
return errors.concat(formatter(matched.reduce(unique, []), restriction));
} else {
return errors;
}
};
})(this);
errors = this.restrictions.reduce(validator, []);
if (errors.length > 0) {
errorMessage = $("<span/>").text(errors.join(', '));
return this.branchNameError.append(errorMessage);
} }
return values;
}; };
formatter = function(values, restriction) {
return NewBranchForm; var formatted;
})(); formatted = values.map(function(value) {
}).call(window); switch (false) {
case !/\s/.test(value):
return 'spaces';
case !/\/{2,}/g.test(value):
return 'consecutive slashes';
default:
return "'" + value + "'";
}
});
return restriction.prefix + " " + (formatted.join(restriction.conjunction));
};
validator = (function(_this) {
return function(errors, restriction) {
var matched;
matched = _this.name.val().match(restriction.pattern);
if (matched) {
return errors.concat(formatter(matched.reduce(unique, []), restriction));
} else {
return errors;
}
};
})(this);
errors = this.restrictions.reduce(validator, []);
if (errors.length > 0) {
errorMessage = $("<span/>").text(errors.join(', '));
return this.branchNameError.append(errorMessage);
}
}
}
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-return-assign, max-len */ /* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-return-assign, max-len */
(function() { export default class NewCommitForm {
this.NewCommitForm = (function() { constructor(form) {
function NewCommitForm(form) { this.form = form;
this.form = form; this.renderDestination = this.renderDestination.bind(this);
this.renderDestination = this.renderDestination.bind(this); this.branchName = form.find('.js-branch-name');
this.branchName = form.find('.js-branch-name'); this.originalBranch = form.find('.js-original-branch');
this.originalBranch = form.find('.js-original-branch'); this.createMergeRequest = form.find('.js-create-merge-request');
this.createMergeRequest = form.find('.js-create-merge-request'); this.createMergeRequestContainer = form.find('.js-create-merge-request-container');
this.createMergeRequestContainer = form.find('.js-create-merge-request-container'); this.branchName.keyup(this.renderDestination);
this.branchName.keyup(this.renderDestination); this.renderDestination();
this.renderDestination(); }
}
NewCommitForm.prototype.renderDestination = function() { renderDestination() {
var different; var different;
different = this.branchName.val() !== this.originalBranch.val(); different = this.branchName.val() !== this.originalBranch.val();
if (different) { if (different) {
this.createMergeRequestContainer.show(); this.createMergeRequestContainer.show();
if (!this.wasDifferent) { if (!this.wasDifferent) {
this.createMergeRequest.prop('checked', true); this.createMergeRequest.prop('checked', true);
}
} else {
this.createMergeRequestContainer.hide();
this.createMergeRequest.prop('checked', false);
} }
return this.wasDifferent = different; } else {
}; this.createMergeRequestContainer.hide();
this.createMergeRequest.prop('checked', false);
return NewCommitForm; }
})(); return this.wasDifferent = different;
}).call(window); }
}
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, quotes, object-shorthand, no-unused-vars, no-shadow, one-var, one-var-declaration-per-line, comma-dangle, max-len */ export default function subscriptionSelect() {
$('.js-subscription-event').each((i, element) => {
const fieldName = $(element).data('field-name');
class SubscriptionSelect { return $(element).glDropdown({
constructor() { selectable: true,
$('.js-subscription-event').each(function(i, el) { fieldName,
var fieldName; toggleLabel(selected, el, instance) {
fieldName = $(el).data("field-name"); let label = 'Subscription';
return $(el).glDropdown({ const $item = instance.dropdown.find('.is-active');
selectable: true, if ($item.length) {
fieldName: fieldName, label = $item.text();
toggleLabel: (function(_this) {
return function(selected, el, instance) {
var $item, label;
label = 'Subscription';
$item = instance.dropdown.find('.is-active');
if ($item.length) {
label = $item.text();
}
return label;
};
})(this),
clicked: function(options) {
return options.e.preventDefault();
},
id: function(obj, el) {
return $(el).data("id");
} }
}); return label;
},
clicked(options) {
return options.e.preventDefault();
},
id(obj, el) {
return $(el).data('id');
},
}); });
} });
} }
window.SubscriptionSelect = SubscriptionSelect;
/* eslint-disable space-before-function-paren, one-var, no-var, one-var-declaration-per-line, no-return-assign, quotes, max-len */ /* eslint-disable space-before-function-paren, one-var, no-var, one-var-declaration-per-line, no-return-assign, quotes, max-len */
/* global NewBranchForm */
import '~/new_branch_form'; import NewBranchForm from '~/new_branch_form';
(function() { (function() {
describe('Branch', function() { describe('Branch', function() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment