dispatcher.js 27.0 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';
F
Filipa Lacerda 已提交
4
import IssuableIndex from './issuable_index';
F
Filipa Lacerda 已提交
5
import Milestone from './milestone';
6
import IssuableForm from './issuable_form';
7
import LabelsSelect from './labels_select';
C
Constance Okoghenun 已提交
8
import MilestoneSelect from './milestone_select';
F
Filipa Lacerda 已提交
9
import NewBranchForm from './new_branch_form';
P
Phil Hughes 已提交
10 11
import NotificationsForm from './notifications_form';
import notificationsDropdown from './notifications_dropdown';
12 13
import groupAvatar from './group_avatar';
import GroupLabelSubscription from './group_label_subscription';
P
Phil Hughes 已提交
14
import LineHighlighter from './line_highlighter';
F
Filipa Lacerda 已提交
15
import NewCommitForm from './new_commit_form';
16 17
import Project from './project';
import projectAvatar from './project_avatar';
P
Phil Hughes 已提交
18
import MergeRequest from './merge_request';
19
import Compare from './compare';
20
import initCompareAutocomplete from './compare_autocomplete';
F
Filipa Lacerda 已提交
21
import ProjectFindFile from './project_find_file';
22
import ProjectNew from './project_new';
23
import projectImport from './project_import';
24 25
import Labels from './labels';
import LabelManager from './label_manager';
P
Phil Hughes 已提交
26
import Sidebar from './right_sidebar';
27
import IssuableTemplateSelectors from './templates/issuable_template_selectors';
28
import Flash from './flash';
29
import CommitsList from './commits';
30
import Issue from './issue';
Z
Z.J. van de Weg 已提交
31
import BindInOut from './behaviors/bind_in_out';
32
import SecretValues from './behaviors/secret_values';
33
import DeleteModal from './branches/branches_delete_modal';
34
import Group from './group';
35
import ProjectsList from './projects_list';
36
import setupProjectEdit from './project_edit';
37
import MiniPipelineGraph from './mini_pipeline_graph_dropdown';
38
import BlobLinePermalinkUpdater from './blob/blob_line_permalink_updater';
E
Eric Eastwood 已提交
39
import BlobForkSuggestion from './blob/blob_fork_suggestion';
M
Mike Greiling 已提交
40
import UserCallout from './user_callout';
G
geoandri 已提交
41
import ShortcutsWiki from './shortcuts_wiki';
D
Douwe Maan 已提交
42
import BlobViewer from './blob/viewer/index';
43
import AutoWidthDropdownSelect from './issuable/auto_width_dropdown_select';
44
import UsersSelect from './users_select';
45
import RefSelectDropdown from './ref_select_dropdown';
46
import GfmAutoComplete from './gfm_auto_complete';
47
import ShortcutsBlob from './shortcuts_blob';
48
import Star from './star';
49
import TreeView from './tree';
50
import Wikis from './wikis';
51
import ZenMode from './zen_mode';
52
import initSettingsPanels from './settings_panels';
53
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
54 55 56
import initNotes from './init_notes';
import initLegacyFilters from './init_legacy_filters';
import initIssuableSidebar from './init_issuable_sidebar';
57
import initProjectVisibilitySelector from './project_visibility';
58
import GpgBadges from './gpg_badges';
59
import initChangesDropdown from './init_changes_dropdown';
60
import NewGroupChild from './groups/new_group_child';
61
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
62
import AjaxLoadingSpinner from './ajax_loading_spinner';
63 64
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
65 66 67 68
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsFindFile from './shortcuts_find_file';
import ShortcutsIssuable from './shortcuts_issuable';
F
Filipa Lacerda 已提交
69
import U2FAuthenticate from './u2f/authenticate';
70 71
import Members from './members';
import memberExpirationDate from './member_expiration_date';
F
Filipa Lacerda 已提交
72
import DueDateSelectors from './due_date_select';
73
import Diff from './diff';
74
import ProjectLabelSubscription from './project_label_subscription';
F
Filipa Lacerda 已提交
75
import SearchAutocomplete from './search_autocomplete';
76
import Activities from './activities';
77

