]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3825 improve rendering of measure filter lists
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 4 Dec 2012 13:55:58 +0000 (14:55 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 4 Dec 2012 13:55:58 +0000 (14:55 +0100)
sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb
sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb
sonar-server/src/main/webapp/stylesheets/style.css

index 582bf95e1204b5ef22c467ac4f56a5757424e918..8023363dea14f136272a47d45476741d0dcf8bef 100644 (file)
@@ -20,8 +20,8 @@
 module DashboardHelper
   include WidgetPropertiesHelper
   include MetricsHelper
-  include FiltersHelper
   include MeasuresHelper
+
   def dashboard_action(action_name, opts={})
     if @resource
       { :action => action_name, :did => @dashboard.id, :id => @resource.id }.merge!(opts)
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb
deleted file mode 100644 (file)
index 1d303e9..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2012 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# Sonar 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.
-#
-# Sonar 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 Sonar; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
-#
-module FiltersHelper
-
-  def goto_page(msg, filter, update_id, override={})
-    link_to_remote msg, {
-      :update => "filter-#{update_id}",
-      :url => params.merge({:controller => :filters, :action => :list, :id => filter.id, :edit_mode => @edit_mode, :update_id => update_id}.merge(override)),
-      :after => "$('filter-pages-#{update_id}').hide();$('filter-loading-#{update_id}').show();"
-    }
-  end
-
-  def column_title(column, filter, update_id)
-    if column.sortable?
-      html=goto_page(h(column.display_name), filter, update_id, {:asc => (!(column.ascending?)).to_s, :sort => column.id})
-    else
-      html=h(column.display_name)
-    end
-    if column.variation
-      html="<img src='#{ApplicationController.root_context}/images/trend-up.png'></img> #{html}"
-    end
-
-    if filter.sorted_column==column
-      html << (column.ascending? ? image_tag("asc12.png") : image_tag("desc12.png"))
-    end
-    html
-  end
-
-  def column_align(column)
-    (column.on_name? || column.on_key?) ? 'left' : 'right'
-  end
-
-  def treemap_metrics(filter)
-    metrics=filter.measure_columns.map { |col| col.metric }
-    size_metric=(metrics.size>=1 ? metrics[0] : Metric.by_key('ncloc'))
-    color_metric=nil
-    if metrics.size>=2
-      color_metric=metrics[1]
-    end
-    if color_metric.nil? || !color_metric.treemap_color?
-      color_metric=Metric.by_key('violations_density')
-    end
-    [size_metric, color_metric]
-  end
-
-  def period_names
-    p1=Property.value('sonar.timemachine.period1', nil, 'previous_analysis')
-    p2=Property.value('sonar.timemachine.period2', nil, '5')
-    p3=Property.value('sonar.timemachine.period3', nil, '30')
-    [period_name(p1), period_name(p2), period_name(p3)]
-  end
-
-  private
-
-  def period_name(property)
-    if property=='previous_analysis'
-      message('delta_since_previous_analysis')
-    elsif property=='previous_version'
-      message('delta_since_previous_version')
-    elsif property =~ /^[\d]+(\.[\d]+){0,1}$/
-      # is integer
-      message('delta_over_x_days', :params => property)
-    elsif property =~ /\d{4}-\d{2}-\d{2}/
-      message('delta_since', :params => property)
-    elsif !property.blank?
-      message('delta_since_version', :params => property)
-    else
-      nil
-    end
-  end
-
-end
index 6417dbae590cc518692e4edb18a80b00a8625111..8c757d0ab12b0e6dcc4d08614c79ebe4ce5f25ed 100644 (file)
@@ -21,9 +21,9 @@ module MeasuresHelper
 
   def list_column_html(filter, column)
     if column.sort?
-      html = link_to_function(h(column.name), "reloadParameters({asc:'#{(!filter.sort_asc?).to_s}', sort:'#{column.key}'})")
+      html = link_to_function(h(column.title_label), "reloadParameters({asc:'#{(!filter.sort_asc?).to_s}', sort:'#{column.key}'})", :title => h(column.tooltip))
     else
-      html=h(column.name)
+      html=h(column.title_label)
     end
     if column.period
       html += "<br><span class='note'>Period #{column.period}</small>"
@@ -31,7 +31,7 @@ module MeasuresHelper
     if filter.sort_key==column.key
       html << (filter.sort_asc? ? image_tag("asc12.png") : image_tag("desc12.png"))
     end
-    "<th class='#{column.align} #{column.css_title}'>#{html}</th>"
+    "<th class='#{column.align} #{column.title_css}'>#{html}</th>"
   end
 
   def list_cell_html(column, result)
index c3d680fe5eb57d2277c89086bdd384c8a8756f16..4c121f98ba0ec1c27470c2c0647b0d7e68099050 100644 (file)
@@ -196,7 +196,7 @@ class MeasureFilter < ActiveRecord::Base
     snapshot_ids = rows.map { |row| row.getSnapshotId() if authorized_project_ids.include?(row.getResourceRootId()) }.compact
     @security_exclusions = (snapshot_ids.size<rows.size)
     @pagination.count = snapshot_ids.size
-    snapshot_ids[@pagination.offset .. (@pagination.offset+@pagination.limit)]
+    snapshot_ids[@pagination.offset ... (@pagination.offset+@pagination.limit)]
   end
 
   def load_results(snapshot_ids)
index 7046b17e3543ca61f0d26153654ac4a3363142e5..1da65830988c0c4199e1a4b5f0c03cbcc9b91437 100644 (file)
@@ -33,12 +33,19 @@ class MeasureFilterDisplayList < MeasureFilterDisplay
       end
     end
 
-    def name
+    def title_label
       if @metric
-        Api::Utils.message("metric.#{@metric.key}.name", :default => @metric.short_name)
+        label = Api::Utils.message("measure_filter.short_col.metric.#{@metric.key}", :default => '')
+        label = Api::Utils.message("metric.#{@metric.key}.name", :default => @metric.short_name) if label==''
       else
-        Api::Utils.message("measure_filter.col.#{@key}", :default => @key)
+        label = Api::Utils.message("measure_filter.short_col.#{@key}", :default => '')
+        label = Api::Utils.message("measure_filter.col.#{@key}", :default => @key) if label==''
       end
+      label
+    end
+
+    def tooltip
+      @metric.description if @metric
     end
 
     def align
@@ -49,10 +56,14 @@ class MeasureFilterDisplayList < MeasureFilterDisplay
         end
     end
 
-    def css_title
+    def title_css
       'thin' if @metric && @metric.val_type==Metric::VALUE_TYPE_LEVEL
     end
 
+    def row_css
+      'nowrap' unless @metric && !@metric.numeric?
+    end
+
     def sort?
       !links?
     end
@@ -60,6 +71,7 @@ class MeasureFilterDisplayList < MeasureFilterDisplay
     def links?
       @key == 'links'
     end
+
   end
 
   attr_reader :columns
index 95a2c98bec17ee09849e3d25e3b94f7a09ba08f4..482efb095f2db5099bba3b1e67c422b1a4694bed 100644 (file)
         <td class="thin"><%= link_to_favourite(filter.base_result.snapshot.resource) -%></td>
       <% end %>
       <% filter.display.columns.each do |column| %>
-        <td class="<%= column.align -%>">
+        <td class="<%= column.align -%> <%= column.row_css -%>">
           <%= list_cell_html(column, filter.base_result) -%>
         </td>
       <% end %>
         <td class="thin"><%= link_to_favourite(result.snapshot.resource) -%></td>
       <% end %>
       <% filter.display.columns.each do |column| %>
-        <td class="<%= column.align -%>">
+        <td class="<%= column.align -%> <%= column.row_css -%>">
           <%= list_cell_html(column, result) -%>
         </td>
       <% end %>
index 751826520ff9db8368bd3fa7b2e405c267e6b4f7..ea8981befafbc0412505d56115f5e1e664937204 100644 (file)
@@ -1,6 +1,7 @@
 <% if defined? widget %>
   <span class="note"><%= message('size') -%>: <b><%= filter.display.size_metric.short_name -%></b></span>
   <% if filter.display.color_metric %>
+    &nbsp;&nbsp;
     <span class="note"><%= message('color') -%>: <b><%= filter.display.color_metric.short_name -%></b> <%= render :partial => 'treemap/gradient', :locals => {:metric => filter.display.color_metric} %></span>
   <% end %>
 <% else %>
index 7f984013c0970899b1cb3cf9f7d5c547bb181055..ea219327ec7a4b04d580388be13d04803bff45b2 100644 (file)
@@ -2243,6 +2243,7 @@ td.spacer-top {
   vertical-align: bottom;
   line-height: 16px;
   padding: 4px 5px;
+  vertical-align: bottom;
 }
 
 .table > tbody > tr > td {