Skip to content
Snippets Groups Projects
dispatcher.js 14.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • /* 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 */
    
    /* global UsernameValidator */
    /* global ActiveTabMemoizer */
    /* global ShortcutsNavigation */
    /* global Build */
    /* global Issuable */
    /* global ShortcutsIssuable */
    /* global ZenMode */
    /* global Milestone */
    /* global IssuableForm */
    /* global LabelsSelect */
    /* global MilestoneSelect */
    /* global MergedButtons */
    /* global Commit */
    /* global NotificationsForm */
    /* global TreeView */
    /* global NotificationsDropdown */
    /* global UsersSelect */
    /* global GroupAvatar */
    /* global LineHighlighter */
    /* global ProjectFork */
    /* global BuildArtifacts */
    /* global GroupsSelect */
    /* global Search */
    /* global Admin */
    /* global NamespaceSelects */
    /* global Project */
    /* global ProjectAvatar */
    /* global CompareAutocomplete */
    /* global ProjectNew */
    /* global Star */
    /* global ProjectShow */
    /* global Labels */
    /* global Shortcuts */
    
    import Issue from './issue';
    
    Z.J. van de Weg's avatar
    Z.J. van de Weg committed
    import BindInOut from './behaviors/bind_in_out';
    
    import Group from './group';
    
    import GroupName from './group_name';
    
    import GroupsList from './groups_list';
    
    import ProjectsList from './projects_list';
    
    import MiniPipelineGraph from './mini_pipeline_graph_dropdown';
    
    import BlobLinePermalinkUpdater from './blob/blob_line_permalink_updater';
    
    import BlobForkSuggestion from './blob/blob_fork_suggestion';
    
    Mike Greiling's avatar
    Mike Greiling committed
    import UserCallout from './user_callout';
    
    import { ProtectedTagCreate, ProtectedTagEditList } from './protected_tags';
    
    const ShortcutsBlob = require('./shortcuts_blob');
    
    
    Fatih Acet's avatar
    Fatih Acet committed
    (function() {
      var Dispatcher;
    
      $(function() {
        return new Dispatcher();
      });
    
      Dispatcher = (function() {
        function Dispatcher() {
          this.initSearch();
    
          this.initFieldErrors();
    
    Fatih Acet's avatar
    Fatih Acet committed
          this.initPageScripts();
        }
    
        Dispatcher.prototype.initPageScripts = function() {
    
          var page, path, shortcut_handler, fileBlobPermalinkUrlElement, fileBlobPermalinkUrl;
    
    Fatih Acet's avatar
    Fatih Acet committed
          page = $('body').attr('data-page');
          if (!page) {
            return false;
          }
          path = page.split(':');
          shortcut_handler = null;
    
    
          function initBlob() {
            new LineHighlighter();
    
            new BlobLinePermalinkUpdater(
              document.querySelector('#blob-content-holder'),
              '.diff-line-num[data-line-number]',
              document.querySelectorAll('.js-data-file-blob-permalink-url, .js-blob-blame-link'),
            );
    
            shortcut_handler = new ShortcutsNavigation();
            fileBlobPermalinkUrlElement = document.querySelector('.js-data-file-blob-permalink-url');
            fileBlobPermalinkUrl = fileBlobPermalinkUrlElement && fileBlobPermalinkUrlElement.getAttribute('href');
            new ShortcutsBlob({
              skipResetBindings: true,
              fileBlobPermalinkUrl,
            });
    
    
            new BlobForkSuggestion(
              document.querySelector('.js-edit-blob-link-fork-toggler'),
              document.querySelector('.js-cancel-fork-suggestion'),
              document.querySelector('.js-file-fork-suggestion-section'),
            );
    
    Fatih Acet's avatar
    Fatih Acet committed
          switch (page) {
    
            case 'sessions:new':
              new UsernameValidator();
    
            case 'projects:boards:show':
    
            case 'projects:boards:index':
    
              shortcut_handler = new ShortcutsNavigation();
              break;
    
            case 'projects:builds:show':
              new Build();
              break;
    
            case 'projects:merge_requests:index':
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'projects:issues:index':
    
    Clement Ho's avatar
    Clement Ho committed
              if (gl.FilteredSearchManager) {
    
                new gl.FilteredSearchManager(page === 'projects:issues:index' ? 'issues' : 'merge_requests');
    
    Clement Ho's avatar
    Clement Ho committed
              }
    
    Fatih Acet's avatar
    Fatih Acet committed
              Issuable.init();
    
              new gl.IssuableBulkActions({
    
    Alfredo Sumaran's avatar
    Alfredo Sumaran committed
                prefixId: page === 'projects:merge_requests:index' ? 'merge_request_' : 'issue_',
    
    Fatih Acet's avatar
    Fatih Acet committed
              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();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'dashboard:todos:index':
    
    Bryce Johnson's avatar
    Bryce Johnson committed
              new gl.Todos();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
    
            case 'dashboard:projects:index':
            case 'dashboard:projects:starred':
            case 'explore:projects:index':
            case 'explore:projects:trending':
            case 'explore:projects:starred':
            case 'admin:projects:index':
              new ProjectsList();
              break;
    
            case 'dashboard:groups:index':
            case 'explore:groups:index':
              new GroupsList();
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'projects:milestones:new':
            case 'projects:milestones:edit':
    
            case 'projects:milestones:update':
    
    Fatih Acet's avatar
    Fatih Acet committed
              new ZenMode();
    
              new gl.DueDateSelectors();
    
    Luke "Jared" Bennett's avatar
    Luke "Jared" Bennett committed
              new gl.GLForm($('.milestone-form'));
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'groups:milestones:new':
              new ZenMode();
              break;
            case 'projects:compare:show':
    
              new gl.Diff();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
    
            case 'projects:branches:index':
              gl.AjaxLoadingSpinner.init();
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'projects:issues:new':
            case 'projects:issues:edit':
              shortcut_handler = new ShortcutsNavigation();
    
    Luke "Jared" Bennett's avatar
    Luke "Jared" Bennett committed
              new gl.GLForm($('.issue-form'));
    
    Fatih Acet's avatar
    Fatih Acet committed
              new IssuableForm($('.issue-form'));
    
              new LabelsSelect();
              new MilestoneSelect();
    
              new gl.IssuableTemplateSelectors();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'projects:merge_requests:new':
    
            case 'projects:merge_requests:new_diffs':
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'projects:merge_requests:edit':
    
              new gl.Diff();
    
    Fatih Acet's avatar
    Fatih Acet committed
              shortcut_handler = new ShortcutsNavigation();
    
    Luke "Jared" Bennett's avatar
    Luke "Jared" Bennett committed
              new gl.GLForm($('.merge-request-form'));
    
    Fatih Acet's avatar
    Fatih Acet committed
              new IssuableForm($('.merge-request-form'));
    
              new LabelsSelect();
              new MilestoneSelect();
    
              new gl.IssuableTemplateSelectors();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'projects:tags:new':
              new ZenMode();
    
    Luke "Jared" Bennett's avatar
    Luke "Jared" Bennett committed
              new gl.GLForm($('.tag-form'));
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'projects:releases:edit':
              new ZenMode();
    
    Luke "Jared" Bennett's avatar
    Luke "Jared" Bennett committed
              new gl.GLForm($('.release-form'));
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'projects:merge_requests:show':
    
              new gl.Diff();
    
    Fatih Acet's avatar
    Fatih Acet committed
              shortcut_handler = new ShortcutsIssuable(true);
              new ZenMode();
              new MergedButtons();
              break;
            case 'projects:merge_requests:commits':
              new MergedButtons();
              break;
            case "projects:merge_requests:diffs":
    
              new gl.Diff();
    
    Fatih Acet's avatar
    Fatih Acet committed
              new ZenMode();
              new MergedButtons();
              break;
            case 'dashboard:activity':
    
              new gl.Activities();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'projects:commit:show':
              new Commit();
    
              new gl.Diff();
    
    Fatih Acet's avatar
    Fatih Acet committed
              new ZenMode();
              shortcut_handler = new ShortcutsNavigation();
    
              new MiniPipelineGraph({
                container: '.js-commit-pipeline-graph',
              }).bindEvents();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
    
            case 'projects:commit:pipelines':
    
              new MiniPipelineGraph({
    
                container: '.js-commit-pipeline-graph',
    
              }).bindEvents();
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
            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
            case 'projects:pipelines:builds':
    
            case 'projects:pipelines:show':
    
              const { controllerAction } = document.querySelector('.js-pipeline-container').dataset;
    
              const pipelineStatusUrl = `${document.querySelector('.js-pipeline-tab-link a').getAttribute('href')}/status.json`;
    
    Filipa Lacerda's avatar
    Filipa Lacerda committed
    
              new gl.Pipelines({
                initTabs: true,
    
    Filipa Lacerda's avatar
    Filipa Lacerda committed
                tabsOptions: {
                  action: controllerAction,
                  defaultAction: 'pipelines',
                  parentEl: '.pipelines-tabs',
                },
              });
    
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'groups:activity':
    
              new gl.Activities();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'groups:show':
              shortcut_handler = new ShortcutsNavigation();
              new NotificationsForm();
              new NotificationsDropdown();
    
              new ProjectsList();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'groups:group_members:index':
    
              new gl.MemberExpirationDate();
    
              new gl.Members();
    
    Fatih Acet's avatar
    Fatih Acet committed
              new UsersSelect();
              break;
    
              new gl.MemberExpirationDate('.js-access-expiration-date-groups');
              new GroupsSelect();
    
              new gl.MemberExpirationDate();
    
              new gl.Members();
    
    Fatih Acet's avatar
    Fatih Acet committed
              new UsersSelect();
              break;
            case 'groups:new':
    
    Luke "Jared" Bennett's avatar
    Luke "Jared" Bennett committed
            case 'admin:groups:new':
    
            case 'groups:create':
            case 'admin:groups:create':
    
    Z.J. van de Weg's avatar
    Z.J. van de Weg committed
              BindInOut.initAll();
    
              new Group();
              new GroupAvatar();
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'groups:edit':
            case 'admin:groups:edit':
              new GroupAvatar();
              break;
            case 'projects:tree:show':
              shortcut_handler = new ShortcutsNavigation();
              new TreeView();
    
              gl.TargetBranchDropDown.bootstrap();
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
            case 'projects:find_file:show':
              shortcut_handler = true;
              break;
    
            case 'projects:blob:new':
              gl.TargetBranchDropDown.bootstrap();
              break;
            case 'projects:blob:create':
              gl.TargetBranchDropDown.bootstrap();
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'projects:blob:show':
    
              gl.TargetBranchDropDown.bootstrap();
    
              break;
            case 'projects:blob:edit':
              gl.TargetBranchDropDown.bootstrap();
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'projects:blame:show':
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
    
            case 'groups:labels:new':
            case 'groups:labels:edit':
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'projects:labels:new':
            case 'projects:labels:edit':
              new Labels();
              break;
            case 'projects:labels:index':
              if ($('.prioritized-labels').length) {
    
                new gl.LabelManager();
    
    Fatih Acet's avatar
    Fatih Acet committed
              }
              break;
            case 'projects:network:show':
    
              // 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
              shortcut_handler = true;
              break;
            case 'projects:forks:new':
              new ProjectFork();
              break;
            case 'projects:artifacts:browse':
              new BuildArtifacts();
              break;
    
            case 'help:index':
              gl.VersionCheckImage.bindErrorEvent($('img.js-version-status-badge'));
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'search:show':
              new Search();
    
              // Initialize Protected Branch Settings
    
              new gl.ProtectedBranchCreate();
              new gl.ProtectedBranchEditList();
    
              // Initialize Protected Tag Settings
    
              new ProtectedTagCreate();
              new ProtectedTagEditList();
    
            case 'projects:ci_cd:show':
    
              new gl.ProjectVariables();
              break;
    
            case 'ci:lints:create':
            case 'ci:lints:show':
              new gl.CILintEditor();
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
          }
          switch (path.first()) {
    
            case 'sessions':
            case 'omniauth_callbacks':
              if (!gon.u2f) break;
              gl.u2fAuthenticate = new gl.U2FAuthenticate(
                $('#js-authenticate-u2f'),
                '#js-login-u2f-form',
                gon.u2f,
                document.querySelector('#js-login-2fa-device'),
                document.querySelector('.js-2fa-form'),
              );
              gl.u2fAuthenticate.start();
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'admin':
              new Admin();
              switch (path[1]) {
                case 'groups':
                  new UsersSelect();
                  break;
                case 'projects':
                  new NamespaceSelects();
    
                    case 'edit':
                      new Labels();
                  }
    
                case 'abuse_reports':
    
                  new gl.AbuseReports();
    
    Fatih Acet's avatar
    Fatih Acet committed
              }
              break;
            case 'dashboard':
            case 'root':
    
    Fatih Acet's avatar
    Fatih Acet committed
              break;
    
            case 'groups':
              new GroupName();
              break;
    
    Fatih Acet's avatar
    Fatih Acet committed
            case 'profiles':
              new NotificationsForm();
              new NotificationsDropdown();
              break;
            case 'projects':
              new Project();
              new ProjectAvatar();
    
              new GroupName();
    
    Fatih Acet's avatar
    Fatih Acet committed
              switch (path[1]) {
                case 'compare':
                  new CompareAutocomplete();
                  break;
                case 'edit':
                  shortcut_handler = new ShortcutsNavigation();
                  new ProjectNew();
                  break;
                case 'new':
                  new ProjectNew();
                  break;
                case 'show':
    
    Fatih Acet's avatar
    Fatih Acet committed
                  new ProjectNew();
                  new ProjectShow();
                  new NotificationsDropdown();
                  break;
                case 'wikis':
    
                  new gl.Wikis();
    
    Fatih Acet's avatar
    Fatih Acet committed
                  shortcut_handler = new ShortcutsNavigation();
                  new ZenMode();
    
    Luke "Jared" Bennett's avatar
    Luke "Jared" Bennett committed
                  new gl.GLForm($('.wiki-form'));
    
    Fatih Acet's avatar
    Fatih Acet committed
                  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();
              }
          }
    
          // If we haven't installed a custom shortcut handler, install the default one
    
    Fatih Acet's avatar
    Fatih Acet committed
          if (!shortcut_handler) {
    
    Fatih Acet's avatar
    Fatih Acet committed
          }
        };
    
        Dispatcher.prototype.initSearch = function() {
    
          // Only when search form is present
    
    Fatih Acet's avatar
    Fatih Acet committed
          if ($('.search').length) {
    
            return new gl.SearchAutocomplete();
    
        Dispatcher.prototype.initFieldErrors = function() {
    
          $('.gl-show-field-errors').each((i, form) => {
    
            new gl.GlFieldErrors(form);
          });
    
    Fatih Acet's avatar
    Fatih Acet committed
        return Dispatcher;
      })();