dispatcher.js.es6 10.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/* 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, padded-blocks */
/* global UsernameValidator */
/* global ActiveTabMemoizer */
/* global ShortcutsNavigation */
/* global Build */
/* global Issuable */
/* global Issue */
/* global ShortcutsIssuable */
/* global ZenMode */
/* global Milestone */
/* global GLForm */
/* global IssuableForm */
/* global LabelsSelect */
/* global MilestoneSelect */
/* global MergedButtons */
/* global Commit */
/* global NotificationsForm */
/* global TreeView */
/* global NotificationsDropdown */
/* global UsersSelect */
/* global GroupAvatar */
/* global LineHighlighter */
/* global ShortcutsBlob */
/* global ProjectFork */
/* global BuildArtifacts */
/* global GroupsSelect */
/* global Search */
/* global Admin */
/* global NamespaceSelects */
/* global ShortcutsDashboardNavigation */
/* global Project */
/* global ProjectAvatar */
/* global CompareAutocomplete */
/* global ProjectNew */
/* global Star */
/* global ProjectShow */
/* global Labels */
/* global Shortcuts */

Fatih Acet's avatar
Fatih Acet committed
40 41 42 43 44 45 46 47 48 49
(function() {
  var Dispatcher;

  $(function() {
    return new Dispatcher();
  });

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
50
      this.initFieldErrors();
Fatih Acet's avatar
Fatih Acet committed
51 52 53 54 55 56 57 58 59 60 61 62
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
      var page, path, shortcut_handler;
      page = $('body').attr('data-page');
      if (!page) {
        return false;
      }
      path = page.split(':');
      shortcut_handler = null;
      switch (page) {
63 64
        case 'sessions:new':
          new UsernameValidator();
65
          new ActiveTabMemoizer();
66
          break;
67
        case 'projects:boards:show':
68
        case 'projects:boards:index':
69 70
          shortcut_handler = new ShortcutsNavigation();
          break;
71 72 73
        case 'projects:builds:show':
          new Build();
          break;
74
        case 'projects:merge_requests:index':
Fatih Acet's avatar
Fatih Acet committed
75 76
        case 'projects:issues:index':
          Issuable.init();
77
          new gl.IssuableBulkActions();
Fatih Acet's avatar
Fatih Acet committed
78 79 80 81 82 83 84 85 86 87 88 89 90
          shortcut_handler = new ShortcutsNavigation();
          break;
        case 'projects:issues:show':
          new Issue();
          shortcut_handler = new ShortcutsIssuable();
          new ZenMode();
          break;
        case 'projects:milestones:show':
        case 'groups:milestones:show':
        case 'dashboard:milestones:show':
          new Milestone();
          break;
        case 'dashboard:todos:index':
Bryce Johnson's avatar
Bryce Johnson committed
91
          new gl.Todos();
Fatih Acet's avatar
Fatih Acet committed
92 93 94 95
          break;
        case 'projects:milestones:new':
        case 'projects:milestones:edit':
          new ZenMode();
96
          new gl.DueDateSelectors();
Fatih Acet's avatar
Fatih Acet committed
97 98 99 100 101 102
          new GLForm($('.milestone-form'));
          break;
        case 'groups:milestones:new':
          new ZenMode();
          break;
        case 'projects:compare:show':
103
          new gl.Diff();
Fatih Acet's avatar
Fatih Acet committed
104 105 106 107 108 109
          break;
        case 'projects:issues:new':
        case 'projects:issues:edit':
          shortcut_handler = new ShortcutsNavigation();
          new GLForm($('.issue-form'));
          new IssuableForm($('.issue-form'));
110 111
          new LabelsSelect();
          new MilestoneSelect();
112
          new gl.IssuableTemplateSelectors();
Fatih Acet's avatar
Fatih Acet committed
113 114 115
          break;
        case 'projects:merge_requests:new':
        case 'projects:merge_requests:edit':
116
          new gl.Diff();
Fatih Acet's avatar
Fatih Acet committed
117 118 119
          shortcut_handler = new ShortcutsNavigation();
          new GLForm($('.merge-request-form'));
          new IssuableForm($('.merge-request-form'));
120 121
          new LabelsSelect();
          new MilestoneSelect();
122
          new gl.IssuableTemplateSelectors();
Fatih Acet's avatar
Fatih Acet committed
123 124 125 126 127 128 129 130 131 132
          break;
        case 'projects:tags:new':
          new ZenMode();
          new GLForm($('.tag-form'));
          break;
        case 'projects:releases:edit':
          new ZenMode();
          new GLForm($('.release-form'));
          break;
        case 'projects:merge_requests:show':
133
          new gl.Diff();
Fatih Acet's avatar
Fatih Acet committed
134 135 136 137 138 139 140 141 142
          shortcut_handler = new ShortcutsIssuable(true);
          new ZenMode();
          new MergedButtons();
          break;
        case 'projects:merge_requests:commits':
        case 'projects:merge_requests:builds':
          new MergedButtons();
          break;
        case "projects:merge_requests:diffs":
143
          new gl.Diff();
Fatih Acet's avatar
Fatih Acet committed
144 145 146 147 148 149 150 151
          new ZenMode();
          new MergedButtons();
          break;
        case 'projects:merge_requests:index':
          shortcut_handler = new ShortcutsNavigation();
          Issuable.init();
          break;
        case 'dashboard:activity':
152
          new gl.Activities();
Fatih Acet's avatar
Fatih Acet committed
153 154
          break;
        case 'dashboard:projects:starred':
155
          new gl.Activities();
Fatih Acet's avatar
Fatih Acet committed
156 157 158
          break;
        case 'projects:commit:show':
          new Commit();
159
          new gl.Diff();
Fatih Acet's avatar
Fatih Acet committed
160 161 162
          new ZenMode();
          shortcut_handler = new ShortcutsNavigation();
          break;
163 164 165
        case 'projects:commit:builds':
          new gl.Pipelines();
          break;
Fatih Acet's avatar
Fatih Acet committed
166 167 168 169 170 171 172 173 174 175 176
        case 'projects:commits:show':
        case 'projects:activity':
          shortcut_handler = new ShortcutsNavigation();
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
          if ($('#tree-slider').length) {
            new TreeView();
          }
          break;
Filipa Lacerda's avatar
Filipa Lacerda committed
177
        case 'projects:pipelines:builds':
Luke Bennett's avatar
Luke Bennett committed
178
        case 'projects:pipelines:show':
Filipa Lacerda's avatar
Filipa Lacerda committed
179
          const { controllerAction } = document.querySelector('.js-pipeline-container').dataset;
Filipa Lacerda's avatar
Filipa Lacerda committed
180 181 182 183 184 185 186 187 188

          new gl.Pipelines({
            initTabs: true,
            tabsOptions: {
              action: controllerAction,
              defaultAction: 'pipelines',
              parentEl: '.pipelines-tabs',
            },
          });
Luke Bennett's avatar
Luke Bennett committed
189
          break;
Fatih Acet's avatar
Fatih Acet committed
190
        case 'groups:activity':
191
          new gl.Activities();
Fatih Acet's avatar
Fatih Acet committed
192 193 194 195 196 197 198
          break;
        case 'groups:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
          new NotificationsDropdown();
          break;
        case 'groups:group_members:index':
199
          new gl.MemberExpirationDate();
200
          new gl.Members();
Fatih Acet's avatar
Fatih Acet committed
201 202 203
          new UsersSelect();
          break;
        case 'projects:project_members:index':
204
          new gl.MemberExpirationDate();
205
          new gl.Members();
Fatih Acet's avatar
Fatih Acet committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
          new UsersSelect();
          break;
        case 'groups:new':
        case 'groups:edit':
        case 'admin:groups:edit':
        case 'admin:groups:new':
          new GroupAvatar();
          break;
        case 'projects:tree:show':
          shortcut_handler = new ShortcutsNavigation();
          new TreeView();
          break;
        case 'projects:find_file:show':
          shortcut_handler = true;
          break;
        case 'projects:blob:show':
        case 'projects:blame:show':
          new LineHighlighter();
          shortcut_handler = new ShortcutsNavigation();
          new ShortcutsBlob(true);
          break;
227 228
        case 'groups:labels:new':
        case 'groups:labels:edit':
Fatih Acet's avatar
Fatih Acet committed
229 230 231 232 233 234
        case 'projects:labels:new':
        case 'projects:labels:edit':
          new Labels();
          break;
        case 'projects:labels:index':
          if ($('.prioritized-labels').length) {
235
            new gl.LabelManager();
Fatih Acet's avatar
Fatih Acet committed
236 237 238
          }
          break;
        case 'projects:network:show':
239 240
          // 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
241 242 243 244 245 246 247 248 249
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
          new ProjectFork();
          break;
        case 'projects:artifacts:browse':
          new BuildArtifacts();
          break;
        case 'projects:group_links:index':
250
          new gl.MemberExpirationDate();
Fatih Acet's avatar
Fatih Acet committed
251 252 253 254
          new GroupsSelect();
          break;
        case 'search:show':
          new Search();
255 256
          break;
        case 'projects:protected_branches:index':
257 258
          new gl.ProtectedBranchCreate();
          new gl.ProtectedBranchEditList();
259
          break;
260 261 262
        case 'projects:variables:index':
          new gl.ProjectVariables();
          break;
Fatih Acet's avatar
Fatih Acet committed
263 264 265 266 267 268 269 270 271 272
      }
      switch (path.first()) {
        case 'admin':
          new Admin();
          switch (path[1]) {
            case 'groups':
              new UsersSelect();
              break;
            case 'projects':
              new NamespaceSelects();
273 274
              break;
            case 'labels':
275
              switch (path[2]) {
276
                case 'new':
277 278 279
                case 'edit':
                  new Labels();
              }
280
            case 'abuse_reports':
281
              new gl.AbuseReports();
282
              break;
Fatih Acet's avatar
Fatih Acet committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
          }
          break;
        case 'dashboard':
        case 'root':
          shortcut_handler = new ShortcutsDashboardNavigation();
          break;
        case 'profiles':
          new NotificationsForm();
          new NotificationsDropdown();
          break;
        case 'projects':
          new Project();
          new ProjectAvatar();
          switch (path[1]) {
            case 'compare':
              new CompareAutocomplete();
              break;
            case 'edit':
              shortcut_handler = new ShortcutsNavigation();
              new ProjectNew();
              break;
            case 'new':
              new ProjectNew();
              break;
            case 'show':
308
              new Star();
Fatih Acet's avatar
Fatih Acet committed
309 310 311 312 313
              new ProjectNew();
              new ProjectShow();
              new NotificationsDropdown();
              break;
            case 'wikis':
314
              new gl.Wikis();
Fatih Acet's avatar
Fatih Acet committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
              shortcut_handler = new ShortcutsNavigation();
              new ZenMode();
              new GLForm($('.wiki-form'));
              break;
            case 'snippets':
              shortcut_handler = new ShortcutsNavigation();
              if (path[2] === 'show') {
                new ZenMode();
              }
              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();
          }
      }
340
      // If we haven't installed a custom shortcut handler, install the default one
Fatih Acet's avatar
Fatih Acet committed
341 342 343 344 345 346
      if (!shortcut_handler) {
        return new Shortcuts();
      }
    };

    Dispatcher.prototype.initSearch = function() {
347
      // Only when search form is present
Fatih Acet's avatar
Fatih Acet committed
348
      if ($('.search').length) {
349
        return new gl.SearchAutocomplete();
Fatih Acet's avatar
Fatih Acet committed
350 351 352
      }
    };

353
    Dispatcher.prototype.initFieldErrors = function() {
354
      $('.gl-show-field-errors').each((i, form) => {
355 356
        new gl.GlFieldErrors(form);
      });
357 358
    };

Fatih Acet's avatar
Fatih Acet committed
359 360 361 362 363
    return Dispatcher;

  })();

}).call(this);