From 6c3fb61212f3eb70666c66aae7136efd3bbd2078 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 6 Dec 2012 16:32:17 +0100 Subject: [PATCH] SONAR-3984 complete Ruby API --- .../app/controllers/measures_controller.rb | 2 +- .../WEB-INF/app/models/measure_filter.rb | 16 ++++++++-------- .../app/models/measure_filter_display.rb | 4 ++-- .../app/models/measure_filter_display_list.rb | 18 +++++++++--------- .../models/measure_filter_display_treemap.rb | 12 ++++++------ 5 files changed, 26 insertions(+), 26 deletions(-) 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 0d1a7296125..82c27224d29 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 @@ -22,7 +22,7 @@ class MeasuresController < ApplicationController # GET /measures/index def index @filter = MeasureFilter.new - @filter.set_criteria_value('qualifiers', 'TRK') + @filter.set_criteria_value(:qualifiers, 'TRK') render :action => 'search' end 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 edb7241669b..9269e17bf0f 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 @@ -96,23 +96,23 @@ class MeasureFilter < ActiveRecord::Base 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 @@ -120,11 +120,11 @@ class MeasureFilter < ActiveRecord::Base # 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 @@ -138,7 +138,7 @@ class MeasureFilter < ActiveRecord::Base 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) @@ -147,7 +147,7 @@ class MeasureFilter < ActiveRecord::Base h end else - @criteria = {} + @criteria = HashWithIndifferentAccess.new end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display.rb index 62270fbfe0e..6fce8261d8c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display.rb @@ -42,8 +42,8 @@ class MeasureFilterDisplay @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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb index 10a336822d4..87486f132ed 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb @@ -83,16 +83,16 @@ class MeasureFilterDisplayList < MeasureFilterDisplay 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 @@ -101,9 +101,9 @@ class MeasureFilterDisplayList < MeasureFilterDisplay 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 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 7e1648f22a4..48323872b37 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 @@ -22,20 +22,20 @@ class MeasureFilterDisplayTreemap < MeasureFilterDisplay 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 @@ -61,7 +61,7 @@ class MeasureFilterDisplayTreemap < MeasureFilterDisplay 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 -- 2.39.5