summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/dispatcher.js.coffee
blob: 1c52933f186bc5d3bbab69bdaf657edb046c8375 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
$ ->
  new Dispatcher()

class Dispatcher
  constructor: () ->
    @initSearch()
    @initHighlight()
    @initPageScripts()

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

    unless page
      return false

    path = page.split(':')
    shortcut_handler = null

    switch page
      when 'projects:issues:index'
        Issues.init()
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:issues:show'
        new Issue()
        shortcut_handler = new ShortcutsIssueable()
        new ZenMode()
      when 'projects:milestones:show'
        new Milestone()
      when 'projects:milestones:new'
        new ZenMode()
      when 'projects:issues:new','projects:issues:edit'
        GitLab.GfmAutoComplete.setup()
        shortcut_handler = new ShortcutsNavigation()
        new ZenMode()
      when 'projects:merge_requests:new', 'projects:merge_requests:edit'
        GitLab.GfmAutoComplete.setup()
        new Diff()
        shortcut_handler = new ShortcutsNavigation()
        new ZenMode()
      when 'projects:merge_requests:show'
        new Diff()
        shortcut_handler = new ShortcutsIssueable()
        new ZenMode()
      when "projects:merge_requests:diffs"
        new Diff()
      when 'projects:merge_requests:index'
        shortcut_handler = new ShortcutsNavigation()
      when 'dashboard:show'
        new Dashboard()
        new Activities()
      when 'projects:commit:show'
        new Commit()
        new Diff()
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:commits:show'
        shortcut_handler = new ShortcutsNavigation()
      when 'groups:show', 'projects:show'
        new Activities()
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:new'
        new Project()
      when 'projects:edit'
        new Project()
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:teams:members:index'
        new TeamMembers()
      when 'groups:members'
        new GroupMembers()
      when 'projects:tree:show'
        new TreeView()
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:blob:show'
        new BlobView()
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:labels:new', 'projects:labels:edit'
        new Labels()
      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
      when 'users:show'
        new User()

    switch path.first()
      when 'admin' then new Admin()
      when 'dashboard'
        shortcut_handler = new ShortcutsDashboardNavigation()
      when 'profiles'
        new Profile()
      when 'projects'
        switch path[1]
          when 'wikis'
            new Wikis()
            shortcut_handler = new ShortcutsNavigation()
            new ZenMode()
          when 'snippets', 'labels', 'graphs'
            shortcut_handler = new ShortcutsNavigation()
          when 'team_members', 'deploy_keys', 'hooks', 'services', 'protected_branches'
            shortcut_handler = new ShortcutsNavigation()


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

  initSearch: ->
    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)

  initHighlight: ->
    $('.highlight pre code').each (i, e) ->
      $(e).html($.map($(e).html().split("\n"), (line, i) ->
        "<span class='line' id='LC" + (i + 1) + "'>" + line + "</span>"
      ).join("\n"))
      hljs.highlightBlock(e)