@expandable=(@lines!=nil)\r
@filtered=!@expanded\r
\r
- conditions='snapshot_id=?'\r
+ conditions='switched_off is not true AND snapshot_id=?'\r
values=[@snapshot.id]\r
unless params[:rule].blank?\r
severity=Sonar::RulePriority.id(params[:rule])\r
render :partial => "list", :locals => { :reviews => reviews }\r
end\r
\r
+ def display_violation\r
+ violation = find_last_rule_failure_with_permanent_id params[:rule_failure_permanent_id]\r
+ render :partial => "resource/violation", :locals => { :violation => violation }\r
+ end\r
+\r
def form\r
rule_failure = find_last_rule_failure_with_permanent_id params[:rule_failure_permanent_id]\r
@review = Review.new\r
@review.rule_failure_permanent_id = rule_failure.permanent_id\r
- @review.user = current_user\r
- @review.assignee = current_user\r
- @user_options = add_all_users []\r
- @review.title = rule_failure.message\r
@review_comment = ReviewComment.new\r
@review_comment.review_text = ""\r
- render :partial => "form"\r
- end\r
-\r
- def form_comment\r
- @review_comment = ReviewComment.new\r
- @review_comment.user = current_user\r
- @review_comment.review_id = params[:review_id]\r
- @review_comment.review_text = ""\r
- @rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
- if params[:update_comment]\r
- @update_comment = "true"\r
- @review_comment.review_text = params[:review_text]\r
+ if params[:switch_off]\r
+ @review.review_type = "f-positive"\r
+ else\r
+ @review.review_type = Review.default_type\r
end\r
- render :partial => "form_comment"\r
+ render :partial => "form"\r
end\r
\r
def create\r
\r
@review = Review.new(params[:review])\r
@review.user = current_user\r
+ if params[:assign_to_me]\r
+ @review.assignee = current_user\r
+ end\r
+ @review.title = rule_failure.message\r
@review.status = Review.default_status\r
- @review.review_type = Review.default_type\r
@review.severity = Sonar::RulePriority.to_s rule_failure.failure_level\r
@review.resource = RuleFailure.find( @review.rule_failure_permanent_id, :include => ['snapshot'] ).snapshot.project\r
@review_comment = ReviewComment.new(params[:review_comment])\r
@review_comment.user = current_user\r
@review.review_comments << @review_comment\r
if @review.valid?\r
+ if @review.review_type == "f-positive" \r
+ if rule_failure.get_open_review\r
+ current_open_review = rule_failure.get_open_review\r
+ current_open_review.status = "closed"\r
+ current_open_review.save\r
+ end\r
+ rule_failure.switched_off = true\r
+ rule_failure.save\r
+ end\r
@review.save\r
- @reviews = find_reviews_for_rule_failure @review.rule_failure_permanent_id\r
- else\r
- @user_options = add_all_users []\r
+ @violation = rule_failure\r
end\r
render "create_result"\r
end\r
\r
+ def form_comment\r
+ @review_comment = ReviewComment.new\r
+ @review_comment.user = current_user\r
+ @review_comment.review_id = params[:review_id]\r
+ @review_comment.review_text = ""\r
+ @rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
+ if params[:update_comment]\r
+ @update_comment = true\r
+ @review_comment.review_text = params[:review_text]\r
+ end\r
+ render :partial => "form_comment"\r
+ end\r
+\r
def create_comment\r
rule_failure = find_last_rule_failure_with_permanent_id params[:rule_failure_permanent_id]\r
unless has_rights_to_create? rule_failure\r
review.updated_at = @review_comment.created_at\r
review.save\r
# -- End of TODO code --\r
- @reviews = find_reviews_for_rule_failure @rule_failure_permanent_id\r
+ @violation = rule_failure\r
end\r
render "create_comment_result"\r
end\r
@rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
if @review_comment.valid?\r
@review_comment.save\r
- @reviews = find_reviews_for_rule_failure @rule_failure_permanent_id\r
+ review.updated_at = @review_comment.updated_at\r
+ review.save\r
+ @violation = find_last_rule_failure_with_permanent_id review.rule_failure_permanent_id\r
end\r
- render "update_comment_result"\r
+ render "create_comment_result"\r
+ end\r
+ \r
+ def form_assign\r
+ @user_options = add_all_users []\r
+ @review_id = params[:review_id]\r
+ @rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
+ render :partial => "form_assign"\r
+ end\r
+ \r
+ def assign\r
+ review = Review.find params[:review_id]\r
+ unless current_user\r
+ render :text => "<b>Cannot edit the review</b> : access denied."\r
+ return\r
+ end\r
+ \r
+ review.assignee = User.find params[:assignee_id]\r
+ review.save\r
+ violation = find_last_rule_failure_with_permanent_id review.rule_failure_permanent_id\r
+ render :partial => "resource/violation", :locals => { :violation => violation }\r
+ end\r
+ \r
+ def close_review\r
+ review = Review.find params[:review_id]\r
+ unless current_user\r
+ render :text => "<b>Cannot edit the review</b> : access denied."\r
+ return\r
+ end\r
+ \r
+ review.status = "closed"\r
+ review.save\r
+ violation = find_last_rule_failure_with_permanent_id review.rule_failure_permanent_id\r
+ render :partial => "resource/violation", :locals => { :violation => violation }\r
end\r
\r
## -------------- PRIVATE -------------- ##\r
@user_names = [["Any", ""]]\r
default_user = [""]\r
if current_user\r
- @user_names << ["Me", current_user.id]\r
default_user = [current_user.id]\r
end\r
add_all_users @user_names\r
\r
def add_all_users ( user_options )\r
User.find( :all ).each do |user|\r
- user_options << [user.name, user.id.to_s]\r
+ userName = user.name\r
+ if current_user.id == user.id\r
+ userName = "Me (" + user.name + ")"\r
+ end\r
+ user_options << [userName, user.id.to_s]\r
end\r
return user_options\r
end\r
belongs_to :resource, :class_name => "Project", :foreign_key => "resource_id"\r
has_many :review_comments, :order => "created_at", :dependent => :destroy\r
validates_presence_of :user, :message => "can't be empty"\r
- validates_presence_of :assignee, :message => "can't be empty"\r
validates_presence_of :title, :message => "can't be empty"\r
validates_presence_of :review_type, :message => "can't be empty"\r
validates_presence_of :status, :message => "can't be empty"\r
belongs_to :snapshot\r
has_many :reviews, :primary_key => "permanent_id", :foreign_key => "rule_failure_permanent_id", :order => "created_at"\r
\r
+ def get_open_review\r
+ reviews.each do |review|\r
+ if review.status == "open"\r
+ return review\r
+ end\r
+ end\r
+ return nil\r
+ end\r
+ \r
def to_hash_json\r
json = {}\r
json['message'] = message\r
-<% \r
- displayReviewFailureDiv = 'block'\r
- if violation.reviews.blank?\r
- displayReviewFailureDiv = 'none'\r
- end\r
-%>\r
-<div class="violation">\r
- <table style="width:100%">\r
- <tr>\r
- <td style="width: 30px; vertical-align: top; text-align: center;">\r
- <% if current_user && violation.reviews.blank? %>\r
- <%= link_to_remote image_tag("reviews/+review.png"), \r
- :url => { :controller => "reviews", :action => "form", :rule_failure_permanent_id => violation.permanent_id },\r
- :update => "reviewFailure" + violation.permanent_id.to_s,\r
- :html => { :id => "createReviewLink" + violation.permanent_id.to_s, :title => "Add a review" },\r
- :complete => "$('reviewFailure" + violation.permanent_id.to_s + "').style.display='';$('reviewText').focus();" -%>\r
- <% end %>\r
- <% unless violation.reviews.blank? %>\r
- <%= image_tag("reviews/review.png") -%>\r
- <% end %>\r
- </td>\r
- \r
- <td>\r
- <img src="<%= ApplicationController.root_context -%>/images/priority/<%=violation.failure_level-%>.png"/>\r
- \r
- <span class="rulename"><a onclick="window.open(this.href,'rule','height=800,width=900,scrollbars=1,resizable=1');return false;" href="<%= url_for :controller => 'rules', :action => 'show', :id => violation.rule.key, :layout => 'false' -%>"><%= h(violation.rule.name) -%></a></span>\r
- ยป\r
- <%= h(violation.message) -%>\r
- <%\r
- if violation.created_at\r
- duration=Date.today - violation.created_at.to_date\r
- %>\r
- <span class="violation_date"><%= duration==0 ? 'today' : "#{duration} days ago" -%></span>\r
- <% end %>\r
- \r
- </td>\r
- </tr>\r
- \r
- <tr>\r
- <td colspan="2">\r
- <div id="reviewFailure<%= violation.permanent_id -%>" style="margin-left: 13px; padding: 10px 5px 5px 10px; border-left: 2px solid #EFEFEF; display:<%= displayReviewFailureDiv -%>">\r
- <%= render :partial => "reviews/list", :locals => { :reviews => violation.reviews } %>\r
- </div>\r
- </td>\r
- </tr>\r
- \r
- </table>\r
-</div>
\ No newline at end of file
+<div id="vId<%= violation.permanent_id -%>">
+<%
+ current_open_review = violation.get_open_review
+%>
+
+<div class="violation">
+
+ <div class="vtitle">
+ <% if current_open_review %>
+ <div style="float: right"><span class="violation_date">#<%= current_open_review.id.to_s -%></span></div>
+ <% end %>
+
+ <%= image_tag("priority/" + violation.failure_level.to_s + ".png") -%>
+
+ <%= image_tag("sep12.png") -%>
+
+ <span class="rulename">
+ <a onclick="window.open(this.href,'rule','height=800,width=900,scrollbars=1,resizable=1');return false;" href="<%= url_for :controller => 'rules', :action => 'show', :id => violation.rule.key, :layout => 'false' -%>"><%= h(violation.rule.name) -%></a>
+ </span>
+
+ <%= image_tag("sep12.png") -%>
+
+ <%
+ if violation.created_at
+ duration=Date.today - violation.created_at.to_date
+ %>
+ <span class="violation_date"><%= duration==0 ? 'today' : "#{duration} days ago" -%></span>
+ <% end %>
+ <% if current_open_review && current_open_review.assignee %>
+ <%= image_tag("sep12.png") -%>
+
+ <%= h(current_open_review.assignee.name) -%>
+ <% end %>
+
+
+ <% if current_user %>
+ <span class="actions" id="vActions<%= violation.permanent_id.to_s -%>">
+
+ <%= image_tag("sep12.png") -%>
+
+ <% if current_open_review %>
+ <%= link_to_remote "Close review",
+ :url => { :controller => "reviews", :action => "close_review", :review_id => current_open_review.id, :rule_failure_permanent_id => violation.permanent_id },
+ :update => "vId" + violation.permanent_id.to_s -%>
+
+ <% if current_open_review.assignee == nil %>
+ <%= link_to_remote "Assign",
+ :url => { :controller => "reviews", :action => "form_assign", :review_id => current_open_review.id, :rule_failure_permanent_id => violation.permanent_id },
+ :update => "vActions" + violation.permanent_id.to_s -%>
+
+ <% end %>
+ <% end %>
+ <% unless current_open_review %>
+ <%= link_to_remote "Review",
+ :url => { :controller => "reviews", :action => "form", :rule_failure_permanent_id => violation.permanent_id },
+ :update => "reviewForm" + violation.permanent_id.to_s,
+ :complete => "$('reviewForm" + violation.permanent_id.to_s + "').style.display='';$('reviewText').focus();" -%>
+
+ <% end %>
+ <%= 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();" -%>
+
+ </span>
+ <% end %>
+
+ </div>
+
+ <div class="comment">
+ <%= h(violation.message) -%>
+ </div>
+
+ <%
+ if current_open_review
+ last_comment = current_open_review.review_comments.last
+ current_open_review.review_comments.each do |review_comment|
+ %>
+ <div class="comment">
+ <h4><%= image_tag("reviews/comment.png") -%> <b><%= review_comment.user.name -%></b> on <%= l review_comment.created_at -%>
+ <% if review_comment == last_comment && current_user && current_user.id == review_comment.user.id %>
+ <span class="actions">
+
+ <%= image_tag("sep12.png") -%>
+
+ <%= link_to_remote "Edit",
+ :url => { :controller => "reviews", :action => "form_comment", :review_id => current_open_review.id, :rule_failure_permanent_id => violation.permanent_id, :review_text => last_comment.review_text, :update_comment => "true" },
+ :update => "lastComment" + violation.permanent_id.to_s,
+ :complete => "$('commentText" + violation.permanent_id.to_s + "').focus()" -%>
+ </span>
+ <% end %>
+ </h4>
+ <% if review_comment == last_comment %>
+ <div id="lastComment<%= violation.id -%>">
+ <%= h(review_comment.review_text) -%>
+ </div>
+ <% else %>
+ <%= h(review_comment.review_text) -%>
+ <% end %>
+ </div>
+ <%
+ end
+ end
+ %>
+
+ <div class="comment" id="reviewForm<%= violation.permanent_id.to_s -%>" style="display: none">
+ </div>
+
+</div>
+
+<% if current_user && current_open_review %>
+<div style="padding: 5px" id="commentAction<%= violation.permanent_id -%>">
+ <%= link_to_remote "Add comment",
+ :url => { :controller => "reviews", :action => "form_comment", :review_id => current_open_review.id, :rule_failure_permanent_id => violation.permanent_id },
+ :update => "reviewForm" + violation.permanent_id.to_s,
+ :complete => "$('commentAction" + violation.permanent_id.to_s + "').style.display='none';$('reviewForm" + violation.permanent_id.to_s + "').style.display='';$('commentText" + violation.permanent_id.to_s + "').focus()" -%>
+</div>
+<% end %>
+
+<div>
\ No newline at end of file
<% end %>
<td class="line <%= status -%>">
<pre><%= line.source -%></pre>
- <% if @display_violations && line.violations? %>
- <div class="violations">
+ </td>
+ </tr>
+ <% if @display_violations && line.violations? %>
+ <tr>
+ <% if @scm_available %>
+ <td class="scm"></td>
+ <% end %>
+ <td class="lid section"></td>
+ <td class="violations">
<% line.violations.each do |violation| %>
<%= render :partial => 'violation', :locals => {:violation => violation} -%>
<% end %>
- </div>
- <% end %>
- </td>
- </tr>
+ </td>
+ </tr>
+ <% end %>
<% end %>
</table>
<% form_for :review, @review do |f| %>\r
- <%= f.hidden_field :rule_failure_permanent_id %>\r
- <b>New review</b>: \r
- <%= f.text_field :title, :size => 100 %>\r
- <br/>\r
- Assignee: \r
- <%= select_tag "review[assignee_id]", options_for_select(@user_options, @review.assignee.id.to_s) %>\r
- <br/>\r
- <%= text_area :review_comment, :review_text, :id => "reviewText", :rows => 8, :style => "width:100%" %>\r
- <br/>\r
+ <%= f.hidden_field :rule_failure_permanent_id -%>\r
+ <%= f.hidden_field :review_type -%>\r
\r
- <%= submit_to_remote "create_btn", "Create review", :url => { :action => 'create' } %>\r
- <input type="button" name="cancel_btn" value="Cancel" \r
- onclick="new Ajax.Updater({success:'reviewFailure<%= @review.rule_failure_permanent_id.to_s -%>'}, '<%= ApplicationController.root_context -%>/reviews/list?rule_failure_permanent_id=<%= @review.rule_failure_permanent_id.to_s -%>', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form), }); $('reviewFailure<%= @review.rule_failure_permanent_id.to_s -%>').style.display='none';">\r
-\r
- <%= f.error_messages :header_message => "Can't create the review", :message => "", :header_tag => :h3 %>\r
+ <% if @review.review_type == "f-positive" %>\r
+ <b>Reason for flagging this violation as a false-positive:</b>\r
+ <% end %>\r
+ <%= text_area :review_comment, :review_text, \r
+ :id => "reviewText", :rows => 8, \r
+ :style => "width:100%", :onKeyUp => "if (this.value=='') $('submit_btn').disabled='true'; else $('submit_btn').disabled='';" -%>\r
+ <br/>\r
\r
+ <div>\r
+ <%\r
+ if @review.review_type == "comments"\r
+ button_text = "Post review"\r
+ else\r
+ button_text = "Switch-off violation"\r
+ end\r
+ %>\r
+ <%= submit_to_remote "submit_btn", button_text, :url => { :action => 'create' }, :html => { :id => "submit_btn", :disabled => "true" } -%>\r
+ \r
+ <a onclick="$('reviewForm<%= @review.rule_failure_permanent_id.to_s -%>').style.display='none';" href="#">Cancel</a>\r
+ <% if @review.review_type == "comments" %>\r
+ \r
+ <%= check_box_tag "assign_to_me", "me", true -%> Assign to me\r
+ <% end %>\r
+ </div>\r
+ </div class="clear"></div> \r
<% end %>
\ No newline at end of file
--- /dev/null
+<% form_tag do %>
+ <%= hidden_field_tag :review_id, @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 => "vId" + @rule_failure_permanent_id.to_s -%>
+
+ <%= link_to_remote 'Cancel',
+ :url => { :action => 'display_violation', :rule_failure_permanent_id => @rule_failure_permanent_id },
+ :update => "vId" + @rule_failure_permanent_id.to_s %>
+<% end %>
\ No newline at end of file
<% form_for :review_comment, @review_comment do |f| %>\r
<%= f.hidden_field :review_id %>\r
<%= f.text_area :review_text, :rows => 8, \r
- :id => "commentText" + @review_comment.review_id.to_s,\r
- :style => "width:100%" %>\r
+ :id => "commentText" + @rule_failure_permanent_id.to_s,\r
+ :style => "width:100%",\r
+ :onKeyUp => "if (this.value=='') $('submit_btn').disabled='true'; else $('submit_btn').disabled='';" %>\r
<br/>\r
+ \r
<% if @update_comment %>\r
- <%= submit_to_remote 'create_btn', 'Update', \r
+ <%= submit_to_remote 'submit_btn', 'Update comment', \r
:url => { :action => 'update_comment', \r
- :rule_failure_permanent_id => @rule_failure_permanent_id } %> \r
+ :rule_failure_permanent_id => @rule_failure_permanent_id },\r
+ :html => { :id => "submit_btn" } %>\r
+ \r
+ <%= link_to_remote 'Cancel', \r
+ :url => { :action => 'display_violation', \r
+ :rule_failure_permanent_id => @rule_failure_permanent_id },\r
+ :update => "vId" + @rule_failure_permanent_id.to_s %> \r
<% else %>\r
- <%= submit_to_remote 'create_btn', 'Post', \r
+ <%= submit_to_remote 'submit_btn', 'Post comment', \r
:url => { :action => 'create_comment', \r
- :rule_failure_permanent_id => @rule_failure_permanent_id } %>\r
+ :rule_failure_permanent_id => @rule_failure_permanent_id },\r
+ :html => { :id => "submit_btn", :disabled => true } %>\r
+ \r
+ <a onclick="$('reviewForm<%= @rule_failure_permanent_id.to_s -%>').style.display='none'; $('commentAction<%= @rule_failure_permanent_id.to_s -%>').style.display='';" href="#">Cancel</a>\r
<% end %>\r
- <%= submit_to_remote 'cancel_btn', 'Cancel', \r
- :url => { :action => 'list', :rule_failure_permanent_id => @rule_failure_permanent_id.to_s },\r
- :update => { :success => "reviewFailure" + @rule_failure_permanent_id.to_s } %>\r
- \r
- <%= f.error_messages :header_message => "Can't save the comment", :message => "", :header_tag => :h3%>\r
\r
<% end %>
\ No newline at end of file
-if @reviews\r
- page.replace_html "reviewFailure" + @rule_failure_permanent_id.to_s, :partial => "list", :locals => { :reviews => @reviews }\r
+if @violation\r
+ page.replace "vId" + @violation.permanent_id.to_s, :partial => "resource/violation", :locals => { :violation => @violation }\r
else\r
- page.replace_html "createComment" + @review_comment.review_id.to_s, :partial => "form_comment"\r
+ page.replace_html "reviewForm" + @rule_failure_permanent_id.to_s, :partial => "form_comment"\r
end
\ No newline at end of file
-if @reviews\r
- page.replace_html "createReviewLink" + @review.rule_failure_permanent_id.to_s, image_tag("reviews/review.png")\r
- page.replace_html "reviewFailure" + @review.rule_failure_permanent_id.to_s, :partial => "list", :locals => { :reviews => @reviews }\r
-else\r
- page.replace_html "reviewFailure" + @review.rule_failure_permanent_id.to_s, :partial => "form"\r
+if @violation\r
+ page.replace "vId" + @violation.permanent_id.to_s, :partial => "resource/violation", :locals => { :violation => @violation }\r
+else \r
+ page.replace_html "reviewForm" + @review.rule_failure_permanent_id.to_s, :partial => "form"\r
end
\ No newline at end of file
+++ /dev/null
-if @reviews\r
- page.replace_html "reviewFailure" + @rule_failure_permanent_id.to_s, :partial => "list", :locals => { :reviews => @reviews }\r
-else\r
- @update_comment = "true"\r
- page.replace_html "lastComment" + @review_comment.review_id.to_s, :partial => "form_comment"\r
-end
\ No newline at end of file
.sources2 span.author, .sources2 span.author a {\r
font-size: 85%;\r
}\r
-.sources2 div.violations {\r
- background-color: #FFFFFF; /* #EFEFEF */\r
- margin: 2px;\r
+.sources2 div.violation {\r
+ background-color:#FFF;\r
+ margin:0;\r
border: 1px solid #DDD;\r
}\r
-.sources2 div.violation {\r
- background-color: #FFFFFF; /* #EFEFEF */\r
- margin: 0;\r
- padding: 3px 5px;\r
+.sources2 div.comment{\r
+ background-color:#FBFBFB;\r
+ margin:0;\r
+ padding:5px 10px;\r
+ border-top: 1px solid #DDD;\r
+ line-height: 1.5em;\r
+}\r
+.sources2 div.comment h4{\r
+ font-size: 90%;\r
+ margin-bottom: 2px;\r
+}\r
+.sources2 div.violation .actions{\r
+ visibility: hidden;\r
+}\r
+.sources2 div.violation:hover .actions{\r
+ visibility: visible;\r
+}\r
+.sources2 div.vtitle{\r
+ background-color:#E4ECF3;\r
+ margin:0;\r
+ padding:0 10px;\r
+ line-height: 2.2em;\r
+ text-shadow: 1px 1px 0 #FFF;\r
+ color:#777\r
+}\r
+.sources2 div.vtitle a.action {\r
+ color: #777;\r
}\r
span.rulename, span.rulename a {\r
- color: #4183C4;\r
- text-decoration: none;\r
+ color:#4183C4;\r
+ text-decoration:none;\r
+ font-weight: bold;\r
}\r
span.violation_date {\r
- color: #AAA;\r
- font-size: 85%;\r
+ color:#777;\r
+ font-size:90%;\r
}\r
span.rulename a:hover {\r
text-decoration: underline;\r
border-bottom: 1px solid #DDD;\r
height: 40px;\r
}\r
+.sources2 td.violations{\r
+ background-color: #FFF;\r
+ padding: 10px;\r
+ border-bottom: 1px solid #DDD;\r
+ border-right: 1px solid #DDD;\r
+ border-top: 1px solid #DDD;\r
+}\r
#source_title {\r
padding: 10px 0;\r
}\r