Commit ea33b040 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'ee-38869-project-1' into 'master'

Exports a couple of project related code as es6 modules

See merge request gitlab-org/gitlab-ee!3374
parents 46a45e65 75036954
/* eslint-disable class-methods-use-this, no-unneeded-ternary, quote-props, no-new */ /* eslint-disable class-methods-use-this, no-unneeded-ternary, quote-props, no-new */
/* global ProjectSelect */
import UsersSelect from './users_select'; import UsersSelect from './users_select';
import groupsSelect from './groups_select'; import groupsSelect from './groups_select';
import './project_select'; import projectSelect from './project_select';
class AuditLogs { class AuditLogs {
constructor() { constructor() {
...@@ -11,7 +10,7 @@ class AuditLogs { ...@@ -11,7 +10,7 @@ class AuditLogs {
} }
initFilters() { initFilters() {
new ProjectSelect(); projectSelect();
groupsSelect(); groupsSelect();
new UsersSelect(); new UsersSelect();
......
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, wrap-iife, no-shadow, consistent-return, one-var, one-var-declaration-per-line, camelcase, default-case, no-new, quotes, no-duplicate-case, no-case-declarations, no-fallthrough, max-len */ /* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, wrap-iife, no-shadow, consistent-return, one-var, one-var-declaration-per-line, camelcase, default-case, no-new, quotes, no-duplicate-case, no-case-declarations, no-fallthrough, max-len */
import { s__ } from './locale'; import { s__ } from './locale';
/* global ProjectSelect */ import projectSelect from './project_select';
import IssuableIndex from './issuable_index'; import IssuableIndex from './issuable_index';
/* global Milestone */ /* global Milestone */
import IssuableForm from './issuable_form'; import IssuableForm from './issuable_form';
...@@ -27,8 +27,7 @@ import projectAvatar from './project_avatar'; ...@@ -27,8 +27,7 @@ import projectAvatar from './project_avatar';
/* global CompareAutocomplete */ /* global CompareAutocomplete */
/* global PathLocks */ /* global PathLocks */
/* global ProjectFindFile */ /* global ProjectFindFile */
/* global ProjectNew */ import ProjectNew from './project_new';
/* global ProjectShow */
import projectImport from './project_import'; import projectImport from './project_import';
import Labels from './labels'; import Labels from './labels';
import LabelManager from './label_manager'; import LabelManager from './label_manager';
...@@ -95,6 +94,8 @@ import Members from './members'; ...@@ -95,6 +94,8 @@ import Members from './members';
import memberExpirationDate from './member_expiration_date'; import memberExpirationDate from './member_expiration_date';
import DueDateSelectors from './due_date_select'; import DueDateSelectors from './due_date_select';
import Diff from './diff'; import Diff from './diff';
import ProjectLabelSubscription from './project_label_subscription';
import ProjectVariables from './project_variables';
// EE-only // EE-only
import ApproversSelect from './approvers_select'; import ApproversSelect from './approvers_select';
...@@ -212,7 +213,7 @@ import initGroupAnalytics from './init_group_analytics'; ...@@ -212,7 +213,7 @@ import initGroupAnalytics from './init_group_analytics';
initIssuableSidebar(); initIssuableSidebar();
break; break;
case 'dashboard:milestones:index': case 'dashboard:milestones:index':
new ProjectSelect(); projectSelect();
break; break;
case 'projects:milestones:show': case 'projects:milestones:show':
new UserCallout(); new UserCallout();
...@@ -223,7 +224,7 @@ import initGroupAnalytics from './init_group_analytics'; ...@@ -223,7 +224,7 @@ import initGroupAnalytics from './init_group_analytics';
break; break;
case 'dashboard:issues': case 'dashboard:issues':
case 'dashboard:merge_requests': case 'dashboard:merge_requests':
new ProjectSelect(); projectSelect();
initLegacyFilters(); initLegacyFilters();
break; break;
case 'groups:issues': case 'groups:issues':
...@@ -232,7 +233,7 @@ import initGroupAnalytics from './init_group_analytics'; ...@@ -232,7 +233,7 @@ import initGroupAnalytics from './init_group_analytics';
const filteredSearchManager = new gl.FilteredSearchManager(page === 'groups:issues' ? 'issues' : 'merge_requests'); const filteredSearchManager = new gl.FilteredSearchManager(page === 'groups:issues' ? 'issues' : 'merge_requests');
filteredSearchManager.setup(); filteredSearchManager.setup();
} }
new ProjectSelect(); projectSelect();
break; break;
case 'dashboard:todos:index': case 'dashboard:todos:index':
new Todos(); new Todos();
...@@ -530,7 +531,7 @@ import initGroupAnalytics from './init_group_analytics'; ...@@ -530,7 +531,7 @@ import initGroupAnalytics from './init_group_analytics';
if ($el.find('.dropdown-group-label').length) { if ($el.find('.dropdown-group-label').length) {
new GroupLabelSubscription($el); new GroupLabelSubscription($el);
} else { } else {
new gl.ProjectLabelSubscription($el); new ProjectLabelSubscription($el);
} }
}); });
break; break;
...@@ -579,7 +580,7 @@ import initGroupAnalytics from './init_group_analytics'; ...@@ -579,7 +580,7 @@ import initGroupAnalytics from './init_group_analytics';
// Initialize expandable settings panels // Initialize expandable settings panels
initSettingsPanels(); initSettingsPanels();
case 'groups:settings:ci_cd:show': case 'groups:settings:ci_cd:show':
new gl.ProjectVariables(); new ProjectVariables();
break; break;
case 'ci:lints:create': case 'ci:lints:create':
case 'ci:lints:show': case 'ci:lints:show':
...@@ -706,7 +707,6 @@ import initGroupAnalytics from './init_group_analytics'; ...@@ -706,7 +707,6 @@ import initGroupAnalytics from './init_group_analytics';
case 'show': case 'show':
new Star(); new Star();
new ProjectNew(); new ProjectNew();
new ProjectShow();
new NotificationsDropdown(); new NotificationsDropdown();
break; break;
case 'wikis': case 'wikis':
......
...@@ -73,11 +73,6 @@ import './pager'; ...@@ -73,11 +73,6 @@ import './pager';
import './preview_markdown'; import './preview_markdown';
import './project_find_file'; import './project_find_file';
import './project_import'; import './project_import';
import './project_label_subscription';
import './project_new';
import './project_select';
import './project_show';
import './project_variables';
import './projects_dropdown'; import './projects_dropdown';
import './projects_list'; import './projects_list';
import './syntax_highlight'; import './syntax_highlight';
......
/* eslint-disable func-names, space-before-function-paren, no-var, consistent-return, no-new, prefer-arrow-callback, no-return-assign, one-var, one-var-declaration-per-line, object-shorthand, no-else-return, newline-per-chained-call, no-shadow, vars-on-top, prefer-template, max-len */ /* eslint-disable func-names, space-before-function-paren, no-var, consistent-return, no-new, prefer-arrow-callback, no-return-assign, one-var, one-var-declaration-per-line, object-shorthand, no-else-return, newline-per-chained-call, no-shadow, vars-on-top, prefer-template, max-len */
/* global ProjectSelect */
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import projectSelect from './project_select';
export default class Project { export default class Project {
constructor() { constructor() {
...@@ -58,7 +58,7 @@ export default class Project { ...@@ -58,7 +58,7 @@ export default class Project {
} }
static projectSelectDropdown() { static projectSelectDropdown() {
new ProjectSelect(); projectSelect();
$('.project-item-select').on('click', e => Project.changeProject($(e.currentTarget).val())); $('.project-item-select').on('click', e => Project.changeProject($(e.currentTarget).val()));
} }
......
/* eslint-disable wrap-iife, func-names, space-before-function-paren, object-shorthand, comma-dangle, one-var, one-var-declaration-per-line, no-restricted-syntax, max-len, no-param-reassign */ export default class ProjectLabelSubscription {
(function(global) {
class ProjectLabelSubscription {
constructor(container) { constructor(container) {
this.$container = $(container); this.$container = $(container);
this.$buttons = this.$container.find('.js-subscribe-button'); this.$buttons = this.$container.find('.js-subscribe-button');
...@@ -22,9 +19,10 @@ ...@@ -22,9 +19,10 @@
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: url url,
}).done(() => { }).done(() => {
let newStatus, newAction; let newStatus;
let newAction;
if (oldStatus === 'unsubscribed') { if (oldStatus === 'unsubscribed') {
[newStatus, newAction] = ['subscribed', 'Unsubscribe']; [newStatus, newAction] = ['subscribed', 'Unsubscribe'];
...@@ -49,7 +47,4 @@ ...@@ -49,7 +47,4 @@
}); });
}); });
} }
} }
global.ProjectLabelSubscription = ProjectLabelSubscription;
})(window.gl || (window.gl = {}));
...@@ -7,9 +7,8 @@ function highlightChanges($elm) { ...@@ -7,9 +7,8 @@ function highlightChanges($elm) {
setTimeout(() => $elm.removeClass('highlight-changes'), 10); setTimeout(() => $elm.removeClass('highlight-changes'), 10);
} }
(function() { export default class ProjectNew {
this.ProjectNew = (function() { constructor() {
function ProjectNew() {
this.toggleSettings = this.toggleSettings.bind(this); this.toggleSettings = this.toggleSettings.bind(this);
this.$selects = $('.features select'); this.$selects = $('.features select');
this.$repoSelects = this.$selects.filter('.js-repo-select'); this.$repoSelects = this.$selects.filter('.js-repo-select');
...@@ -30,12 +29,12 @@ function highlightChanges($elm) { ...@@ -30,12 +29,12 @@ function highlightChanges($elm) {
this.toggleRepoVisibility(); this.toggleRepoVisibility();
} }
ProjectNew.prototype.bindEvents = function() { bindEvents () {
this.$selects.on('change', () => this.toggleSettings()); this.$selects.on('change', () => this.toggleSettings());
$('#require_approvals').on('change', e => this.toggleApproverSettingsVisibility(e)); $('#require_approvals').on('change', e => this.toggleApproverSettingsVisibility(e));
}; }
ProjectNew.prototype.initVisibilitySelect = function() { initVisibilitySelect() {
const visibilityContainer = document.querySelector('.js-visibility-select'); const visibilityContainer = document.querySelector('.js-visibility-select');
if (!visibilityContainer) return; if (!visibilityContainer) return;
const visibilitySelect = new VisibilitySelect(visibilityContainer); const visibilitySelect = new VisibilitySelect(visibilityContainer);
...@@ -76,30 +75,28 @@ function highlightChanges($elm) { ...@@ -76,30 +75,28 @@ function highlightChanges($elm) {
projectVisibility = newProjectVisibility; projectVisibility = newProjectVisibility;
} }
}); });
}; }
ProjectNew.prototype.toggleApproverSettingsVisibility = function(e) { toggleApproverSettingsVisibility(e) {
this.$requiredApprovals = $('#project_approvals_before_merge'); this.$requiredApprovals = $('#project_approvals_before_merge');
const enabled = $(e.target).prop('checked'); const enabled = $(e.target).prop('checked');
const val = enabled ? 1 : 0; const val = enabled ? 1 : 0;
this.$requiredApprovals.val(val); this.$requiredApprovals.val(val);
this.$requiredApprovals.prop('min', val); this.$requiredApprovals.prop('min', val);
$('.nested-settings').toggleClass('hidden', !enabled); $('.nested-settings').toggleClass('hidden', !enabled);
}; }
ProjectNew.prototype.toggleSettings = function() {
var self = this;
toggleSettings() {
this.$selects.each(function () { this.$selects.each(function () {
var $select = $(this); var $select = $(this);
var className = $select.data('field') var className = $select.data('field')
.replace(/_/g, '-') .replace(/_/g, '-')
.replace('access-level', 'feature'); .replace('access-level', 'feature');
self._showOrHide($select, '.' + className); ProjectNew._showOrHide($select, '.' + className);
}); });
}; }
ProjectNew.prototype._showOrHide = function(checkElement, container) { static _showOrHide(checkElement, container) {
var $container = $(container); var $container = $(container);
if ($(checkElement).val() !== '0') { if ($(checkElement).val() !== '0') {
...@@ -107,9 +104,9 @@ function highlightChanges($elm) { ...@@ -107,9 +104,9 @@ function highlightChanges($elm) {
} else { } else {
return $container.hide(); return $container.hide();
} }
}; }
ProjectNew.prototype.toggleRepoVisibility = function () { toggleRepoVisibility () {
var $repoAccessLevel = $('.js-repo-access-level select'); var $repoAccessLevel = $('.js-repo-access-level select');
var $lfsEnabledOption = $('.js-lfs-enabled select'); var $lfsEnabledOption = $('.js-lfs-enabled select');
var containerRegistry = document.querySelectorAll('.js-container-registry')[0]; var containerRegistry = document.querySelectorAll('.js-container-registry')[0];
...@@ -163,8 +160,5 @@ function highlightChanges($elm) { ...@@ -163,8 +160,5 @@ function highlightChanges($elm) {
prevSelectedVal = selectedVal; prevSelectedVal = selectedVal;
}.bind(this)); }.bind(this));
}; }
}
return ProjectNew;
})();
}).call(window);
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
import Api from './api'; import Api from './api';
import ProjectSelectComboButton from './project_select_combo_button'; import ProjectSelectComboButton from './project_select_combo_button';
(function () { export default function projectSelect() {
this.ProjectSelect = (function () {
function ProjectSelect() {
$('.ajax-project-select').each(function(i, select) { $('.ajax-project-select').each(function(i, select) {
var placeholder; var placeholder;
const simpleFilter = $(select).data('simple-filter') || false; const simpleFilter = $(select).data('simple-filter') || false;
...@@ -73,8 +71,4 @@ import ProjectSelectComboButton from './project_select_combo_button'; ...@@ -73,8 +71,4 @@ import ProjectSelectComboButton from './project_select_combo_button';
if (simpleFilter) return select; if (simpleFilter) return select;
return new ProjectSelectComboButton(select); return new ProjectSelectComboButton(select);
}); });
} }
return ProjectSelect;
})();
}).call(window);
/* eslint-disable func-names, space-before-function-paren, wrap-iife */
(function() {
this.ProjectShow = (function() {
function ProjectShow() {}
return ProjectShow;
})();
}).call(window);
// I kept class for future
(() => {
const HIDDEN_VALUE_TEXT = '******';
class ProjectVariables { const HIDDEN_VALUE_TEXT = '******';
export default class ProjectVariables {
constructor() { constructor() {
this.$revealBtn = $('.js-btn-toggle-reveal-values'); this.$revealBtn = $('.js-btn-toggle-reveal-values');
this.$revealBtn.on('click', this.toggleRevealState.bind(this)); this.$revealBtn.on('click', this.toggleRevealState.bind(this));
...@@ -36,8 +36,4 @@ ...@@ -36,8 +36,4 @@
this.$revealBtn.text(newAction); this.$revealBtn.text(newAction);
} }
} }
window.gl = window.gl || {};
window.gl.ProjectVariables = ProjectVariables;
})();
import '~/project_new'; import ProjectNew from '~/project_new';
describe('ApproversSelect', function () { describe('ApproversSelect', function () {
const projectSettingsTemplate = 'projects/edit.html.raw'; const projectSettingsTemplate = 'projects/edit.html.raw';
...@@ -7,7 +7,7 @@ describe('ApproversSelect', function () { ...@@ -7,7 +7,7 @@ describe('ApproversSelect', function () {
beforeEach(() => { beforeEach(() => {
loadFixtures(projectSettingsTemplate); loadFixtures(projectSettingsTemplate);
this.$requireApprovalsToggle = $('.js-require-approvals-toggle'); this.$requireApprovalsToggle = $('.js-require-approvals-toggle');
this.project = new window.ProjectNew(); this.project = new ProjectNew();
}); });
it('shows approver settings if enabled', () => { it('shows approver settings if enabled', () => {
......
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