dispatcher.js 25.1 KB
Newer Older
1
/* 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 */
2
import { s__ } from './locale';
3
import projectSelect from './project_select';
Filipa Lacerda's avatar
Filipa Lacerda committed
4
import IssuableIndex from './issuable_index';
5
import Milestone from './milestone';
6
import IssuableForm from './issuable_form';
7
import LabelsSelect from './labels_select';
8
/* global MilestoneSelect */
9
import NewBranchForm from './new_branch_form';
10 11
/* global NotificationsForm */
/* global NotificationsDropdown */
12 13
import groupAvatar from './group_avatar';
import GroupLabelSubscription from './group_label_subscription';
14
/* global LineHighlighter */
15 16
import BuildArtifacts from './build_artifacts';
import CILintEditor from './ci_lint_editor';
17
import groupsSelect from './groups_select';
18 19
/* global Search */
/* global Admin */
20
import NamespaceSelect from './namespace_select';
21
import NewCommitForm from './new_commit_form';
22 23
import Project from './project';
import projectAvatar from './project_avatar';
24 25
/* global MergeRequest */
/* global Compare */
26
/* global CompareAutocomplete */
27
/* global ProjectFindFile */
28
import ProjectNew from './project_new';
29
import projectImport from './project_import';
30 31
import Labels from './labels';
import LabelManager from './label_manager';
32 33
/* global Sidebar */

34
import Flash from './flash';
35
import CommitsList from './commits';
36
import Issue from './issue';
Z.J. van de Weg's avatar
Z.J. van de Weg committed
37
import BindInOut from './behaviors/bind_in_out';
38
import DeleteModal from './branches/branches_delete_modal';
39
import Group from './group';
40
import GroupsList from './groups_list';
41
import ProjectsList from './projects_list';
42
import setupProjectEdit from './project_edit';
43
import MiniPipelineGraph from './mini_pipeline_graph_dropdown';
44
import BlobLinePermalinkUpdater from './blob/blob_line_permalink_updater';
45
import Landing from './landing';
46
import BlobForkSuggestion from './blob/blob_fork_suggestion';
Mike Greiling's avatar
Mike Greiling committed
47
import UserCallout from './user_callout';
geoandri's avatar
geoandri committed
48
import ShortcutsWiki from './shortcuts_wiki';
49
import Pipelines from './pipelines';
Douwe Maan's avatar
Douwe Maan committed
50
import BlobViewer from './blob/viewer/index';
51
import AutoWidthDropdownSelect from './issuable/auto_width_dropdown_select';
52
import UsersSelect from './users_select';
53
import RefSelectDropdown from './ref_select_dropdown';
54
import GfmAutoComplete from './gfm_auto_complete';
55
import ShortcutsBlob from './shortcuts_blob';
56
import SigninTabsMemoizer from './signin_tabs_memoizer';
57
import Star from './star';
58
import Todos from './todos';
59
import TreeView from './tree';
60
import UsagePing from './usage_ping';
61
import UsernameValidator from './username_validator';
62
import VersionCheckImage from './version_check_image';
63
import Wikis from './wikis';
64
import ZenMode from './zen_mode';
65
import initSettingsPanels from './settings_panels';
66
import initExperimentalFlags from './experimental_flags';
67
import OAuthRememberMe from './oauth_remember_me';
68
import PerformanceBar from './performance_bar';
69
import initBroadcastMessagesForm from './broadcast_message';
70 71 72
import initNotes from './init_notes';
import initLegacyFilters from './init_legacy_filters';
import initIssuableSidebar from './init_issuable_sidebar';
73
import initProjectVisibilitySelector from './project_visibility';
74
import GpgBadges from './gpg_badges';
75
import UserFeatureHelper from './helpers/user_feature_helper';
76
import initChangesDropdown from './init_changes_dropdown';
77
import NewGroupChild from './groups/new_group_child';
78
import AbuseReports from './abuse_reports';
79
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
80
import AjaxLoadingSpinner from './ajax_loading_spinner';
81 82
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
83 84 85 86
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsFindFile from './shortcuts_find_file';
import ShortcutsIssuable from './shortcuts_issuable';
87
import U2FAuthenticate from './u2f/authenticate';
88 89
import Members from './members';
import memberExpirationDate from './member_expiration_date';
Filipa Lacerda's avatar
Filipa Lacerda committed
90
import DueDateSelectors from './due_date_select';
91
import Diff from './diff';
92 93
import ProjectLabelSubscription from './project_label_subscription';
import ProjectVariables from './project_variables';
94

