dispatcher.js 25.9 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';
3
import Milestone from './milestone';
4
import IssuableForm from './issuable_form';
5
import LabelsSelect from './labels_select';
6
import MilestoneSelect from './milestone_select';
Phil Hughes's avatar
Phil Hughes committed
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';
11 12
import LineHighlighter from './line_highlighter';
import MergeRequest from './merge_request';
13
import Compare from './compare';
14 15
import Labels from './labels';
import LabelManager from './label_manager';
16
import Sidebar from './right_sidebar';
17

18
import IssuableTemplateSelectors from './templates/issuable_template_selectors';
19
import Flash from './flash';
Z.J. van de Weg's avatar
Z.J. van de Weg committed
20
import BindInOut from './behaviors/bind_in_out';
21
import SecretValues from './behaviors/secret_values';
22
import Group from './group';
23
import ProjectsList from './projects_list';
Mike Greiling's avatar
Mike Greiling committed
24
import UserCallout from './user_callout';
25
import BlobViewer from './blob/viewer/index';
26
import UsersSelect from './users_select';
27
import GfmAutoComplete from './gfm_auto_complete';
28
import Star from './star';
29
import TreeView from './tree';
30
import ZenMode from './zen_mode';
31
import initSettingsPanels from './settings_panels';
32
import PerformanceBar from './performance_bar';
Phil Hughes's avatar
Phil Hughes committed
33 34
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
Phil Hughes's avatar
Phil Hughes committed
35 36
import GpgBadges from './gpg_badges';
import initChangesDropdown from './init_changes_dropdown';
37
import NewGroupChild from './groups/new_group_child';
38
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
39 40
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
41 42 43
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsIssuable from './shortcuts_issuable';
44
import U2FAuthenticate from './u2f/authenticate';
45 46
import Members from './members';
import memberExpirationDate from './member_expiration_date';
47
import Diff from './diff';
48
import ProjectLabelSubscription from './project_label_subscription';
49
import SearchAutocomplete from './search_autocomplete';
Phil Hughes's avatar
Phil Hughes committed
50
import Activities from './activities';
51

52
// EE-only
Phil Hughes's avatar
Phil Hughes committed
53 54 55 56 57
import initGeoInfoModal from 'ee/init_geo_info_modal'; // eslint-disable-line import/first
import initGroupAnalytics from 'ee/init_group_analytics'; // eslint-disable-line import/first
import initPathLocks from 'ee/path_locks'; // eslint-disable-line import/first
import initApprovals from 'ee/approvals'; // eslint-disable-line import/first
import initLDAPGroupsSelect from 'ee/ldap_groups_select'; // eslint-disable-line import/first
58

Fatih Acet's avatar
Fatih Acet committed
59 60 61 62 63 64
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
65
      this.initFieldErrors();
Fatih Acet's avatar
Fatih Acet committed
66 67 68 69
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
70
      var path, shortcut_handler;
71
      const page = $('body').attr('data-page');
Fatih Acet's avatar
Fatih Acet committed
72 73 74
      if (!page) {
        return false;
      }
75

Phil Hughes's avatar
Phil Hughes committed
76
      const fail = () => Flash('Error loading dynamic module');
77
      const callDefault = m => m.default();
78

Fatih Acet's avatar
Fatih Acet committed
79 80
      path = page.split(':');
      shortcut_handler = null;
81

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

95 96 97 98 99 100 101 102 103
      function initBlobEE() {
        const dataEl = document.getElementById('js-file-lock');

        if (dataEl) {
          const {
            toggle_path,
            path,
           } = JSON.parse(dataEl.innerHTML);

Phil Hughes's avatar
Phil Hughes committed
104
          initPathLocks(toggle_path, path);
105 106 107
        }
      }

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

