From 1ca2b0d56c4056c0d9d3cca22a54656979e758c4 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Thu, 21 Apr 2011 10:18:23 +0200 Subject: SONAR-1973 Improve Resource Viewer --- .../WEB-INF/app/controllers/resource_controller.rb | 35 +++++++++++----------- .../WEB-INF/app/controllers/reviews_controller.rb | 23 ++++++++++++-- .../WEB-INF/app/views/resource/_options.html.erb | 4 --- .../app/views/resource/_rules_filter.html.erb | 3 +- .../WEB-INF/app/views/resource/_violation.html.erb | 10 ++++++- 5 files changed, 49 insertions(+), 26 deletions(-) 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 ad8dfbed1ba..4c2f796a5dd 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 @@ -173,15 +173,25 @@ class ResourceController < ApplicationController conditions='snapshot_id=?' values=[@snapshot.id] - unless params[:rule].blank? - severity=Sonar::RulePriority.id(params[:rule]) - if severity - conditions += ' AND failure_level=?' - values< ['rule', 'reviews' ], :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation| # sorted by severity => from blocker to info diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb index a0efbef1645..dd98d5a3ecc 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb @@ -59,7 +59,7 @@ class ReviewsController < ApplicationController def create rule_failure = find_last_rule_failure_with_permanent_id params[:review][:rule_failure_permanent_id] - unless has_rights_to_create? rule_failure + unless has_rights_to_modify? rule_failure render :text => "Cannot create the review : access denied." return end @@ -107,7 +107,7 @@ class ReviewsController < ApplicationController def create_comment rule_failure = find_last_rule_failure_with_permanent_id params[:rule_failure_permanent_id] - unless has_rights_to_create? rule_failure + unless has_rights_to_modify? rule_failure render :text => "Cannot create the comment : access denied." return end @@ -179,6 +179,23 @@ class ReviewsController < ApplicationController violation = find_last_rule_failure_with_permanent_id review.rule_failure_permanent_id render :partial => "resource/violation", :locals => { :violation => violation } end + + def switch_on_violation + rule_failure = RuleFailure.find params[:rule_failure_id] + unless has_rights_to_modify? rule_failure + render :text => "Cannot switch on the violation : access denied." + return + end + + rule_failure.switched_off = false + rule_failure.save + + review = rule_failure.get_open_review + review.status = "closed" + review.save + + render :partial => "resource/violation", :locals => { :violation => rule_failure } + end ## -------------- PRIVATE -------------- ## private @@ -246,7 +263,7 @@ class ReviewsController < ApplicationController return RuleFailure.last( :all, :conditions => [ "permanent_id = ?", rule_failure_permanent_id ], :include => ['snapshot'] ) end - def has_rights_to_create? ( rule_failure ) + def has_rights_to_modify? ( rule_failure ) return false unless current_user project = rule_failure.snapshot.root_project diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb index e1594d7d441..7e765102206 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb @@ -49,10 +49,6 @@ end %> <% if @display_violations %> - - onclick="applyOptions()"/> - - - + + <% if blocker_violations value=(@period ? blocker_violations.variation(@period) : blocker_violations.value) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb index 880786791c8..1fec9f4e7bc 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb @@ -32,11 +32,13 @@ <%= image_tag("sep12.png") -%>    False-Positive +    <% end %> <% if current_open_review && current_open_review.assignee %> <%= image_tag("sep12.png") -%>    <%= h(current_open_review.assignee.name) -%> +    <% end %> @@ -62,10 +64,16 @@ :complete => "$('reviewForm" + violation.permanent_id.to_s + "').style.display='';$('reviewText').focus();" -%>    <% end %> - <%= link_to_remote "Switch-off", + <% if violation.switched_off %> + <%= link_to_remote "Switch-on", + :url => { :controller => "reviews", :action => "switch_on_violation", :rule_failure_id => violation.id }, + :update => "vId" + violation.permanent_id.to_s -%> + <% else %> + <%= link_to_remote "Switch-off", :url => { :controller => "reviews", :action => "form", :rule_failure_permanent_id => violation.permanent_id, :switch_off => true }, :update => "reviewForm" + violation.permanent_id.to_s, :complete => "$('reviewForm" + violation.permanent_id.to_s + "').style.display='';$('reviewText').focus();" -%> + <% end %>    <% end %> -- cgit v1.2.3