Fatih Acet's avatar
Fatih Acet committed
95 96 97 98 99 100
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
101
      this.initFieldErrors();
Fatih Acet's avatar
Fatih Acet committed
102 103 104 105
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
106 107
      var path, shortcut_handler, fileBlobPermalinkUrlElement, fileBlobPermalinkUrl;
      const page = $('body').attr('data-page');
Fatih Acet's avatar
Fatih Acet committed
108 109 110
      if (!page) {
        return false;
      }
111

Fatih Acet's avatar
Fatih Acet committed
112 113
      path = page.split(':');
      shortcut_handler = null;
114

115
      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
116
        const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
117
        const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
118 119 120 121 122 123 124 125 126
        gfm.setup($(el), {
          emojis: true,
          members: enableGFM,
          issues: enableGFM,
          milestones: enableGFM,
          mergeRequests: enableGFM,
          labels: enableGFM,
        });
      });
127

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
      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,
        });
144

145 146 147 148 149 150
        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'),
151 152
        })
          .init();
153 154
      }

155 156
      const filteredSearchEnabled = gl.FilteredSearchManager && document.querySelector('.filtered-search');

Fatih Acet's avatar
Fatih Acet committed
157
      switch (page) {
158 159 160
        case 'profiles:preferences:show':
          initExperimentalFlags();
          break;
161 162
        case 'sessions:new':
          new UsernameValidator();
163
          new SigninTabsMemoizer();
164
          new OAuthRememberMe({ container: $(".omniauth-container") }).bindEvents();
165
          break;
166
        case 'projects:boards:show':
167
        case 'projects:boards:index':
168
          shortcut_handler = new ShortcutsNavigation();
169
          new UsersSelect();
170
          break;
171
        case 'projects:merge_requests:index':
Fatih Acet's avatar
Fatih Acet committed
172
        case 'projects:issues:index':
173
          if (filteredSearchEnabled) {
174 175
            const filteredSearchManager = new gl.FilteredSearchManager(page === 'projects:issues:index' ? 'issues' : 'merge_requests');
            filteredSearchManager.setup();
Clement Ho's avatar
Clement Ho committed
176
          }
177
          const pagePrefix = page === 'projects:merge_requests:index' ? 'merge_request_' : 'issue_';
Filipa Lacerda's avatar
Filipa Lacerda committed
178
          new IssuableIndex(pagePrefix);
179

Fatih Acet's avatar
Fatih Acet committed
180
          shortcut_handler = new ShortcutsNavigation();
181
          new UsersSelect();
Fatih Acet's avatar
Fatih Acet committed
182 183 184 185 186
          break;
        case 'projects:issues:show':
          new Issue();
          shortcut_handler = new ShortcutsIssuable();
          new ZenMode();
187
          initIssuableSidebar();
Fatih Acet's avatar
Fatih Acet committed
188
          break;
Phil Hughes's avatar
Phil Hughes committed
189
        case 'dashboard:milestones:index':
190
          projectSelect();
Phil Hughes's avatar
Phil Hughes committed
191
          break;
Fatih Acet's avatar
Fatih Acet committed
192 193 194 195
        case 'projects:milestones:show':
        case 'groups:milestones:show':
        case 'dashboard:milestones:show':
          new Milestone();
196
          new Sidebar();
Fatih Acet's avatar
Fatih Acet committed
197
          break;
198 199
        case 'dashboard:issues':
        case 'dashboard:merge_requests':
200
          projectSelect();
201
          initLegacyFilters();
202
          break;
203
        case 'groups:issues':
204
        case 'groups:merge_requests':
205
          if (filteredSearchEnabled) {
206
            const filteredSearchManager = new gl.FilteredSearchManager(page === 'groups:issues' ? 'issues' : 'merge_requests');
207 208
            filteredSearchManager.setup();
          }
209
          projectSelect();
210
          break;
Fatih Acet's avatar
Fatih Acet committed
211
        case 'dashboard:todos:index':
212
          new Todos();
Fatih Acet's avatar
Fatih Acet committed
213
          break;
214 215 216 217 218 219 220 221
        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;
222 223
        case 'explore:groups:index':
          new GroupsList();
224 225 226 227 228 229 230 231
          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();
232
          break;
Fatih Acet's avatar
Fatih Acet committed
233 234
        case 'projects:milestones:new':
        case 'projects:milestones:edit':
235
        case 'projects:milestones:update':
236 237 238 239
          new ZenMode();
          new DueDateSelectors();
          new GLForm($('.milestone-form'), true);
          break;
240 241 242
        case 'groups:milestones:new':
        case 'groups:milestones:edit':
        case 'groups:milestones:update':
Fatih Acet's avatar
Fatih Acet committed
243
          new ZenMode();
Filipa Lacerda's avatar
Filipa Lacerda committed
244
          new DueDateSelectors();
245
          new GLForm($('.milestone-form'), false);
Fatih Acet's avatar
Fatih Acet committed
246 247
          break;
        case 'projects:compare:show':
248
          new Diff();
249 250
          const paddingTop = 16;
          initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight - paddingTop);
