aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/coffee/analysis-reports/app.coffee
blob: 80b07c5f073a593f824644d25fad32a4f4f5dd5b (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
requirejs.config
  baseUrl: "#{baseUrl}/js"

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

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


requirejs [
  'backbone', 'backbone.marionette'

  'analysis-reports/router'
  'analysis-reports/layout'
  'analysis-reports/models/reports'
  'analysis-reports/views/reports-view'
  'analysis-reports/views/actions-view'

  'common/handlebars-extensions'
], (
  Backbone, Marionette
  Router
  Layout
  Reports
  ReportsView
  ActionsView
) ->

  # Add html class to mark the page as navigator page
  jQuery('html').addClass 'navigator-page'


  # Create an Application
  App = new Marionette.Application


  App.fetchReports = ->
    process = window.process.addBackgroundProcess()
    fetch = if @state.get 'active' then @reports.fetchActive() else @reports.fetchHistory()
    @layout.showSpinner 'actionsRegion'
    @layout.resultsRegion.reset()
    fetch.done =>
      @state.set page: @reports.paging.page
      @reportsView = new ReportsView
        app: @
        collection: @reports
      @layout.resultsRegion.show @reportsView

      unless @state.get('active') || @reports.paging.maxResultsReached
        @reportsView.bindScrollEvents() unless @state.get 'active'

      @actionsView = new ActionsView
        app: @
        collection: @reports
      @layout.actionsRegion.show @actionsView

      window.process.finishBackgroundProcess process


  App.fetchNextPage = ->
    process = window.process.addBackgroundProcess()
    @reports.fetchHistory
      data:
        p: @state.get('page') + 1
      remove: false
    .done =>
      @state.set page: @reports.paging.page
      window.process.finishBackgroundProcess process


  App.addInitializer ->
    @state = new Backbone.Model()
    @state.on 'change:active', => @fetchReports()


  App.addInitializer ->
    @layout = new Layout app: @
    jQuery('#analysis-reports').empty().append @layout.render().el


  App.addInitializer ->
    @reports = new Reports()
    @router = new Router app: @
    Backbone.history.start()


  l10nXHR = window.requestMessages()
  jQuery.when(l10nXHR).done -> App.start()