From afd06085aa9dd960700aa276f1f1b5d118a6180e Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Fri, 11 Jan 2013 14:35:20 +0100 Subject: [PATCH] SONAR-4031 Compare service should suggest "LATEST" if required => This is useful for Views or Developers, as they don't have a version on their latest snapshot --- .../main/resources/org/sonar/l10n/core.properties | 1 + .../app/controllers/comparison_controller.rb | 14 ++++++++++++++ .../WEB-INF/app/views/comparison/index.html.erb | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index ee4df06325b..d9735330d4c 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -539,6 +539,7 @@ comparison.move_left=Move left comparison.move_right=Move right comparison.move_down=Move down comparison.move_up=Move up +comparison.version.latest=LATEST #------------------------------------------------------------------------------ diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb index fb56070f4b2..3f8de96258e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb @@ -29,6 +29,12 @@ class ComparisonController < ApplicationController # the request comes from a project: let's select its 5 latest versions project = Project.by_key(resource_key) snapshots = project.events.select { |event| !event.snapshot_id.nil? && event.category==EventCategory::KEY_VERSION }[0..5].reverse.map {|e| e.snapshot} + # if last snapshot is not in the list, add it at the end (=> might be the case for views or developers which do not have events) + last_snapshot = project.last_snapshot + unless snapshots.last == last_snapshot + snapshots.shift + snapshots.push(last_snapshot) + end else # the request comes from the comparison page: let's compare the given snapshots sids = get_params_as_array(:sids) @@ -66,8 +72,16 @@ class ComparisonController < ApplicationController unless key.blank? resource = Project.by_key(params[:resource]) + # we look for the events that are versions and that are not linked to snapshots already displayed on the page @versions = resource.events.select { |event| !event.snapshot_id.nil? && event.category==EventCategory::KEY_VERSION && !sids.include?(event.snapshot_id.to_s) } + + # check if the latest snapshot if suggested or not (and if not, suggest it as "LATEST" => this is used for views or developers which do not have events) + latest_snapshot_id = resource.last_snapshot.id + current_and_suggested_sids = sids + @versions.map {|e| e.snapshot_id.to_s} + unless current_and_suggested_sids.include?(latest_snapshot_id.to_s) + @versions.unshift Event.new(:name => Api::Utils.message('comparison.version.latest'), :snapshot_id => latest_snapshot_id) + end end render :partial => 'versions' diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb index d3000dce1cb..185d02d6dbf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb @@ -192,11 +192,12 @@ <% last_index = @snapshots.size-1 @snapshots.each_with_index do |s, index| + event = s.event(EventCategory::KEY_VERSION) %> <%= s.resource.name(true) -%>
- <%= s.event(EventCategory::KEY_VERSION).name -%> + <%= event ? event.name : message('comparison.version.latest') -%>
<%= human_short_date s.created_at -%> -- 2.39.5