F
Fatih Acet 已提交
78 79 80 81 82 83
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
84
      this.initFieldErrors();
F
Fatih Acet 已提交
85 86 87 88
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
89 90
      var path, shortcut_handler, fileBlobPermalinkUrlElement, fileBlobPermalinkUrl;
      const page = $('body').attr('data-page');
F
Fatih Acet 已提交
91 92 93
      if (!page) {
        return false;
      }
94

95
      const fail = () => Flash('Error loading dynamic module');
96
      const callDefault = m => m.default();
97

F
Fatih Acet 已提交
98 99
      path = page.split(':');
      shortcut_handler = null;
100

F
Filipa Lacerda 已提交
101
      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
102
        const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
103
        const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
104 105 106 107 108 109 110 111 112
        gfm.setup($(el), {
          emojis: true,
          members: enableGFM,
          issues: enableGFM,
          milestones: enableGFM,
          mergeRequests: enableGFM,
          labels: enableGFM,
        });
      });
113

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
      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,
        });
E
Eric Eastwood 已提交
130

131 132 133 134 135 136
        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'),
137 138
        })
          .init();
139 140
      }

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

F
Fatih Acet 已提交
143
      switch (page) {
144
        case 'sessions:new':
C
Clement Ho 已提交
145 146 147
          import('./pages/sessions/new')
            .then(callDefault)
            .catch(fail);
148
          break;
149
        case 'projects:boards:show':
150
        case 'projects:boards:index':
151
          shortcut_handler = new ShortcutsNavigation();
152
          new UsersSelect();
153
          break;
154
        case 'projects:merge_requests:index':
F
Fatih Acet 已提交
155
        case 'projects:issues:index':
156
          if (filteredSearchEnabled) {
157 158
            const filteredSearchManager = new gl.FilteredSearchManager(page === 'projects:issues:index' ? 'issues' : 'merge_requests');
            filteredSearchManager.setup();
C
Clement Ho 已提交
159
          }
160
          const pagePrefix = page === 'projects:merge_requests:index' ? 'merge_request_' : 'issue_';
F
Filipa Lacerda 已提交
161
          new IssuableIndex(pagePrefix);
162

F
Fatih Acet 已提交
163
          shortcut_handler = new ShortcutsNavigation();
164
          new UsersSelect();
F
Fatih Acet 已提交
165 166 167 168 169
          break;
        case 'projects:issues:show':
          new Issue();
          shortcut_handler = new ShortcutsIssuable();
          new ZenMode();
170
          initIssuableSidebar();
F
Fatih Acet 已提交
171
          break;
P
Phil Hughes 已提交
172
        case 'dashboard:milestones:index':
173 174 175
          import('./pages/dashboard/milestones/index')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
176
          break;
F
Fatih Acet 已提交
177 178 179
        case 'projects:milestones:show':
        case 'groups:milestones:show':
          new Milestone();
180
          new Sidebar();
F
Fatih Acet 已提交
181
          break;
182 183 184 185 186
        case 'dashboard:milestones:show':
          import('./pages/dashboard/milestones/show')
            .then(callDefault)
            .catch(fail);
          break;
187
        case 'dashboard:issues':
C
Clement Ho 已提交
188 189 190
          import('./pages/dashboard/issues')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
191
          break;
192
        case 'dashboard:merge_requests':
193
          projectSelect();
194
          initLegacyFilters();
195
          break;
196
        case 'groups:issues':
197
        case 'groups:merge_requests':
198
          if (filteredSearchEnabled) {
199
            const filteredSearchManager = new gl.FilteredSearchManager(page === 'groups:issues' ? 'issues' : 'merge_requests');
200 201
            filteredSearchManager.setup();
          }
202
          projectSelect();
203
          break;
F
Fatih Acet 已提交
204
        case 'dashboard:todos:index':
205
          import('./pages/dashboard/todos/index').then(callDefault).catch(fail);
F
Fatih Acet 已提交
206
          break;
207 208
        case 'dashboard:projects:index':
        case 'dashboard:projects:starred':
C
Clement Ho 已提交
209 210 211
          import('./pages/dashboard/projects')
            .then(callDefault)
            .catch(fail);
212
          break;
213 214 215
        case 'explore:projects:index':
        case 'explore:projects:trending':
        case 'explore:projects:starred':
216
          import('./pages/explore/projects')
J
Jacob Schatz 已提交
217
            .then(callDefault)
J
Jacob Schatz 已提交
218 219
            .catch(fail);
          break;
F
Filipa Lacerda 已提交
220
        case 'explore:groups:index':
221
          import('./pages/explore/groups')
J
Jacob Schatz 已提交
222
            .then(callDefault)
J
Jacob Schatz 已提交
223
            .catch(fail);
F
Filipa Lacerda 已提交
224
          break;
F
Fatih Acet 已提交
225 226
        case 'projects:milestones:new':
        case 'projects:milestones:edit':
227
        case 'projects:milestones:update':
228 229 230 231
          new ZenMode();
          new DueDateSelectors();
          new GLForm($('.milestone-form'), true);
          break;
232 233 234
        case 'groups:milestones:new':
        case 'groups:milestones:edit':
        case 'groups:milestones:update':
F
Fatih Acet 已提交
235
          new ZenMode();
F
Filipa Lacerda 已提交
236
          new DueDateSelectors();
237
          new GLForm($('.milestone-form'), false);
F
Fatih Acet 已提交
238 239
          break;
        case 'projects:compare:show':
240
          new Diff();
241 242
          const paddingTop = 16;
          initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight - paddingTop);
