From e4316bd324d4dfc6fc6766e8cac87076c918c13f Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Tue, 26 Apr 2011 19:09:32 +0200 Subject: [PATCH] SONAR-2327 Provide a new "Reviews" service --- .../app/controllers/reviews_controller.rb | 80 +++++++++++++++++- .../app/views/resource/_violation.html.erb | 2 +- .../app/views/reviews/_assign_form.html.erb | 12 +++ .../app/views/reviews/_comment_form.html.erb | 39 +++++++++ .../reviews/_false_positive_form.html.erb | 7 ++ .../app/views/reviews/_review.html.erb | 34 +++++++- .../reviews/_violation_comment_form.html.erb | 2 - .../_violation_false_positive_form.html.erb | 2 +- .../WEB-INF/app/views/reviews/index.html.erb | 10 ++- .../images/status/{closed.png => CLOSED.png} | Bin .../images/status/{open.png => OPEN.png} | Bin .../src/main/webapp/stylesheets/style.css | 8 +- 12 files changed, 186 insertions(+), 10 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_assign_form.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_comment_form.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb rename sonar-server/src/main/webapp/images/status/{closed.png => CLOSED.png} (100%) rename sonar-server/src/main/webapp/images/status/{open.png => OPEN.png} (100%) 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 05ce979a1c3..03472fde201 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 @@ -22,7 +22,10 @@ class ReviewsController < ApplicationController SECTION=Navigation::SECTION_HOME - verify :method => :post, :only => [:violation_assign, :violation_flag_as_false_positive,:violation_save_comment, :violation_delete_comment], :redirect_to => {:action => :error_not_post} + verify :method => :post, + :only => [:assign, :comment_form, :flag_as_false_positive, + :violation_assign, :violation_flag_as_false_positive,:violation_save_comment, :violation_delete_comment], + :redirect_to => {:action => :error_not_post} helper(:reviews,:markdown) def index @@ -35,6 +38,81 @@ class ReviewsController < ApplicationController render :partial => 'reviews/show' end + # GET + def assign_form + @user_options = options_for_users() + render :partial => "assign_form" + end + + # POST + def assign + @review = Review.find (params[:id]) + unless current_user + render :text => "Cannot edit the review : access denied." + return + end + + @review.assignee = User.find params[:assignee_id] + @review.save + + render :partial => 'reviews/show' + end + + # GET + def comment_form + @review = Review.find (params[:id]) + render :partial => 'reviews/comment_form' + end + + # POST + def save_comment + @review = Review.find (params[:id]) + unless current_user + render :text => "Cannot create the comment : access denied." + return + end + + if params[:comment_id] + comment = @review.comments.find(params[:comment_id].to_i) + if comment + comment.text=params[:text] + comment.save! + end + else + @review.comments.create!(:user => current_user, :text => params[:text]) + end + + render :partial => "reviews/show" + end + + # GET + def false_positive_form + render :partial => 'reviews/false_positive_form' + end + + # POST + def flag_as_false_positive + @review = Review.find (params[:id]) + unless current_user + render :text => "Cannot create the comment : access denied." + return + end + + RuleFailure.find( :all, :conditions => [ "permanent_id = ?", @review.rule_failure_permanent_id ] ).each do |violation| + violation.switched_off=true + violation.save! + end + + @review.review_type = Review::TYPE_FALSE_POSITIVE + @review.status = Review::STATUS_CLOSED + @review.save! + unless params[:comment].blank? + @review.comments.create(:review_text => params[:comment], :user_id => current_user.id) + end + + render :partial => "reviews/show" + end + # # 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 6dd08dd9fb6..7231e3aa75f 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 @@ -53,7 +53,7 @@ <%= link_to_remote (violation.false_positive? ? "Unflag false-positive" : "Flag as false-positive"), :url => { :controller => "reviews", :action => "violation_false_positive_form", :id => violation.id, :false_positive => !violation.false_positive? }, :update => "reviewForm" + violation.id.to_s, - :complete => "$('vActions" + violation.id.to_s + "').hide();$('reviewForm" + violation.id.to_s + "').show();$('reviewText" + violation.id.to_s + "').focus();" -%> + :complete => "$('vActions" + violation.id.to_s + "').hide();$('reviewForm" + violation.id.to_s + "').show();$('commentText" + violation.id.to_s + "').focus();" -%> <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_assign_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_assign_form.html.erb new file mode 100644 index 00000000000..7aff44c3d4c --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_assign_form.html.erb @@ -0,0 +1,12 @@ +<% form_tag :html => {:style => "display:inline"} do %> + <%= hidden_field_tag :id, params[:review_id] -%> + <%= select_tag "assignee_id", options_for_select(@user_options, current_user.id.to_s) %> +    + <%= submit_to_remote "submit_btn", "Assign", + :url => { :action => 'assign' }, + :update => "review" -%> +    + <%= link_to_remote 'Cancel', + :url => { :action => 'show', :id => params[:review_id] }, + :update => "review" %> +<% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_comment_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_comment_form.html.erb new file mode 100644 index 00000000000..6cb2a2bd58e --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_comment_form.html.erb @@ -0,0 +1,39 @@ +<% + button=(@comment ? 'Update comment' : 'Add comment') +%> +
+ + <% if @comment %> + + <% end %> + + + + + + + +
+ +
+ <%= submit_to_remote "submit_btn", button, :url => { :action => 'save_comment'}, :html => { :id => "submit_btn", :disabled => "true" }, :update => 'review' -%> + <%= link_to_remote 'Cancel', :url => {:action => 'show', :id => params[:id]}, :update => 'review' -%> +
+