Fatih Acet's avatar
Fatih Acet committed
251
          break;
252 253 254 255
        case 'projects:branches:new':
        case 'projects:branches:create':
          new NewBranchForm($('.js-create-branch-form'), JSON.parse(document.getElementById('availableRefs').innerHTML));
          break;
256
        case 'projects:branches:index':
257
          AjaxLoadingSpinner.init();
258
          new DeleteModal();
259
          break;
Fatih Acet's avatar
Fatih Acet committed
260 261 262
        case 'projects:issues:new':
        case 'projects:issues:edit':
          shortcut_handler = new ShortcutsNavigation();
263
          new GLForm($('.issue-form'), true);
Fatih Acet's avatar
Fatih Acet committed
264
          new IssuableForm($('.issue-form'));
265 266
          new LabelsSelect();
          new MilestoneSelect();
267
          new gl.IssuableTemplateSelectors();
Fatih Acet's avatar
Fatih Acet committed
268
          break;
269
        case 'projects:merge_requests:creations:new':
270 271 272 273 274 275 276 277 278 279 280 281 282
          const mrNewCompareNode = document.querySelector('.js-merge-request-new-compare');
          if (mrNewCompareNode) {
            new Compare({
              targetProjectUrl: mrNewCompareNode.dataset.targetProjectUrl,
              sourceBranchUrl: mrNewCompareNode.dataset.sourceBranchUrl,
              targetBranchUrl: mrNewCompareNode.dataset.targetBranchUrl,
            });
          } else {
            const mrNewSubmitNode = document.querySelector('.js-merge-request-new-submit');
            new MergeRequest({
              action: mrNewSubmitNode.dataset.mrSubmitAction,
            });
          }
283
        case 'projects:merge_requests:creations:diffs':
Fatih Acet's avatar
Fatih Acet committed
284
        case 'projects:merge_requests:edit':
285
          new Diff();
Fatih Acet's avatar
Fatih Acet committed
286
          shortcut_handler = new ShortcutsNavigation();
287
          new GLForm($('.merge-request-form'), true);
Fatih Acet's avatar
Fatih Acet committed
288
          new IssuableForm($('.merge-request-form'));
289 290
          new LabelsSelect();
          new MilestoneSelect();
291
          new gl.IssuableTemplateSelectors();
292
          new AutoWidthDropdownSelect($('.js-target-branch-select')).init();
Fatih Acet's avatar
Fatih Acet committed
293 294 295
          break;
        case 'projects:tags:new':
          new ZenMode();
296
          new GLForm($('.tag-form'), true);
