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
@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
attr_reader :pagination, :security_exclusions, :base_result, :results, :display
+
def sort_key
criteria['sort']
end
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 ||= {}
# 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
@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)
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
<% 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)
%>