Quellcode durchsuchen

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
tags/3.5
Fabrice Bellingard vor 11 Jahren
Ursprung
Commit
afd06085aa

+ 1
- 0
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties Datei anzeigen

@@ -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


#------------------------------------------------------------------------------

+ 14
- 0
sonar-server/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb Datei anzeigen

@@ -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'

+ 2
- 1
sonar-server/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb Datei anzeigen

@@ -192,11 +192,12 @@
<%
last_index = @snapshots.size-1
@snapshots.each_with_index do |s, index|
event = s.event(EventCategory::KEY_VERSION)
%>
<th style="text-align: center; vertical-align: top;">
<a href="<%= ApplicationController.root_context -%>/dashboard/index/<%= s.resource.key -%>"><%= s.resource.name(true) -%></a>
<br/>
<span class="note"><b><%= s.event(EventCategory::KEY_VERSION).name -%></b></span>
<span class="note"><b><%= event ? event.name : message('comparison.version.latest') -%></b></span>
<br/>
<span class="note"><%= human_short_date s.created_at -%></span>
</th>

Laden…
Abbrechen
Speichern