297
          new RefSelectDropdown($('.js-branch-select'));
Fatih Acet's avatar
Fatih Acet committed
298
          break;
299 300 301
        case 'projects:snippets:show':
          initNotes();
          break;
302 303 304 305
        case 'projects:snippets:new':
        case 'projects:snippets:edit':
        case 'projects:snippets:create':
        case 'projects:snippets:update':
306
          new GLForm($('.snippet-form'), true);
307
          break;
308 309 310 311
        case 'snippets:new':
        case 'snippets:edit':
        case 'snippets:create':
        case 'snippets:update':
312
          new GLForm($('.snippet-form'), false);
313
          break;
Fatih Acet's avatar
Fatih Acet committed
314 315
        case 'projects:releases:edit':
          new ZenMode();
316
          new GLForm($('.release-form'), true);
Fatih Acet's avatar
Fatih Acet committed
317 318
          break;
        case 'projects:merge_requests:show':
319
          new Diff();
Fatih Acet's avatar
Fatih Acet committed
320
          new ZenMode();
321

322 323
          initIssuableSidebar();
          initNotes();
324

325 326 327 328
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
329 330

          shortcut_handler = new ShortcutsIssuable(true);
Fatih Acet's avatar
Fatih Acet committed
331 332
          break;
        case 'dashboard:activity':
333
          new gl.Activities();
Fatih Acet's avatar
Fatih Acet committed
334 335
          break;
        case 'projects:commit:show':
336
          new Diff();
Fatih Acet's avatar
Fatih Acet committed
337 338
          new ZenMode();
          shortcut_handler = new ShortcutsNavigation();
339 340 341
          new MiniPipelineGraph({
            container: '.js-commit-pipeline-graph',
          }).bindEvents();
342
          initNotes();
343 344
          const stickyBarPaddingTop = 16;
          initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight - stickyBarPaddingTop);
345
          $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
Fatih Acet's avatar
Fatih Acet committed
346
          break;
347
        case 'projects:commit:pipelines':
348
          new MiniPipelineGraph({
349
            container: '.js-commit-pipeline-graph',
350
          }).bindEvents();
351
          $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
352
          break;
353 354
        case 'projects:activity':
          new gl.Activities();
355 356
          shortcut_handler = new ShortcutsNavigation();
          break;
357 358
        case 'projects:commits:show':
          CommitsList.init(document.querySelector('.js-project-commits-show').dataset.commitsLimit);
Fatih Acet's avatar
Fatih Acet committed
359
          shortcut_handler = new ShortcutsNavigation();
360
          GpgBadges.fetch();
Fatih Acet's avatar
Fatih Acet committed
361 362 363 364
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
365 366 367 368
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
369 370

          if ($('#tree-slider').length) new TreeView();
371
          if ($('.blob-viewer').length) new BlobViewer();
372
          if ($('.project-show-activity').length) new gl.Activities();
373
          $('#tree-slider').waitForImages(function() {
374
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
375
          });
Fatih Acet's avatar
Fatih Acet committed
376
          break;
377
        case 'projects:edit':
378
          setupProjectEdit();
379 380
          // Initialize expandable settings panels
          initSettingsPanels();
381
          break;
382
        case 'projects:imports:show':
383
          projectImport();
384
          break;
385
        case 'projects:pipelines:new':
386
        case 'projects:pipelines:create':
387
          new NewBranchForm($('.js-new-pipeline-form'));
388
          break;
Filipa Lacerda's avatar
Filipa Lacerda committed
389
        case 'projects:pipelines:builds':
390
        case 'projects:pipelines:failures':
Luke Bennett's avatar
Luke Bennett committed
391
        case 'projects:pipelines:show':
Filipa Lacerda's avatar
Filipa Lacerda committed
392
          const { controllerAction } = document.querySelector('.js-pipeline-container').dataset;
393
          const pipelineStatusUrl = `${document.querySelector('.js-pipeline-tab-link a').getAttribute('href')}/status.json`;
Filipa Lacerda's avatar
Filipa Lacerda committed
394

