diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-08-26 16:21:38 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-08-26 16:21:38 +0200 |
commit | 1a60b0efffc6f369fdb1796cf6abc5035c558b18 (patch) | |
tree | d6e97304f22a917927ff9cd33bf1015f85d91074 | |
parent | 97a58214d83c500121ff2e9e5ddd98730e4e48fd (diff) | |
download | sonarqube-1a60b0efffc6f369fdb1796cf6abc5035c558b18.tar.gz sonarqube-1a60b0efffc6f369fdb1796cf6abc5035c558b18.zip |
SONAR-2701 Improve "Time Machine" widget
- Rename numberOfVersions into numberOfColumns
- Always take the last snapshot to display
3 files changed, 20 insertions, 26 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimeMachineWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimeMachineWidget.java index 5d8af7e9a35..185e814374c 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimeMachineWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimeMachineWidget.java @@ -27,7 +27,7 @@ import org.sonar.api.web.WidgetPropertyType; @WidgetProperties( { - @WidgetProperty(key = "numberOfVersions", type = WidgetPropertyType.INTEGER, defaultValue = "4"), + @WidgetProperty(key = "numberOfColumns", type = WidgetPropertyType.INTEGER, defaultValue = "4"), @WidgetProperty(key = "displaySparkLine", type = WidgetPropertyType.BOOLEAN), @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, defaultValue = "ncloc"), @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC), diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/time_machine.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/time_machine.html.erb index 5ebeab3724f..e4244e0c700 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/time_machine.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/time_machine.html.erb @@ -12,7 +12,7 @@ ncloc = Metric.find(:first, :conditions => "name = 'ncloc'") metric_ids << ncloc.id end - numberOfVersions = widget_properties["numberOfVersions"].to_i == 0 ? 4 : widget_properties["numberOfVersions"].to_i + numberOfColumns = widget_properties["numberOfColumns"].to_i == 0 ? 4 : widget_properties["numberOfColumns"].to_i displaySparkLine = widget_properties["displaySparkLine"] # Retrieve the measures for each metric on each snapshot @@ -21,7 +21,7 @@ if from_date options[:from] = from_date end - snapshots=Snapshot.for_timemachine_widget(@resource, numberOfVersions, options) + snapshots=Snapshot.for_timemachine_widget(@resource, numberOfColumns, options) sids = snapshots.collect{|s| s.id}.uniq measures=ProjectMeasure.find(:all, :conditions => {:snapshot_id => sids, :metric_id => metric_ids}) 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 c50e5e54f40..ab8a024f9c3 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 @@ -68,36 +68,30 @@ class Snapshot < ActiveRecord::Base snapshots.compact.uniq end - def self.for_timemachine_widget(resource, number_of_versions, options={}) + def self.for_timemachine_widget(resource, number_of_columns, options={}) + if number_of_columns == 1 + # Display only the latest snapshot + return [resource.last_snapshot] + end + + # Get 1rst & latests snapshots of the period snapshot_conditions = ["snapshots.project_id=? AND snapshots.status=? AND snapshots.scope=? AND snapshots.qualifier=?", resource.id, STATUS_PROCESSED, resource.scope, resource.qualifier] - event_conditions = ["events.category=? AND events.resource_id=?", "Version", resource.id] - if (options[:from]) + if options[:from] snapshot_conditions[0] += " AND snapshots.created_at>=?" snapshot_conditions << options[:from] - event_conditions[0] += " AND events.event_date>=?" - event_conditions << options[:from] end - - if number_of_versions == 1 - # Display only the latest snapshot - last_snapshot = Snapshot.find(:last, :conditions => snapshot_conditions, :order => 'snapshots.created_at ASC') - return [last_snapshot] - end - - # Look for 1rst snapshot of the period first_snapshot=Snapshot.find(:first, :conditions => snapshot_conditions, :order => 'snapshots.created_at ASC') + last_snapshot=resource.last_snapshot - # Look for the number_of_versions-1 last events to display - events_to_display = Event.find(:all, :conditions => event_conditions, :order => 'events.event_date ASC').last(number_of_versions-1) - - # And retrieve the wanted snapshots corresponding to the events - sids = [] - events_to_display.each() do |event| - sids << event.snapshot_id unless event.snapshot_id == first_snapshot.id - end - last_snapshots=Snapshot.find(:all, :conditions => ["snapshots.id IN (?)", sids], :include => 'events', :order => 'snapshots.created_at ASC') + # Look for the number_of_columns-2 last snapshots to display (they must have 'Version' events) + version_snapshots = [] + if number_of_columns > 2 + snapshot_conditions[0] += " AND events.snapshot_id=snapshots.id AND events.category='Version' AND snapshots.id NOT IN (?)" + snapshot_conditions << [first_snapshot.id, last_snapshot.id] + version_snapshots=Snapshot.find(:all, :conditions => snapshot_conditions, :include => 'events', :order => 'snapshots.created_at ASC').last(number_of_columns-2) + end - return [first_snapshot] + last_snapshots + return [first_snapshot] + version_snapshots + [last_snapshot] end def last? |