# GET /measures/index
def index
@filter = MeasureFilter.new
- @filter.set_criteria_value('qualifiers', 'TRK')
+ @filter.set_criteria_value(:qualifiers, 'TRK')
render :action => 'search'
end
end
def criteria(key=nil)
- @criteria ||= {}
+ @criteria ||= HashWithIndifferentAccess.new
if key
- @criteria[key.to_s]
+ @criteria[key]
else
@criteria
end
end
def criteria=(hash)
- @criteria = {}
+ @criteria = HashWithIndifferentAccess.new
hash.each_pair do |k, v|
set_criteria_value(k, v)
end
end
def override_criteria(hash)
- @criteria ||= {}
+ @criteria ||= HashWithIndifferentAccess.new
hash.each_pair do |k, v|
set_criteria_value(k, v)
end
# API used by Displays
def set_criteria_value(key, value)
- @criteria ||= {}
+ @criteria ||= HashWithIndifferentAccess.new
if key
if value && value!='' && value!=['']
value = value.to_s if value.is_a?(Fixnum)
- @criteria[key.to_s]=value
+ @criteria[key]=value
else
@criteria.delete(key)
end
def load_criteria_from_data
if self.data
- @criteria = self.data.split(CRITERIA_SEPARATOR).inject({}) do |h, s|
+ @criteria = self.data.split(CRITERIA_SEPARATOR).inject(HashWithIndifferentAccess.new) do |h, s|
k, v=s.split('=')
if k && v
v=v.split(CRITERIA_KEY_VALUE_SEPARATOR) if v.include?(CRITERIA_KEY_VALUE_SEPARATOR)
h
end
else
- @criteria = {}
+ @criteria = HashWithIndifferentAccess.new
end
end
@options = options
if filter.base_resource
- qualifiers = filter.criteria('qualifiers')
- filter.set_criteria_value('onBaseComponents', 'true') unless qualifiers && !qualifiers.empty?
+ qualifiers = filter.criteria(:qualifiers)
+ filter.set_criteria_value(:onBaseComponents, 'true') unless qualifiers && !qualifiers.empty?
end
end
super(filter, options)
# default values
- filter.set_criteria_default_value('cols', ['metric:alert_status', 'name', 'date', 'metric:ncloc', 'metric:violations', 'links'])
- filter.set_criteria_default_value('sort', 'name')
- filter.set_criteria_default_value('asc', 'true')
- filter.set_criteria_default_value('pageSize', '30')
- filter.pagination.per_page = [filter.criteria['pageSize'].to_i, 200].min
- filter.pagination.page = (filter.criteria['page'] || 1).to_i
+ filter.set_criteria_default_value(:cols, ['metric:alert_status', 'name', 'date', 'metric:ncloc', 'metric:violations', 'links'])
+ filter.set_criteria_default_value(:sort, 'name')
+ filter.set_criteria_default_value(:asc, 'true')
+ filter.set_criteria_default_value(:pageSize, '30')
+ filter.pagination.per_page = [filter.criteria[:pageSize].to_i, 200].min
+ filter.pagination.page = (filter.criteria[:page] || 1).to_i
@columns = []
metrics = []
- filter.criteria('cols').each do |column_key|
+ filter.criteria(:cols).each do |column_key|
column = Column.new(column_key)
@columns << column
metrics << column.metric if column.metric
filter.metrics=(metrics)
end
- PROPERTY_KEYS = Set.new(['cols', 'sort', 'asc', 'pageSize'])
+ PROPERTY_KEYS = Set.new([:cols, :sort, :asc, :pageSize])
def url_params
- @filter.criteria.select { |k, v| PROPERTY_KEYS.include?(k) }
+ @filter.criteria.select { |k, v| PROPERTY_KEYS.include?(k.to_sym) }
end
end
include ActionView::Helpers::UrlHelper
KEY = :treemap
- PROPERTY_KEYS = Set.new(['tmSize', 'tmColor'])
+ PROPERTY_KEYS = Set.new([:tmSize, :tmColor])
MAX_RESULTS = 1000
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')||'violations_density')
+ @size_metric = Metric.by_key(@filter.criteria(:tmSize)||'ncloc')
+ @color_metric = Metric.by_key(@filter.criteria(:tmColor)||'violations_density')
@filter.metrics=([@size_metric, @color_metric].compact)
@id_count = 0
- filter.set_criteria_value('sort', "metric:#{@size_metric.key}") if @size_metric
- filter.set_criteria_value('asc', 'true')
+ filter.set_criteria_value(:sort, "metric:#{@size_metric.key}") if @size_metric
+ filter.set_criteria_value(:asc, 'true')
filter.pagination.per_page = MAX_RESULTS
filter.pagination.page = 1
end
end
def url_params
- @filter.criteria.select { |k, v| PROPERTY_KEYS.include?(k) }
+ @filter.criteria.select { |k, v| PROPERTY_KEYS.include?(k.to_sym) }
end
private