395
          new Pipelines({
Filipa Lacerda's avatar
Filipa Lacerda committed
396
            initTabs: true,
397
            pipelineStatusUrl,
Filipa Lacerda's avatar
Filipa Lacerda committed
398 399 400 401 402 403
            tabsOptions: {
              action: controllerAction,
              defaultAction: 'pipelines',
              parentEl: '.pipelines-tabs',
            },
          });
Luke Bennett's avatar
Luke Bennett committed
404
          break;
Fatih Acet's avatar
Fatih Acet committed
405
        case 'groups:activity':
406
          new gl.Activities();
Fatih Acet's avatar
Fatih Acet committed
407 408
          break;
        case 'groups:show':
409
          const newGroupChildWrapper = document.querySelector('.js-new-project-subgroup');
Fatih Acet's avatar
Fatih Acet committed
410 411 412
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
          new NotificationsDropdown();
413
          new ProjectsList();
414 415 416 417

          if (newGroupChildWrapper) {
            new NewGroupChild(newGroupChildWrapper);
          }
Fatih Acet's avatar
Fatih Acet committed
418 419
          break;
        case 'groups:group_members:index':
420 421
          memberExpirationDate();
          new Members();
Fatih Acet's avatar
Fatih Acet committed
422 423
          new UsersSelect();
          break;
424
        case 'projects:project_members:index':
425
          memberExpirationDate('.js-access-expiration-date-groups');
426
          groupsSelect();
427 428
          memberExpirationDate();
          new Members();
Fatih Acet's avatar
Fatih Acet committed
429 430 431
          new UsersSelect();
          break;
        case 'groups:new':
Luke "Jared" Bennett's avatar
Luke "Jared" Bennett committed
432
        case 'admin:groups:new':
433 434
        case 'groups:create':
        case 'admin:groups:create':
Z.J. van de Weg's avatar
Z.J. van de Weg committed
435
          BindInOut.initAll();
436
          new Group();
437
          groupAvatar();
438
          break;
Fatih Acet's avatar
Fatih Acet committed
439 440
        case 'groups:edit':
        case 'admin:groups:edit':
441
          groupAvatar();
Fatih Acet's avatar
Fatih Acet committed
442
          break;
443 444 445
        case 'projects:tree:show':
          shortcut_handler = new ShortcutsNavigation();

446
          if (UserFeatureHelper.isNewRepoEnabled()) break;
447 448 449

          new TreeView();
          new BlobViewer();
450
          new NewCommitForm($('.js-create-dir-form'));
451
          $('#tree-slider').waitForImages(function() {
452
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
453
          });
454
          break;
Fatih Acet's avatar
Fatih Acet committed
455
        case 'projects:find_file:show':
456 457 458 459 460 461 462
          const findElement = document.querySelector('.js-file-finder');
          const projectFindFile = new ProjectFindFile($(".file-finder-holder"), {
            url: findElement.dataset.fileFindUrl,
            treeUrl: findElement.dataset.findTreeUrl,
            blobUrlTemplate: findElement.dataset.blobUrlTemplate,
          });
          new ShortcutsFindFile(projectFindFile);
Fatih Acet's avatar
Fatih Acet committed
463 464
          shortcut_handler = true;
          break;
465
        case 'projects:blob:show':
466
          if (UserFeatureHelper.isNewRepoEnabled()) break;
467 468 469
          new BlobViewer();
          initBlob();
          break;
Fatih Acet's avatar
Fatih Acet committed
470
        case 'projects:blame:show':
471
          initBlob();
Fatih Acet's avatar
Fatih Acet committed
472
          break;
473 474
        case 'groups:labels:new':
        case 'groups:labels:edit':
Fatih Acet's avatar
Fatih Acet committed
475 476 477 478
        case 'projects:labels:new':
        case 'projects:labels:edit':
          new Labels();
          break;
479
        case 'groups:labels:index':
Fatih Acet's avatar
Fatih Acet committed
480 481
        case 'projects:labels:index':
          if ($('.prioritized-labels').length) {
482
            new LabelManager();
Fatih Acet's avatar
Fatih Acet committed
483
          }
