dispatcher.js 25.3 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 Milestone from './milestone';
5
import IssuableForm from './issuable_form';
6
import LabelsSelect from './labels_select';
C
Constance Okoghenun 已提交
7
import MilestoneSelect from './milestone_select';
P
Phil Hughes 已提交
8 9
import NotificationsForm from './notifications_form';
import notificationsDropdown from './notifications_dropdown';
10 11
import groupAvatar from './group_avatar';
import GroupLabelSubscription from './group_label_subscription';
P
Phil Hughes 已提交
12
import LineHighlighter from './line_highlighter';
13 14
import Project from './project';
import projectAvatar from './project_avatar';
P
Phil Hughes 已提交
15
import MergeRequest from './merge_request';
16
import Compare from './compare';
17
import initCompareAutocomplete from './compare_autocomplete';
18
import ProjectNew from './project_new';
19 20
import Labels from './labels';
import LabelManager from './label_manager';
P
Phil Hughes 已提交
21
import Sidebar from './right_sidebar';
22
import IssuableTemplateSelectors from './templates/issuable_template_selectors';
23
import Flash from './flash';
24
import CommitsList from './commits';
Z
Z.J. van de Weg 已提交
25
import BindInOut from './behaviors/bind_in_out';
26
import SecretValues from './behaviors/secret_values';
27
import Group from './group';
28
import ProjectsList from './projects_list';
29
import MiniPipelineGraph from './mini_pipeline_graph_dropdown';
M
Mike Greiling 已提交
30
import UserCallout from './user_callout';
G
geoandri 已提交
31
import ShortcutsWiki from './shortcuts_wiki';
D
Douwe Maan 已提交
32
import BlobViewer from './blob/viewer/index';
33
import UsersSelect from './users_select';
34
import GfmAutoComplete from './gfm_auto_complete';
35
import Star from './star';
36
import TreeView from './tree';
37
import Wikis from './wikis';
38
import ZenMode from './zen_mode';
39
import initSettingsPanels from './settings_panels';
40
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
41 42
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
43
import initProjectVisibilitySelector from './project_visibility';
44
import GpgBadges from './gpg_badges';
45
import initChangesDropdown from './init_changes_dropdown';
46
import NewGroupChild from './groups/new_group_child';
47
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
48 49
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
50 51 52
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsIssuable from './shortcuts_issuable';
F
Filipa Lacerda 已提交
53
import U2FAuthenticate from './u2f/authenticate';
54 55
import Members from './members';
import memberExpirationDate from './member_expiration_date';
F
Filipa Lacerda 已提交
56
import DueDateSelectors from './due_date_select';
57
import Diff from './diff';
58
import ProjectLabelSubscription from './project_label_subscription';
F
Filipa Lacerda 已提交
59
import SearchAutocomplete from './search_autocomplete';
60
import Activities from './activities';
61
import { fetchCommitMergeRequests } from './commit_merge_requests';
62

F
Fatih Acet 已提交
63 64 65 66 67 68
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
69
      this.initFieldErrors();
F
Fatih Acet 已提交
70 71 72 73
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
74
      var path, shortcut_handler;
75
      const page = $('body').attr('data-page');
F
Fatih Acet 已提交
76 77 78
      if (!page) {
        return false;
      }
79

80
      const fail = () => Flash('Error loading dynamic module');
81
      const callDefault = m => m.default();
82

F
Fatih Acet 已提交
83 84
      path = page.split(':');
      shortcut_handler = null;
85

F
Filipa Lacerda 已提交
86
      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
87
        const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
88
        const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
89 90 91 92 93 94 95 96 97
        gfm.setup($(el), {
          emojis: true,
          members: enableGFM,
          issues: enableGFM,
          milestones: enableGFM,
          mergeRequests: enableGFM,
          labels: enableGFM,
        });
      });
98

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

