summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-07-20 12:24:42 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-07-20 12:25:05 +0200
commit2c89cde5852c1920c187ce87505ac9e96b9b7910 (patch)
tree30acecc7a22cd413cafd4a9207e3d9289283ac08 /sonar-server
parentbd5bd39acfbb71c6a731064a535a9e89d8a1715a (diff)
downloadsonarqube-2c89cde5852c1920c187ce87505ac9e96b9b7910.tar.gz
sonarqube-2c89cde5852c1920c187ce87505ac9e96b9b7910.zip
SONAR-2628 create manual measure
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb19
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/manual_measure.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_row.html.erb22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/index.html.erb84
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/new.html.erb84
5 files changed, 111 insertions, 102 deletions
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 53c4f15f165..947da59ca2f 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
@@ -28,18 +28,13 @@ class ManualMeasuresController < ApplicationController
end
def new
- load_measures()
- end
-
- def edit
- load_measures()
- @metric=Metric.by_key(params[:metric])
- @edited_measure=@measures.find{|m| m.metric==@metric}
- render :action => 'index'
- end
-
- def create
-
+ if params[:metric].present?
+ @metric=Metric.by_key(params[:metric])
+ @measure=ManualMeasure.find(:first, :conditions => ['resource_id=? and metric_id=?', @resource.id, @metric.id]) || ManualMeasure.new
+ else
+ @metric=nil
+ @measure=nil
+ end
end
def save
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 264708a452d..7273e229d7d 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
@@ -39,6 +39,10 @@ class ManualMeasure < ActiveRecord::Base
end
end
+ def username
+ user ? user.name : user_login
+ end
+
def metric=(m)
@metric = m
write_attribute(:metric_id, m.id) if m.id
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
deleted file mode 100644
index d9092e83c72..00000000000
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_row.html.erb
+++ /dev/null
@@ -1,22 +0,0 @@
-<tr class="<%= cycle('even', 'odd') -%>">
- <td class="thin nowrap"><%= measure.metric.domain -%></td>
- <td class="thin nowrap"><%= measure.metric.short_name -%></td>
- <td class="thin nowrap" align="right"><%= measure.value -%></td>
- <td id="desc"><%= measure.description -%></td>
- <td align="right">
- <% unless @edited_measure %>
- <%= measure.user.name if measure.user -%>
- <% end %>
- </td>
- <td align="right">
- <% unless @edited_measure %>
- <%= l(measure.updated_at) -%>
- <% end %>
- </td>
- <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>
- <%= link_to 'Delete', {:action => 'delete', :metric => measure.metric.key, :resource => @resource.id}, {:method => 'POST', :confirm => "This measure will be deleted during next project analysis", :class => 'action'} -%>
- <% end %>
- </td>
-</tr>
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 c638aed67b5..5f5ba47e5b5 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
@@ -5,57 +5,49 @@
</style>
<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>
+ <%= image_tag 'add.png' -%>
+ <a href="<%= ApplicationController.root_context -%>/manual_measures/new?resource=<%= @resource.id -%>" id="addMeasureLink">Add measure</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 -%>"/>
+<table class="width100 data" id="manualMeasures">
+ <thead>
+ <tr>
+ <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>
+ <th style="text-align: right">Author</th>
+ <th style="text-align: right">Date</th>
+ <th class="thin nowrap">Operations</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% if @measures.empty? %>
+ <td colspan="7" class="even">No measures</td>
<% end %>
- <table class="width100 data" id="manualMeasures">
- <thead>
- <tr>
- <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>
- <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>
+ <%
+ @measures.each do |measure|
+ %>
+ <a name="<%= measure.metric.key -%>"></a>
+ <tr class="<%= cycle('even', 'odd') -%>">
+ <td class="thin nowrap"><%= measure.metric.domain -%></td>
+ <td class="thin nowrap"><%= measure.metric.short_name -%></td>
+ <td class="thin nowrap" align="right"><%= measure.value -%></td>
+ <td id="desc"><%= measure.description -%></td>
+ <td align="right"><%= measure.username -%>
+ </td>
+ <td align="right">
+ <%= l(measure.updated_at) -%>
+ </td>
+ <td class="thin nowrap">
+ <a href="<%= url_for :controller => 'manual_measures', :action => 'new', :metric => measure.metric.key, :resource => @resource.key -%>">Edit</a>
+ <%= link_to 'Delete', {:action => 'delete', :metric => measure.metric.key, :resource => @resource.id}, {:method => 'POST', :confirm => "This measure will be deleted during next project analysis", :class => 'action'} -%>
+ </td>
</tr>
- </thead>
- <tbody>
- <% if @measures.empty? %>
- <td colspan="7" class="even">No measures</td>
- <% end %>
- <%
- @measures.each do |measure|
- %>
- <a name="<%= measure.metric.key -%>"></a>
- <% if @edited_measure && @edited_measure==measure %>
- <%= render :partial => 'edit_form', :locals => {:measure => @edited_measure} -%>
- <% else %>
- <%= render :partial => 'row', :locals => {:measure => measure} -%>
-
- <% end
- end
- %>
- </tbody>
- </table>
-</form>
-<% if @edited_measure %>
- <script type="text/javascript">
- location.href = '#<%= @edited_measure.metric.key -%>';
- Form.Element.focus('value_input');
- </script>
-<% end %>
+ <% end %>
+ </tbody>
+</table> \ No newline at end of file
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
index a4e14175eb5..8e917aead2a 100644
--- 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
@@ -1,35 +1,75 @@
-<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>
+<script type="text/javascript">
+ function changeMetric() {
+ document.location = '<%= ApplicationController.root_context-%>/manual_measures/new?resource=<%= @resource.key -%>&metric=' + $('metricSelect').getValue();
+ return false;
+ }
+</script>
-<form action="<%= url_for :action => 'create' -%>" method="POST" id="createForm">
+<form action="<%= url_for :action => (@measure ? 'save' : 'new') -%>" 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>
+ <table class="width100 form">
<tbody>
- <tr class="admin">
+ <tr>
+ <td class="first">
+ Metric:
+ </td>
<td>
- <select name="metric">
- <option>ncloc</option>
+ <select name="metric" onchange="changeMetric();" id="metricSelect">
+ <option value="">Select metric</option>
+ <% Metric.all.select { |m| m.user_managed? }.sort.each do |metric| %>
+ <option value="<%= metric.key -%>" <%= 'selected' if @metric && @metric.id==metric.id -%>><%= metric.short_name -%></option>
+ <% end %>
</select>
+
+ <% if @metric %>
+ <span class="note"><%= @metric.description -%></span>
+ <% end %>
</td>
- <td>
- <input type="text" name="val" size="8"/>
+ </tr>
+ <% if @measure %>
+ <tr>
+ <td class="first">
+ Value:
+ </td>
+ <td>
+ <input type="text" name="val" id="valueText" value="<%= @measure.value -%>"/>
+ </td>
+ </tr>
+ <tr>
+ <td class="first">
+ Description:
+ </td>
+ <td>
+ <textarea rows="5" cols="80" name="desc" class="width100"><%= @measure.description -%></textarea>
+ </td>
+ </tr>
+ <% unless @measure.new_record?() %>
+ <tr>
+ <td class="first">
+ Last change:
+ </td>
+ <td>
+ By <%= @measure.username -%> on <%= l(@measure.updated_at) -%>
+ </td>
+ </tr>
+ <% end %>
+ <% end %>
+ <tr>
+ <td class="first">
</td>
<td>
- <textarea name="desc" rows="3" class="width100"></textarea>
+ <% if @measure %>
+ <input type="submit" value="Save"/>
+ <% end %>
+ <%= link_to 'Cancel', :action => 'index', :resource => @resource.key -%>
</td>
</tr>
</tbody>
</table>
</form>
+
+<% if @metric %>
+ <script type="text/javascript">
+ $('valueText').focus();
+ </script>
+<% end %> \ No newline at end of file