]> source.dussan.org Git - sonarqube.git/commitdiff
TEMP commit before changing review_data into review_comment
authorFabrice Bellingard <bellingard@gmail.com>
Wed, 6 Apr 2011 10:22:52 +0000 (12:22 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 20 Apr 2011 06:49:56 +0000 (08:49 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review_data.rb
sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/db/migrate/190_create_review.rb

index da4dbd299fbb5355936665f036c21a8c944eef6f..41eb70554b74f7a23a351ada35083435a94ac57e 100644 (file)
@@ -195,7 +195,7 @@ class ResourceController < ApplicationController
       end
     end
 
-    RuleFailure.find(:all, :include => 'rule', :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation|
+    RuleFailure.find(:all, :include => ['rule', 'reviews', { 'reviews' => 'review_data' } ], :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation|
       # sorted by severity => from blocker to info
       if violation.line && violation.line>0 && @lines
         @lines[violation.line-1].add_violation(violation)
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
new file mode 100644 (file)
index 0000000..e78b995
--- /dev/null
@@ -0,0 +1,54 @@
+#
+# 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 ReviewsController < ApplicationController
+
+       SECTION=Navigation::SECTION_CONFIGURATION
+       
+       def index
+       end
+       
+       def form
+         @review = Review.new
+         @review.rule_failure_id = params[:violation_id]
+         @review.user = current_user
+         @review_data = ReviewData.new
+         @review_data.user = current_user
+         @review_data.review = @review
+         @review_data.review_text = "Enter your review here"
+         render "_form", :layout => false
+       end
+       
+       def create
+         review = Review.new(params[:review])
+         review.user = current_user
+         review.save
+      review_data = ReviewData.new(params[:review_data])
+         review_data.user = current_user
+         review_data.review_id = review.id
+         review_data.save
+         #render "_view", :layout => false
+       end
+       
+       def cancel_create
+         render :nothing => true
+       end
+       
+end
index c271a3115d6ffcf14e5a7fc970f63f5ca0a09db4..eea61dffc9cf1b560cd6098342b2f644a47e6588 100644 (file)
@@ -21,15 +21,9 @@ class Review < ActiveRecord::Base
   belongs_to :user
   belongs_to :rule_failure
   belongs_to :resource, :class_name => 'Project', :foreign_key => 'resource_id'
-  has_many :review_data, :order => created_at, :dependent => :destroy
+  has_many :review_data, :order => "created_at", :dependent => :destroy
   validates_presence_of :user
   validates_presence_of :review_type
   validates_presence_of :status
-  validate :review_must_have_at_least_one_comment
-
-  def review_must_have_at_least_one_comment
-    errors.add("A review must have at least one comment.") if
-      review_data.length < 1
-  end
 
 end
index 7933d7f818794e193bc01f45e9e851fc746e7cef..a0b250ea30dbcc7178a2e83e904778f2710b1bff 100644 (file)
@@ -18,6 +18,8 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 #
 class ReviewData < ActiveRecord::Base
+  set_table_name :review_data
+
   belongs_to :user
   belongs_to :review
   validates_presence_of :user
index 3b4886f2dad501ec4587a58ef58a6464e38d6540..3cac05b8463af63ea956fcdae96ba754912cd9cc 100644 (file)
@@ -22,6 +22,7 @@ class RuleFailure < ActiveRecord::Base
 
   belongs_to :rule
   belongs_to :snapshot
+  has_many :reviews, :order => "created_at"
 
   def to_hash_json
     json = {}
index 4ede0c4139826a88de2d49914eab593da5463780..678064fd2657df5164b653e8b09f9de8531883e4 100644 (file)
@@ -1,14 +1,40 @@
 <div class="violation">
-<img src="<%= ApplicationController.root_context -%>/images/priority/<%=violation.failure_level-%>.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>
- »
-<%= violation_html_message(violation) -%>
-<%
-   if violation.created_at
-    duration=Date.today - violation.created_at.to_date
-
-%>
-  <span class="violation_date"><%= duration==0 ? 'today' : "#{duration} days ago" -%></span>
-<% end %>
-  </div>
\ No newline at end of file
+  <table>
+    <tr>
+    
+      <td width="30px" valign="top">
+       <% if current_user %>
+          <%= link_to_remote(image_tag("add.png"), 
+                       :update => "review" + violation.id.to_s , 
+                       :url => { :controller => "reviews", :action => "form", :violation_id => violation.id }) -%>
+       <% end %>
+      </td>
+      
+      <td>
+               <img src="<%= ApplicationController.root_context -%>/images/priority/<%=violation.failure_level-%>.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>
+                »
+               <%= h(violation.message) -%>
+               <%
+                  if violation.created_at
+                   duration=Date.today - violation.created_at.to_date
+               %>
+                 <span class="violation_date"><%= duration==0 ? 'today' : "#{duration} days ago" -%></span>
+               <% end %>
+                       
+               <div id="review<%= violation.id -%>" style="padding:5px; background:white">
+                 <% unless violation.reviews.blank? 
+                      violation.reviews.each do |review|
+                 %>
+                   <%= render :partial => "reviews/view", :locals => { :review => review } %>
+                 <% 
+                      end
+                    end
+                 %>
+               </div>
+      </td>
+      
+    </tr>
+  </table>
+</div>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb
new file mode 100644 (file)
index 0000000..b26e64c
--- /dev/null
@@ -0,0 +1,23 @@
+<% form_for :review, @review, :url => { :action => 'create', :id => @review.id } do |f| %>
+      <%= f.hidden_field :rule_failure_id %>
+      Review by: <%= @review.user.login -%>
+      <br/>
+      Review type: <%= f.text_field :review_type %>
+      <br/>
+      Status: <%= f.text_field :status %>
+      <br/>
+      Severity: <%= f.text_field :severity %>
+      <br/>
+      External Link: <%= f.text_field :external_link %>
+      <br/>
+      Comment:
+      <br/>
+      <%= text_area :review_data, :review_text, :rows => 10 %>
+      <br/>
+      <%= submit_to_remote 'create_btn', 'Create review', 
+                     :url => { :action => 'create', :id => @review.id },
+                     :update => { :success => "review" + @review.rule_failure_id.to_s, :failure => "fail" } %>
+      <%= submit_to_remote 'cancel_btn', 'Cancel', 
+                     :url => { :action => 'cancel_create' },
+                     :update => { :success => "review" + @review.rule_failure_id.to_s } %>
+<% end %>
\ No newline at end of file
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
new file mode 100644 (file)
index 0000000..1541b84
--- /dev/null
@@ -0,0 +1,24 @@
+<div>
+      Review Id: <%= review.id -%>
+      <br/>
+      Review Id: <%= review.user.name -%>
+      <br/>
+      Review type: <%= review.review_type -%>
+      <br/>
+      Status: <%= review.status -%>
+      <br/>
+      Severity: <%= review.severity -%>
+      <br/>
+      External Link: <%= review.external_link -%>
+      <br/>
+      
+                 <% unless review.review_data.blank? 
+                      review.review_data.each do |review_data|
+                 %>
+                   Comment: <%= review_data.review_text -%>
+            <br/>
+                 <% 
+                      end
+                    end
+                 %>
+</div>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create.html.erb
new file mode 100644 (file)
index 0000000..5ddd60c
--- /dev/null
@@ -0,0 +1 @@
+Created!
\ No newline at end of file
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
new file mode 100644 (file)
index 0000000..c95d9de
--- /dev/null
@@ -0,0 +1 @@
+Hello !
\ No newline at end of file
index a7a03a251fd94806f6745600361461586bf07e6a..378b69db9683cecd54542a9fefb406b4751a91a7 100644 (file)
@@ -29,7 +29,7 @@ class CreateReview < ActiveRecord::Migration
       t.column 'user_id',                      :integer,       :null => true
       t.column 'review_type',          :string,        :null => true,  :limit => 10
       t.column 'status',                       :string,        :null => true,  :limit => 10
-      t.column 'severity',                     :integer,       :null => true
+      t.column 'severity',                     :string,        :null => true,  :limit => 10
       t.column 'external_link',        :string,        :null => true,  :limit => 200  
       t.column 'rule_failure_id',      :integer,       :null => true   
       t.column 'resource_id',          :integer,       :null => true