]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5250 Initialize backbone app for API documentation
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 30 Apr 2014 16:34:35 +0000 (18:34 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 30 Apr 2014 16:34:42 +0000 (18:34 +0200)
19 files changed:
sonar-server/Gruntfile.coffee
sonar-server/src/main/coffee/api-documentation/app.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/api-documentation/collections/web-service-actions.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/api-documentation/collections/web-services.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/api-documentation/layout.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/api-documentation/models/web-service-action.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/api-documentation/models/web-service.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/api-documentation/views/api-documentation-action-view.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/api-documentation/views/api-documentation-actions-list-view.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/api-documentation/views/api-documentation-list-view.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/api-documentation/views/api-documentation-web-service-view.coffee [new file with mode: 0644]
sonar-server/src/main/hbs/api-documentation/api-documentation-action.hbs [new file with mode: 0644]
sonar-server/src/main/hbs/api-documentation/api-documentation-actions.hbs [new file with mode: 0644]
sonar-server/src/main/hbs/api-documentation/api-documentation-layout.hbs [new file with mode: 0644]
sonar-server/src/main/hbs/api-documentation/api-documentation-web-service.hbs [new file with mode: 0644]
sonar-server/src/main/less/api-documentation.less [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/controllers/api_documentation_controller.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/api_documentation/index.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb

index 3dc59ffafc98d369f161ba2ac206de20cd4e61ed..c4387bffef0c446db5e7015d24cb7d15fadda891 100644 (file)
@@ -163,6 +163,10 @@ module.exports = (grunt) ->
         name: 'common/select-list'
         out: '<%= pkg.assets %>build/js/common/select-list.js'
 
+      apiDocumentation: options:
+        name: 'api-documentation/app'
+        out: '<%= pkg.assets %>build/js/api-documentation/app.js'
+
 
     handlebars:
       options:
@@ -193,6 +197,9 @@ module.exports = (grunt) ->
             '<%= pkg.sources %>hbs/common/**/*.hbs'
             '<%= pkg.sources %>hbs/issues/**/*.hbs'
           ]
+          '<%= pkg.assets %>js/templates/api-documentation.js': [
+            '<%= pkg.sources %>hbs/api-documentation/**/*.hbs'
+          ]
 
 
     clean:
diff --git a/sonar-server/src/main/coffee/api-documentation/app.coffee b/sonar-server/src/main/coffee/api-documentation/app.coffee
new file mode 100644 (file)
index 0000000..a902210
--- /dev/null
@@ -0,0 +1,62 @@
+requirejs.config
+  baseUrl: "#{baseUrl}/js"
+
+  paths:
+    'jquery': 'third-party/jquery'
+    'backbone': 'third-party/backbone'
+    'backbone.marionette': 'third-party/backbone.marionette'
+    'handlebars': 'third-party/handlebars'
+    'moment': 'third-party/moment'
+
+  shim:
+    'backbone.marionette':
+      deps: ['backbone']
+      exports: 'Marionette'
+    'backbone':
+      exports: 'Backbone'
+    'handlebars':
+      exports: 'Handlebars'
+    'moment':
+      exports: 'moment'
+
+
+requirejs [
+  'backbone', 'backbone.marionette', 'handlebars',
+  'api-documentation/collections/web-services',
+  'api-documentation/views/api-documentation-list-view',
+  'api-documentation/layout',
+  'common/handlebars-extensions'
+], (
+  Backbone, Marionette, Handlebars,
+  WebServices,
+  ApiDocumentationListView,
+  ApiDocumentationLayout
+) ->
+
+  # Create a Quality Gate Application
+  App = new Marionette.Application
+
+
+  App.webServices = new WebServices
+
+  # Construct layout
+  App.addInitializer ->
+    @layout = new ApiDocumentationLayout app: @
+    jQuery('#body').append @layout.render().el
+
+  # Construct sidebar
+  App.addInitializer ->
+    @apiDocumentationListView = new ApiDocumentationListView
+      collection: @webServices
+      app: @
+    @layout.resultsRegion.show @apiDocumentationListView
+
+  webServicesXHR = App.webServices.fetch()
+
+  jQuery.when(webServicesXHR)
+    .done ->
+      # Remove the initial spinner
+      jQuery('#api-documentation-page-loader').remove()
+
+      # Start the application
+      App.start()
diff --git a/sonar-server/src/main/coffee/api-documentation/collections/web-service-actions.coffee b/sonar-server/src/main/coffee/api-documentation/collections/web-service-actions.coffee
new file mode 100644 (file)
index 0000000..378c5aa
--- /dev/null
@@ -0,0 +1,11 @@
+define [
+  'backbone',
+  'api-documentation/models/web-service-action'
+], (
+  Backbone,
+  WebServiceAction
+) ->
+
+  class WebServiceActions extends Backbone.Collection
+    model: WebServiceAction
+    comparator: 'key'
diff --git a/sonar-server/src/main/coffee/api-documentation/collections/web-services.coffee b/sonar-server/src/main/coffee/api-documentation/collections/web-services.coffee
new file mode 100644 (file)
index 0000000..c8b7676
--- /dev/null
@@ -0,0 +1,19 @@
+define [
+  'backbone',
+  'api-documentation/models/web-service'
+], (
+  Backbone,
+  WebService
+) ->
+
+  class WebServices extends Backbone.Collection
+    model: WebService
+
+    url: ->
+      "#{baseUrl}/api/webservices/list"
+
+    parse: (r) ->
+      r.webServices.map (webService) ->
+        _.extend webService
+
+    comparator: (item) -> item.get('path')
diff --git a/sonar-server/src/main/coffee/api-documentation/layout.coffee b/sonar-server/src/main/coffee/api-documentation/layout.coffee
new file mode 100644 (file)
index 0000000..7265fa6
--- /dev/null
@@ -0,0 +1,14 @@
+define [
+  'backbone.marionette',
+  'templates/api-documentation'
+], (
+  Marionette,
+  Templates
+) ->
+
+  class AppLayout extends Marionette.Layout
+    className: 'api-documentation-layout'
+    template: Templates['api-documentation-layout']
+
+    regions:
+      resultsRegion: '.api-documentation-results'
diff --git a/sonar-server/src/main/coffee/api-documentation/models/web-service-action.coffee b/sonar-server/src/main/coffee/api-documentation/models/web-service-action.coffee
new file mode 100644 (file)
index 0000000..9b4bf6e
--- /dev/null
@@ -0,0 +1,7 @@
+define [
+  'backbone'
+], (
+  Backbone
+) ->
+
+  class WebServiceAction extends Backbone.Model
diff --git a/sonar-server/src/main/coffee/api-documentation/models/web-service.coffee b/sonar-server/src/main/coffee/api-documentation/models/web-service.coffee
new file mode 100644 (file)
index 0000000..f33a2fc
--- /dev/null
@@ -0,0 +1,7 @@
+define [
+  'backbone'
+], (
+  Backbone
+) ->
+
+  class WebService extends Backbone.Model
diff --git a/sonar-server/src/main/coffee/api-documentation/views/api-documentation-action-view.coffee b/sonar-server/src/main/coffee/api-documentation/views/api-documentation-action-view.coffee
new file mode 100644 (file)
index 0000000..7ff3d0d
--- /dev/null
@@ -0,0 +1,14 @@
+define [
+  'backbone.marionette',
+  'templates/api-documentation'
+], (
+  Marionette,
+  Templates
+) ->
+
+  class ApiDocumentationActionView extends Marionette.ItemView
+    tagName: 'div'
+    className: 'api-documentation-action'
+    template: Templates['api-documentation-action']
+    spinner: '<i class="spinner"></i>'
+
diff --git a/sonar-server/src/main/coffee/api-documentation/views/api-documentation-actions-list-view.coffee b/sonar-server/src/main/coffee/api-documentation/views/api-documentation-actions-list-view.coffee
new file mode 100644 (file)
index 0000000..584aa4e
--- /dev/null
@@ -0,0 +1,18 @@
+define [
+  'backbone.marionette',
+  'templates/api-documentation'
+  'api-documentation/models/web-service-action',
+  'api-documentation/views/api-documentation-action-view'
+], (
+  Marionette,
+  Templates
+  WebServiceAction,
+  ApiDocumentationActionView
+) ->
+
+  class ApiDocumentationActionsListView extends Marionette.CompositeView
+    tagName: 'div'
+    template: Templates['api-documentation-actions']
+    itemView: ApiDocumentationActionView
+    itemViewContainer: '.api-documentation-actions-list'
+
diff --git a/sonar-server/src/main/coffee/api-documentation/views/api-documentation-list-view.coffee b/sonar-server/src/main/coffee/api-documentation/views/api-documentation-list-view.coffee
new file mode 100644 (file)
index 0000000..f0e65f2
--- /dev/null
@@ -0,0 +1,16 @@
+define [
+  'backbone.marionette',
+  'api-documentation/views/api-documentation-web-service-view'
+], (
+  Marionette,
+  ApiDocumentationWebServiceView
+) ->
+
+  class ApiDocumentationListView extends Marionette.CollectionView
+    tagName: 'table'
+    className: 'web-services-list'
+    itemView: ApiDocumentationWebServiceView
+
+
+    itemViewOptions: (model) ->
+      app: @options.app
diff --git a/sonar-server/src/main/coffee/api-documentation/views/api-documentation-web-service-view.coffee b/sonar-server/src/main/coffee/api-documentation/views/api-documentation-web-service-view.coffee
new file mode 100644 (file)
index 0000000..3669dfa
--- /dev/null
@@ -0,0 +1,31 @@
+define [
+  'backbone.marionette',
+  'templates/api-documentation',
+  'api-documentation/collections/web-service-actions'
+  'api-documentation/views/api-documentation-actions-list-view'
+], (
+  Marionette,
+  Templates,
+  WebServiceActions,
+  ApiDocumentationActionsListView
+) ->
+
+  class ApiDocumentationWebServiceView extends Marionette.Layout
+    tagName: 'tr'
+    template: Templates['api-documentation-web-service']
+    spinner: '<i class="spinner"></i>'
+
+    regions:
+      actionsRegion: '.web-service-actions'
+
+    onRender: ->
+      @showActions()
+
+
+    showActions: ->
+      actions = new WebServiceActions @model.get('actions')
+      view = new ApiDocumentationActionsListView
+        app: @options.app
+        collection: actions
+        webService: @model
+      @actionsRegion.show view
diff --git a/sonar-server/src/main/hbs/api-documentation/api-documentation-action.hbs b/sonar-server/src/main/hbs/api-documentation/api-documentation-action.hbs
new file mode 100644 (file)
index 0000000..3ccf94c
--- /dev/null
@@ -0,0 +1,2 @@
+<h3>{{key}}</h3>
+<p>{{description}}</p>
\ No newline at end of file
diff --git a/sonar-server/src/main/hbs/api-documentation/api-documentation-actions.hbs b/sonar-server/src/main/hbs/api-documentation/api-documentation-actions.hbs
new file mode 100644 (file)
index 0000000..8f24e09
--- /dev/null
@@ -0,0 +1 @@
+<div class="api-documentation-actions-list"></div>
\ No newline at end of file
diff --git a/sonar-server/src/main/hbs/api-documentation/api-documentation-layout.hbs b/sonar-server/src/main/hbs/api-documentation/api-documentation-layout.hbs
new file mode 100644 (file)
index 0000000..23ba2ff
--- /dev/null
@@ -0,0 +1,4 @@
+<div class="api-documentation-layout">
+       <div class="api-documentation-results">
+       </div>
+</div>
diff --git a/sonar-server/src/main/hbs/api-documentation/api-documentation-web-service.hbs b/sonar-server/src/main/hbs/api-documentation/api-documentation-web-service.hbs
new file mode 100644 (file)
index 0000000..88c4399
--- /dev/null
@@ -0,0 +1,6 @@
+<td><h2>{{path}}</h2></td>
+<td>
+       <p class="web-service-description">{{description}}</p>
+       <div class="web-service-actions">
+       </div>
+</td>
\ No newline at end of file
diff --git a/sonar-server/src/main/less/api-documentation.less b/sonar-server/src/main/less/api-documentation.less
new file mode 100644 (file)
index 0000000..b12bc15
--- /dev/null
@@ -0,0 +1,21 @@
+@import "variables";
+@import "mixins";
+@import "navigator/config";
+
+.web-services-list {
+       width: 100%;
+       margin: 10px;
+
+       td {
+               vertical-align: top;
+               padding-bottom: 10px;
+       }
+
+       .web-service-description {
+               margin-bottom: 20px;
+       }
+
+       .api-documentation-action {
+               margin-bottom: 10px;
+       }
+}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api_documentation_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api_documentation_controller.rb
new file mode 100644 (file)
index 0000000..2505027
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+
+class ApiDocumentationController < ApplicationController
+
+  # GET /api_documentation/index
+  def index
+
+  end
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/api_documentation/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/api_documentation/index.html.erb
new file mode 100644 (file)
index 0000000..da8a834
--- /dev/null
@@ -0,0 +1,7 @@
+<% content_for :script do %>
+  <script data-main="<%= ApplicationController.root_context -%>/js/api-documentation/app" src="<%= ApplicationController.root_context -%>/js/require.js"></script>
+<% end %>
+
+<div id="api-documentation-page-loader" class="navigator-page-loader">
+  <i class="spinner"></i>
+</div>
index 92f6894cdeb7034063da5e4972cb8d9f0229eba5..38d86a3f656d60ad3d69e2130f3e48d2fa1f6a84 100644 (file)
         <a href="http://www.sonarqube.org" target="sonar">Community</a> -
         <a href="http://www.sonarqube.org/documentation" target="sonar_doc">Documentation</a> -
         <a href="http://www.sonarqube.org/support" target="support">Get Support</a> -
-        <a href="http://sonar-plugins.codehaus.org" target="plugins">Plugins</a>
+        <a href="http://sonar-plugins.codehaus.org" target="plugins">Plugins</a> -
+        <a href="<%= ApplicationController.root_context -%>/api_documentation">API</a>
         <% unless DatabaseVersion.production? %>
           <br><br><span class="error big" id="evaluation_warning">Embedded database should be used for evaluation purpose only</span>
           <br><br><span class="error">The embedded database will not scale, it will not support upgrading to newer versions of SonarQube, and there is no support for migrating your data out of it into a different database engine.</span>