From: Jean-Baptiste Lievremont Date: Thu, 9 Oct 2014 15:15:33 +0000 (+0200) Subject: SONAR-5538 Fix comparison page on projects when snapshot_id != null but referenced... X-Git-Tag: 4.5.1-RC1~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0a0522f18f9267c0e895905530f0e8221e2c5bb9;p=sonarqube.git SONAR-5538 Fix comparison page on projects when snapshot_id != null but referenced snapshot has disappeared --- diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb index 1828bff6877..8966df0f57a 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb @@ -21,7 +21,7 @@ class ComparisonController < ApplicationController SECTION=Navigation::SECTION_HOME - + def index snapshots = [] resource_key = params[:resource] @@ -30,7 +30,7 @@ class ComparisonController < ApplicationController project = Project.by_key(resource_key) return render_not_found('Project not found') unless project - snapshots = project.events.select { |event| !event.snapshot_id.nil? && event.category==EventCategory::KEY_VERSION }[0..5].reverse.map {|e| e.snapshot} + snapshots = project.events.select { |event| !event.snapshot.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 @@ -46,15 +46,15 @@ class ComparisonController < ApplicationController sids.each do |id| selected_snapshots.each do |s| snapshots << s if id==s.id.to_s - end + end end end - end + end @snapshots = select_authorized(:user, snapshots) - + metrics = get_params_as_array(:metrics) if metrics.empty? - metrics = [ + metrics = [ 'ncloc', 'complexity', 'comment_lines_density', @@ -64,20 +64,20 @@ class ComparisonController < ApplicationController ] end @metrics = Metric.by_keys(metrics) - + @metric_to_choose = Metric.all.select {|m| m.display? && !m.on_new_code? && !@metrics.include?(m)}.sort_by(&:short_name) end - + def versions key = params[:resource] sids = get_params_as_array(:sids) - + 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} @@ -85,13 +85,13 @@ class ComparisonController < ApplicationController @versions.unshift Event.new(:name => Api::Utils.message('comparison.version.latest'), :snapshot_id => latest_snapshot_id) end end - + render :partial => 'versions' end - + private - + def get_params_as_array(name) list = params[name] if list.blank? diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb index 71a1b4463a1..78e2b2f6c8d 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb @@ -93,7 +93,7 @@ }); - +
<%= resource_select_tag 'new_resource', { :resource_type_property => 'comparable', @@ -147,14 +147,14 @@ });
- + - + - + <% last_index = @snapshots.size-1 @snapshots.each_with_index do |s, index| @@ -184,9 +184,9 @@
- <% end %> + <% end %> - + <% @@ -205,7 +205,7 @@ <% end %> - + @@ -236,7 +236,7 @@ <%= format_measure s.measure(m) -%> <% end %> - + <% end %>