Fatih Acet's avatar
Fatih Acet committed
110
      switch (page) {
111
        case 'sessions:new':
112 113 114
          import('./pages/sessions/new')
            .then(callDefault)
            .catch(fail);
115
          break;
116
        case 'projects:boards:show':
117
        case 'projects:boards:index':
118 119 120 121
          import('./pages/projects/boards/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
122
          break;
123
        case 'projects:merge_requests:index':
124 125 126 127 128
          import('./pages/projects/merge_requests/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
Fatih Acet's avatar
Fatih Acet committed
129
        case 'projects:issues:index':
130 131 132 133
          import('./pages/projects/issues/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
Fatih Acet's avatar
Fatih Acet committed
134 135
          break;
        case 'projects:issues:show':
136 137 138 139
          import('./pages/projects/issues/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
Fatih Acet's avatar
Fatih Acet committed
140
          break;
141
        case 'dashboard:milestones:index':
142 143 144
          import('./pages/dashboard/milestones/index')
            .then(callDefault)
            .catch(fail);
145
          break;
Fatih Acet's avatar
Fatih Acet committed
146
        case 'projects:milestones:show':
147
          new UserCallout();
Fatih Acet's avatar
Fatih Acet committed
148 149
        case 'groups:milestones:show':
          new Milestone();
150
          new Sidebar();
Fatih Acet's avatar
Fatih Acet committed
151
          break;
152 153 154 155 156
        case 'dashboard:milestones:show':
          import('./pages/dashboard/milestones/show')
            .then(callDefault)
            .catch(fail);
          break;
Phil Hughes's avatar
Phil Hughes committed
157
        case 'dashboard:issues':
Clement Ho's avatar
Clement Ho committed
158 159 160
          import('./pages/dashboard/issues')
            .then(callDefault)
            .catch(fail);
Clement Ho's avatar
Clement Ho committed
161
          break;
Phil Hughes's avatar
Phil Hughes committed
162
        case 'dashboard:merge_requests':
163 164 165
          import('./pages/dashboard/merge_requests')
            .then(callDefault)
            .catch(fail);
166
          break;
167
        case 'groups:issues':
168
        case 'groups:merge_requests':
169
          if (filteredSearchEnabled) {
170
            const filteredSearchManager = new gl.FilteredSearchManager(page === 'groups:issues' ? 'issues' : 'merge_requests');
171 172
            filteredSearchManager.setup();
          }
173
          projectSelect();
174
          break;
Fatih Acet's avatar
Fatih Acet committed
175
        case 'dashboard:todos:index':
176
          import('./pages/dashboard/todos/index').then(callDefault).catch(fail);
Fatih Acet's avatar
Fatih Acet committed
177
          break;
178 179
        case 'dashboard:projects:index':
        case 'dashboard:projects:starred':
Clement Ho's avatar
Clement Ho committed
180 181 182
          import('./pages/dashboard/projects')
            .then(callDefault)
            .catch(fail);
183
          break;
184 185 186
        case 'explore:projects:index':
        case 'explore:projects:trending':
        case 'explore:projects:starred':
187 188 189 190
          import('./pages/explore/projects')
            .then(callDefault)
            .catch(fail);
          break;
191
        case 'explore:groups:index':
192 193 194
          import('./pages/explore/groups')
            .then(callDefault)
            .catch(fail);
195
          break;
Fatih Acet's avatar
Fatih Acet committed
196
        case 'projects:milestones:new':
197 198 199 200 201
        case 'projects:milestones:create':
          import('./pages/projects/milestones/new')
            .then(callDefault)
            .catch(fail);
          break;
Fatih Acet's avatar
Fatih Acet committed
202
        case 'projects:milestones:edit':
203
        case 'projects:milestones:update':
204 205 206
          import('./pages/projects/milestones/edit')
            .then(callDefault)
            .catch(fail);
207
          break;
208
        case 'groups:milestones:new':
209 210 211 212 213
        case 'groups:milestones:create':
          import('./pages/groups/milestones/new')
            .then(callDefault)
            .catch(fail);
          break;
214 215
        case 'groups:milestones:edit':
        case 'groups:milestones:update':
216 217 218
          import('./pages/groups/milestones/edit')
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
219
          break;
Clement Ho's avatar
Clement Ho committed
220 221 222
        case 'groups:epics:show':
          new ZenMode();
          break;
Fatih Acet's avatar
Fatih Acet committed
223
        case 'projects:compare:show':
224 225 226
          import('./pages/projects/compare/show')
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
227
          break;
228
        case 'projects:branches:new':
229 230 231 232
          import('./pages/projects/branches/new')
            .then(callDefault)
            .catch(fail);
          break;
233
        case 'projects:branches:create':
234 235 236
          import('./pages/projects/branches/new')
            .then(callDefault)
            .catch(fail);
237
          break;
238
        case 'projects:branches:index':
239 240 241
          import('./pages/projects/branches/index')
            .then(callDefault)
            .catch(fail);
242
          break;
Fatih Acet's avatar
Fatih Acet committed
243
        case 'projects:issues:new':
244 245 246 247 248
          import('./pages/projects/issues/new')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
Fatih Acet's avatar
Fatih Acet committed
249
        case 'projects:issues:edit':
250 251 252 253
          import('./pages/projects/issues/edit')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
Fatih Acet's avatar
Fatih Acet committed
254
          break;
255
        case 'projects:merge_requests:creations:new':
256 257 258 259 260 261 262 263 264 265 266 267 268
          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,
            });
          }
Tim Zallmann's avatar
Tim Zallmann committed
269
          new UserCallout();
270
        case 'projects:merge_requests:creations:diffs':
Fatih Acet's avatar
Fatih Acet committed
271
        case 'projects:merge_requests:edit':
272
          new Diff();
Fatih Acet's avatar
Fatih Acet committed
273
          shortcut_handler = new ShortcutsNavigation();
274
          new GLForm($('.merge-request-form'), true);
Fatih Acet's avatar
Fatih Acet committed
275
          new IssuableForm($('.merge-request-form'));
276 277
          new LabelsSelect();
          new MilestoneSelect();
278
          new IssuableTemplateSelectors();
Phil Hughes's avatar
Phil Hughes committed
279

280
          // ee-start
Phil Hughes's avatar
Phil Hughes committed
281
          initApprovals();
282
          // ee-end
Fatih Acet's avatar
Fatih Acet committed
283 284
          break;
        case 'projects:tags:new':
285 286 287
          import('./pages/projects/tags/new')
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
288
          break;
Phil Hughes's avatar
Phil Hughes committed
289 290
        case 'projects:snippets:show':
          initNotes();
291
          new ZenMode();
Fatih Acet's avatar
Fatih Acet committed
292
          break;
293 294 295 296
        case 'projects:snippets:new':
        case 'projects:snippets:edit':
        case 'projects:snippets:create':
        case 'projects:snippets:update':
297
          new GLForm($('.snippet-form'), true);
298
          new ZenMode();
299
          break;
300
        case 'snippets:new':
301 302 303 304
          import('./pages/snippets/new')
            .then(callDefault)
            .catch(fail);
          break;
305
        case 'snippets:edit':
306 307 308 309
          import('./pages/snippets/edit')
            .then(callDefault)
            .catch(fail);
          break;
310
        case 'snippets:create':
Clement Ho's avatar
Clement Ho committed
311
          import('./pages/snippets/new')
312 313 314
            .then(callDefault)
            .catch(fail);
          break;
315
        case 'snippets:update':
Clement Ho's avatar
Clement Ho committed
316
          import('./pages/snippets/edit')
317 318
            .then(callDefault)
            .catch(fail);
319
          break;
Fatih Acet's avatar
Fatih Acet committed
320 321
        case 'projects:releases:edit':
          new ZenMode();
322
          new GLForm($('.release-form'), true);
Fatih Acet's avatar
Fatih Acet committed
323 324
          break;
        case 'projects:merge_requests:show':
325
          new Diff();
Fatih Acet's avatar
Fatih Acet committed
326
          new ZenMode();
327

328 329
          initIssuableSidebar();
          initNotes();
330

331 332 333 334
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
335
          shortcut_handler = new ShortcutsIssuable(true);
Fatih Acet's avatar
Fatih Acet committed
336 337
          break;
        case 'dashboard:activity':
338 339 340
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
341 342
          break;
        case 'projects:commit:show':
343 344 345 346
          import('./pages/projects/commit/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
Fatih Acet's avatar
Fatih Acet committed
347
          break;
348
        case 'projects:commit:pipelines':
349 350 351
          import('./pages/projects/commit/pipelines')
            .then(callDefault)
            .catch(fail);
352
          break;
Fatih Acet's avatar
Fatih Acet committed
353
        case 'projects:activity':
354
          import('./pages/projects/activity')
355 356
            .then(callDefault)
            .catch(fail);
357
          shortcut_handler = true;
358 359
          break;
        case 'projects:commits:show':
360 361 362 363
          import('./pages/projects/commits/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
Fatih Acet's avatar
Fatih Acet committed
364 365 366 367
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
368 369 370 371
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
372 373

          if ($('#tree-slider').length) new TreeView();
374
          if ($('.blob-viewer').length) new BlobViewer();
Phil Hughes's avatar
Phil Hughes committed
375
          if ($('.project-show-activity').length) new Activities();
376
          $('#tree-slider').waitForImages(function() {
377
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
378
          });
Phil Hughes's avatar
Phil Hughes committed
379 380

          initGeoInfoModal();
Fatih Acet's avatar
Fatih Acet committed
381
          break;
382
        case 'projects:edit':
383 384 385
          import('./pages/projects/edit')
            .then(callDefault)
            .catch(fail);
386
          break;
387
        case 'projects:imports:show':
388 389 390
          import('./pages/projects/imports/show')
            .then(callDefault)
            .catch(fail);
391
          break;
392
        case 'projects:pipelines:new':
393
        case 'projects:pipelines:create':
394 395 396
          import('./pages/projects/pipelines/new')
            .then(callDefault)
            .catch(fail);
397
          break;
Filipa Lacerda's avatar
Filipa Lacerda committed
398
        case 'projects:pipelines:builds':
399
        case 'projects:pipelines:failures':
Luke Bennett's avatar
Luke Bennett committed
400
        case 'projects:pipelines:show':
401 402 403
          import('./pages/projects/pipelines/builds')
            .then(callDefault)
            .catch(fail);
Luke Bennett's avatar
Luke Bennett committed
404
          break;
Fatih Acet's avatar
Fatih Acet committed
405
        case 'groups:activity':
Phil Hughes's avatar
Phil Hughes committed
406
          new Activities();
Fatih Acet's avatar
Fatih Acet committed
407 408
          break;
        case 'groups:show':
409
          const newGroupChildWrapper = document.querySelector('.js-new-project-subgroup');
Fatih Acet's avatar
Fatih Acet committed
410 411
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
Phil Hughes's avatar
Phil Hughes committed
412
          notificationsDropdown();
413
          new ProjectsList();
414 415 416 417

          if (newGroupChildWrapper) {
            new NewGroupChild(newGroupChildWrapper);
          }
Fatih Acet's avatar
Fatih Acet committed
418 419
          break;
        case 'groups:group_members:index':
420 421
          memberExpirationDate();
          new Members();
Fatih Acet's avatar
Fatih Acet committed
422 423
          new UsersSelect();
          break;
424
        case 'projects:project_members:index':
425 426 427
          import('./pages/projects/project_members/')
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
428 429
          break;
        case 'groups:new':
430
        case 'groups:create':
Z.J. van de Weg's avatar
Z.J. van de Weg committed
431
          BindInOut.initAll();
432
          new Group();
433
          groupAvatar();
434
          break;
Phil Hughes's avatar
Phil Hughes committed
435 436
        case 'admin:groups:create':
        case 'admin:groups:new':
Phil Hughes's avatar
Phil Hughes committed
437 438 439
          import('./pages/admin/groups/new')
            .then(callDefault)
            .catch(fail);
Phil Hughes's avatar
Phil Hughes committed
440
          break;
Fatih Acet's avatar
Fatih Acet committed
441
        case 'admin:groups:edit':
Phil Hughes's avatar
Phil Hughes committed
442 443 444
          import('./pages/admin/groups/edit')
            .then(callDefault)
            .catch(fail);
Phil Hughes's avatar
Phil Hughes committed
445 446
          break;
        case 'groups:edit':
447
          groupAvatar();
Fatih Acet's avatar
Fatih Acet committed
448 449
          break;
        case 'projects:tree:show':
450 451 452 453
          import('./pages/projects/tree/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
454
          break;
Fatih Acet's avatar
Fatih Acet committed
455
        case 'projects:find_file:show':
456 457 458
          import('./pages/projects/find_file/show')
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
459 460 461
          shortcut_handler = true;
          break;
        case 'projects:blob:show':
462 463 464 465 466
          import('./pages/projects/blob/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          initBlobEE();
467
          break;
Fatih Acet's avatar
Fatih Acet committed
468
        case 'projects:blame:show':
469 470 471 472 473
          import('./pages/projects/blame/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          initBlobEE();
Fatih Acet's avatar
Fatih Acet committed
474
          break;
475 476
        case 'groups:labels:new':
        case 'groups:labels:edit':
Clement Ho's avatar
Clement Ho committed
477 478
          new Labels();
          break;
Fatih Acet's avatar
Fatih Acet committed
479
        case 'projects:labels:new':
Jacob Schatz's avatar
Jacob Schatz committed
480 481 482 483
          import('./pages/projects/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
Fatih Acet's avatar
Fatih Acet committed
484
        case 'projects:labels:edit':
Clement Ho's avatar
Clement Ho committed
485
          import('./pages/projects/labels/edit')
Jacob Schatz's avatar
Jacob Schatz committed
486 487
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
488 489
          break;
        case 'projects:labels:index':
Jacob Schatz's avatar
Jacob Schatz committed
490 491 492 493 494
          import('./pages/projects/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
        case 'groups:labels:index':
Fatih Acet's avatar
Fatih Acet committed
495
          if ($('.prioritized-labels').length) {
496
            new LabelManager();
Fatih Acet's avatar
Fatih Acet committed
497
          }
Phil Hughes's avatar
Phil Hughes committed
498 499 500 501
          $('.label-subscription').each((i, el) => {
            const $el = $(el);

            if ($el.find('.dropdown-group-label').length) {
502
              new GroupLabelSubscription($el);
Phil Hughes's avatar
Phil Hughes committed
503
            } else {
504
              new ProjectLabelSubscription($el);
Phil Hughes's avatar
Phil Hughes committed
505 506
            }
          });
Fatih Acet's avatar
Fatih Acet committed
507 508
          break;
        case 'projects:network:show':
509 510
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
Fatih Acet's avatar
Fatih Acet committed
511 512 513
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
514
          import('./pages/projects/forks/new')
515 516
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
517 518
          break;
        case 'projects:artifacts:browse':
519
          import('./pages/projects/artifacts/browse')
520 521
            .then(callDefault)
            .catch(fail);
522
          shortcut_handler = true;
Fatih Acet's avatar
Fatih Acet committed
523
          break;
524
        case 'projects:artifacts:file':
525
          import('./pages/projects/artifacts/file')
526 527
            .then(callDefault)
            .catch(fail);
528
          shortcut_handler = true;
529
          break;
530
        case 'help:index':
531 532 533
          import('./pages/help')
            .then(callDefault)
            .catch(fail);
534
          break;
Fatih Acet's avatar
Fatih Acet committed
535
        case 'search:show':
536 537 538
          import('./pages/search/show')
            .then(callDefault)
            .catch(fail);
539
          new UserCallout();
Fatih Acet's avatar
Fatih Acet committed
540 541 542 543 544 545
          break;
        case 'projects:mirrors:show':
        case 'projects:mirrors:update':
          new UsersSelect();
          break;
        case 'admin:emails:show':
Phil Hughes's avatar
Phil Hughes committed
546
          import(/* webpackChunkName: "ee_admin_emails_show" */ 'ee/pages/admin/emails/show').then(m => m.default()).catch(fail);
547
          break;
548
        case 'admin:audit_logs:index':
Phil Hughes's avatar
Phil Hughes committed
549
          import(/* webpackChunkName: "ee_audit_logs" */ 'ee/pages/admin/audit_logs').then(m => m.default()).catch(fail);
550
          break;
551
        case 'projects:settings:repository:show':
552
          new UsersSelect();
Tim Zallmann's avatar
Tim Zallmann committed
553
          new UserCallout();
554 555
          // Initialize expandable settings panels
          initSettingsPanels();
556
          break;
557
        case 'projects:settings:ci_cd:show':
558 559
          // Initialize expandable settings panels
          initSettingsPanels();
560 561 562 563 564 565

          const runnerToken = document.querySelector('.js-secret-runner-token');
          if (runnerToken) {
            const runnerTokenSecretValue = new SecretValues(runnerToken);
            runnerTokenSecretValue.init();
          }
Shinya Maeda's avatar
Shinya Maeda committed
566
        case 'groups:settings:ci_cd:show':
567 568 569 570 571
          const secretVariableTable = document.querySelector('.js-secret-variable-table');
          if (secretVariableTable) {
            const secretVariableTableValues = new SecretValues(secretVariableTable);
            secretVariableTableValues.init();
          }
572
          break;
573 574
        case 'ci:lints:create':
        case 'ci:lints:show':
Phil Hughes's avatar
Phil Hughes committed
575
          import('./pages/ci/lints').then(m => m.default()).catch(fail);
576
          break;
577
        case 'users:show':
578
          import('./pages/users/show').then(callDefault).catch(fail);
579
          break;
580
        case 'admin:conversational_development_index:show':
Phil Hughes's avatar
Phil Hughes committed
581
          import('./pages/admin/conversational_development_index/show').then(m => m.default()).catch(fail);
582
          break;
Douwe Maan's avatar
Douwe Maan committed
583
        case 'snippets:show':
584 585 586
          import('./pages/snippets/show')
            .then(callDefault)
            .catch(fail);
Douwe Maan's avatar
Douwe Maan committed
587
          break;
588
        case 'import:fogbugz:new_user_map':
Phil Hughes's avatar
Phil Hughes committed
589
          import('./pages/import/fogbugz/new_user_map').then(m => m.default()).catch(fail);
590
          break;
591
        case 'profiles:personal_access_tokens:index':
592 593 594 595
          import('./pages/profiles/personal_access_tokens')
            .then(callDefault)
            .catch(fail);
          break;
Phil Hughes's avatar
Phil Hughes committed
596
        case 'admin:impersonation_tokens:index':
Phil Hughes's avatar
Phil Hughes committed
597 598 599
          import('./pages/admin/impersonation_tokens')
            .then(callDefault)
            .catch(fail);
Phil Hughes's avatar
Phil Hughes committed
600 601
          break;
        case 'profiles:personal_access_tokens:index':
602 603 604
          import('./pages/profiles/personal_access_tokens')
            .then(callDefault)
            .catch(fail);
Phil Hughes's avatar
Phil Hughes committed
605
          break;
606
        case 'projects:clusters:show':
607 608
        case 'projects:clusters:update':
        case 'projects:clusters:destroy':
609 610 611
          import('./pages/projects/clusters/show')
            .then(callDefault)
            .catch(fail);
612 613
          break;
        case 'projects:clusters:index':
614 615 616
          import('./pages/projects/clusters/index')
            .then(callDefault)
            .catch(fail);
617
          break;
618
        case 'admin:licenses:new':
Phil Hughes's avatar
Phil Hughes committed
619
          import(/* webpackChunkName: "admin_licenses" */ 'ee/pages/admin/licenses/new').then(m => m.default()).catch(fail);
620 621 622 623
          break;
        case 'groups:analytics:show':
          initGroupAnalytics();
          break;
Phil Hughes's avatar
Phil Hughes committed
624 625 626
        case 'groups:ldap_group_links:index':
          initLDAPGroupsSelect();
          break;
Fatih Acet's avatar
Fatih Acet committed
627
      }
628
      switch (path[0]) {
629 630 631
        case 'sessions':
        case 'omniauth_callbacks':
          if (!gon.u2f) break;
632
          const u2fAuthenticate = new U2FAuthenticate(
633 634 635 636 637 638
            $('#js-authenticate-u2f'),
            '#js-login-u2f-form',
            gon.u2f,
            document.querySelector('#js-login-2fa-device'),
            document.querySelector('.js-2fa-form'),
          );
639 640 641
          u2fAuthenticate.start();
          // needed in rspec
          gl.u2fAuthenticate = u2fAuthenticate;
Fatih Acet's avatar
Fatih Acet committed
642
        case 'admin':
Phil Hughes's avatar
Phil Hughes committed
643 644 645
          import('./pages/admin')
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
646
          switch (path[1]) {
647
            case 'broadcast_messages':
Phil Hughes's avatar
Phil Hughes committed
648 649 650
              import('./pages/admin/broadcast_messages')
                .then(callDefault)
                .catch(fail);
651
              break;
652
            case 'cohorts':
Phil Hughes's avatar
Phil Hughes committed
653 654 655
              import('./pages/admin/cohorts')
                .then(callDefault)
                .catch(fail);
656
              break;
Fatih Acet's avatar
Fatih Acet committed
657
            case 'groups':
Phil Hughes's avatar
Phil Hughes committed
658
              switch (path[2]) {
Phil Hughes's avatar
Phil Hughes committed
659
                case 'show':
Phil Hughes's avatar
Phil Hughes committed
660 661 662
                  import('./pages/admin/groups/show')
                    .then(callDefault)
                    .catch(fail);
Phil Hughes's avatar
Phil Hughes committed
663
                  break;
Phil Hughes's avatar
Phil Hughes committed
664
                case 'edit':
Phil Hughes's avatar
Phil Hughes committed
665
                  import(/* webpackChunkName: "ee_admin_groups_edit" */ 'ee/pages/admin/groups/edit').then(m => m.default()).catch(fail);
Phil Hughes's avatar
Phil Hughes committed
666 667 668
                  break;
              }

Fatih Acet's avatar
Fatih Acet committed
669 670
              break;
            case 'projects':
Phil Hughes's avatar
Phil Hughes committed
671 672 673
              import('./pages/admin/projects')
                .then(callDefault)
                .catch(fail);
674 675
              break;
            case 'labels':
676
              switch (path[2]) {
677
                case 'new':
Phil Hughes's avatar
Phil Hughes committed
678 679 680
                  import('./pages/admin/labels/new')
                    .then(callDefault)
                    .catch(fail);
Phil Hughes's avatar
Phil Hughes committed
681
                  break;
682
                case 'edit':
Phil Hughes's avatar
Phil Hughes committed
683 684 685
                  import('./pages/admin/labels/edit')
                    .then(callDefault)
                    .catch(fail);
Phil Hughes's avatar
Phil Hughes committed
686
                  break;
687
              }
688
            case 'abuse_reports':
Phil Hughes's avatar
Phil Hughes committed
689 690 691
              import('./pages/admin/abuse_reports')
                .then(callDefault)
                .catch(fail);
692
              break;
693
            case 'geo_nodes':
694 695 696
              import(/* webpackChunkName: 'geo_node_form' */ './geo/geo_node_form')
                .then(geoNodeForm => geoNodeForm.default($('.js-geo-node-form')))
                .catch(() => {});
697
              break;
Fatih Acet's avatar
Fatih Acet committed
698 699 700 701
          }
          break;
        case 'dashboard':
        case 'root':
702
          new UserCallout();
Fatih Acet's avatar
Fatih Acet committed
703 704
          break;
        case 'profiles':
705 706 707
          import('./pages/profiles/index/')
            .then(callDefault)
            .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
708 709
          break;
        case 'projects':
710 711 712 713
          import('./pages/projects')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
Fatih Acet's avatar
Fatih Acet committed
714
          switch (path[1]) {
715 716 717
            case 'create':
            case 'new':
              import('./pages/projects/new')
718 719
                .then(callDefault)
                .catch(fail);
Fatih Acet's avatar
Fatih Acet committed
720 721
              break;
            case 'show':
722
              new Star();
Phil Hughes's avatar
Phil Hughes committed
723
              notificationsDropdown();
Fatih Acet's avatar
Fatih Acet committed
724 725
              break;
            case 'wikis':
726 727 728 729
              import('./pages/projects/wikis')
                .then(callDefault)
                .catch(fail);
              shortcut_handler = true;
Fatih Acet's avatar
Fatih Acet committed
730 731 732 733
              break;
            case 'snippets':
              if (path[2] === 'show') {
                new ZenMode();
Douwe Maan's avatar
Douwe Maan committed
734 735
                new LineHighlighter();
                new BlobViewer();
Fatih Acet's avatar
Fatih Acet committed
736 737 738
              }
              break;
          }
739
          break;
Fatih Acet's avatar
Fatih Acet committed
740
      }
741
      // If we haven't installed a custom shortcut handler, install the default one
Fatih Acet's avatar
Fatih Acet committed
742
      if (!shortcut_handler) {
743
        new Shortcuts();
Fatih Acet's avatar
Fatih Acet committed
744
      }
745 746 747 748

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
Fatih Acet's avatar
Fatih Acet committed
749 750 751
    };

    Dispatcher.prototype.initSearch = function() {
752
      // Only when search form is present
Fatih Acet's avatar
Fatih Acet committed
753
      if ($('.search').length) {
754
        return new SearchAutocomplete();
Fatih Acet's avatar
Fatih Acet committed
755 756 757
      }
    };

758
    Dispatcher.prototype.initFieldErrors = function() {
759
      $('.gl-show-field-errors').each((i, form) => {
760
        new GlFieldErrors(form);
761
      });
762 763
    };

Fatih Acet's avatar
Fatih Acet committed
764 765
    return Dispatcher;
  })();
766

767
  $(window).on('load', function() {
768 769
    new Dispatcher();
  });
770
}).call(window);