Skip to content

Commit

Permalink
Exports a couple of project related code as es6 modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipa Lacerda authored and iamphill committed Nov 17, 2017
1 parent 2dff377 commit 77b1def
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 311 deletions.
18 changes: 9 additions & 9 deletions app/assets/javascripts/dispatcher.js
@@ -1,6 +1,6 @@
/* 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';
/* global ProjectSelect */
import projectSelect from './project_select';
import IssuableIndex from './issuable_index';
/* global Milestone */
import IssuableForm from './issuable_form';
Expand All @@ -26,8 +26,7 @@ import projectAvatar from './project_avatar';
/* global Compare */
/* global CompareAutocomplete */
/* global ProjectFindFile */
/* global ProjectNew */
/* global ProjectShow */
import ProjectNew from './project_new';
import projectImport from './project_import';
import Labels from './labels';
import LabelManager from './label_manager';
Expand Down Expand Up @@ -91,6 +90,8 @@ import Members from './members';
import memberExpirationDate from './member_expiration_date';
import DueDateSelectors from './due_date_select';
import Diff from './diff';
import ProjectLabelSubscription from './project_label_subscription';
import ProjectVariables from './project_variables';

(function() {
var Dispatcher;
Expand Down Expand Up @@ -187,7 +188,7 @@ import Diff from './diff';
initIssuableSidebar();
break;
case 'dashboard:milestones:index':
new ProjectSelect();
projectSelect();
break;
case 'projects:milestones:show':
case 'groups:milestones:show':
Expand All @@ -197,7 +198,7 @@ import Diff from './diff';
break;
case 'dashboard:issues':
case 'dashboard:merge_requests':
new ProjectSelect();
projectSelect();
initLegacyFilters();
break;
case 'groups:issues':
Expand All @@ -206,7 +207,7 @@ import Diff from './diff';
const filteredSearchManager = new gl.FilteredSearchManager(page === 'groups:issues' ? 'issues' : 'merge_requests');
filteredSearchManager.setup();
}
new ProjectSelect();
projectSelect();
break;
case 'dashboard:todos:index':
new Todos();
Expand Down Expand Up @@ -484,7 +485,7 @@ import Diff from './diff';
if ($el.find('.dropdown-group-label').length) {
new GroupLabelSubscription($el);
} else {
new gl.ProjectLabelSubscription($el);
new ProjectLabelSubscription($el);
}
});
break;
Expand Down Expand Up @@ -520,7 +521,7 @@ import Diff from './diff';
// Initialize expandable settings panels
initSettingsPanels();
case 'groups:settings:ci_cd:show':
new gl.ProjectVariables();
new ProjectVariables();
break;
case 'ci:lints:create':
case 'ci:lints:show':
Expand Down Expand Up @@ -623,7 +624,6 @@ import Diff from './diff';
case 'show':
new Star();
new ProjectNew();
new ProjectShow();
new NotificationsDropdown();
break;
case 'wikis':
Expand Down
5 changes: 0 additions & 5 deletions app/assets/javascripts/main.js
Expand Up @@ -71,11 +71,6 @@ import './pager';
import './preview_markdown';
import './project_find_file';
import './project_import';
import './project_label_subscription';
import './project_new';
import './project_select';
import './project_show';
import './project_variables';
import './projects_dropdown';
import './projects_list';
import './syntax_highlight';
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/project.js
@@ -1,7 +1,7 @@
/* 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 projectSelect from './project_select';

export default class Project {
constructor() {
Expand Down Expand Up @@ -46,7 +46,7 @@ export default class Project {
}

static projectSelectDropdown () {
new ProjectSelect();
projectSelect();
$('.project-item-select').on('click', e => Project.changeProject($(e.currentTarget).val()));
}

Expand Down
79 changes: 37 additions & 42 deletions app/assets/javascripts/project_label_subscription.js
@@ -1,55 +1,50 @@
/* 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 {
constructor(container) {
this.$container = $(container);
this.$buttons = this.$container.find('.js-subscribe-button');

(function(global) {
class ProjectLabelSubscription {
constructor(container) {
this.$container = $(container);
this.$buttons = this.$container.find('.js-subscribe-button');

this.$buttons.on('click', this.toggleSubscription.bind(this));
}
this.$buttons.on('click', this.toggleSubscription.bind(this));
}

toggleSubscription(event) {
event.preventDefault();
toggleSubscription(event) {
event.preventDefault();

const $btn = $(event.currentTarget);
const $span = $btn.find('span');
const url = $btn.attr('data-url');
const oldStatus = $btn.attr('data-status');
const $btn = $(event.currentTarget);
const $span = $btn.find('span');
const url = $btn.attr('data-url');
const oldStatus = $btn.attr('data-status');

$btn.addClass('disabled');
$span.toggleClass('hidden');
$btn.addClass('disabled');
$span.toggleClass('hidden');

$.ajax({
type: 'POST',
url: url
}).done(() => {
let newStatus, newAction;
$.ajax({
type: 'POST',
url,
}).done(() => {
let newStatus;
let newAction;

if (oldStatus === 'unsubscribed') {
[newStatus, newAction] = ['subscribed', 'Unsubscribe'];
} else {
[newStatus, newAction] = ['unsubscribed', 'Subscribe'];
}
if (oldStatus === 'unsubscribed') {
[newStatus, newAction] = ['subscribed', 'Unsubscribe'];
} else {
[newStatus, newAction] = ['unsubscribed', 'Subscribe'];
}

$span.toggleClass('hidden');
$btn.removeClass('disabled');
$span.toggleClass('hidden');
$btn.removeClass('disabled');

this.$buttons.attr('data-status', newStatus);
this.$buttons.find('> span').text(newAction);
this.$buttons.attr('data-status', newStatus);
this.$buttons.find('> span').text(newAction);

this.$buttons.map((button) => {
const $button = $(button);
this.$buttons.map((button) => {
const $button = $(button);

if ($button.attr('data-original-title')) {
$button.tooltip('hide').attr('data-original-title', newAction).tooltip('fixTitle');
}
if ($button.attr('data-original-title')) {
$button.tooltip('hide').attr('data-original-title', newAction).tooltip('fixTitle');
}

return button;
});
return button;
});
}
});
}

global.ProjectLabelSubscription = ProjectLabelSubscription;
})(window.gl || (window.gl = {}));
}

0 comments on commit 77b1def

Please sign in to comment.