From e5d8c474f9e3eb542a6a06e95a1ff06a84cea022 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Fri, 26 Aug 2011 12:01:17 +0200 Subject: [PATCH] SONAR-2701 Adjustments on TimeMachine widget - Display only latest snapshot if number_of_versions set to 1 - Fix bug and actually always display oldest snapshot of the selected time frame - Improve CSS rendering - Do not display last column if no sparkline - Do not display metric domain if selected metrics all belong to the same domain (= if there's only one domain to display) --- .../core/widgets/time_machine.html.erb | 16 +++++++--- .../webapp/WEB-INF/app/models/snapshot.rb | 32 +++++++++++++------ .../src/main/webapp/stylesheets/style.css | 5 +-- 3 files changed, 37 insertions(+), 16 deletions(-) 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 e1d0aee470f..5ebeab3724f 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 @@ -49,6 +49,12 @@ end end + domains = [] + rows.select{|row| row.metric.val_type != Metric::VALUE_TYPE_DISTRIB}.each do |row| + domains << row.domain + end + display_domains = domains.uniq.size > 1 + rows.sort! %> @@ -70,7 +76,9 @@ <% end %> <% end %> + <% if displaySparkLine %> + <% end %> @@ -78,10 +86,10 @@ <% previous_domain='' rows.select{|row| row.metric.val_type != Metric::VALUE_TYPE_DISTRIB}.each do |row| - if previous_domain != row.domain + if display_domains && previous_domain != row.domain %> - <%= row.domain %> + <%= row.domain %> <% end @@ -97,14 +105,14 @@ %> <%= format_measure(measure, :skip_span_id => true) %> <% end %> - <% sparkline_url=row.sparkline_url if displaySparkLine && sparkline_url %> + <%= image_tag(sparkline_url) %> - <% 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 bc1d8d5e9ce..c50e5e54f40 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 @@ -69,23 +69,35 @@ class Snapshot < ActiveRecord::Base end def self.for_timemachine_widget(resource, number_of_versions, options={}) - conditions = ["events.category=? AND events.resource_id=?", "Version", resource.id] + 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]) - conditions[0] += " AND events.event_date>=?" - conditions << 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 - events = Event.find(:all, :conditions => conditions, :order => 'events.event_date ASC') - events_to_display = events - if number_of_versions < events.size - events_to_display = [events.first] + events[events.size-number_of_versions+1 .. events.size-1] + 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') + + # 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 - end + 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') - snapshots=Snapshot.find(:all, :conditions => ["snapshots.id IN (?)", sids], :include => 'events', :order => 'snapshots.created_at ASC') + return [first_snapshot] + last_snapshots end def last? diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 00f2bfb027f..df92e7de875 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -1793,11 +1793,12 @@ table.matrix tbody td.title { } div.widget-matrix { - overflow:auto; + overflow:auto; } table.widget-matrix { font-size: 12px; + margin: 1px; } table.widget-matrix thead { @@ -1820,7 +1821,7 @@ table.widget-matrix tbody td.title { table.widget-matrix tbody td { border: 1px solid #ddd; margin: 0; - padding: 1px 0 1px 10px; + padding: 1px 2px 1px 10px; } -- 2.39.5