aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-04-15 10:58:49 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-04-20 08:57:56 +0200
commit4ea14c2121c8de34a90b07e0f35e116c74ac2c7e (patch)
tree859a776be1805e372c594100e38ec0290be3ce33
parent70ee50737cb8a03ef51cedaa6158142be93ede49 (diff)
downloadsonarqube-4ea14c2121c8de34a90b07e0f35e116c74ac2c7e.tar.gz
sonarqube-4ea14c2121c8de34a90b07e0f35e116c74ac2c7e.zip
[SONAR-1973] Make it possible to edit the last comment
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb25
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/reviews/update_comment_result.js.rjs6
4 files changed, 53 insertions, 11 deletions
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 05151fca017..39207c27671 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
@@ -57,6 +57,10 @@ class ReviewsController < ApplicationController
@review_comment.review_id = params[:review_id]
@review_comment.review_text = ""
@rule_failure_permanent_id = params[:rule_failure_permanent_id]
+ if params[:update_comment]
+ @update_comment = "true"
+ @review_comment.review_text = params[:review_text]
+ end
render :partial => "form_comment"
end
@@ -107,6 +111,24 @@ class ReviewsController < ApplicationController
render "create_comment_result"
end
+ def update_comment
+ review = Review.find params[:review_comment][:review_id]
+ @review_comment = review.review_comments.last
+ unless current_user && current_user.id == @review_comment.user_id
+ render :text => "<b>Cannot modify the comment</b> : access denied."
+ return
+ end
+
+ @review_comment.review_text = params[:review_comment][:review_text]
+ @review_comment.created_at = DateTime.now
+ @rule_failure_permanent_id = params[:rule_failure_permanent_id]
+ if @review_comment.valid?
+ @review_comment.save
+ @reviews = find_reviews_for_rule_failure @rule_failure_permanent_id
+ end
+ render "update_comment_result"
+ end
+
## -------------- PRIVATE -------------- ##
private
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb
index f15ed482af9..8d5b25accd3 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb
@@ -4,8 +4,15 @@
:id => "commentText" + @review_comment.review_id.to_s,
:style => "width:100%" %>
<br/>
- <%= submit_to_remote 'create_btn', 'Post',
- :url => { :action => 'create_comment', :rule_failure_permanent_id => @rule_failure_permanent_id } %>
+ <% if @update_comment %>
+ <%= submit_to_remote 'create_btn', 'Update',
+ :url => { :action => 'update_comment',
+ :rule_failure_permanent_id => @rule_failure_permanent_id } %>
+ <% else %>
+ <%= submit_to_remote 'create_btn', 'Post',
+ :url => { :action => 'create_comment',
+ :rule_failure_permanent_id => @rule_failure_permanent_id } %>
+ <% end %>
<%= submit_to_remote 'cancel_btn', 'Cancel',
:url => { :action => 'list', :rule_failure_permanent_id => @rule_failure_permanent_id.to_s },
:update => { :success => "reviewFailure" + @rule_failure_permanent_id.to_s } %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb
index 41788df91b9..36f3b97f88c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb
@@ -1,6 +1,3 @@
-<%
- last_comment_user_id = -1
-%>
<div id="review<%= review.id -%>">
<div>
<b>Review #<%= review.id -%> - <%= h(review.title) -%></b>
@@ -9,9 +6,9 @@
</div>
<div style="margin-top: 10px; margin-left: 20px">
- <% unless review.review_comments.blank?
+ <% unless review.review_comments.blank?
+ last_comment = review.review_comments.last
review.review_comments.each do |review_comment|
- last_comment_user_id = review_comment.user_id
%>
<table style="width:100%; margin-bottom: 3px">
<tr style="border: solid 1px grey; background-color: #F7F7F7">
@@ -24,7 +21,13 @@
</tr>
<tr style="border: solid 1px grey;">
<td colspan="2" style="padding: 5px;">
- <%= h(review_comment.review_text) -%>
+ <% if review_comment == last_comment %>
+ <div id="lastComment<%= review.id -%>">
+ <%= h(review_comment.review_text) -%>
+ </div>
+ <% else %>
+ <%= h(review_comment.review_text) -%>
+ <% end %>
</td>
</tr>
</table>
@@ -35,11 +38,15 @@
<% if current_user %>
<div style="text-align: right; padding: 5px">
- <% if current_user.id == last_comment_user_id %>
+ <% if current_user.id == review.review_comments.last.user_id %>
<%= image_tag("pencil.png") -%>
<%= link_to_remote "Edit my last comment",
- :url => { :controller => "reviews", :action => "form_comment", :review_id => review.id, :rule_failure_permanent_id => review.rule_failure_permanent_id },
- :update => "createComment" + review.id.to_s,
+ :url => { :controller => "reviews", :action => "form_comment",
+ :review_id => review.id,
+ :rule_failure_permanent_id => review.rule_failure_permanent_id,
+ :review_text => review.review_comments.last.review_text,
+ :update_comment => "true" },
+ :update => "lastComment" + review.id.to_s,
:complete => "$('commentText" + review.id.to_s + "').focus()" -%>
&nbsp;
<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/update_comment_result.js.rjs b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/update_comment_result.js.rjs
new file mode 100644
index 00000000000..f127394f53a
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/update_comment_result.js.rjs
@@ -0,0 +1,6 @@
+if @reviews
+ page.replace_html "reviewFailure" + @rule_failure_permanent_id.to_s, :partial => "list", :locals => { :reviews => @reviews }
+else
+ @update_comment = "true"
+ page.replace_html "lastComment" + @review_comment.review_id.to_s, :partial => "form_comment"
+end \ No newline at end of file