Help Tips

+ + + + + + + + + + + + + + +
*bold*bold
''code''code
* Bulleted point
+
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb new file mode 100644 index 00000000000..6cc844cb38e --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb @@ -0,0 +1,7 @@ +
+ +

Why is it a false-positive ?

+ + <%= submit_to_remote "submit_btn", "Flag as false-positive", :url => { :action => 'flag_as_false_positive' }, :html => { :id => "submit_btn", :disabled => "true" }, :update => 'review' -%> + <%= link_to_remote 'Cancel', :url => {:action => 'show', :id => params[:id]}, :update => 'review' -%> +
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb index f9b6a8cd35a..bf7b8b55f2e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb @@ -2,6 +2,25 @@
#<%= review.id.to_s -%>

<%= h(review.title) -%>

+ + <% if current_user && review.status != "CLOSED" %> + +   + <%= image_tag("sep12.png") -%> +   + <%= link_to_remote (review.assignee_id ? "Reassign" : "Assign"), + :url => { :controller => "reviews", :action => "assign_form", :review_id => review.id}, + :update => "assignForm", + :complete => "$('rActions').hide(); $('commentAction').hide(); $('assignee_id').focus();" -%> + +   + <%= link_to_remote ("Flag as false-positive"), + :url => { :controller => "reviews", :action => "false_positive_form", :id => review.id }, + :update => "reviewForm", + :complete => "$('rActions').hide(); $('commentAction').hide(); $('reviewForm').show();$('commentText').focus();" -%> + + <% end %> +
@@ -24,7 +43,9 @@ Assignee: - + + @@ -103,14 +104,17 @@ %> - + + <% end diff --git a/sonar-server/src/main/webapp/images/status/closed.png b/sonar-server/src/main/webapp/images/status/CLOSED.png similarity index 100% rename from sonar-server/src/main/webapp/images/status/closed.png rename to sonar-server/src/main/webapp/images/status/CLOSED.png diff --git a/sonar-server/src/main/webapp/images/status/open.png b/sonar-server/src/main/webapp/images/status/OPEN.png similarity index 100% rename from sonar-server/src/main/webapp/images/status/open.png rename to sonar-server/src/main/webapp/images/status/OPEN.png diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 513a1962de2..00e5cb59976 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -816,7 +816,7 @@ span.rulename a:hover { div.reportTitle { - background-color: #CAE3F2; + background-color: #E4ECF3; color: #4B9FD5; line-height: 2.2em; margin: 0; @@ -830,6 +830,9 @@ div.reportTitle h2 { font-size: 100%; text-shadow: 0 1px 0 #FFFFFF; } +div.reportTitle span.actions { + font-size: 12px; +} table.reportDetails { width: 100%; border: 0; @@ -869,6 +872,9 @@ div.discussionComment h4 { div.discussionComment h4 img { vertical-align: sub; } +div.discussionComment li { + list-style: square inside; +} -- 2.39.5
- <%= review.assignee ? h(review.assignee.name) : '-'-%> + + <%= review.assignee ? h(review.assignee.name) : '-'-%> + Created by: @@ -72,4 +93,15 @@ <% end %> + + <% if current_user && review.status != "CLOSED" %> + +
+ <%= link_to_remote "Add comment", + :url => { :controller => "reviews", :action => "comment_form", :id => review.id }, + :update => "reviewForm", + :complete => "$('rActions').hide();$('commentAction').hide();$('reviewForm').show();$('commentText').focus()" -%> +
+ <% end %> + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_comment_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_comment_form.html.erb index 933326b8914..daa7600ffcf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_comment_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_comment_form.html.erb @@ -1,5 +1,3 @@ - - <% button=(@comment ? 'Update comment' : 'Add comment') %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb index 109f3a292bd..f0e5574fd22 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb @@ -13,7 +13,7 @@ <% end %>

<%= title -%>

- + <%= submit_to_remote "submit_btn", button, :url => { :action => 'violation_flag_as_false_positive' }, :html => { :id => "submit_btn", :disabled => "true" }, :update => 'vId'+params[:id] -%> <%= link_to_remote 'Cancel', :url => {:action => 'display_violation', :id => params[:id]}, :update => 'vId' + params[:id] -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb index 0000c7478bc..6d4daf0d084 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb @@ -84,11 +84,12 @@
St.Project TitleProject Se. Assignee AgeId
<%= review.project.name -%> -
<%= review.resource.long_name -%>
<%= link_to_remote(h(review.title), :update => 'review', :url => {:action => 'show', :id => review.id}, :loading => 'onReviewLoading()', :complete => "onReviewLoaded()") -%> <%= review.project.name -%> +
<%= review.resource.long_name -%>
<%= review.assignee ? h(review.assignee.name) : '-' -%> <%= distance_of_time_in_words_to_now(review.created_at) -%> + <%= link_to_remote( "#"+h(review.id), :update => 'review', :url => {:action => 'show', :id => review.id}, :loading => 'onReviewLoading()', :complete => "onReviewLoaded()") -%> +