F
Fatih Acet 已提交
243
          break;
244 245 246 247
        case 'projects:branches:new':
        case 'projects:branches:create':
          new NewBranchForm($('.js-create-branch-form'), JSON.parse(document.getElementById('availableRefs').innerHTML));
          break;
248
        case 'projects:branches:index':
249
          AjaxLoadingSpinner.init();
250
          new DeleteModal();
251
          break;
F
Fatih Acet 已提交
252 253 254
        case 'projects:issues:new':
        case 'projects:issues:edit':
          shortcut_handler = new ShortcutsNavigation();
255
          new GLForm($('.issue-form'), true);
F
Fatih Acet 已提交
256
          new IssuableForm($('.issue-form'));
257 258
          new LabelsSelect();
          new MilestoneSelect();
259
          new IssuableTemplateSelectors();
F
Fatih Acet 已提交
260
          break;
D
Douwe Maan 已提交
261
        case 'projects:merge_requests:creations:new':
262 263 264 265 266 267 268 269 270 271 272 273 274
          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,
            });
          }
D
Douwe Maan 已提交
275
        case 'projects:merge_requests:creations:diffs':
F
Fatih Acet 已提交
276
        case 'projects:merge_requests:edit':
277
          new Diff();
F
Fatih Acet 已提交
278
          shortcut_handler = new ShortcutsNavigation();
279
          new GLForm($('.merge-request-form'), true);
F
Fatih Acet 已提交
280
          new IssuableForm($('.merge-request-form'));
281 282
          new LabelsSelect();
          new MilestoneSelect();
283
          new IssuableTemplateSelectors();
284
          new AutoWidthDropdownSelect($('.js-target-branch-select')).init();
F
Fatih Acet 已提交
285 286 287
          break;
        case 'projects:tags:new':
          new ZenMode();
288
          new GLForm($('.tag-form'), true);
289
          new RefSelectDropdown($('.js-branch-select'));
F
Fatih Acet 已提交
290
          break;
291 292
        case 'projects:snippets:show':
          initNotes();
F
Filipa Lacerda 已提交
293
          new ZenMode();
294
          break;
295 296 297 298
        case 'projects:snippets:new':
        case 'projects:snippets:edit':
        case 'projects:snippets:create':
        case 'projects:snippets:update':
299
          new GLForm($('.snippet-form'), true);
F
Filipa Lacerda 已提交
300
          new ZenMode();
301
          break;
