From e03a8ada7e3f17c6e1fa768f3637917a46577649 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 5 Dec 2012 11:50:08 +0100 Subject: [PATCH] SONAR-3825 keep display parameters when re-executing the search --- .../core/widgets/measure_filter_treemap.html.erb | 14 +++++++++++--- .../WEB-INF/app/controllers/measures_controller.rb | 6 +++++- .../webapp/WEB-INF/app/models/measure_filter.rb | 8 ++++++++ .../app/models/measure_filter_display_treemap.rb | 11 ++++++++--- .../WEB-INF/app/views/measures/_sidebar.html.erb | 3 +++ 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb index c273a4022b2..26f15dac1b9 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb index e6289a8d233..dd1e4a557fc 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb index 4c121f98ba0..143a6a5a9e0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb @@ -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 ||= {} diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_treemap.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_treemap.rb index d672ed5dc19..59dc40aaa2e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_treemap.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_treemap.rb @@ -17,18 +17,19 @@ # 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 "#{node_label(node)}" + "href=\"#{ApplicationController.root_context}/resource/index/#{node.rid}\">#{node_label(node)}" else "#{node_label(node)}" end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_sidebar.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_sidebar.html.erb index a94295e3871..e6776650136 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_sidebar.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_sidebar.html.erb @@ -65,6 +65,9 @@ <% end %> <% if @filter.display + %> + + <% @filter.display.url_params.each do |k_v_array| if k_v_array[1].is_a?(String) %> -- 2.39.5