]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2628 Add a page to manage manual measures
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 19 Jul 2011 21:02:36 +0000 (23:02 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 19 Jul 2011 21:02:36 +0000 (23:02 +0200)
15 files changed:
plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest/testCopyManualMeasures.xml
plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties
sonar-core/src/main/java/org/sonar/jpa/entity/ManualMeasure.java
sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/manual_measures_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/manual_measure.rb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_edit_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_row.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/new.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/db/migrate/211_create_manual_measures.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/214_add_index_on_manual_measures.rb [new file with mode: 0644]
sonar-server/src/main/webapp/stylesheets/style.css

index 78f114c5c0afcbfdb2e403b543a7f6d3268a8eda..9b672c60a237f2bec638e68c3b80805511fb2c89 100644 (file)
@@ -5,7 +5,7 @@
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
 
 
-  <manual_measures id="1" metric_id="2" resource_id="30" value="3.14" text_value="pi" created_at="[null]" updated_at="[null]" description="this is pi" url="http://pi"/>
-  <manual_measures id="2" metric_id="2" resource_id="40" value="6" text_value="six" created_at="[null]" updated_at="[null]" description="this is six" url="http://six"/>
+  <manual_measures id="1" metric_id="2" resource_id="30" value="3.14" text_value="pi" created_at="[null]" updated_at="[null]" description="this is pi" url="http://pi" user_login="me"/>
+  <manual_measures id="2" metric_id="2" resource_id="40" value="6" text_value="six" created_at="[null]" updated_at="[null]" description="this is six" url="http://six" user_login="me"/>
 
 </dataset>
\ No newline at end of file
index 35df5c65bdb7e0759282f7cee4b33407cd4f00f1..fa937b8587935275955a1645c62ab0083da242c4 100644 (file)
@@ -225,6 +225,7 @@ filters.size=Size
 filters.color=Color
 global_roles.page=Global roles
 manual_metrics.page=Manual metrics
+manual_measures.page=Manual measures
 my_profile.page=My profile
 project_roles.page=Project roles
 project_settings.page=Settings
index 3e3544df58296525817ef12e6185afd9cd2f5a0f..ea1bb22921d8a1d474487b36c781bdf9f71e6494 100644 (file)
@@ -56,6 +56,9 @@ public final class ManualMeasure {
   @Column(name = "updated_at", updatable = true, nullable = true)
   private Date updatedAt;
 
+  @Column(name = "user_login", updatable = true, nullable = true, length = 40)
+  private String userLogin;
+
   public Long getId() {
     return id;
   }
@@ -91,4 +94,8 @@ public final class ManualMeasure {
   public Date getUpdatedAt() {
     return updatedAt;
   }
+
+  public String getUserLogin() {
+    return userLogin;
+  }
 }
index 0a9a08813a0b9f951b267d8aaba58aa34ea4f33e..a77283fd703223e3bd926c90075d0b633f947a10 100644 (file)
@@ -40,7 +40,7 @@ public class SchemaMigration {
       - complete the Derby DDL file used for unit tests : sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl
 
    */
-  public static final int LAST_VERSION = 213;
+  public static final int LAST_VERSION = 214;
 
   public final static String TABLE_NAME = "schema_migrations";
 
index e131f23c30943a46d08553f6bfe1df4702a6d283..3bd9e29ef9c699a63900efa9ce14beec1f273745 100644 (file)
@@ -60,7 +60,7 @@ class Api::ManualMeasuresController < Api::ApiController
 
     measure=ManualMeasure.find(:first, :conditions => ['resource_id=? and metric_id=?', resource.id, metric.id])
     if measure.nil?
-      measure=ManualMeasure.new(:resource => resource, :user => current_user, :metric_id => metric.id)
+      measure=ManualMeasure.new(:resource => resource, :user_login => current_user.login, :metric_id => metric.id)
     end
 
     measure.value = value
@@ -109,7 +109,7 @@ class Api::ManualMeasuresController < Api::ApiController
     hash[:created_at]=format_datetime(manual_measure.created_at)
     hash[:updated_at]=format_datetime(manual_measure.updated_at) if manual_measure.updated_at
     if manual_measure.user
-      hash[:login]=manual_measure.user.login
+      hash[:login]=manual_measure.user_login
       hash[:username]=manual_measure.user.name
     end
     hash
index 12dcf579e525e950dd132e42366a7f20e2547b57..53c4f15f165ac1c7c6e4e7f5a3e07c09f6eba286 100644 (file)
@@ -27,6 +27,10 @@ class ManualMeasuresController < ApplicationController
     load_measures()
   end
 
+  def new
+    load_measures()
+  end
+
   def edit
     load_measures()
     @metric=Metric.by_key(params[:metric])
@@ -34,11 +38,15 @@ class ManualMeasuresController < ApplicationController
     render :action => 'index'
   end
 
+  def create
+
+  end
+
   def save
     metric=Metric.by_key(params[:metric])
     measure=ManualMeasure.find(:first, :conditions => ['resource_id=? and metric_id=?', @resource.id, metric.id])
     if measure.nil?
-      measure=ManualMeasure.new(:resource => @resource, :user => current_user, :metric_id => metric.id)
+      measure=ManualMeasure.new(:resource => @resource, :user_login => current_user.login, :metric_id => metric.id)
     end
     # TODO use measure.text_value if string metric
     measure.value = params[:val]
index e5500e0d5f9933d65debd9cc2dcbda93120ef8a4..264708a452dd23833fd101e8f839cf440d6f754a 100644 (file)
 #
 class ManualMeasure < ActiveRecord::Base
   belongs_to :resource, :class_name => 'Project'
-  belongs_to :user
   validates_uniqueness_of :metric_id, :scope => :resource_id
   validates_length_of :text_value, :maximum => 4000, :allow_nil => true, :allow_blank => true
   validates_length_of :url, :maximum => 4000, :allow_nil => true, :allow_blank => true
   validates_length_of :description, :maximum => 4000, :allow_nil => true, :allow_blank => true
   validate :validate_metric
-  
+
   def metric
     @metric ||=
-      begin
-        Metric.by_id(metric_id)
-      end
+        begin
+          Metric.by_id(metric_id)
+        end
+  end
+
+  def user
+    @user ||=
+        begin
+          user_login ? User.find(:first, :conditions => ['login=?', user_login]) : nil
+        end
   end
 
   def metric=(m)
index a8585dfb75c2077d1cac9e3dc536f191deb7b9f5..8a6e7b55b5c21a9a5526d2879962be202241387a 100644 (file)
@@ -48,8 +48,9 @@
           <% controller.java_facade.getPages(Navigation::SECTION_RESOURCE, @project.scope, @project.qualifier, @project.language).each do |page| %>
           <li class="<%= 'selected' if request.request_uri.include?("page=#{page.getId()}") -%>"><a href="<%= ApplicationController.root_context -%>/plugins/resource/<%= @project.id-%>?page=<%= page.getId() -%>"><%= message(page.getId() + '.page', :default => page.getTitle()) %></a></li>
           <% end %>
-          <% if has_role?(:admin, @project) && @project.set? %>
+          <% if has_role?(:admin, @project) %>
             <li class="h2"><%= message('sidebar.project_system') -%></li>
+            <li class="<%= 'selected' if request.request_uri.include?('/manual_measures/') -%>"><a href="<%= ApplicationController.root_context -%>/manual_measures?resource=<%= @project.id -%>"><%= message('manual_measures.page') -%></a></li>
             <% if (@project.project? || @project.module?) %>
               <li class="<%= 'selected' if request.request_uri.include?('/project/settings') -%>"><a href="<%= ApplicationController.root_context -%>/project/settings/<%= @project.id -%>"><%= message('project_settings.page') -%></a></li>
             <% end %>
index 80209c1934ca4ba705033c8b70aa619e90265d00..24eb195c0f24d029ef4ee7ccbb216f82a81d8967 100644 (file)
@@ -4,8 +4,8 @@
   <td class="thin nowrap" align="right">
     <input type="text" name="val" value="<%= h(measure.value) -%>" id="value_input" size="8"/>
   </td>
-  <td>
-    <textarea name="desc" rows="3"><%= measure.description -%></textarea>
+  <td colspan="3">
+    <textarea name="desc" rows="3" class="width100"><%= measure.description -%></textarea>
   </td>
   <td class="thin nowrap">
     <input type="submit" value="Save"/>
index 399bcebd65ed43ea0453f10ae3ab76205df3dee7..d9092e83c72408b1f0828ec8249e30338f122869 100644 (file)
@@ -3,12 +3,16 @@
   <td class="thin nowrap"><%= measure.metric.short_name -%></td>
   <td class="thin nowrap" align="right"><%= measure.value -%></td>
   <td id="desc"><%= measure.description -%></td>
-  <% unless @edited_measure %>
   <td align="right">
-    <%= measure.user.name if measure.user -%>
-    <span class="note">(<%= l(measure.updated_at) -%>)</span>
+    <% unless @edited_measure %>
+      <%= measure.user.name if measure.user -%>
+    <% end %>
+  </td>
+  <td align="right">
+    <% unless @edited_measure %>
+      <%= l(measure.updated_at) -%>
+    <% end %>
   </td>
-  <% end %>
   <td class="thin nowrap">
     <% unless @edited_measure %>
     <a href="<%= url_for :controller => 'manual_measures', :action => 'edit', :metric => measure.metric.key, :resource => @resource.key -%>">Edit</a>
index c9de9337e31adc2d8ef7248ccedcaaac48aebb4d..c638aed67b5994c47f00621cb3caf1114101d5c1 100644 (file)
@@ -1,35 +1,42 @@
-<h1>Manual Measures</h1>
 <style type="text/css">
   #manualMeasures td {
     vertical-align: top;
   }
-
-  #manualMeasures textarea {
-    width: 100%;
-    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-    -moz-box-sizing: border-box; /* Firefox, other Gecko */
-    box-sizing: border-box; /* Opera/IE 8+ */
-  }
 </style>
-<form action="<%= url_for :action => 'save'-%>" method="POST" id="edit-form">
+<div class="line-block marginbottom10">
+  <ul class="operations">
+    <li>
+      <%= image_tag 'add.png' -%>
+      <a href="<%= ApplicationController.root_context-%>/manual_measures/new?resource=<%= @resource.id -%>" id="addMeasureLink">Add measure</a>
+    </li>
+    <li class="last">
+      <a href="<%= ApplicationController.root_context-%>/metrics/index" id="adminMetricsLink">Manage metrics</a>
+    </li>
+  </ul>
+</div>
+
+<form action="<%= url_for :action => 'save' -%>" method="POST" id="editForm">
   <input type="hidden" name="resource" value="<%= @resource.id -%>"/>
+
   <% if @metric %>
     <input type="hidden" name="metric" value="<%= @metric.key -%>"/>
   <% end %>
   <table class="width100 data" id="manualMeasures">
     <thead>
     <tr>
-      <th>Domain</th>
-      <th>Metric</th>
-      <th style="text-align: right">Value</th>
+      <th class="thin nowrap">Domain</th>
+      <th class="thin nowrap">Metric</th>
+      <th class="thin nowrap" style="text-align: right">Value</th>
       <th>Description</th>
-      <% unless @edited_measure %>
-        <th style="text-align: right">Author</th>
-      <% end %>
-      <th>Operations</th>
+      <th style="text-align: right"><% unless @edited_measure %>Author<% end %></th>
+      <th style="text-align: right"><% unless @edited_measure %>Date<% end %></th>
+      <th class="thin nowrap">Operations</th>
     </tr>
     </thead>
     <tbody>
+    <% if @measures.empty? %>
+      <td colspan="7" class="even">No measures</td>
+    <% end %>
     <%
        @measures.each do |measure|
     %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/new.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/new.html.erb
new file mode 100644 (file)
index 0000000..a4e1417
--- /dev/null
@@ -0,0 +1,35 @@
+<div class="line-block marginbottom10">
+  <ul class="operations">
+    <li class="last">
+      <a href="<%= ApplicationController.root_context -%>/metrics/index" id="adminMetricsLink">Manage metrics</a>
+    </li>
+  </ul>
+</div>
+
+<form action="<%= url_for :action => 'create' -%>" method="POST" id="createForm">
+  <input type="hidden" name="resource" value="<%= @resource.id -%>"/>
+  <table class="width100 data" id="manualMeasures">
+    <thead>
+    <tr>
+      <th class="thin nowrap">Metric</th>
+      <th class="thin nowrap" style="text-align: right">Value</th>
+      <th>Description</th>
+    </tr>
+    </thead>
+    <tbody>
+    <tr class="admin">
+      <td>
+        <select name="metric">
+          <option>ncloc</option>
+        </select>
+      </td>
+      <td>
+        <input type="text" name="val" size="8"/>
+      </td>
+      <td>
+        <textarea name="desc" rows="3" class="width100"></textarea>
+      </td>
+    </tr>
+    </tbody>
+  </table>
+</form>
index cc3dee143afe8b0a57523ed36a8075dd46c9796d..f0631c680c1c503f62efcb09648c11fe001e88c3 100644 (file)
@@ -29,7 +29,7 @@ class CreateManualMeasures < ActiveRecord::Migration
       t.column 'resource_id', :integer, :null => true
       t.column 'value', :decimal,   :null => true, :precision => 30, :scale => 20
       t.column 'text_value', :string, :null => true, :limit => 4000
-      t.column 'user_id', :integer, :null => true
+      t.column 'user_login', :string, :null => true, :limit => 40
       t.column 'description', :string, :null => true, :limit => 4000
       t.column 'url', :string, :null => true, :limit => 4000
       t.timestamps
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/214_add_index_on_manual_measures.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/214_add_index_on_manual_measures.rb
new file mode 100644 (file)
index 0000000..3c9babe
--- /dev/null
@@ -0,0 +1,30 @@
+#
+# 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
+#
+
+#
+# Sonar 2.10
+#
+class AddIndexOnManualMeasures < ActiveRecord::Migration
+
+  def self.up
+    add_index('manual_measures', 'resource_id', :name => 'manual_measures_resource_id')
+  end
+
+end
index 32347f77aff56a0df9ff38d43589e47cf2b6ea28..70738451f96d9e3e0f29009f7d673a10ee87a34b 100644 (file)
@@ -670,6 +670,7 @@ div.operations {
 }
 ul.operations {
   float: right;
+  height: 20px;
   list-style-type: none;
   margin: 0;
   background-color: #ECECEC;
@@ -1872,6 +1873,12 @@ div.break30 {
 .width100 {
   width: 100%;
 }
+textarea.width100 {
+  width: 100%;
+  -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
+  -moz-box-sizing: border-box; /* Firefox, other Gecko */
+  box-sizing: border-box; /* Opera/IE 8+ */
+}
 ul.horizontal {
   list-style-type: none;
 }