302
        case 'snippets:new':
303 304 305 306
          import('./pages/snippets/new')
            .then(callDefault)
            .catch(fail);
          break;
307
        case 'snippets:edit':
308 309 310 311
          import('./pages/snippets/edit')
            .then(callDefault)
            .catch(fail);
          break;
312
        case 'snippets:create':
313 314 315 316
          import('./pages/snippets/create')
            .then(callDefault)
            .catch(fail);
          break;
317
        case 'snippets:update':
318 319 320
          import('./pages/snippets/update')
            .then(callDefault)
            .catch(fail);
321
          break;
F
Fatih Acet 已提交
322 323
        case 'projects:releases:edit':
          new ZenMode();
324
          new GLForm($('.release-form'), true);
F
Fatih Acet 已提交
325 326
          break;
        case 'projects:merge_requests:show':
327
          new Diff();
F
Fatih Acet 已提交
328
          new ZenMode();
329

330 331
          initIssuableSidebar();
          initNotes();
332

333 334 335 336
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
337 338

          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
339 340
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
341 342 343
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
344 345
          break;
        case 'projects:commit:show':
346
          new Diff();
F
Fatih Acet 已提交
347 348
          new ZenMode();
          shortcut_handler = new ShortcutsNavigation();
349 350 351
          new MiniPipelineGraph({
            container: '.js-commit-pipeline-graph',
          }).bindEvents();
352
          initNotes();
P
Phil Hughes 已提交
353 354
          const stickyBarPaddingTop = 16;
          initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight - stickyBarPaddingTop);
355
          $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
F
Fatih Acet 已提交
356
          break;
357
        case 'projects:commit:pipelines':
358
          new MiniPipelineGraph({
359
            container: '.js-commit-pipeline-graph',
360
          }).bindEvents();
361
          $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
362
          break;
363
        case 'projects:activity':
364
          import('./pages/projects/activity')
365 366
            .then(callDefault)
            .catch(fail);
367
          shortcut_handler = true;
368
          break;
369 370
        case 'projects:commits:show':
          CommitsList.init(document.querySelector('.js-project-commits-show').dataset.commitsLimit);
F
Fatih Acet 已提交
371
          shortcut_handler = new ShortcutsNavigation();
372
          GpgBadges.fetch();
F
Fatih Acet 已提交
373 374 375 376
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
F
Filipa Lacerda 已提交
377 378 379 380
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
381 382

          if ($('#tree-slider').length) new TreeView();
383
          if ($('.blob-viewer').length) new BlobViewer();
384
          if ($('.project-show-activity').length) new Activities();
385
          $('#tree-slider').waitForImages(function() {
F
Filipa Lacerda 已提交
386
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
387
          });
F
Fatih Acet 已提交
388
          break;
389
        case 'projects:edit':
390
          setupProjectEdit();
391 392
          // Initialize expandable settings panels
          initSettingsPanels();
393
          break;
394
        case 'projects:imports:show':
395
          projectImport();
396
          break;
397
        case 'projects:pipelines:new':
398
        case 'projects:pipelines:create':
399 400 401
          import('./pages/projects/pipelines/new')
            .then(callDefault)
            .catch(fail);
402
          break;
F
Filipa Lacerda 已提交
403
        case 'projects:pipelines:builds':
404
        case 'projects:pipelines:failures':
L
Luke Bennett 已提交
405
        case 'projects:pipelines:show':
406 407 408
          import('./pages/projects/pipelines/builds')
            .then(callDefault)
            .catch(fail);
L
Luke Bennett 已提交
409
          break;
F
Fatih Acet 已提交
410
        case 'groups:activity':
411
          new Activities();
F
Fatih Acet 已提交
412 413
          break;
        case 'groups:show':
414
          const newGroupChildWrapper = document.querySelector('.js-new-project-subgroup');
F
Fatih Acet 已提交
415 416
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
P
Phil Hughes 已提交
417
          notificationsDropdown();
418
          new ProjectsList();
419 420 421 422

          if (newGroupChildWrapper) {
            new NewGroupChild(newGroupChildWrapper);
          }
