aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/coffee/api-documentation/app.coffee
blob: ec6713598e11357b4573a58a00e7ecb881fb572d (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
#
# SonarQube, open source software quality management tool.
# Copyright (C) 2008-2014 SonarSource
# mailto:contact AT sonarsource DOT com
#
# SonarQube is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# SonarQube is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

requirejs.config
  baseUrl: "#{baseUrl}/js"

requirejs [
  'api-documentation/collections/web-services',
  'api-documentation/views/api-documentation-list-view',
  'api-documentation/router',
  'api-documentation/layout'
], (
  WebServices,
  ApiDocumentationListView,
  ApiDocumentationRouter,
  ApiDocumentationLayout
) ->

  # Create a Quality Gate Application
  App = new Marionette.Application

  App.webServices = new WebServices

  App.openFirstWebService = ->
    if @webServices.length > 0
      @router.navigate "#{@webServices.models[0].get('path')}", trigger: true
    else
      App.layout.detailsRegion.reset()

  App.refresh = ->
    App.apiDocumentationListView = new ApiDocumentationListView
      collection: App.webServices
      app: App
    App.layout.resultsRegion.show App.apiDocumentationListView
    if (Backbone.history.fragment)
      App.router.show Backbone.history.fragment, trigger: true

  # Construct layout
  App.addInitializer ->
    @layout = new ApiDocumentationLayout app: App
    jQuery('#api-documentation').append @layout.render().el
    jQuery('#footer').addClass 'search-navigator-footer'

  # Construct sidebar
  App.addInitializer ->
    App.refresh()

  # Start router
  App.addInitializer ->
    @router = new ApiDocumentationRouter app: @
    Backbone.history.start()

  # Open first Web Service when page is opened
  App.addInitializer ->
    initial = Backbone.history.fragment == ''
    App.openFirstWebService() if initial

  webServicesXHR = App.webServices.fetch()

  jQuery.when(webServicesXHR)
    .done ->
      # Remove the initial spinner
      jQuery('#api-documentation-page-loader').remove()

      # Start the application
      App.start()