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

517 lines
17 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 ShortcutsIssuable */
/* global ZenMode */
/* global Milestone */
/* global IssuableForm */
/* global LabelsSelect */
/* global MilestoneSelect */
/* global Commit */
/* global NotificationsForm */
/* global TreeView */
/* global NotificationsDropdown */
/* global GroupAvatar */
/* global LineHighlighter */
/* global ProjectFork */
/* global BuildArtifacts */
/* global GroupsSelect */
/* global Search */
/* global Admin */
/* global NamespaceSelects */
/* global Project */
/* global ProjectAvatar */
/* global CompareAutocomplete */
/* global ProjectNew */
/* global Star */
/* global ProjectShow */
/* global Labels */
/* global Shortcuts */
/* global Sidebar */
2017-03-26 16:16:55 -04:00
/* global ShortcutsWiki */
2017-03-01 14:54:04 -05:00
import Issue from './issue';
2017-03-06 08:06:33 -05:00
import BindInOut from './behaviors/bind_in_out';
import DeleteModal from './branches/branches_delete_modal';
import Group from './group';
2017-02-28 21:59:55 -05:00
import GroupName from './group_name';
2017-03-02 06:05:48 -05:00
import GroupsList from './groups_list';
import ProjectsList from './projects_list';
import MiniPipelineGraph from './mini_pipeline_graph_dropdown';
import BlobLinePermalinkUpdater from './blob/blob_line_permalink_updater';
2017-05-02 04:05:43 -04:00
import Landing from './landing';
2017-04-06 12:36:38 -04:00
import BlobForkSuggestion from './blob/blob_fork_suggestion';
2017-03-22 04:26:12 -04:00
import UserCallout from './user_callout';
2017-04-06 04:48:03 -04:00
import { ProtectedTagCreate, ProtectedTagEditList } from './protected_tags';
2017-03-29 07:47:34 -04:00
import ShortcutsWiki from './shortcuts_wiki';
import Pipelines from './pipelines';
2017-04-13 13:05:09 -04:00
import BlobViewer from './blob/viewer/index';
import AutoWidthDropdownSelect from './issuable/auto_width_dropdown_select';
2017-05-12 04:15:28 -04:00
import UsersSelect from './users_select';
import RefSelectDropdown from './ref_select_dropdown';
import GfmAutoComplete from './gfm_auto_complete';
const ShortcutsBlob = require('./shortcuts_blob');
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, fileBlobPermalinkUrlElement, fileBlobPermalinkUrl;
2016-07-24 16:45:11 -04:00
page = $('body').attr('data-page');
if (!page) {
return false;
}
path = page.split(':');
shortcut_handler = null;
new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources).setup();
function initBlob() {
new LineHighlighter();
new BlobLinePermalinkUpdater(
document.querySelector('#blob-content-holder'),
'.diff-line-num[data-line-number]',
document.querySelectorAll('.js-data-file-blob-permalink-url, .js-blob-blame-link'),
);
shortcut_handler = new ShortcutsNavigation();
fileBlobPermalinkUrlElement = document.querySelector('.js-data-file-blob-permalink-url');
fileBlobPermalinkUrl = fileBlobPermalinkUrlElement && fileBlobPermalinkUrlElement.getAttribute('href');
new ShortcutsBlob({
skipResetBindings: true,
fileBlobPermalinkUrl,
});
2017-04-06 12:36:38 -04:00
new BlobForkSuggestion({
openButtons: document.querySelectorAll('.js-edit-blob-link-fork-toggler'),
forkButtons: document.querySelectorAll('.js-fork-suggestion-button'),
cancelButtons: document.querySelectorAll('.js-cancel-fork-suggestion-button'),
suggestionSections: document.querySelectorAll('.js-file-fork-suggestion-section'),
actionTextPieces: document.querySelectorAll('.js-file-fork-suggestion-section-action'),
})
.init();
}
2016-07-24 16:45:11 -04:00
switch (page) {
case 'sessions:new':
new UsernameValidator();
new ActiveTabMemoizer();
break;
case 'projects:boards:show':
case 'projects:boards:index':
shortcut_handler = new ShortcutsNavigation();
2017-05-12 04:15:28 -04:00
new UsersSelect();
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) {
2017-02-15 17:13:53 -05:00
new gl.FilteredSearchManager(page === 'projects:issues:index' ? 'issues' : 'merge_requests');
2016-11-04 17:27:11 -04:00
}
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();
2017-05-12 04:15:28 -04:00
new UsersSelect();
2016-07-24 16:45:11 -04:00
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();
new Sidebar();
2016-07-24 16:45:11 -04:00
break;
2017-05-12 04:15:28 -04:00
case 'groups:issues':
case 'groups:merge_requests':
new UsersSelect();
break;
2016-07-24 16:45:11 -04:00
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 'dashboard:projects:index':
case 'dashboard:projects:starred':
case 'explore:projects:index':
case 'explore:projects:trending':
case 'explore:projects:starred':
case 'admin:projects:index':
new ProjectsList();
break;
2017-03-02 06:05:48 -05:00
case 'dashboard:groups:index':
2017-05-02 04:05:43 -04:00
new GroupsList();
break;
2017-03-02 06:05:48 -05:00
case 'explore:groups:index':
new GroupsList();
2017-05-02 04:05:43 -04:00
const landingElement = document.querySelector('.js-explore-groups-landing');
if (!landingElement) break;
const exploreGroupsLanding = new Landing(
landingElement,
landingElement.querySelector('.dismiss-button'),
'explore_groups_landing_dismissed',
);
exploreGroupsLanding.toggle();
2017-03-02 06:05:48 -05:00
break;
2016-07-24 16:45:11 -04:00
case 'projects:milestones:new':
case 'projects:milestones:edit':
2017-01-04 08:16:14 -05:00
case 'projects:milestones:update':
case 'groups:milestones:new':
case 'groups:milestones:edit':
case 'groups:milestones:update':
2016-07-24 16:45:11 -04:00
new ZenMode();
new gl.DueDateSelectors();
new gl.GLForm($('.milestone-form'));
2016-07-24 16:45:11 -04:00
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:branches:index':
gl.AjaxLoadingSpinner.init();
new DeleteModal();
break;
2016-07-24 16:45:11 -04:00
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:new_diffs':
2016-07-24 16:45:11 -04:00
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();
new AutoWidthDropdownSelect($('.js-target-branch-select')).init();
2016-07-24 16:45:11 -04:00
break;
case 'projects:tags:new':
new ZenMode();
new gl.GLForm($('.tag-form'));
new RefSelectDropdown($('.js-branch-select'), window.gl.availableRefs);
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();
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();
break;
case 'dashboard:activity':
new gl.Activities();
2016-07-24 16:45:11 -04:00
break;
2017-05-12 04:15:28 -04:00
case 'dashboard:issues':
case 'dashboard:merge_requests':
new UsersSelect();
break;
2016-07-24 16:45:11 -04:00
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();
new MiniPipelineGraph({
container: '.js-commit-pipeline-graph',
}).bindEvents();
2016-07-24 16:45:11 -04:00
break;
case 'projects:commit:pipelines':
new MiniPipelineGraph({
container: '.js-commit-pipeline-graph',
}).bindEvents();
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();
2017-05-08 19:52:05 -04:00
new BlobViewer();
2016-07-24 16:45:11 -04:00
}
break;
2016-12-21 06:21:11 -05:00
case 'projects:pipelines:builds':
case 'projects:pipelines:failures':
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;
const pipelineStatusUrl = `${document.querySelector('.js-pipeline-tab-link a').getAttribute('href')}/status.json`;
new Pipelines({
initTabs: true,
pipelineStatusUrl,
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();
new ProjectsList();
2016-07-24 16:45:11 -04:00
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':
2017-02-28 11:32:30 -05:00
case 'admin:groups:new':
case 'groups:create':
case 'admin:groups:create':
2017-03-03 03:01:54 -05:00
BindInOut.initAll();
new Group();
new GroupAvatar();
break;
2016-07-24 16:45:11 -04:00
case 'groups:edit':
case 'admin:groups:edit':
new GroupAvatar();
break;
case 'projects:tree:show':
shortcut_handler = new ShortcutsNavigation();
new TreeView();
2017-05-08 19:52:05 -04:00
new BlobViewer();
gl.TargetBranchDropDown.bootstrap();
2016-07-24 16:45:11 -04:00
break;
case 'projects:find_file:show':
shortcut_handler = true;
break;
case 'projects:blob:new':
gl.TargetBranchDropDown.bootstrap();
break;
case 'projects:blob:create':
gl.TargetBranchDropDown.bootstrap();
break;
2016-07-24 16:45:11 -04:00
case 'projects:blob:show':
2017-04-13 13:05:09 -04:00
new BlobViewer();
gl.TargetBranchDropDown.bootstrap();
initBlob();
break;
case 'projects:blob:edit':
gl.TargetBranchDropDown.bootstrap();
break;
2016-07-24 16:45:11 -04:00
case 'projects:blame:show':
initBlob();
2016-07-24 16:45:11 -04:00
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 'projects:artifacts:file':
new BlobViewer();
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:repository:show':
// Initialize Protected Branch Settings
new gl.ProtectedBranchCreate();
new gl.ProtectedBranchEditList();
// Initialize Protected Tag Settings
2017-04-06 04:48:03 -04:00
new ProtectedTagCreate();
new ProtectedTagEditList();
break;
2017-01-23 19:51:16 -05:00
case 'projects:ci_cd:show':
new gl.ProjectVariables();
break;
case 'ci:lints:create':
case 'ci:lints:show':
new gl.CILintEditor();
break;
case 'users:show':
new UserCallout();
break;
2017-04-13 12:47:28 -04:00
case 'snippets:show':
new LineHighlighter();
new BlobViewer();
break;
2017-05-12 04:15:28 -04:00
case 'import:fogbugz:new_user_map':
new UsersSelect();
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]) {
2017-04-05 06:24:15 -04:00
case 'cohorts':
2017-04-17 10:54:10 -04:00
new gl.UsagePing();
break;
2016-07-24 16:45:11 -04:00
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':
new UserCallout();
2016-07-24 16:45:11 -04:00
break;
2017-02-28 21:59:55 -05:00
case 'groups':
new GroupName();
break;
2016-07-24 16:45:11 -04:00
case 'profiles':
new NotificationsForm();
new NotificationsDropdown();
break;
case 'projects':
new Project();
new ProjectAvatar();
2017-02-28 21:59:55 -05:00
new GroupName();
2016-07-24 16:45:11 -04:00
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();
2017-03-26 16:16:55 -04:00
shortcut_handler = new ShortcutsWiki();
2016-07-24 16:45:11 -04:00
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();
2017-04-13 12:47:28 -04:00
new LineHighlighter();
new BlobViewer();
2016-07-24 16:45:11 -04:00
}
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(window);