F
Fatih Acet 已提交
423 424
          break;
        case 'groups:group_members:index':
425 426
          memberExpirationDate();
          new Members();
F
Fatih Acet 已提交
427 428
          new UsersSelect();
          break;
429
        case 'projects:project_members:index':
430 431 432
          import('./pages/projects/project_members/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
433 434
          break;
        case 'groups:new':
435
        case 'groups:create':
Z
Z.J. van de Weg 已提交
436
          BindInOut.initAll();
437
          new Group();
438
          groupAvatar();
439
          break;
P
Phil Hughes 已提交
440 441
        case 'admin:groups:create':
        case 'admin:groups:new':
P
Phil Hughes 已提交
442 443 444
          import('./pages/admin/groups/new')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
445
          break;
F
Fatih Acet 已提交
446
        case 'admin:groups:edit':
P
Phil Hughes 已提交
447 448 449
          import('./pages/admin/groups/edit')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
450 451
          break;
        case 'groups:edit':
452
          groupAvatar();
F
Fatih Acet 已提交
453
          break;
454 455 456 457
        case 'projects:tree:show':
          shortcut_handler = new ShortcutsNavigation();
          new TreeView();
          new BlobViewer();
458
          new NewCommitForm($('.js-create-dir-form'));
T
Tim Zallmann 已提交
459
          $('#tree-slider').waitForImages(function() {
F
Filipa Lacerda 已提交
460
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
T
Tim Zallmann 已提交
461
          });
462
          break;
F
Fatih Acet 已提交
463
        case 'projects:find_file:show':
464 465 466 467 468 469 470
          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);
F
Fatih Acet 已提交
471 472
          shortcut_handler = true;
          break;
473 474 475 476
        case 'projects:blob:show':
          new BlobViewer();
          initBlob();
          break;
F
Fatih Acet 已提交
477
        case 'projects:blame:show':
478
          initBlob();
F
Fatih Acet 已提交
479
          break;
480 481
        case 'groups:labels:new':
        case 'groups:labels:edit':
F
Fatih Acet 已提交
482 483 484 485
        case 'projects:labels:new':
        case 'projects:labels:edit':
          new Labels();
          break;
486
        case 'groups:labels:index':
F
Fatih Acet 已提交
487 488
        case 'projects:labels:index':
          if ($('.prioritized-labels').length) {
489
            new LabelManager();
F
Fatih Acet 已提交
490
          }
491 492 493 494
          $('.label-subscription').each((i, el) => {
            const $el = $(el);

            if ($el.find('.dropdown-group-label').length) {
495
              new GroupLabelSubscription($el);
496
            } else {
497
              new ProjectLabelSubscription($el);
498 499
            }
          });
F
Fatih Acet 已提交
500 501
          break;
        case 'projects:network:show':
502 503
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
F
Fatih Acet 已提交
504 505 506
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
507
          import(/* webpackChunkName: 'project_fork' */ './project_fork')
J
Jacob Schatz 已提交
508 509
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
510 511
          break;
        case 'projects:artifacts:browse':
512
          import('./pages/projects/artifacts/browse')
513 514
            .then(callDefault)
            .catch(fail);
515
          shortcut_handler = true;
F
Fatih Acet 已提交
516
          break;
517
        case 'projects:artifacts:file':
518
          import('./pages/projects/artifacts/file')
519 520
            .then(callDefault)
            .catch(fail);
521
          shortcut_handler = true;
522
          break;
523
        case 'help:index':
524 525 526
          import('./pages/help')
            .then(callDefault)
            .catch(fail);
527
          break;
F
Fatih Acet 已提交
528
        case 'search:show':
C
Clement Ho 已提交
529 530 531
          import('./pages/search/show')
            .then(callDefault)
            .catch(fail);
532
          break;
D
Douwe Maan 已提交
533
        case 'projects:settings:repository:show':
534 535
          // Initialize expandable settings panels
          initSettingsPanels();
536
          break;
D
Douwe Maan 已提交
537
        case 'projects:settings:ci_cd:show':
