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

F
Fatih Acet 已提交
56 57 58 59 60 61
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
62
      this.initFieldErrors();
F
Fatih Acet 已提交
63 64 65 66
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
67
      var path, shortcut_handler;
68
      const page = $('body').attr('data-page');
F
Fatih Acet 已提交
69 70 71
      if (!page) {
        return false;
      }
72

73
      const fail = () => Flash('Error loading dynamic module');
74
      const callDefault = m => m.default();
75

F
Fatih Acet 已提交
76 77
      path = page.split(':');
      shortcut_handler = null;
78

F
Filipa Lacerda 已提交
79
      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
80
        const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
81
        const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
82 83 84 85 86 87 88 89 90
        gfm.setup($(el), {
          emojis: true,
          members: enableGFM,
          issues: enableGFM,
          milestones: enableGFM,
          mergeRequests: enableGFM,
          labels: enableGFM,
        });
      });
91

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

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

304 305
          initIssuableSidebar();
          initNotes();
306

307 308 309 310
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
311 312

          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
313 314
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
315 316 317
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
318 319
          break;
        case 'projects:commit:show':
320 321 322 323
          import('./pages/projects/commit/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
324
          break;
325
        case 'projects:commit:pipelines':
326 327 328
          import('./pages/projects/commit/pipelines')
            .then(callDefault)
            .catch(fail);
329
          break;
330
        case 'projects:activity':
331
          import('./pages/projects/activity')
332 333
            .then(callDefault)
            .catch(fail);
334
          shortcut_handler = true;
335
          break;
336
        case 'projects:commits:show':
337 338 339 340
          import('./pages/projects/commits/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
341 342 343 344
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
F
Filipa Lacerda 已提交
345 346 347 348
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
349 350

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

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

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

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

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
707 708 709
    };

    Dispatcher.prototype.initSearch = function() {
710
      // Only when search form is present
F
Fatih Acet 已提交
711
      if ($('.search').length) {
F
Filipa Lacerda 已提交
712
        return new SearchAutocomplete();
F
Fatih Acet 已提交
713 714 715
      }
    };

716
    Dispatcher.prototype.initFieldErrors = function() {
717
      $('.gl-show-field-errors').each((i, form) => {
718
        new GlFieldErrors(form);
719
      });
720 721
    };

F
Fatih Acet 已提交
722 723
    return Dispatcher;
  })();
724

725
  $(window).on('load', function() {
726 727
    new Dispatcher();
  });
728
}).call(window);