diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-30 18:34:35 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-30 18:34:42 +0200 |
commit | 1a73ae4ff587baf9e81f10db490c7aacfae3a90a (patch) | |
tree | 65f49271944ab11dd20ce8d39abde72f276fad1a | |
parent | 8f61950f75475d6d88b9cd62cab49a5614d12b6c (diff) | |
download | sonarqube-1a73ae4ff587baf9e81f10db490c7aacfae3a90a.tar.gz sonarqube-1a73ae4ff587baf9e81f10db490c7aacfae3a90a.zip |
SONAR-5250 Initialize backbone app for API documentation
19 files changed, 277 insertions, 1 deletions
diff --git a/sonar-server/Gruntfile.coffee b/sonar-server/Gruntfile.coffee index 3dc59ffafc9..c4387bffef0 100644 --- a/sonar-server/Gruntfile.coffee +++ b/sonar-server/Gruntfile.coffee @@ -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 index 00000000000..a9022104547 --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/app.coffee @@ -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 index 00000000000..378c5aa2b5b --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/collections/web-service-actions.coffee @@ -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 index 00000000000..c8b767618cf --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/collections/web-services.coffee @@ -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 index 00000000000..7265fa6529a --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/layout.coffee @@ -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 index 00000000000..9b4bf6e5983 --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/models/web-service-action.coffee @@ -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 index 00000000000..f33a2fce9f2 --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/models/web-service.coffee @@ -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 index 00000000000..7ff3d0d5c51 --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/views/api-documentation-action-view.coffee @@ -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 index 00000000000..584aa4ea7b2 --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/views/api-documentation-actions-list-view.coffee @@ -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 index 00000000000..f0e65f24c0f --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/views/api-documentation-list-view.coffee @@ -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 index 00000000000..3669dfafc6d --- /dev/null +++ b/sonar-server/src/main/coffee/api-documentation/views/api-documentation-web-service-view.coffee @@ -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 index 00000000000..3ccf94cdbc4 --- /dev/null +++ b/sonar-server/src/main/hbs/api-documentation/api-documentation-action.hbs @@ -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 index 00000000000..8f24e090486 --- /dev/null +++ b/sonar-server/src/main/hbs/api-documentation/api-documentation-actions.hbs @@ -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 index 00000000000..23ba2ff172a --- /dev/null +++ b/sonar-server/src/main/hbs/api-documentation/api-documentation-layout.hbs @@ -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 index 00000000000..88c4399c793 --- /dev/null +++ b/sonar-server/src/main/hbs/api-documentation/api-documentation-web-service.hbs @@ -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 index 00000000000..b12bc15430e --- /dev/null +++ b/sonar-server/src/main/less/api-documentation.less @@ -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 index 00000000000..2505027da6a --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api_documentation_controller.rb @@ -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 index 00000000000..da8a834d102 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/api_documentation/index.html.erb @@ -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> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index 92f6894cdeb..38d86a3f656 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -210,7 +210,8 @@ <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> |