538 539
          // Initialize expandable settings panels
          initSettingsPanels();
540 541 542 543 544 545

          const runnerToken = document.querySelector('.js-secret-runner-token');
          if (runnerToken) {
            const runnerTokenSecretValue = new SecretValues(runnerToken);
            runnerTokenSecretValue.init();
          }
S
Shinya Maeda 已提交
546
        case 'groups:settings:ci_cd:show':
547 548 549 550 551
          const secretVariableTable = document.querySelector('.js-secret-variable-table');
          if (secretVariableTable) {
            const secretVariableTableValues = new SecretValues(secretVariableTable);
            secretVariableTableValues.init();
          }
S
Stan Hu 已提交
552
          break;
553 554
        case 'ci:lints:create':
        case 'ci:lints:show':
555
          import('./pages/ci/lints').then(m => m.default()).catch(fail);
556
          break;
557
        case 'users:show':
558
          import('./pages/users/show').then(callDefault).catch(fail);
559
          break;
560
        case 'admin:conversational_development_index:show':
561
          import('./pages/admin/conversational_development_index/show').then(m => m.default()).catch(fail);
562
          break;
D
Douwe Maan 已提交
563
        case 'snippets:show':
C
Clement Ho 已提交
564 565 566
          import('./pages/snippets/show')
            .then(callDefault)
            .catch(fail);
D
Douwe Maan 已提交
567
          break;
568
        case 'import:fogbugz:new_user_map':
569
          import('./pages/import/fogbugz/new_user_map').then(m => m.default()).catch(fail);
570
          break;
571
        case 'profiles:personal_access_tokens:index':
572 573 574 575
          import('./pages/profiles/personal_access_tokens')
            .then(callDefault)
            .catch(fail);
          break;
576
        case 'admin:impersonation_tokens:index':
P
Phil Hughes 已提交
577 578 579
          import('./pages/admin/impersonation_tokens')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
580
          break;
F
Filipa Lacerda 已提交
581
        case 'projects:clusters:show':
582
          import(/* webpackChunkName: "clusters" */ './clusters/clusters_bundle')
F
Filipa Lacerda 已提交
583
            .then(cluster => new cluster.default()) // eslint-disable-line new-cap
584
            .catch((err) => {
585 586 587 588 589 590
              Flash(s__('ClusterIntegration|Problem setting up the cluster'));
              throw err;
            });
          break;
        case 'projects:clusters:index':
          import(/* webpackChunkName: "clusters_index" */ './clusters/clusters_index')
591
            .then(clusterIndex => clusterIndex.default())
592 593
            .catch((err) => {
              Flash(s__('ClusterIntegration|Problem setting up the clusters list'));
594 595
              throw err;
            });
F
Filipa Lacerda 已提交
596
          break;
F
Fatih Acet 已提交
597
      }
