aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/coffee/component-viewer/app.coffee
blob: 7994287166a7187f3b52f4541e00960b5cce5b63 (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
requirejs.config
  baseUrl: "#{baseUrl}/js"

  paths:
    'backbone': 'third-party/backbone'
    'backbone.marionette': 'third-party/backbone.marionette'
    'handlebars': 'third-party/handlebars'
    'jquery.mockjax': 'third-party/jquery.mockjax'

  shim:
    'backbone.marionette':
      deps: ['backbone']
      exports: 'Marionette'
    'backbone':
      exports: 'Backbone'
    'handlebars':
      exports: 'Handlebars'


requirejs [
  'backbone.marionette'
  'component-viewer/main'
], (
  Marionette
  ComponentViewer
) ->

  $ = jQuery
  API_ISSUE = "#{baseUrl}/api/issues/show"
  App = new Marionette.Application()


  App.addRegions
    viewerRegion: '#component-viewer'


  App.requestComponentViewer = (s, currentIssue) ->
    if s?
      settings = issues: false, coverage: false, duplications: false, scm: false, workspace: false
      s.split(',').forEach (d) -> settings[d] = true
      settings.issues = false if currentIssue?
    else settings = null
    unless App.componentViewer?
      App.componentViewer = new ComponentViewer settings: settings
      App.viewerRegion.show App.componentViewer
    App.componentViewer


  App.addInitializer ->
    # Define parameters
    paramsHash = location.hash.substr(1)
    params = {}
    paramsHash.split('&').forEach (d) ->
      t = d.split '='
      params[t[0]] = decodeURIComponent t[1]

    viewer = App.requestComponentViewer params.settings, params.currentIssue
    if params.component?
      loadIssue = (key) ->
        $.get API_ISSUE, key: key, (r) =>
          viewer.showIssues false, r.issue

      if params.line?
        viewer.sourceView.highlightedLine = params.line
        viewer.on 'sized', ->
          viewer.off 'sized'
          viewer.scrollToLine params.line

      if params.blocks?
        blocks = params.blocks.split(';').map (b) ->
          t = b.split ','
          from: +t[0], to: +t[1]
        viewer.on 'resetShowBlocks', -> viewer.sourceView.showBlocks = blocks

      viewer.open params.component

      viewer.on 'loaded', ->
        viewer.off 'loaded'
        if params.tab? && params.item? && params.period?
          viewer.headerView.enableBar(params.tab).done ->
            viewer.enablePeriod +params.period, params.item
        else if params.tab? && params.item?
          viewer.state.set activeHeaderTab: params.tab, activeHeaderItem: params.item
          viewer.headerView.render()
        else if params.tab? && params.period?
          viewer.headerView.enableBar(params.tab).done ->
            viewer.enablePeriod params.period
        else if params.tab? && params.currentIssue?
          loadIssue(params.currentIssue).done ->
            viewer.state.set activeHeaderTab: params.tab
            viewer.headerView.render()
        else if params.tab?
          viewer.state.set activeHeaderTab: params.tab
          viewer.headerView.render()
          viewer.showAllLines()
        else if params.currentIssue?
          loadIssue params.currentIssue
        else viewer.showAllLines()



  # Message bundles
  l10nXHR = window.requestMessages()


  $.when(l10nXHR).done ->
    # Start the application
    App.start()