From 1a73ae4ff587baf9e81f10db490c7aacfae3a90a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Wed, 30 Apr 2014 18:34:35 +0200 Subject: [PATCH] SONAR-5250 Initialize backbone app for API documentation --- sonar-server/Gruntfile.coffee | 7 +++ .../main/coffee/api-documentation/app.coffee | 62 +++++++++++++++++++ .../collections/web-service-actions.coffee | 11 ++++ .../collections/web-services.coffee | 19 ++++++ .../coffee/api-documentation/layout.coffee | 14 +++++ .../models/web-service-action.coffee | 7 +++ .../models/web-service.coffee | 7 +++ .../api-documentation-action-view.coffee | 14 +++++ ...api-documentation-actions-list-view.coffee | 18 ++++++ .../views/api-documentation-list-view.coffee | 16 +++++ .../api-documentation-web-service-view.coffee | 31 ++++++++++ .../api-documentation-action.hbs | 2 + .../api-documentation-actions.hbs | 1 + .../api-documentation-layout.hbs | 4 ++ .../api-documentation-web-service.hbs | 6 ++ .../src/main/less/api-documentation.less | 21 +++++++ .../api_documentation_controller.rb | 28 +++++++++ .../views/api_documentation/index.html.erb | 7 +++ .../app/views/layouts/_layout.html.erb | 3 +- 19 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 sonar-server/src/main/coffee/api-documentation/app.coffee create mode 100644 sonar-server/src/main/coffee/api-documentation/collections/web-service-actions.coffee create mode 100644 sonar-server/src/main/coffee/api-documentation/collections/web-services.coffee create mode 100644 sonar-server/src/main/coffee/api-documentation/layout.coffee create mode 100644 sonar-server/src/main/coffee/api-documentation/models/web-service-action.coffee create mode 100644 sonar-server/src/main/coffee/api-documentation/models/web-service.coffee create mode 100644 sonar-server/src/main/coffee/api-documentation/views/api-documentation-action-view.coffee create mode 100644 sonar-server/src/main/coffee/api-documentation/views/api-documentation-actions-list-view.coffee create mode 100644 sonar-server/src/main/coffee/api-documentation/views/api-documentation-list-view.coffee create mode 100644 sonar-server/src/main/coffee/api-documentation/views/api-documentation-web-service-view.coffee create mode 100644 sonar-server/src/main/hbs/api-documentation/api-documentation-action.hbs create mode 100644 sonar-server/src/main/hbs/api-documentation/api-documentation-actions.hbs create mode 100644 sonar-server/src/main/hbs/api-documentation/api-documentation-layout.hbs create mode 100644 sonar-server/src/main/hbs/api-documentation/api-documentation-web-service.hbs create mode 100644 sonar-server/src/main/less/api-documentation.less create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/controllers/api_documentation_controller.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/api_documentation/index.html.erb 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: '' + 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: '' + + 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 @@ +

{{key}}

+

{{description}}

\ 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 @@ +
\ 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 @@ +
+
+
+
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 @@ +

{{path}}

+ +

{{description}}

+
+
+ \ 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 %> + +<% end %> + + 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 @@ Community - Documentation - Get Support - - Plugins + Plugins - + API <% unless DatabaseVersion.production? %>

Embedded database should be used for evaluation purpose only

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. -- 2.39.5