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