]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3825 keep display parameters when re-executing the search
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 5 Dec 2012 10:50:08 +0000 (11:50 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 5 Dec 2012 11:24:37 +0000 (12:24 +0100)
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb
sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.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_treemap.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_sidebar.html.erb

index c273a4022b25dee0914d84376669e14fd4e3579c..26f15dac1b9ec266918864053fc20e6b005694b1 100644 (file)
@@ -4,12 +4,20 @@
    color_metric = widget_properties['colorMetric']
    filter = MeasureFilter.find_by_id(filter_id.to_i) if filter_id
    if filter
+     url_options = {:controller => 'measures', :action => 'filter', :id => filter.id, :display => 'treemap'}
      filter.load_criteria_from_data
      filter.set_criteria_value('display', 'treemap')
-     filter.set_criteria_value('tmSize', size_metric.key) if size_metric
-     filter.set_criteria_value('tmColor', color_metric.key) if color_metric
+     if size_metric
+      filter.set_criteria_value('tmSize', size_metric.key)
+      url_options['tmSize']=size_metric.key
+     end
+     if color_metric
+      filter.set_criteria_value('tmColor', color_metric.key)
+      url_options['tmColor']=color_metric.key
+     end
      filter.execute(self, :user => current_user)
-     @widget_title = link_to h(filter.name), {:controller => 'measures', :action => 'filter', :id => filter.id, :display => 'treemap'}
+
+     @widget_title = link_to h(filter.name), url_options
 %>
   <%= render :partial => "measures/display_#{filter.display.key}", :locals => {:edit_mode => false, :widget => widget, :filter => filter} %>
 <% end %>
\ No newline at end of file
index e6289a8d2334acd4880b5b387c50b74ca6a43e4b..dd1e4a557fce44c29f1dd545f00ef2040f12d9fb 100644 (file)
@@ -43,7 +43,11 @@ class MeasuresController < ApplicationController
 
     @filter = find_filter(params[:id])
     @filter.load_criteria_from_data
-    redirect_to @filter.criteria.merge({:action => 'search', :id => params[:id]})
+
+    # criteria can be overridden
+    @filter.override_criteria(params.reject{|k,v| k=='controller' || k=='action' || k=='id'})
+
+    redirect_to @filter.criteria.merge({:controller => 'measures', :action => 'search', :id => params[:id]})
   end
 
   def save_form
index 4c121f98ba0ec1c27470c2c0647b0d7e68099050..143a6a5a9e02281b6eda2937f6609b9b48782bdf 100644 (file)
@@ -66,6 +66,7 @@ class MeasureFilter < ActiveRecord::Base
 
   attr_reader :pagination, :security_exclusions, :base_result, :results, :display
 
+
   def sort_key
     criteria['sort']
   end
@@ -108,6 +109,13 @@ class MeasureFilter < ActiveRecord::Base
     end
   end
 
+  def override_criteria(hash)
+    @criteria ||= {}
+    hash.each_pair do |k, v|
+      set_criteria_value(k, v)
+    end
+  end
+
   # API used by Displays
   def set_criteria_value(key, value)
     @criteria ||= {}
index d672ed5dc19880d454c7a64d84e85929898109aa..59dc40aaa2e7e3f7c1789f8dad249ab344eef065 100644 (file)
 # License along with Sonar; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 #
+require 'set'
 class MeasureFilterDisplayTreemap < MeasureFilterDisplay
   include ActionView::Helpers::UrlHelper
 
   KEY = :treemap
-
+  PROPERTY_KEYS = Set.new(['tmSize', 'tmColor'])
   attr_reader :id, :size, :size_metric, :color_metric
 
   def initialize(filter, options)
     super(filter, options)
 
     @size_metric = Metric.by_key(@filter.criteria('tmSize')||'ncloc')
-    @color_metric = Metric.by_key(@filter.criteria('tmColor'))
+    @color_metric = Metric.by_key(@filter.criteria('tmColor')||'violations_density')
     @filter.metrics=([@size_metric, @color_metric].compact)
     @id_count = 0
 
@@ -58,6 +59,10 @@ class MeasureFilterDisplayTreemap < MeasureFilterDisplay
     @filter.results.nil? || @filter.results.empty?
   end
 
+  def url_params
+    @filter.criteria.select { |k, v| PROPERTY_KEYS.include?(k) }
+  end
+
   private
 
   def build_tree(node)
@@ -137,7 +142,7 @@ class Sonar::HtmlOutput < Treemap::HtmlOutput
   def draw_label(node)
     if node.leaf
       "<a onclick=\"window.open(this.href,'resource','height=800,width=900,scrollbars=1,resizable=1');return false;\" " +
-          "href=\"#{ApplicationController.root_context}/resource/index/#{node.rid}\">#{node_label(node)}</a>"
+        "href=\"#{ApplicationController.root_context}/resource/index/#{node.rid}\">#{node_label(node)}</a>"
     else
       "<a href='#{ApplicationController.root_context}/dashboard/index/#{node.rid}'>#{node_label(node)}</a>"
     end
index a94295e38718e08b3f2199c4694d505869b6d3ec..e6776650136643c6a0faf47bf427a533afa6951d 100644 (file)
@@ -65,6 +65,9 @@
     <% end %>
     <%
        if @filter.display
+    %>
+      <input type="hidden" name="display" value="<%= @filter.display.key -%>"/>
+    <%
          @filter.display.url_params.each do |k_v_array|
            if k_v_array[1].is_a?(String)
     %>