From 64f0e0c21941c80d28d947f11db5a2b26f8a45ea Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Wed, 18 Jan 2012 16:09:53 +0100 Subject: [PATCH] SONAR-3012 Add filters for reviews on the violations viewer And make sure that when someone comes from the drilldown with a review metric, then the filter is set to the correct value --- .../widgets/reviews/reviews_metrics.html.erb | 2 +- .../resources/org/sonar/l10n/core.properties | 16 ++++++- .../app/controllers/resource_controller.rb | 43 +++++++++++++++---- .../main/webapp/WEB-INF/app/models/review.rb | 8 ++++ .../views/project_reviews/_review.html.erb | 2 +- .../app/views/resource/_rules_filter.html.erb | 26 ++++++++++- 6 files changed, 83 insertions(+), 14 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/reviews/reviews_metrics.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/reviews/reviews_metrics.html.erb index b33f2a42151..dbb02475816 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/reviews/reviews_metrics.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/reviews/reviews_metrics.html.erb @@ -10,7 +10,7 @@
-

<%= message('widget.reviews_metrics.open_reviews') -%>

+

<%= message('widget.reviews_metrics.active_reviews') -%>

<% if active_reviews %>

<%= format_measure(active_reviews, :suffix => '', :url => url_for_drilldown(active_reviews)) -%> diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties index 527af0e351b..8b738111ef1 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -727,7 +727,7 @@ widget.unplanned_reviews.description=Shows all the reviews of the project that a widget.reviews_metrics.name=Review Activity widget.reviews_metrics.description=Reports metrics about reviews widget.reviews_metrics.no_data=No data -widget.reviews_metrics.open_reviews=Open reviews +widget.reviews_metrics.active_reviews=Active reviews widget.reviews_metrics.unassigned.suffix=\ unassigned widget.reviews_metrics.unplanned.suffix=\ unplanned widget.reviews_metrics.false_positives=False positives @@ -761,6 +761,19 @@ violations_drilldown.col.rule=Rule violations_drilldown.no_violations=No violations +#------------------------------------------------------------------------------ +# +# VIOLATIONS VIEWER +# +#------------------------------------------------------------------------------ + +violations_viewer.review_filter.false_positives=False positives +violations_viewer.review_filter.active=Active +violations_viewer.review_filter.unassigned=Unassigned +violations_viewer.review_filter.unplanned=Unplanned +violations_viewer.review_filter.unreviewed_violations=Unreviewed violations + + #------------------------------------------------------------------------------ # # DUPLICATION VIEWER @@ -801,6 +814,7 @@ code_viewer.create_violation.missing_severity=Missing severity code_viewer.create_violation.no_rules=No rules. Please contact your administrator. code_viewer.create_violation.bad_assignee=Unknown assignee + #------------------------------------------------------------------------------ # # MANUAL MEASURES diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index 86d8053101c..4a6b7673eec 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -322,26 +322,51 @@ class ResourceController < ApplicationController @expandable=(@lines!=nil) @filtered=!@expanded + if params[:rule].blank? + metric = Metric.by_id(params[:metric]) + if metric && (metric.name=="active_reviews" || metric.name=="unassigned_reviews" || metric.name=="unplanned_reviews" || metric.name=="false_positive_reviews"|| metric.name=="unreviewed_violations" || metric.name=="new_unreviewed_violations") + params[:rule] = metric.name.gsub(/new_/, "") + end + end + conditions='snapshot_id=?' values=[@snapshot.id] if params[:rule].blank? conditions+=' AND (switched_off IS NULL OR switched_off=?)' values< ["resource_id=? AND (status=? OR status=?)", @snapshot.resource_id, Review::STATUS_OPEN, Review::STATUS_REOPENED]) + values << open_reviews.map {|r| r.rule_failure_permanent_id} + elsif params[:rule] == "unassigned_reviews" + conditions+=' AND permanent_id IN (?)' + unassigned_reviews = Review.find(:all, :conditions => ["resource_id=? AND (status=? OR status=?) AND assignee_id IS NULL", @snapshot.resource_id, Review::STATUS_OPEN, Review::STATUS_REOPENED]) + values << unassigned_reviews.map {|r| r.rule_failure_permanent_id} + elsif params[:rule] == "unplanned_reviews" + conditions+=' AND permanent_id IN (?)' + open_reviews = Review.find(:all, :include => ['action_plans'], :conditions => ["resource_id=? AND (status=? OR status=?)", @snapshot.resource_id, Review::STATUS_OPEN, Review::STATUS_REOPENED]) + values << open_reviews.reject{|r| r.planned?} .map {|r| r.rule_failure_permanent_id} + elsif params[:rule] == "unreviewed_violations" + conditions+=' AND permanent_id NOT IN (?)' + not_closed_reviews = Review.find(:all, :conditions => ["resource_id=? AND status!=?", @snapshot.resource_id, Review::STATUS_CLOSED]) + values << not_closed_reviews.map {|r| r.rule_failure_permanent_id} else - rule=Rule.by_key_or_id(params[:rule]) - conditions += ' AND rule_id=?' - values<<(rule ? rule.id : -1) + severity=Sonar::RulePriority.id(params[:rule]) + if severity + conditions += ' AND failure_level=?' + values< 1) end end - + RuleFailure.find(:all, :include => ['rule', 'review'], :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation| # sorted by severity => from blocker to info if violation.line && violation.line>0 && @lines diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb index b3d7cf14072..c1dad7a4d35 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb @@ -229,6 +229,10 @@ class Review < ActiveRecord::Base def open? status == STATUS_OPEN end + + def active? + status == STATUS_OPEN || status == STATUS_REOPENED + end def linked_to? (action_plan) action_plans.include? action_plan @@ -238,6 +242,10 @@ class Review < ActiveRecord::Base action_plans.size!=0 end + def assigned? + assignee_id != nil + end + # used as long as we currently allow to link a review to only 1 action plan. def action_plan action_plans[0] diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb index c662654654e..2b4e3edd658 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb @@ -123,7 +123,7 @@ <%= qualifier_icon(review.resource) -%> <% if !review.on_project? %> <%= review.project.long_name -%> <%= image_tag 'sep12.png' -%> <% end %> - <%= link_to_resource(review.resource, review.resource.long_name, {:tab => :violations, :rule => review.false_positive ? "f-positive" : ""}) %> + <%= link_to_resource(review.resource, review.resource.long_name, {:tab => :violations, :rule => review.false_positive ? "false_positive_reviews" : ""}) %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_rules_filter.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_rules_filter.html.erb index 540713cf1ec..3354f90e6d5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_rules_filter.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_rules_filter.html.erb @@ -41,9 +41,31 @@ rule_options<<[label, rule.id] end %> + \ No newline at end of file -- 2.39.5