598
      switch (path[0]) {
599 600 601
        case 'sessions':
        case 'omniauth_callbacks':
          if (!gon.u2f) break;
F
Filipa Lacerda 已提交
602
          const u2fAuthenticate = new U2FAuthenticate(
603 604 605 606 607 608
            $('#js-authenticate-u2f'),
            '#js-login-u2f-form',
            gon.u2f,
            document.querySelector('#js-login-2fa-device'),
            document.querySelector('.js-2fa-form'),
          );
F
Filipa Lacerda 已提交
609 610 611
          u2fAuthenticate.start();
          // needed in rspec
          gl.u2fAuthenticate = u2fAuthenticate;
F
Fatih Acet 已提交
612
        case 'admin':
P
Phil Hughes 已提交
613 614 615
          import('./pages/admin')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
616
          switch (path[1]) {
M
Mike Greiling 已提交
617
            case 'broadcast_messages':
P
Phil Hughes 已提交
618 619 620
              import('./pages/admin/broadcast_messages')
                .then(callDefault)
                .catch(fail);
M
Mike Greiling 已提交
621
              break;
S
Sean McGivern 已提交
622
            case 'cohorts':
P
Phil Hughes 已提交
623 624 625
              import('./pages/admin/cohorts')
                .then(callDefault)
                .catch(fail);
626
              break;
F
Fatih Acet 已提交
627
            case 'groups':
P
Phil Hughes 已提交
628 629
              switch (path[2]) {
                case 'show':
P
Phil Hughes 已提交
630 631 632
                  import('./pages/admin/groups/show')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
633 634
                  break;
              }
F
Fatih Acet 已提交
635 636
              break;
            case 'projects':
P
Phil Hughes 已提交
637 638 639
              import('./pages/admin/projects')
                .then(callDefault)
                .catch(fail);
640 641
              break;
            case 'labels':
642
              switch (path[2]) {
643
                case 'new':
P
Phil Hughes 已提交
644 645 646
                  import('./pages/admin/labels/new')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
647
                  break;
648
                case 'edit':
P
Phil Hughes 已提交
649 650 651
                  import('./pages/admin/labels/edit')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
652
                  break;
653
              }
654
            case 'abuse_reports':
P
Phil Hughes 已提交
655 656 657
              import('./pages/admin/abuse_reports')
                .then(callDefault)
                .catch(fail);
658
              break;
F
Fatih Acet 已提交
659 660 661 662
          }
          break;
        case 'dashboard':
        case 'root':
663
          new UserCallout();
F
Fatih Acet 已提交
664 665
          break;
        case 'profiles':
666 667 668
          import('./pages/profiles/index/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
669 670 671
          break;
        case 'projects':
          new Project();
672
          projectAvatar();
F
Fatih Acet 已提交
673 674
          switch (path[1]) {
            case 'compare':
675
              initCompareAutocomplete();
F
Fatih Acet 已提交
676 677 678 679
              break;
            case 'edit':
              shortcut_handler = new ShortcutsNavigation();
              new ProjectNew();
680
              import(/* webpackChunkName: 'project_permissions' */ './projects/permissions')
J
Jacob Schatz 已提交
681 682
                .then(callDefault)
                .catch(fail);
F
Fatih Acet 已提交
683 684 685
              break;
            case 'new':
              new ProjectNew();
686
              initProjectVisibilitySelector();
F
Fatih Acet 已提交
687 688
              break;
            case 'show':
689
              new Star();
F
Fatih Acet 已提交
690
              new ProjectNew();
P
Phil Hughes 已提交
691
              notificationsDropdown();
F
Fatih Acet 已提交
692 693
              break;
            case 'wikis':
694
              new Wikis();
695
              shortcut_handler = new ShortcutsWiki();
F
Fatih Acet 已提交
696
              new ZenMode();
697
              new GLForm($('.wiki-form'), true);
F
Fatih Acet 已提交
698 699 700 701 702
              break;
            case 'snippets':
              shortcut_handler = new ShortcutsNavigation();
              if (path[2] === 'show') {
                new ZenMode();
D
Douwe Maan 已提交
703 704
                new LineHighlighter();
                new BlobViewer();
F
Fatih Acet 已提交
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
              }
              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();
          }
721
          break;
F
Fatih Acet 已提交
722
      }
723
      // If we haven't installed a custom shortcut handler, install the default one
F
Fatih Acet 已提交
724
      if (!shortcut_handler) {
725
        new Shortcuts();
F
Fatih Acet 已提交
726
      }
727 728 729 730

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
731 732 733
    };

    Dispatcher.prototype.initSearch = function() {
734
      // Only when search form is present
F
Fatih Acet 已提交
735
      if ($('.search').length) {
F
Filipa Lacerda 已提交
736
        return new SearchAutocomplete();
F
Fatih Acet 已提交
737 738 739
      }
    };

740
    Dispatcher.prototype.initFieldErrors = function() {
741
      $('.gl-show-field-errors').each((i, form) => {
742
        new GlFieldErrors(form);
743
      });
744 745
    };

F
Fatih Acet 已提交
746 747
    return Dispatcher;
  })();
748

749
  $(window).on('load', function() {
750 751
    new Dispatcher();
  });
752
}).call(window);