From ba80308af044487d736ecb66d6f7874d82d172f1 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 20 Aug 2014 18:09:12 +0600 Subject: [PATCH] SONAR-4407 Refactor the libraries page in order to drop GWT List the component's libraries --- server/sonar-web/Gruntfile.coffee | 7 +++ .../src/main/coffee/libraries/app.coffee | 51 ++++++++++++++++++ .../src/main/coffee/libraries/view.coffee | 14 +++++ .../src/main/hbs/libraries/libraries.hbs | 43 +++++++++++++++ .../main/js/common/handlebars-extensions.js | 20 ++++++- server/sonar-web/src/main/less/libraries.less | 52 +++++++++++++++++++ .../app/controllers/libraries_controller.rb | 38 ++++++++++++++ .../app/views/layouts/_layout.html.erb | 3 ++ .../app/views/libraries/index.html.erb | 11 ++++ 9 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 server/sonar-web/src/main/coffee/libraries/app.coffee create mode 100644 server/sonar-web/src/main/coffee/libraries/view.coffee create mode 100644 server/sonar-web/src/main/hbs/libraries/libraries.hbs create mode 100644 server/sonar-web/src/main/less/libraries.less create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/app/controllers/libraries_controller.rb create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/app/views/libraries/index.html.erb diff --git a/server/sonar-web/Gruntfile.coffee b/server/sonar-web/Gruntfile.coffee index 6221292a235..88e35c0930a 100644 --- a/server/sonar-web/Gruntfile.coffee +++ b/server/sonar-web/Gruntfile.coffee @@ -202,6 +202,10 @@ module.exports = (grunt) -> name: 'design/app' out: '<%= pkg.assets %>build/js/design/app.js' + libraries: options: + name: 'libraries/app' + out: '<%= pkg.assets %>build/js/libraries/app.js' + handlebars: options: @@ -244,6 +248,9 @@ module.exports = (grunt) -> '<%= pkg.assets %>js/templates/design.js': [ '<%= pkg.sources %>hbs/design/**/*.hbs' ] + '<%= pkg.assets %>js/templates/libraries.js': [ + '<%= pkg.sources %>hbs/libraries/**/*.hbs' + ] clean: diff --git a/server/sonar-web/src/main/coffee/libraries/app.coffee b/server/sonar-web/src/main/coffee/libraries/app.coffee new file mode 100644 index 00000000000..ee5e8c5d39a --- /dev/null +++ b/server/sonar-web/src/main/coffee/libraries/app.coffee @@ -0,0 +1,51 @@ +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' + 'libraries/view' + 'common/handlebars-extensions' +], ( + Backbone, Marionette + LibrariesView +) -> + + $ = jQuery + RESOURCES_URL = "#{baseUrl}/api/resources" + DEPENDENCY_TREE_URL = "#{baseUrl}/api/dependency_tree" + App = new Marionette.Application + + + App.addInitializer -> + $.get RESOURCES_URL, resource: window.resourceKey, scopes: 'PRJ', depth: -1, (rawData) -> + components = new Backbone.Collection rawData + requests = components.map (component) -> + id = component.get 'id' + $.get DEPENDENCY_TREE_URL, resource: id, scopes: 'PRJ', (data) -> + component.set 'libraries', data + + $.when.apply($, requests).done => + @view = new LibrariesView app: @, collection: components + $('#project-libraries').empty().append @view.render().el + + + # Message bundles + l10nXHR = window.requestMessages() + + + jQuery.when(l10nXHR).done -> App.start() diff --git a/server/sonar-web/src/main/coffee/libraries/view.coffee b/server/sonar-web/src/main/coffee/libraries/view.coffee new file mode 100644 index 00000000000..f135af43f5d --- /dev/null +++ b/server/sonar-web/src/main/coffee/libraries/view.coffee @@ -0,0 +1,14 @@ +define [ + 'backbone.marionette' + 'templates/libraries' +], ( + Marionette, + Templates +) -> + + $ = jQuery + + + + class extends Marionette.ItemView + template: Templates['libraries'] diff --git a/server/sonar-web/src/main/hbs/libraries/libraries.hbs b/server/sonar-web/src/main/hbs/libraries/libraries.hbs new file mode 100644 index 00000000000..e97a22cf7f9 --- /dev/null +++ b/server/sonar-web/src/main/hbs/libraries/libraries.hbs @@ -0,0 +1,43 @@ +
+
+ + +
+ +
+ + +
+ + +
+ +
+ +
diff --git a/server/sonar-web/src/main/js/common/handlebars-extensions.js b/server/sonar-web/src/main/js/common/handlebars-extensions.js index 36efca0ffd3..1d3d78bec50 100644 --- a/server/sonar-web/src/main/js/common/handlebars-extensions.js +++ b/server/sonar-web/src/main/js/common/handlebars-extensions.js @@ -21,8 +21,9 @@ define(['handlebars'], function (Handlebars) { var defaultActions = ['comment', 'assign', 'assign_to_me', 'plan', 'set_severity']; - Handlebars.registerHelper('log', function(variable) { - console.log(variable); + Handlebars.registerHelper('log', function() { + var args = Array.prototype.slice.call(arguments, 0, -1); + console.log.apply(console, args); }); Handlebars.registerHelper('capitalize', function(string) { @@ -265,6 +266,21 @@ define(['handlebars'], function (Handlebars) { } }); + var audaciousFn; + Handlebars.registerHelper('recursive', function(children, options) { + var out = ''; + + if (options.fn !== undefined) { + audaciousFn = options.fn; + } + + children.forEach(function(child){ + out = out + audaciousFn(child); + }); + + return out; + }); + Handlebars.registerHelper('sources', function(source, scm, options) { if (options == null) { options = scm; diff --git a/server/sonar-web/src/main/less/libraries.less b/server/sonar-web/src/main/less/libraries.less new file mode 100644 index 00000000000..1ed8917f6d3 --- /dev/null +++ b/server/sonar-web/src/main/less/libraries.less @@ -0,0 +1,52 @@ +@import (reference) "variables"; +@import (reference) "mixins"; + + +.libraries-header { + margin-bottom: 20px; + font-size: 0; +} + +.libraries-header-filter, +.libraries-header-test, +.libraries-header-actions { + display: inline-block; + vertical-align: middle; + font-size: @baseFontSize; +} + +.libraries-header-test, +.libraries-header-actions { + margin-left: 30px; +} + + +.libraries-tree { + + & > ul ul { + padding-left: 24px; + } + + & > ul ul ul { + margin-left: 3px; + padding-left: 20px; + border-left: 1px dashed #ddd; + } + + & > ul > li + li { + margin-top: 15px; + } + + & > ul > li > .libraries-tree-name { + font-weight: 500; + } + + li { + padding: 3px 0; + } + + li:last-child { + padding-bottom: 0; + } + +} diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/libraries_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/libraries_controller.rb new file mode 100644 index 00000000000..68f2fd9a066 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/libraries_controller.rb @@ -0,0 +1,38 @@ +# +# 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 LibrariesController < ApplicationController + + SECTION=Navigation::SECTION_RESOURCE + before_filter :load_resource + + def index + + end + + + private + + def load_resource + @resource=Project.by_key(params[:id]) + return redirect_to(home_path) unless @resource + @snapshot=@resource.last_snapshot + end + +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index f200186bcb2..0bb0f9e1ae3 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -108,6 +108,9 @@
  • Design (NEW)
  • +
  • + Libraries (NEW) +
  • <% if controller.java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'comparable') %>
  • <%= message('comparison.page') -%> diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/libraries/index.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/libraries/index.html.erb new file mode 100644 index 00000000000..6c1608bc39a --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/libraries/index.html.erb @@ -0,0 +1,11 @@ +<% content_for :script do %> + + +<% end %> + + +
    + +
    -- 2.39.5