F
Fatih Acet 已提交
101
      switch (page) {
102
        case 'sessions:new':
C
Clement Ho 已提交
103 104 105
          import('./pages/sessions/new')
            .then(callDefault)
            .catch(fail);
106
          break;
107
        case 'projects:boards:show':
108
        case 'projects:boards:index':
109 110 111 112
          import('./pages/projects/boards/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
113
          break;
114
        case 'projects:merge_requests:index':
115 116 117 118
          import('./pages/projects/merge_requests/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
119
          break;
S
Simon Knox 已提交
120 121 122 123 124 125
        case 'projects:issues:index':
          import('./pages/projects/issues/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
F
Fatih Acet 已提交
126
        case 'projects:issues:show':
S
Simon Knox 已提交
127 128 129 130
          import('./pages/projects/issues/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
131
          break;
P
Phil Hughes 已提交
132
        case 'dashboard:milestones:index':
133 134 135
          import('./pages/dashboard/milestones/index')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
136
          break;
F
Fatih Acet 已提交
137 138 139
        case 'projects:milestones:show':
        case 'groups:milestones:show':
          new Milestone();
140
          new Sidebar();
F
Fatih Acet 已提交
141
          break;
142 143 144 145 146
        case 'dashboard:milestones:show':
          import('./pages/dashboard/milestones/show')
            .then(callDefault)
            .catch(fail);
          break;
147
        case 'dashboard:issues':
C
Clement Ho 已提交
148 149 150
          import('./pages/dashboard/issues')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
151
          break;
152
        case 'dashboard:merge_requests':
153 154 155
          import('./pages/dashboard/merge_requests')
            .then(callDefault)
            .catch(fail);
156
          break;
157
        case 'groups:issues':
158
        case 'groups:merge_requests':
159
          if (filteredSearchEnabled) {
160
            const filteredSearchManager = new gl.FilteredSearchManager(page === 'groups:issues' ? 'issues' : 'merge_requests');
161 162
            filteredSearchManager.setup();
          }
163
          projectSelect();
164
          break;
F
Fatih Acet 已提交
165
        case 'dashboard:todos:index':
166
          import('./pages/dashboard/todos/index').then(callDefault).catch(fail);
F
Fatih Acet 已提交
167
          break;
168 169
        case 'dashboard:projects:index':
        case 'dashboard:projects:starred':
C
Clement Ho 已提交
170 171 172
          import('./pages/dashboard/projects')
            .then(callDefault)
            .catch(fail);
173
          break;
174 175 176
        case 'explore:projects:index':
        case 'explore:projects:trending':
        case 'explore:projects:starred':
177
          import('./pages/explore/projects')
J
Jacob Schatz 已提交
178
            .then(callDefault)
J
Jacob Schatz 已提交
179 180
            .catch(fail);
          break;
F
Filipa Lacerda 已提交
181
        case 'explore:groups:index':
182
          import('./pages/explore/groups')
J
Jacob Schatz 已提交
183
            .then(callDefault)
J
Jacob Schatz 已提交
184
            .catch(fail);
F
Filipa Lacerda 已提交
185
          break;
F
Fatih Acet 已提交
186 187
        case 'projects:milestones:new':
        case 'projects:milestones:edit':
188
        case 'projects:milestones:update':
189 190 191 192
          new ZenMode();
          new DueDateSelectors();
          new GLForm($('.milestone-form'), true);
          break;
193 194 195
        case 'groups:milestones:new':
        case 'groups:milestones:edit':
        case 'groups:milestones:update':
F
Fatih Acet 已提交
196
          new ZenMode();
F
Filipa Lacerda 已提交
197
          new DueDateSelectors();
198
          new GLForm($('.milestone-form'), false);
F
Fatih Acet 已提交
199 200
          break;
        case 'projects:compare:show':
201
          new Diff();
202 203
          const paddingTop = 16;
          initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight - paddingTop);
F
Fatih Acet 已提交
204
          break;
205
        case 'projects:branches:new':
206 207 208 209
          import('./pages/projects/branches/new')
            .then(callDefault)
            .catch(fail);
          break;
210
        case 'projects:branches:create':
211 212 213
          import('./pages/projects/branches/new')
            .then(callDefault)
            .catch(fail);
214
          break;
215
        case 'projects:branches:index':
216 217 218
          import('./pages/projects/branches/index')
            .then(callDefault)
            .catch(fail);
219
          break;
F
Fatih Acet 已提交
220
        case 'projects:issues:new':
S
Simon Knox 已提交
221 222 223 224 225
          import('./pages/projects/issues/new')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
F
Fatih Acet 已提交
226
        case 'projects:issues:edit':
S
Simon Knox 已提交
227 228 229 230
          import('./pages/projects/issues/edit')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
231
          break;
D
Douwe Maan 已提交
232
        case 'projects:merge_requests:creations:new':
233 234 235 236 237 238 239 240 241 242 243 244 245
          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 已提交
246
        case 'projects:merge_requests:creations:diffs':
F
Fatih Acet 已提交
247
        case 'projects:merge_requests:edit':
248
          new Diff();
F
Fatih Acet 已提交
249
          shortcut_handler = new ShortcutsNavigation();
250
          new GLForm($('.merge-request-form'), true);
F
Fatih Acet 已提交
251
          new IssuableForm($('.merge-request-form'));
252 253
          new LabelsSelect();
          new MilestoneSelect();
254
          new IssuableTemplateSelectors();
F
Fatih Acet 已提交
255 256
          break;
        case 'projects:tags:new':
257 258 259
          import('./pages/projects/tags/new')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
260
          break;
261 262
        case 'projects:snippets:show':
          initNotes();
F
Filipa Lacerda 已提交
263
          new ZenMode();
264
          break;
265 266 267 268
        case 'projects:snippets:new':
        case 'projects:snippets:edit':
        case 'projects:snippets:create':
        case 'projects:snippets:update':
269
          new GLForm($('.snippet-form'), true);
F
Filipa Lacerda 已提交
270
          new ZenMode();
271
          break;
272
        case 'snippets:new':
273 274 275 276
          import('./pages/snippets/new')
            .then(callDefault)
            .catch(fail);
          break;
277
        case 'snippets:edit':
278 279 280 281
          import('./pages/snippets/edit')
            .then(callDefault)
            .catch(fail);
          break;
282
        case 'snippets:create':
C
Clement Ho 已提交
283
          import('./pages/snippets/new')
284 285 286
            .then(callDefault)
            .catch(fail);
          break;
287
        case 'snippets:update':
C
Clement Ho 已提交
288
          import('./pages/snippets/edit')
289 290
            .then(callDefault)
            .catch(fail);
291
          break;
F
Fatih Acet 已提交
292 293
        case 'projects:releases:edit':
          new ZenMode();
294
          new GLForm($('.release-form'), true);
F
Fatih Acet 已提交
295 296
          break;
        case 'projects:merge_requests:show':
297
          new Diff();
F
Fatih Acet 已提交
298
          new ZenMode();
299

300 301
          initIssuableSidebar();
          initNotes();
302

303 304 305 306
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
307 308

          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
309 310
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
311 312 313
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
314 315
          break;
        case 'projects:commit:show':
316
          new Diff();
F
Fatih Acet 已提交
317 318
          new ZenMode();
          shortcut_handler = new ShortcutsNavigation();
319 320 321
          new MiniPipelineGraph({
            container: '.js-commit-pipeline-graph',
          }).bindEvents();
322
          initNotes();
P
Phil Hughes 已提交
323 324
          const stickyBarPaddingTop = 16;
          initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight - stickyBarPaddingTop);
325
          $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
326
          fetchCommitMergeRequests();
F
Fatih Acet 已提交
327
          break;
328
        case 'projects:commit:pipelines':
329
          new MiniPipelineGraph({
330
            container: '.js-commit-pipeline-graph',
331
          }).bindEvents();
332
          $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
333
          break;
334
        case 'projects:activity':
335
          import('./pages/projects/activity')
336 337
            .then(callDefault)
            .catch(fail);
338
          shortcut_handler = true;
339
          break;
340 341
        case 'projects:commits:show':
          CommitsList.init(document.querySelector('.js-project-commits-show').dataset.commitsLimit);
F
Fatih Acet 已提交
342
          shortcut_handler = new ShortcutsNavigation();
343
          GpgBadges.fetch();
F
Fatih Acet 已提交
344 345 346 347
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
F
Filipa Lacerda 已提交
348 349 350 351
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
352 353

          if ($('#tree-slider').length) new TreeView();
354
          if ($('.blob-viewer').length) new BlobViewer();
355
          if ($('.project-show-activity').length) new Activities();
356
          $('#tree-slider').waitForImages(function() {
F
Filipa Lacerda 已提交
357
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
358
          });
F
Fatih Acet 已提交
359
          break;
360
        case 'projects:edit':
S
Simon Knox 已提交
361 362 363
          import('./pages/projects/edit')
            .then(callDefault)
            .catch(fail);
364
          break;
365
        case 'projects:imports:show':
S
Simon Knox 已提交
366 367 368
          import('./pages/projects/imports/show')
            .then(callDefault)
            .catch(fail);
369
          break;
370
        case 'projects:pipelines:new':
371
        case 'projects:pipelines:create':
372 373 374
          import('./pages/projects/pipelines/new')
            .then(callDefault)
            .catch(fail);
375
          break;
F
Filipa Lacerda 已提交
376
        case 'projects:pipelines:builds':
377
        case 'projects:pipelines:failures':
L
Luke Bennett 已提交
378
        case 'projects:pipelines:show':
379 380 381
          import('./pages/projects/pipelines/builds')
            .then(callDefault)
            .catch(fail);
L
Luke Bennett 已提交
382
          break;
F
Fatih Acet 已提交
383
        case 'groups:activity':
384
          new Activities();
F
Fatih Acet 已提交
385 386
          break;
        case 'groups:show':
387
          const newGroupChildWrapper = document.querySelector('.js-new-project-subgroup');
F
Fatih Acet 已提交
388 389
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
P
Phil Hughes 已提交
390
          notificationsDropdown();
391
          new ProjectsList();
392 393 394 395

          if (newGroupChildWrapper) {
            new NewGroupChild(newGroupChildWrapper);
          }
F
Fatih Acet 已提交
396 397
          break;
        case 'groups:group_members:index':
398 399
          memberExpirationDate();
          new Members();
F
Fatih Acet 已提交
400 401
          new UsersSelect();
          break;
402
        case 'projects:project_members:index':
403 404 405
          import('./pages/projects/project_members/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
406 407
          break;
        case 'groups:new':
408
        case 'groups:create':
Z
Z.J. van de Weg 已提交
409
          BindInOut.initAll();
410
          new Group();
411
          groupAvatar();
412
          break;
P
Phil Hughes 已提交
413 414
        case 'admin:groups:create':
        case 'admin:groups:new':
P
Phil Hughes 已提交
415 416 417
          import('./pages/admin/groups/new')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
418
          break;
F
Fatih Acet 已提交
419
        case 'admin:groups:edit':
P
Phil Hughes 已提交
420 421 422
          import('./pages/admin/groups/edit')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
423 424
          break;
        case 'groups:edit':
425
          groupAvatar();
F
Fatih Acet 已提交
426
          break;
427
        case 'projects:tree:show':
428
          import('./pages/projects/tree/show')
429
            .then(callDefault)
430
            .catch(fail);
431
          shortcut_handler = true;
432
          break;
F
Fatih Acet 已提交
433
        case 'projects:find_file:show':
S
Simon Knox 已提交
434 435 436
          import('./pages/projects/find_file/show')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
437 438
          shortcut_handler = true;
          break;
439
        case 'projects:blob:show':
440 441 442 443
          import('./pages/projects/blob/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
444
          break;
F
Fatih Acet 已提交
445
        case 'projects:blame:show':
446 447 448 449
          import('./pages/projects/blame/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
450
          break;
451 452
        case 'groups:labels:new':
        case 'groups:labels:edit':
C
Clement Ho 已提交
453 454
          new Labels();
          break;
F
Fatih Acet 已提交
455
        case 'projects:labels:new':
J
Jacob Schatz 已提交
456 457 458 459
          import('./pages/projects/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
460
        case 'projects:labels:edit':
C
Clement Ho 已提交
461
          import('./pages/projects/labels/edit')
J
Jacob Schatz 已提交
462 463
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
464 465
          break;
        case 'projects:labels:index':
J
Jacob Schatz 已提交
466 467 468 469 470
          import('./pages/projects/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
        case 'groups:labels:index':
F
Fatih Acet 已提交
471
          if ($('.prioritized-labels').length) {
472
            new LabelManager();
F
Fatih Acet 已提交
473
          }
474 475 476 477
          $('.label-subscription').each((i, el) => {
            const $el = $(el);

            if ($el.find('.dropdown-group-label').length) {
478
              new GroupLabelSubscription($el);
479
            } else {
480
              new ProjectLabelSubscription($el);
481 482
            }
          });
F
Fatih Acet 已提交
483 484
          break;
        case 'projects:network:show':
485 486
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
F
Fatih Acet 已提交
487 488 489
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
S
Simon Knox 已提交
490
          import('./pages/projects/forks/new')
J
Jacob Schatz 已提交
491 492
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
493 494
          break;
        case 'projects:artifacts:browse':
495
          import('./pages/projects/artifacts/browse')
496 497
            .then(callDefault)
            .catch(fail);
498
          shortcut_handler = true;
F
Fatih Acet 已提交
499
          break;
500
        case 'projects:artifacts:file':
501
          import('./pages/projects/artifacts/file')
502 503
            .then(callDefault)
            .catch(fail);
504
          shortcut_handler = true;
505
          break;
506
        case 'help:index':
507 508 509
          import('./pages/help')
            .then(callDefault)
            .catch(fail);
510
          break;
F
Fatih Acet 已提交
511
        case 'search:show':
C
Clement Ho 已提交
512 513 514
          import('./pages/search/show')
            .then(callDefault)
            .catch(fail);
515
          break;
D
Douwe Maan 已提交
516
        case 'projects:settings:repository:show':
517 518
          // Initialize expandable settings panels
          initSettingsPanels();
519
          break;
D
Douwe Maan 已提交
520
        case 'projects:settings:ci_cd:show':
521 522
          // Initialize expandable settings panels
          initSettingsPanels();
523 524 525 526 527 528

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

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
714 715 716
    };

    Dispatcher.prototype.initSearch = function() {
717
      // Only when search form is present
F
Fatih Acet 已提交
718
      if ($('.search').length) {
F
Filipa Lacerda 已提交
719
        return new SearchAutocomplete();
F
Fatih Acet 已提交
720 721 722
      }
    };

723
    Dispatcher.prototype.initFieldErrors = function() {
724
      $('.gl-show-field-errors').each((i, form) => {
725
        new GlFieldErrors(form);
726
      });
727 728
    };

F
Fatih Acet 已提交
729 730
    return Dispatcher;
  })();
731

732
  $(window).on('load', function() {
733 734
    new Dispatcher();
  });
735
}).call(window);