dispatcher.js.coffee 4.21 KB
Newer Older
1 2
$ ->
  new Dispatcher()
3

4 5
class Dispatcher
  constructor: () ->
6
    @initSearch()
7
    @initHighlight()
8 9 10
    @initPageScripts()

  initPageScripts: ->
11
    page = $('body').attr('data-page')
12
    project_id = $('body').attr('data-project-id')
13

14 15 16
    unless page
      return false

17
    path = page.split(':')
18
    shortcut_handler = null
19 20

    switch page
21
      when 'projects:issues:index'
22
        Issues.init()
23
        shortcut_handler = new ShortcutsNavigation()
24 25
      when 'projects:issues:show'
        new Issue()
26
        shortcut_handler = new ShortcutsIssueable()
27
        new ZenMode()
28 29
      when 'projects:milestones:show'
        new Milestone()
30 31
      when 'projects:milestones:new'
        new ZenMode()
32
      when 'projects:issues:new','projects:issues:edit'
33
        GitLab.GfmAutoComplete.setup()
34
        shortcut_handler = new ShortcutsNavigation()
35 36
        new ZenMode()
      when 'projects:merge_requests:new', 'projects:merge_requests:edit'
skv's avatar
skv committed
37 38
        GitLab.GfmAutoComplete.setup()
        new Diff()
39
        shortcut_handler = new ShortcutsNavigation()
40
        new ZenMode()
skv's avatar
skv committed
41 42
      when 'projects:merge_requests:show'
        new Diff()
43
        shortcut_handler = new ShortcutsIssueable()
44
        new ZenMode()
skv's avatar
skv committed
45 46
      when "projects:merge_requests:diffs"
        new Diff()
47 48
      when 'projects:merge_requests:index'
        shortcut_handler = new ShortcutsNavigation()
49 50
      when 'dashboard:show'
        new Dashboard()
51
        new Activities()
52
      when 'projects:commit:show'
53
        new Commit()
skv's avatar
skv committed
54
        new Diff()
55 56 57
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:commits:show'
        shortcut_handler = new ShortcutsNavigation()
58
      when 'groups:show', 'projects:show'
59
        new Activities()
60
        shortcut_handler = new ShortcutsNavigation()
61
      when 'projects:teams:members:index'
62
        new TeamMembers()
63
      when 'groups:members'
64
        new GroupMembers()
65
        new UsersSelect()
66 67
      when 'groups:new', 'groups:edit', 'admin:groups:edit'
        new GroupAvatar()
68 69
      when 'projects:tree:show'
        new TreeView()
70
        shortcut_handler = new ShortcutsNavigation()
71 72
      when 'projects:blob:show'
        new BlobView()
73
        shortcut_handler = new ShortcutsNavigation()
74
      when 'projects:labels:new', 'projects:labels:edit'
75
        new Labels()
76 77 78 79
      when 'projects:network:show'
        # Ensure we don't create a particular shortcut handler here. This is
        # already created, where the network graph is created.
        shortcut_handler = true
80 81
      when 'users:show'
        new User()
82 83

    switch path.first()
84 85 86
      when 'admin'
        new Admin()
        switch path[1]
87 88
          when 'groups'
            new UsersSelect()
89 90
          when 'projects'
            new NamespaceSelect()
91 92
      when 'dashboard'
        shortcut_handler = new ShortcutsDashboardNavigation()
93 94
      when 'profiles'
        new Profile()
95
      when 'projects'
96
        new Project()
97
        switch path[1]
98 99 100 101 102 103 104
          when 'edit'
            shortcut_handler = new ShortcutsNavigation()
            new ProjectNew()
          when 'new'
            new ProjectNew()
          when 'show'
            new ProjectShow()
105 106
          when 'issues', 'merge_requests'
            new ProjectUsersSelect()
107 108 109
          when 'wikis'
            new Wikis()
            shortcut_handler = new ShortcutsNavigation()
110
            new ZenMode()
111 112 113 114
          when 'snippets', 'labels', 'graphs'
            shortcut_handler = new ShortcutsNavigation()
          when 'team_members', 'deploy_keys', 'hooks', 'services', 'protected_branches'
            shortcut_handler = new ShortcutsNavigation()
115
            new UsersSelect()
116

117

118 119 120
    # If we haven't installed a custom shortcut handler, install the default one
    if not shortcut_handler
      new Shortcuts()
121

122
  initSearch: ->
123 124 125 126 127 128
    opts = $('.search-autocomplete-opts')
    path = opts.data('autocomplete-path')
    project_id = opts.data('autocomplete-project-id')
    project_ref = opts.data('autocomplete-project-ref')

    new SearchAutocomplete(path, project_id, project_ref)
129 130

  initHighlight: ->
131
    $('.highlight pre code').each (i, e) ->
132
      $(e).html($.map($(e).html().split("\n"), (line, i) ->
Evan Lucas's avatar
Evan Lucas committed
133
        "<span class='line' id='LC" + (i + 1) + "'>" + line + "</span>"
134
      ).join("\n"))
Evan Lucas's avatar
Evan Lucas committed
135
      hljs.highlightBlock(e)