gitlab-org--gitlab-foss/app/assets/javascripts/dispatcher.js.es6

379 lines
12 KiB
JavaScript
Raw Normal View History

/* 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 */
/* global UsernameValidator */
/* global ActiveTabMemoizer */
/* global ShortcutsNavigation */
/* global Build */
/* global Issuable */
/* global Issue */
/* global ShortcutsIssuable */
/* global ZenMode */
/* global Milestone */
/* global IssuableForm */
/* global LabelsSelect */
/* global MilestoneSelect */
/* global MergedButtons */
/* global Commit */
/* global NotificationsForm */
/* global TreeView */
/* global NotificationsDropdown */
/* global UsersSelect */
/* global GroupAvatar */
/* global LineHighlighter */
/* global ShortcutsBlob */
/* global ProjectFork */
/* global BuildArtifacts */
/* global GroupsSelect */
/* global Search */
/* global Admin */
/* global NamespaceSelects */
/* global ShortcutsDashboardNavigation */
/* global Project */
/* global ProjectAvatar */
/* global CompareAutocomplete */
/* global ProjectNew */
/* global Star */
/* global ProjectShow */
/* global Labels */
/* global Shortcuts */
2016-07-24 16:45:11 -04:00
(function() {
var Dispatcher;
$(function() {
return new Dispatcher();
});
Dispatcher = (function() {
function Dispatcher() {
this.initSearch();
this.initFieldErrors();
2016-07-24 16:45:11 -04:00
this.initPageScripts();
}
Dispatcher.prototype.initPageScripts = function() {
var page, path, shortcut_handler;
page = $('body').attr('data-page');
if (!page) {
return false;
}
path = page.split(':');
shortcut_handler = null;
switch (page) {
case 'sessions:new':
new UsernameValidator();
new ActiveTabMemoizer();
break;
case 'projects:boards:show':
case 'projects:boards:index':
shortcut_handler = new ShortcutsNavigation();
break;
case 'projects:builds:show':
new Build();
break;
case 'projects:merge_requests:index':
2016-07-24 16:45:11 -04:00
case 'projects:issues:index':
2017-01-09 12:33:17 -05:00
if (gl.FilteredSearchManager) {
2016-11-04 17:27:11 -04:00
new gl.FilteredSearchManager();
}
2016-07-24 16:45:11 -04:00
Issuable.init();
new gl.IssuableBulkActions({
2016-12-15 18:02:45 -05:00
prefixId: page === 'projects:merge_requests:index' ? 'merge_request_' : 'issue_',
});
2016-07-24 16:45:11 -04:00
shortcut_handler = new ShortcutsNavigation();
break;
case 'projects:issues:show':
new Issue();
shortcut_handler = new ShortcutsIssuable();
new ZenMode();
break;
case 'projects:milestones:show':
case 'groups:milestones:show':
case 'dashboard:milestones:show':
new Milestone();
break;
case 'dashboard:todos:index':
2016-09-08 09:13:15 -04:00
new gl.Todos();
2016-07-24 16:45:11 -04:00
break;
case 'projects:milestones:new':
case 'projects:milestones:edit':
new ZenMode();
new gl.DueDateSelectors();
new gl.GLForm($('.milestone-form'));
2016-07-24 16:45:11 -04:00
break;
case 'groups:milestones:new':
new ZenMode();
break;
case 'projects:compare:show':
2016-10-25 15:25:46 -04:00
new gl.Diff();
2016-07-24 16:45:11 -04:00
break;
case 'projects:issues:new':
case 'projects:issues:edit':
shortcut_handler = new ShortcutsNavigation();
new gl.GLForm($('.issue-form'));
2016-07-24 16:45:11 -04:00
new IssuableForm($('.issue-form'));
new LabelsSelect();
new MilestoneSelect();
new gl.IssuableTemplateSelectors();
2016-07-24 16:45:11 -04:00
break;
case 'projects:merge_requests:new':
case 'projects:merge_requests:edit':
2016-10-25 15:25:46 -04:00
new gl.Diff();
2016-07-24 16:45:11 -04:00
shortcut_handler = new ShortcutsNavigation();
new gl.GLForm($('.merge-request-form'));
2016-07-24 16:45:11 -04:00
new IssuableForm($('.merge-request-form'));
new LabelsSelect();
new MilestoneSelect();
new gl.IssuableTemplateSelectors();
2016-07-24 16:45:11 -04:00
break;
case 'projects:tags:new':
new ZenMode();
new gl.GLForm($('.tag-form'));
2016-07-24 16:45:11 -04:00
break;
case 'projects:releases:edit':
new ZenMode();
new gl.GLForm($('.release-form'));
2016-07-24 16:45:11 -04:00
break;
case 'projects:merge_requests:show':
2016-10-25 15:25:46 -04:00
new gl.Diff();
2016-07-24 16:45:11 -04:00
shortcut_handler = new ShortcutsIssuable(true);
new ZenMode();
new MergedButtons();
break;
case 'projects:merge_requests:commits':
new MergedButtons();
break;
case "projects:merge_requests:diffs":
2016-10-25 15:25:46 -04:00
new gl.Diff();
2016-07-24 16:45:11 -04:00
new ZenMode();
new MergedButtons();
break;
case 'dashboard:activity':
new gl.Activities();
2016-07-24 16:45:11 -04:00
break;
case 'dashboard:projects:starred':
new gl.Activities();
2016-07-24 16:45:11 -04:00
break;
case 'projects:commit:show':
new Commit();
2016-10-25 15:25:46 -04:00
new gl.Diff();
2016-07-24 16:45:11 -04:00
new ZenMode();
shortcut_handler = new ShortcutsNavigation();
break;
2016-12-19 12:47:45 -05:00
case 'projects:commit:pipelines':
new gl.MiniPipelineGraph({
container: '.js-pipeline-table',
});
break;
2016-07-24 16:45:11 -04:00
case 'projects:commits:show':
case 'projects:activity':
shortcut_handler = new ShortcutsNavigation();
break;
case 'projects:show':
shortcut_handler = new ShortcutsNavigation();
new NotificationsForm();
if ($('#tree-slider').length) {
new TreeView();
}
break;
2016-12-21 06:21:11 -05:00
case 'projects:pipelines:builds':
2016-09-29 17:24:37 -04:00
case 'projects:pipelines:show':
2016-11-29 05:35:53 -05:00
const { controllerAction } = document.querySelector('.js-pipeline-container').dataset;
new gl.Pipelines({
initTabs: true,
tabsOptions: {
action: controllerAction,
defaultAction: 'pipelines',
parentEl: '.pipelines-tabs',
},
});
2016-09-29 17:24:37 -04:00
break;
2016-07-24 16:45:11 -04:00
case 'groups:activity':
new gl.Activities();
2016-07-24 16:45:11 -04:00
break;
case 'groups:show':
shortcut_handler = new ShortcutsNavigation();
new NotificationsForm();
new NotificationsDropdown();
break;
case 'groups:group_members:index':
new gl.MemberExpirationDate();
2016-09-02 09:19:11 -04:00
new gl.Members();
2016-07-24 16:45:11 -04:00
new UsersSelect();
break;
case 'projects:members:show':
new gl.MemberExpirationDate('.js-access-expiration-date-groups');
new GroupsSelect();
new gl.MemberExpirationDate();
2016-09-02 09:19:11 -04:00
new gl.Members();
2016-07-24 16:45:11 -04:00
new UsersSelect();
break;
case 'groups:new':
case 'groups:edit':
case 'admin:groups:edit':
case 'admin:groups:new':
new GroupAvatar();
break;
case 'projects:tree:show':
shortcut_handler = new ShortcutsNavigation();
new TreeView();
break;
case 'projects:find_file:show':
shortcut_handler = true;
break;
case 'projects:blob:show':
case 'projects:blame:show':
new LineHighlighter();
shortcut_handler = new ShortcutsNavigation();
new ShortcutsBlob(true);
break;
2016-09-19 15:49:08 -04:00
case 'groups:labels:new':
case 'groups:labels:edit':
2016-07-24 16:45:11 -04:00
case 'projects:labels:new':
case 'projects:labels:edit':
new Labels();
break;
case 'projects:labels:index':
if ($('.prioritized-labels').length) {
2016-09-12 13:05:47 -04:00
new gl.LabelManager();
2016-07-24 16:45:11 -04:00
}
break;
case 'projects:network:show':
// Ensure we don't create a particular shortcut handler here. This is
// already created, where the network graph is created.
2016-07-24 16:45:11 -04:00
shortcut_handler = true;
break;
case 'projects:forks:new':
new ProjectFork();
break;
case 'projects:artifacts:browse':
new BuildArtifacts();
break;
case 'help:index':
gl.VersionCheckImage.bindErrorEvent($('img.js-version-status-badge'));
break;
2016-07-24 16:45:11 -04:00
case 'search:show':
new Search();
break;
case 'projects:protected_branches:index':
new gl.ProtectedBranchCreate();
new gl.ProtectedBranchEditList();
break;
case 'projects:ci_cd_pipelines:show':
new gl.ProjectVariables();
break;
case 'ci:lints:create':
case 'ci:lints:show':
new gl.CILintEditor();
break;
2016-07-24 16:45:11 -04:00
}
switch (path.first()) {
case 'sessions':
case 'omniauth_callbacks':
if (!gon.u2f) break;
gl.u2fAuthenticate = new gl.U2FAuthenticate(
$('#js-authenticate-u2f'),
'#js-login-u2f-form',
gon.u2f,
document.querySelector('#js-login-2fa-device'),
document.querySelector('.js-2fa-form'),
);
gl.u2fAuthenticate.start();
2016-07-24 16:45:11 -04:00
case 'admin':
new Admin();
switch (path[1]) {
case 'groups':
new UsersSelect();
break;
case 'projects':
new NamespaceSelects();
break;
case 'labels':
switch (path[2]) {
case 'new':
case 'edit':
new Labels();
}
case 'abuse_reports':
2016-08-08 09:04:18 -04:00
new gl.AbuseReports();
break;
2016-07-24 16:45:11 -04:00
}
break;
case 'dashboard':
case 'root':
shortcut_handler = new ShortcutsDashboardNavigation();
break;
case 'profiles':
new NotificationsForm();
new NotificationsDropdown();
break;
case 'projects':
new Project();
new ProjectAvatar();
switch (path[1]) {
case 'compare':
new CompareAutocomplete();
break;
case 'edit':
shortcut_handler = new ShortcutsNavigation();
new ProjectNew();
break;
case 'new':
new ProjectNew();
break;
case 'show':
new Star();
2016-07-24 16:45:11 -04:00
new ProjectNew();
new ProjectShow();
new NotificationsDropdown();
break;
case 'wikis':
new gl.Wikis();
2016-07-24 16:45:11 -04:00
shortcut_handler = new ShortcutsNavigation();
new ZenMode();
new gl.GLForm($('.wiki-form'));
2016-07-24 16:45:11 -04:00
break;
case 'snippets':
shortcut_handler = new ShortcutsNavigation();
if (path[2] === 'show') {
new ZenMode();
}
break;
case 'labels':
case 'graphs':
case 'compare':
case 'pipelines':
case 'forks':
case 'milestones':
case 'project_members':
case 'deploy_keys':
case 'builds':
case 'hooks':
case 'services':
case 'protected_branches':
shortcut_handler = new ShortcutsNavigation();
}
}
// If we haven't installed a custom shortcut handler, install the default one
2016-07-24 16:45:11 -04:00
if (!shortcut_handler) {
new Shortcuts();
2016-07-24 16:45:11 -04:00
}
};
Dispatcher.prototype.initSearch = function() {
// Only when search form is present
2016-07-24 16:45:11 -04:00
if ($('.search').length) {
return new gl.SearchAutocomplete();
2016-07-24 16:45:11 -04:00
}
};
Dispatcher.prototype.initFieldErrors = function() {
$('.gl-show-field-errors').each((i, form) => {
new gl.GlFieldErrors(form);
});
};
2016-07-24 16:45:11 -04:00
return Dispatcher;
})();
}).call(this);