484 485 486 487
          $('.label-subscription').each((i, el) => {
            const $el = $(el);

            if ($el.find('.dropdown-group-label').length) {
488
              new GroupLabelSubscription($el);
489
            } else {
490
              new ProjectLabelSubscription($el);
491 492
            }
          });
Fatih Acet's avatar
Fatih Acet committed
493 494
          break;
        case 'projects:network:show':
495 496
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
Fatih Acet's avatar
Fatih Acet committed
497 498 499
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
500 501 502
          import(/* webpackChunkName: 'project_fork' */ './project_fork')
            .then(fork => fork.default())
            .catch(() => {});
Fatih Acet's avatar
Fatih Acet committed
503 504
          break;
        case 'projects:artifacts:browse':
505
          new ShortcutsNavigation();
Fatih Acet's avatar
Fatih Acet committed
506 507
          new BuildArtifacts();
          break;
508
        case 'projects:artifacts:file':
509
          new ShortcutsNavigation();
510 511
          new BlobViewer();
          break;
512
        case 'help:index':
513
          VersionCheckImage.bindErrorEvent($('img.js-version-status-badge'));
514
          break;
Fatih Acet's avatar
Fatih Acet committed
515 516
        case 'search:show':
          new Search();
517
          break;
518
        case 'projects:settings:repository:show':
519 520
          // Initialize expandable settings panels
          initSettingsPanels();
521
          break;
522
        case 'projects:settings:ci_cd:show':
523 524
          // Initialize expandable settings panels
          initSettingsPanels();
525 526 527 528 529 530 531

          import(/* webpackChunkName: "ci-cd-settings" */ './projects/ci_cd_settings_bundle')
            .then(ciCdSettings => ciCdSettings.default())
            .catch((err) => {
              Flash(s__('ProjectSettings|Problem setting up the CI/CD settings JavaScript'));
              throw err;
            });
Shinya Maeda's avatar
Shinya Maeda committed
532
        case 'groups:settings:ci_cd:show':
533
          new ProjectVariables();
534
          break;
535 536
        case 'ci:lints:create':
        case 'ci:lints:show':
537
          new CILintEditor();
538
          break;
539 540 541
        case 'users:show':
          new UserCallout();
          break;
542 543 544
        case 'admin:conversational_development_index:show':
          new UserCallout();
          break;
Douwe Maan's avatar
Douwe Maan committed
545 546 547
        case 'snippets:show':
          new LineHighlighter();
          new BlobViewer();
548
          initNotes();
Douwe Maan's avatar
Douwe Maan committed
549
          break;
550 551 552
        case 'import:fogbugz:new_user_map':
          new UsersSelect();
          break;
553 554
        case 'profiles:personal_access_tokens:index':
        case 'admin:impersonation_tokens:index':
Filipa Lacerda's avatar
Filipa Lacerda committed
555
          new DueDateSelectors();
556
          break;
Filipa Lacerda's avatar
Filipa Lacerda committed
557
        case 'projects:clusters:show':
558
          import(/* webpackChunkName: "clusters" */ './clusters/clusters_bundle')
Filipa Lacerda's avatar
Filipa Lacerda committed
559
            .then(cluster => new cluster.default()) // eslint-disable-line new-cap
560 561 562 563
            .catch((err) => {
              Flash(s__('ClusterIntegration|Problem setting up the cluster JavaScript'));
              throw err;
            });
Filipa Lacerda's avatar
Filipa Lacerda committed
564
          break;
Fatih Acet's avatar
Fatih Acet committed
565
      }
