]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4407 Refactor the libraries page in order to drop GWT
authorStas Vilchik <vilchiks@gmail.com>
Wed, 20 Aug 2014 12:09:12 +0000 (18:09 +0600)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 20 Aug 2014 12:09:12 +0000 (18:09 +0600)
List the component's libraries

server/sonar-web/Gruntfile.coffee
server/sonar-web/src/main/coffee/libraries/app.coffee [new file with mode: 0644]
server/sonar-web/src/main/coffee/libraries/view.coffee [new file with mode: 0644]
server/sonar-web/src/main/hbs/libraries/libraries.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/common/handlebars-extensions.js
server/sonar-web/src/main/less/libraries.less [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/libraries_controller.rb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
server/sonar-web/src/main/webapp/WEB-INF/app/views/libraries/index.html.erb [new file with mode: 0644]

index 6221292a2351d73149e6e20bea107e564d6fb8be..88e35c0930a070485fb56573a9df981a0dc68aae 100644 (file)
@@ -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 (file)
index 0000000..ee5e8c5
--- /dev/null
@@ -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 (file)
index 0000000..f135af4
--- /dev/null
@@ -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 (file)
index 0000000..e97a22c
--- /dev/null
@@ -0,0 +1,43 @@
+<div class="libraries-header">
+  <div class="libraries-header-filter">
+    <input type="text">
+    <button>Filter</button>
+  </div>
+
+  <div class="libraries-header-test">
+    <input type="checkbox" id="display-test-libraries">
+    <label for="display-test-libraries">Display test libraries</label>
+  </div>
+
+  <div class="libraries-header-actions">
+    <a>Collapse All</a>
+    <a>Expand All</a>
+    <a href="#">Usages</a>
+  </div>
+</div>
+
+<div class="libraries-tree">
+  <ul>
+    {{#each items}}
+      <li>
+        {{qualifierIcon qualifier}}
+        <span class="libraries-tree-name">{{lname}}</span>
+        <ul>
+          {{#recursive libraries}}
+            <li>
+              <i class="icon-dropdown" style="{{#unless to}}visibility: hidden;{{/unless}}"></i>&nbsp;
+              {{qualifierIcon q}}
+              <span class="libraries-tree-name">{{n}}</span>
+              {{#if u}}
+                <span class="subtitle">({{u}})</span>
+              {{/if}}
+              {{#if to}}
+                <ul>{{{recursive to}}}</ul>
+              {{/if}}
+            </li>
+          {{/recursive}}
+        </ul>
+      </li>
+    {{/each}}
+  </ul>
+</div>
index 36efca0ffd3d11ceb44e4e7880f3b58c102ea552..1d3d78bec5089f888be297ec1583bb958930c7dc 100644 (file)
@@ -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 (file)
index 0000000..1ed8917
--- /dev/null
@@ -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 (file)
index 0000000..68f2fd9
--- /dev/null
@@ -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
index f200186bcb2d3dc05b3774dbd27edfe2d29a71ad..0bb0f9e1ae34370c12fd2d7a6959574938695e5e 100644 (file)
               <li class="<%= 'active' if request.request_uri.include?('/design/index') -%>">
                 <a href="<%= ApplicationController.root_context -%>/design/index/<%= @project.key -%>">Design (NEW)</a>
               </li>
+              <li class="<%= 'active' if request.request_uri.include?('/libraries/index') -%>">
+                <a href="<%= ApplicationController.root_context -%>/libraries/index/<%= @project.key -%>">Libraries (NEW)</a>
+              </li>
               <% if controller.java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'comparable') %>
               <li class="<%= 'active' if request.request_uri.include?('/comparison/index') -%>">
                 <a href="<%= ApplicationController.root_context -%>/comparison/index?resource=<%= @project.key -%>"><%= message('comparison.page') -%></a>
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 (file)
index 0000000..6c1608b
--- /dev/null
@@ -0,0 +1,11 @@
+<% content_for :script do %>
+  <script data-main="<%= ApplicationController.root_context -%>/js/libraries/app" src="<%= ApplicationController.root_context -%>/js/require.js"></script>
+  <script>
+    window.resourceKey = '<%= @resource.key -%>';
+  </script>
+<% end %>
+
+
+<div id="project-libraries">
+  <i class="spinner"></i>
+</div>