aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-02-11 11:58:51 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-02-11 11:58:51 +0100
commit8b5d920b54f89cb29f1b40df465d70c217cd07e6 (patch)
tree19cd5a4d767272691bdeccbedad5f86068c90264 /sonar-server
parent62055a7968c1590f13b74af6dc06b4f311e87bf7 (diff)
downloadsonarqube-8b5d920b54f89cb29f1b40df465d70c217cd07e6.tar.gz
sonarqube-8b5d920b54f89cb29f1b40df465d70c217cd07e6.zip
SONAR-2188 API: add parameters from and to to timemachine chart
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/charts_controller.rb16
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb6
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/api/dashboard_configuration.rb10
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb12
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/trends_chart.rb62
6 files changed, 83 insertions, 31 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/charts_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/charts_controller.rb
index 69e07954865..6b4dfbb7cf3 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/charts_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/charts_controller.rb
@@ -31,18 +31,26 @@ class ChartsController < ApplicationController
metric_keys=params[:metrics]
- metrics=[]
+ metric_ids=[]
if metric_keys
metric_keys.split(',').each do |key|
- metrics<<Metric.by_key(key)
+ metric_ids<<Metric.by_key(key)
end
end
- unless metrics.empty?
+ unless metric_ids.empty?
width=(params[:w] ? params[:w].to_i : DEFAULT_TRENDS_WIDTH)
height=(params[:h] ? params[:h].to_i : DEFAULT_TRENDS_HEIGHT)
display_legend = (params[:legend] ? params[:legend]=='true' : true)
- stream = TrendsChart.png_chart(width, height, resource, metrics, params[:sids], params[:locale] || I18n.locale, display_legend)
+ options={}
+ if params[:from]
+ options[:from]=Date::strptime(params[:from])
+ end
+ if params[:to]
+ options[:to]=Date::strptime(params[:to])
+ end
+
+ stream = TrendsChart.png_chart(width, height, resource, metric_ids, params[:locale] || I18n.locale, display_legend, options)
send_data stream, :type => 'image/png', :disposition => 'inline'
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
index 38afc36f524..62c6456e142 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
@@ -26,21 +26,21 @@ class DashboardController < ApplicationController
def index
# TODO display error page if no dashboard or no resource
- load_dashboard()
load_resource()
+ load_dashboard()
load_authorized_widget_definitions()
end
def configure
# TODO display error page if no dashboard or no resource
- load_dashboard()
load_resource()
+ load_dashboard()
load_widget_definitions()
end
def edit_layout
- load_dashboard()
load_resource()
+ load_dashboard()
end
def set_layout
@@ -169,7 +169,7 @@ class DashboardController < ApplicationController
end
end
@dashboard=(@active ? @active.dashboard : nil)
- @dashboard_configuration=Api::DashboardConfiguration.new(@dashboard, :period_index => params[:period])
+ @dashboard_configuration=Api::DashboardConfiguration.new(@dashboard, :period_index => params[:period], :snapshot => @snapshot)
end
def load_resource
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
index 96e5742d1e9..630cc6598c4 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
@@ -77,9 +77,9 @@ module ApplicationHelper
def period_label(snapshot, period_index)
return nil if snapshot.nil? || snapshot.project_snapshot.nil?
- mode=snapshot.project_snapshot.send "period#{period_index}_mode"
- mode_param=snapshot.project_snapshot.send "period#{period_index}_param"
- date=snapshot.project_snapshot.send "period#{period_index}_date"
+ mode=snapshot.period_mode(period_index)
+ mode_param=snapshot.period_param(period_index)
+ date=snapshot.period_datetime(period_index)
label=nil
if mode
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/dashboard_configuration.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/dashboard_configuration.rb
index 5b2d189a173..3ae393f9d9e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/api/dashboard_configuration.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/dashboard_configuration.rb
@@ -19,12 +19,13 @@
#
class Api::DashboardConfiguration
- attr_accessor :dashboard, :period_index, :selected_period
+ attr_accessor :dashboard, :period_index, :selected_period, :snapshot
def initialize(dashboard, options={})
@dashboard=dashboard
@period_index=options[:period_index].to_i
@selected_period=(@period_index>0)
+ @snapshot=options[:snapshot]
end
def name
@@ -47,4 +48,11 @@ class Api::DashboardConfiguration
@selected_period
end
+ def from_datetime
+ if selected_period? && @snapshot
+ @snapshot.period_datetime(@period_index)
+ else
+ nil
+ end
+ end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
index 065bbbe2fa9..bed213aed75 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
@@ -200,6 +200,18 @@ class Snapshot < ActiveRecord::Base
result
end
+ def period_mode(period_index)
+ project_snapshot.send "period#{period_index}_mode"
+ end
+
+ def period_param(period_index)
+ project_snapshot.send "period#{period_index}_param"
+ end
+
+ def period_datetime(period_index)
+ project_snapshot.send "period#{period_index}_date"
+ end
+
private
def measures_hash
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/trends_chart.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/trends_chart.rb
index eb820ad2f92..ecf25e69052 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/trends_chart.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/trends_chart.rb
@@ -19,13 +19,13 @@
#
class TrendsChart
- def self.png_chart(width, height, resource, metrics, snapshots_id, locale, display_legend)
+ def self.png_chart(width, height, resource, metrics, locale, display_legend, options={})
java_chart = Java::OrgSonarServerChartsJruby::TrendsChart.new(width, height, locale.gsub(/\-/, '_'), display_legend)
init_series(java_chart, metrics)
metric_ids=metrics.map{|m| m.id}
- add_measures(java_chart, time_machine_measures(resource, metric_ids))
- add_measures(java_chart, time_machine_reviews(resource, metric_ids))
+ add_measures(java_chart, time_machine_measures(resource, metric_ids, options))
+ add_measures(java_chart, time_machine_reviews(resource, metric_ids, options))
add_labels(java_chart, resource);
export_chart_as_png(java_chart)
@@ -40,32 +40,56 @@ class TrendsChart
end
end
- def self.time_machine_measures(resource, metric_ids)
+ def self.time_machine_measures(resource, metric_ids, options={})
unless metric_ids.empty?
- sql = Project.send(:sanitize_sql, [
- "select s.created_at as created_at, m.value as value, m.metric_id as metric_id " +
+ sql= "select s.created_at as created_at, m.value as value, m.metric_id as metric_id " +
" from project_measures m LEFT OUTER JOIN snapshots s ON s.id=m.snapshot_id " +
" where m.rule_id is null " +
- " and s.status='%s' " +
- " and s.project_id=%s " +
- " and m.metric_id in (%s) " +
- " and m.rule_priority is null and m.characteristic_id is null", Snapshot::STATUS_PROCESSED, resource.id, metric_ids * ','] )
- ProjectMeasure.connection.select_all( sql )
+ " and s.status=? " +
+ " and s.project_id=? " +
+ " and m.metric_id in (?) " +
+ " and m.rule_priority is null and m.characteristic_id is null"
+ if (options[:from])
+ sql += ' and s.created_at>=?'
+ end
+ if (options[:to])
+ sql += ' and s.created_at<=?'
+ end
+ conditions=[sql, Snapshot::STATUS_PROCESSED, resource.id, metric_ids]
+ if (options[:from])
+ conditions<<options[:from]
+ end
+ if (options[:to])
+ conditions<<options[:to]
+ end
+ ProjectMeasure.connection.select_all(Project.send(:sanitize_sql, conditions))
end
end
- def self.time_machine_reviews(resource, metric_ids)
+ def self.time_machine_reviews(resource, metric_ids, options={})
unless metric_ids.empty?
- sql = Project.send(:sanitize_sql, [
- "SELECT m.measure_date as created_at, m.value as value, m.metric_id as metric_id " +
+ sql= "SELECT m.measure_date as created_at, m.value as value, m.metric_id as metric_id " +
"FROM project_measures m " +
"WHERE m.snapshot_id IS NULL " +
"AND m.rule_id is null " +
- "AND m.project_id=%s " +
- "AND m.metric_id in (%s) " +
- "and m.rule_priority is null and m.characteristic_id IS NULL", resource.id, metric_ids * ','] )
- ProjectMeasure.connection.select_all( sql )
- end
+ "AND m.project_id=? " +
+ "AND m.metric_id in (?) " +
+ "and m.rule_priority is null and m.characteristic_id IS NULL"
+ if (options[:from])
+ sql += ' and m.measure_date>=?'
+ end
+ if (options[:to])
+ sql += ' and m.measure_date<=?'
+ end
+ conditions=[sql, resource.id, metric_ids]
+ if (options[:from])
+ conditions<<options[:from]
+ end
+ if (options[:to])
+ conditions<<options[:to]
+ end
+ ProjectMeasure.connection.select_all(Project.send(:sanitize_sql, conditions))
+ end
end
def self.add_measures(java_chart, sqlresult)