566
      switch (path[0]) {
567 568 569
        case 'sessions':
        case 'omniauth_callbacks':
          if (!gon.u2f) break;
570
          const u2fAuthenticate = new U2FAuthenticate(
571 572 573 574 575 576
            $('#js-authenticate-u2f'),
            '#js-login-u2f-form',
            gon.u2f,
            document.querySelector('#js-login-2fa-device'),
            document.querySelector('.js-2fa-form'),
          );
577 578 579
          u2fAuthenticate.start();
          // needed in rspec
          gl.u2fAuthenticate = u2fAuthenticate;
Fatih Acet's avatar
Fatih Acet committed
580 581 582
        case 'admin':
          new Admin();
          switch (path[1]) {
583 584 585
            case 'broadcast_messages':
              initBroadcastMessagesForm();
              break;
586
            case 'cohorts':
587
              new UsagePing();
588
              break;
Fatih Acet's avatar
Fatih Acet committed
589 590 591 592
            case 'groups':
              new UsersSelect();
              break;
            case 'projects':
593 594
              document.querySelectorAll('.js-namespace-select')
                .forEach(dropdown => new NamespaceSelect({ dropdown }));
595 596
              break;
            case 'labels':
597
              switch (path[2]) {
598
                case 'new':
599 600 601
                case 'edit':
                  new Labels();
              }
602
            case 'abuse_reports':
603
              new AbuseReports();
604
              break;
Fatih Acet's avatar
Fatih Acet committed
605 606 607 608
          }
          break;
        case 'dashboard':
        case 'root':
609
          new UserCallout();
Fatih Acet's avatar
Fatih Acet committed
610 611 612 613 614 615 616
          break;
        case 'profiles':
          new NotificationsForm();
          new NotificationsDropdown();
          break;
        case 'projects':
          new Project();
617
          projectAvatar();
Fatih Acet's avatar
Fatih Acet committed
618 619 620 621 622 623 624
          switch (path[1]) {
            case 'compare':
              new CompareAutocomplete();
              break;
            case 'edit':
              shortcut_handler = new ShortcutsNavigation();
              new ProjectNew();
625 626 627
              import(/* webpackChunkName: 'project_permissions' */ './projects/permissions')
                .then(permissions => permissions.default())
                .catch(() => {});
Fatih Acet's avatar
Fatih Acet committed
628 629 630
              break;
            case 'new':
              new ProjectNew();
631
              initProjectVisibilitySelector();
Fatih Acet's avatar
Fatih Acet committed
632 633
              break;
            case 'show':
634
              new Star();
Fatih Acet's avatar
Fatih Acet committed
635 636 637 638
              new ProjectNew();
              new NotificationsDropdown();
              break;
            case 'wikis':
639
              new Wikis();
640
              shortcut_handler = new ShortcutsWiki();
Fatih Acet's avatar
Fatih Acet committed
641
              new ZenMode();
642
              new GLForm($('.wiki-form'), true);
Fatih Acet's avatar
Fatih Acet committed
643 644 645 646 647
              break;
            case 'snippets':
              shortcut_handler = new ShortcutsNavigation();
              if (path[2] === 'show') {
                new ZenMode();
Douwe Maan's avatar
Douwe Maan committed
648 649
                new LineHighlighter();
                new BlobViewer();
Fatih Acet's avatar
Fatih Acet committed
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
              }
              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();
          }
666
          break;
Fatih Acet's avatar
Fatih Acet committed
667
      }
668
      // If we haven't installed a custom shortcut handler, install the default one
Fatih Acet's avatar
Fatih Acet committed
669
      if (!shortcut_handler) {
670
        new Shortcuts();
Fatih Acet's avatar
Fatih Acet committed
671
      }
672 673 674 675

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
Fatih Acet's avatar
Fatih Acet committed
676 677 678
    };

    Dispatcher.prototype.initSearch = function() {
679
      // Only when search form is present
Fatih Acet's avatar
Fatih Acet committed
680
      if ($('.search').length) {
681
        return new gl.SearchAutocomplete();
Fatih Acet's avatar
Fatih Acet committed
682 683 684
      }
    };

685
    Dispatcher.prototype.initFieldErrors = function() {
686
      $('.gl-show-field-errors').each((i, form) => {
687
        new GlFieldErrors(form);
688
      });
689 690
    };

Fatih Acet's avatar
Fatih Acet committed
691 692
    return Dispatcher;
  })();
693

694
  $(window).on('load', function() {
695 696
    new Dispatcher();
  });
697
}).call(window);