]> source.dussan.org Git - sonarqube.git/commitdiff
[SONAR-1973] Add title & assignee on review, improve UI
authorFabrice Bellingard <bellingard@gmail.com>
Thu, 14 Apr 2011 16:17:57 +0000 (18:17 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 20 Apr 2011 06:57:56 +0000 (08:57 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb
sonar-server/src/main/webapp/WEB-INF/db/migrate/191_create_review.rb

index cc41f63549a37f5f383fac42d0521f79e5d3b104..05151fca0173931aecc11413d449ae97f9543321 100644 (file)
@@ -39,10 +39,13 @@ class ReviewsController < ApplicationController
   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 = params[:rule_failure_permanent_id]\r
+    @review.rule_failure_permanent_id = rule_failure.permanent_id\r
     @review.user = current_user\r
-    @review.severity = Review.default_severity\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
@@ -58,7 +61,8 @@ class ReviewsController < ApplicationController
   end\r
 \r
   def create\r
-    unless has_rights_to_create? params[:review][:rule_failure_permanent_id]\r
+    rule_failure = find_last_rule_failure_with_permanent_id params[:review][:rule_failure_permanent_id]\r
+    unless has_rights_to_create? rule_failure\r
       render :text => "<b>Cannot create the review</b> : access denied."\r
       return\r
     end\r
@@ -67,6 +71,7 @@ class ReviewsController < ApplicationController
     @review.user = current_user\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
@@ -74,12 +79,15 @@ class ReviewsController < ApplicationController
     if @review.valid?\r
       @review.save\r
       @reviews = find_reviews_for_rule_failure @review.rule_failure_permanent_id\r
+    else\r
+      @user_options = add_all_users []\r
     end\r
     render "create_result"\r
   end\r
 \r
   def create_comment\r
-    unless has_rights_to_create? params[:rule_failure_permanent_id]\r
+    rule_failure = find_last_rule_failure_with_permanent_id params[:rule_failure_permanent_id]\r
+    unless has_rights_to_create? rule_failure\r
       render :text => "<b>Cannot create the comment</b> : access denied."\r
       return\r
     end\r
@@ -109,14 +117,19 @@ class ReviewsController < ApplicationController
       @user_names << ["Me", current_user.id]\r
       default_user = [current_user.id]\r
     end\r
-    User.find( :all ).each do |user|\r
-      @user_names << [user.name, user.id.to_s]\r
-    end\r
+    add_all_users @user_names\r
     @review_authors = filter_any(params[:review_authors]) || default_user\r
     @comment_authors = filter_any(params[:comment_authors]) || default_user\r
     @severities = filter_any(params[:severities]) || [""]\r
     @statuses = filter_any(params[:statuses]) || ["open"]\r
   end\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
+    end\r
+    return user_options\r
+  end\r
 \r
   def filter_any(array)\r
     if array && array.size>1 && array.include?("")\r
@@ -153,14 +166,14 @@ class ReviewsController < ApplicationController
     return Review.find :all, :conditions => ['rule_failure_permanent_id=?', rule_failure_permanent_id]\r
   end\r
 \r
-  def find_rule_failure_with_permanent_id ( rule_failure_permanent_id )\r
+  def find_last_rule_failure_with_permanent_id ( rule_failure_permanent_id )\r
     return RuleFailure.last( :all, :conditions => [ "permanent_id = ?", rule_failure_permanent_id ], :include => ['snapshot'] )\r
   end\r
 \r
-  def has_rights_to_create? ( rule_failure_permanent_id )\r
+  def has_rights_to_create? ( rule_failure )\r
     return false unless current_user\r
     \r
-    project = find_rule_failure_with_permanent_id( rule_failure_permanent_id).snapshot.root_project\r
+    project = rule_failure.snapshot.root_project\r
     unless has_role?(:user, project)\r
       return false\r
     end\r
index 6fc2db26717b660cbd6cefc277b64e622f3f2dd7..9c6cb791852dabf925296ba0abe78b18df1869f6 100644 (file)
@@ -1,71 +1,73 @@
-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2011 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# Sonar is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# Sonar is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Sonar; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
-#
-class Review < ActiveRecord::Base
-  belongs_to :user
-  belongs_to :rule_failure
-  belongs_to :resource, :class_name => "Project", :foreign_key => "resource_id"
-  has_many :review_comments, :order => "created_at", :dependent => :destroy
-  validates_presence_of :user, :message => "can't be empty"
-  validates_presence_of :review_type, :message => "can't be empty"
-  validates_presence_of :status, :message => "can't be empty"
-
-  SEVERITY_INFO = "info"
-  SEVERITY_MINOR = "minor"
-  SEVERITY_MAJOR = "major"
-  SEVERITY_CRITICAL = "critical"
-  SEVERITY_BLOCKER = "blocker"
-  
-  TYPE_COMMENTS = "comments"
-  TYPE_FALSE_POSITIVE = "f-positive"
-  
-  STATUS_OPEN = "open"
-  STATUS_CLOSED = "closed"
-
-
-  def self.default_severity
-    return SEVERITY_MAJOR
-  end
-  
-  def self.default_type
-    return TYPE_COMMENTS
-  end
-
-  def self.default_status
-    return STATUS_OPEN
-  end
-  
-  def self.severity_options
-    severity_ops = []
-    severity_ops << ["Info", SEVERITY_INFO]
-    severity_ops << ["Minor", SEVERITY_MINOR]
-    severity_ops << ["Major", SEVERITY_MAJOR]
-    severity_ops << ["Critical", SEVERITY_CRITICAL]
-    severity_ops << ["Blocker", SEVERITY_BLOCKER]
-    return severity_ops
-  end
-  
-  def self.status_options
-    status_ops = []
-    status_ops << ["Open", STATUS_OPEN]
-    status_ops << ["Closed", STATUS_CLOSED]
-    return status_ops
-  end
-
-end
+#\r
+# Sonar, entreprise quality control tool.\r
+# Copyright (C) 2008-2011 SonarSource\r
+# mailto:contact AT sonarsource DOT com\r
+#\r
+# Sonar is free software; you can redistribute it and/or\r
+# modify it under the terms of the GNU Lesser General Public\r
+# License as published by the Free Software Foundation; either\r
+# version 3 of the License, or (at your option) any later version.\r
+#\r
+# Sonar is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+# Lesser General Public License for more details.\r
+#\r
+# You should have received a copy of the GNU Lesser General Public\r
+# License along with Sonar; if not, write to the Free Software\r
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02\r
+#\r
+class Review < ActiveRecord::Base\r
+  belongs_to :user\r
+  belongs_to :assignee, :class_name => "User", :foreign_key => "assignee_id"\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
+\r
+  SEVERITY_INFO = "INFO"\r
+  SEVERITY_MINOR = "MINOR"\r
+  SEVERITY_MAJOR = "MAJOR"\r
+  SEVERITY_CRITICAL = "CRITICAL"\r
+  SEVERITY_BLOCKER = "BLOCKER"\r
+  \r
+  TYPE_COMMENTS = "comments"\r
+  TYPE_FALSE_POSITIVE = "f-positive"\r
+  \r
+  STATUS_OPEN = "open"\r
+  STATUS_CLOSED = "closed"\r
+\r
+\r
+  def self.default_severity\r
+    return SEVERITY_MAJOR\r
+  end\r
+  \r
+  def self.default_type\r
+    return TYPE_COMMENTS\r
+  end\r
+\r
+  def self.default_status\r
+    return STATUS_OPEN\r
+  end\r
+  \r
+  def self.severity_options\r
+    severity_ops = []\r
+    severity_ops << ["Info", SEVERITY_INFO]\r
+    severity_ops << ["Minor", SEVERITY_MINOR]\r
+    severity_ops << ["Major", SEVERITY_MAJOR]\r
+    severity_ops << ["Critical", SEVERITY_CRITICAL]\r
+    severity_ops << ["Blocker", SEVERITY_BLOCKER]\r
+    return severity_ops\r
+  end\r
+  \r
+  def self.status_options\r
+    status_ops = []\r
+    status_ops << ["Open", STATUS_OPEN]\r
+    status_ops << ["Closed", STATUS_CLOSED]\r
+    return status_ops\r
+  end\r
+\r
+end\r
index d31edd0dca2a7acb569eb7444b4d72f47a1b8647..16e214941c6c3796b02e9ac260df60f0d0d58243 100644 (file)
@@ -1,8 +1,10 @@
-<b>Create a new review</b>\r
 <% form_for :review, @review do |f| %>\r
       <%= f.hidden_field :rule_failure_permanent_id %>\r
-      Severity: \r
-      <%= select_tag "review[severity]", options_for_select(Review.severity_options, @review.severity)  %>\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
index b0da98bae3171ab27e49f6d59e67757c9d710bc4..f15ed482af9c2162ccd5f73c3a6fb2a95e57fd07 100644 (file)
@@ -4,7 +4,7 @@
             :id => "commentText" + @review_comment.review_id.to_s,\r
             :style => "width:100%" %>\r
       <br/>\r
-      <%= submit_to_remote 'create_btn', 'Add comment', \r
+      <%= submit_to_remote 'create_btn', 'Post', \r
                      :url => { :action => 'create_comment', :rule_failure_permanent_id => @rule_failure_permanent_id } %>\r
       <%= submit_to_remote 'cancel_btn', 'Cancel', \r
                      :url => { :action => 'list', :rule_failure_permanent_id => @rule_failure_permanent_id.to_s },\r
index 639a3f036fb1323c7bbcaeec57cf1b423c9d1f50..41788df91b9fee5a18a85398163867a93125e322 100644 (file)
@@ -1,33 +1,50 @@
+<%\r
+  last_comment_user_id = -1\r
+%>\r
   <div id="review<%= review.id -%>">\r
          <div>\r
-       <b>Review initiated by <%= h(review.user.name) -%></b> - <%= l review.created_at -%>\r
-        <br/>\r
-        Status: <%= h(review.status) -%> / Severity: <%= h(review.severity) -%>      \r
+       <b>Review #<%= review.id -%> - <%= h(review.title) -%></b>\r
+       <br/>\r
+       <i>Assigned to <%= h(review.assignee.name) -%></i>\r
       </div>\r
       \r
-      <div style="margin-top: 10px">\r
-        <table style="width:100%">\r
+      <div style="margin-top: 10px; margin-left: 20px">\r
         <% unless review.review_comments.blank? \r
                     review.review_comments.each do |review_comment|\r
+                      last_comment_user_id = review_comment.user_id\r
                %>\r
-                 <tr>\r
-                   <td style="width:180px; vertical-align:top; padding: 5px; border:solid 1px grey; background-color: #F7F7F7">\r
-                               <%= image_tag("user.png") -%> <b><%= h(review_comment.user.name) -%></b> ยป\r
-                               <br/><%= l review_comment.created_at -%>\r
+        <table style="width:100%; margin-bottom: 3px">\r
+                 <tr style="border: solid 1px grey; background-color: #F7F7F7">\r
+                   <td style="width:180px; vertical-align:top; padding: 2px 2px 2px 10px; font-weight: bold">\r
+                               <%= image_tag("user.png") -%> <b><%= h(review_comment.user.name) -%></b>\r
                    </td>\r
-                   <td style="vertical-align:top; padding: 5px; border:solid 1px grey; background: white">\r
-                       <%= h(review_comment.review_text) -%>\r
+                   <td style="vertical-align: top; padding: 2px 10px 2px 2px; color: grey; text-align: right; font-style: italic">\r
+                       <%= l review_comment.created_at -%>\r
                    </td>\r
                  </tr>\r
+                 <tr style="border: solid 1px grey;">\r
+                   <td colspan="2" style="padding: 5px;">\r
+                     <%= h(review_comment.review_text) -%>\r
+                   </td>\r
+                 </tr>\r
+               </table>\r
                <% \r
                     end\r
                   end\r
                %>\r
-               </table>\r
       \r
         <% if current_user %>\r
            <div style="text-align: right; padding: 5px">\r
-             <%= link_to_remote "Add a comment", \r
+             <% if current_user.id == last_comment_user_id %>\r
+               <%= image_tag("pencil.png") -%>\r
+               <%= link_to_remote "Edit my last comment", \r
+                  :url => { :controller => "reviews", :action => "form_comment", :review_id => review.id, :rule_failure_permanent_id => review.rule_failure_permanent_id },\r
+                  :update => "createComment" + review.id.to_s, \r
+                  :complete => "$('commentText" + review.id.to_s + "').focus()" -%>\r
+               &nbsp;\r
+             <% end %>\r
+             <%= image_tag("pencil.png") -%>\r
+             <%= link_to_remote "Add a new comment", \r
                        :url => { :controller => "reviews", :action => "form_comment", :review_id => review.id, :rule_failure_permanent_id => review.rule_failure_permanent_id },\r
                        :update => "createComment" + review.id.to_s, \r
                        :complete => "$('commentText" + review.id.to_s + "').focus()" -%>\r
index 467e8c63fcdf7460549d711b000e640b3d9d3698..a1abf37a7acf120cfe8f54a911cdaf75ea626be7 100644 (file)
@@ -28,6 +28,8 @@ class CreateReview < ActiveRecord::Migration
       t.column 'created_at',                                   :datetime\r
       t.column 'updated_at',                                   :datetime\r
       t.column 'user_id',                                              :integer,       :null => true\r
+      t.column 'assignee_id',                                  :integer,       :null => true\r
+      t.column 'title',                                                        :string,        :null => true,  :limit => 500\r
       t.column 'review_type',                                  :string,        :null => true,  :limit => 10\r
       t.column 'status',                                               :string,        :null => true,  :limit => 10\r
       t.column 'severity',                                             :string,        :null => true,  :limit => 10\r