aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-07-19 23:02:36 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-07-19 23:02:36 +0200
commitbd5bd39acfbb71c6a731064a535a9e89d8a1715a (patch)
tree78ddf77977c11810c2a66965df56687351ea64d1 /sonar-server
parentcb4aedaf172eadbef66f816320c8931eae8e6929 (diff)
downloadsonarqube-bd5bd39acfbb71c6a731064a535a9e89d8a1715a.tar.gz
sonarqube-bd5bd39acfbb71c6a731064a535a9e89d8a1715a.zip
SONAR-2628 Add a page to manage manual measures
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/manual_measures_controller.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb10
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/manual_measure.rb16
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_edit_form.html.erb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_row.html.erb12
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/index.html.erb39
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/new.html.erb35
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/211_create_manual_measures.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/214_add_index_on_manual_measures.rb30
-rw-r--r--sonar-server/src/main/webapp/stylesheets/style.css7
11 files changed, 130 insertions, 32 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/manual_measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/manual_measures_controller.rb
index e131f23c309..3bd9e29ef9c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/manual_measures_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/manual_measures_controller.rb
@@ -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
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb
index 12dcf579e52..53c4f15f165 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb
@@ -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]
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/manual_measure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/manual_measure.rb
index e5500e0d5f9..264708a452d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/manual_measure.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/manual_measure.rb
@@ -19,18 +19,24 @@
#
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)
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
index a8585dfb75c..8a6e7b55b5c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
@@ -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 %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_edit_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_edit_form.html.erb
index 80209c1934c..24eb195c0f2 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_edit_form.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_edit_form.html.erb
@@ -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"/>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_row.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_row.html.erb
index 399bcebd65e..d9092e83c72 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_row.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_row.html.erb
@@ -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>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/index.html.erb
index c9de9337e31..c638aed67b5 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/index.html.erb
@@ -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
index 00000000000..a4e14175eb5
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/new.html.erb
@@ -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>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/211_create_manual_measures.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/211_create_manual_measures.rb
index cc3dee143af..f0631c680c1 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/211_create_manual_measures.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/211_create_manual_measures.rb
@@ -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
index 00000000000..3c9babea7b2
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/214_add_index_on_manual_measures.rb
@@ -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
diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css
index 32347f77aff..70738451f96 100644
--- a/sonar-server/src/main/webapp/stylesheets/style.css
+++ b/sonar-server/src/main/webapp/stylesheets/style.css
@@ -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;
}