--- /dev/null
+#
+# 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 ManualMeasuresController < ApplicationController
+
+ SECTION=Navigation::SECTION_RESOURCE
+ before_filter :load_resource
+ verify :method => :post, :only => [:save, :delete], :redirect_to => { :action => :index }
+
+ def index
+ 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 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)
+ end
+ # TODO use measure.text_value if string metric
+ measure.value = params[:val]
+ measure.description = params[:desc]
+ measure.save!
+ redirect_to :action => 'index', :resource => params[:resource], :metric => params[:metric]
+ end
+
+ def delete
+ metric=Metric.by_key(params[:metric])
+ ManualMeasure.destroy_all(['resource_id=? and metric_id=?', @resource.id, metric.id])
+ redirect_to :action => 'index', :resource => params[:resource], :metric => params[:metric]
+ end
+
+ private
+
+ def load_resource
+ @resource=Project.by_key(params[:resource])
+ return redirect_to home_path unless @resource
+ return access_denied unless has_role?(:admin, @resource)
+ end
+
+ def load_measures
+ @measures=ManualMeasure.find(:all, :conditions => ['resource_id=?', @resource.id]).select{|m| m.metric.enabled}.sort_by{|m| m.metric.domain}
+ end
+end
#
def format_measure(metric_or_measure, options={})
html=''
-
+ m=nil
if metric_or_measure.is_a? ProjectMeasure
m = metric_or_measure
elsif @snapshot
[COMPLEXITY, COVERAGE, VIOLATIONS_DENSITY]
end
- def self.review_types
- all.select{|metric| metric.user_managed?}
- end
-
def self.by_keys(keys)
result=[]
keys.each do |k|
-<% selected_section = controller.class::SECTION %>
+<%
+ selected_section = controller.class::SECTION
+ @project=@resource unless @project
+%>
<div id="container">
<div id="hd">
<%= render :partial => 'layouts/breadcrumb' %>
--- /dev/null
+<tr class="admin ">
+ <td class="thin nowrap"><%= measure.metric.domain -%></td>
+ <td class="thin nowrap"><%= measure.metric.short_name -%></td>
+ <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>
+ <td class="thin nowrap">
+ <input type="submit" value="Save"/>
+ <a href="<%= url_for :controller => 'manual_measures', :action => 'index', :metric => measure.metric.key, :resource => @resource.key -%>">Cancel</a>
+ </td>
+</tr>
--- /dev/null
+<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>
+ <% unless @edited_measure %>
+ <td align="right">
+ <%= measure.user.name if measure.user -%>
+ <span class="note">(<%= l(measure.updated_at) -%>)</span>
+ </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>
+ <%= 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>
--- /dev/null
+<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">
+ <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>Description</th>
+ <% unless @edited_measure %>
+ <th style="text-align: right">Author</th>
+ <% end %>
+ <th>Operations</th>
+ </tr>
+ </thead>
+ <tbody>
+ <%
+ @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 %>
+++ /dev/null
-<%= render :partial => 'layouts/flashes', :object => 'reviews_flashes' %>
-
-<% form_for :review, @review, :url => { :action => 'add_review', :sid => @snapshot.id }, :method => 'post' do |f| %>
- <table class="spaced admin" style="padding: 5px">
-
- <% review_metrics = [''] + @review_types.collect do |metric|
- ["#{metric.short_name}", metric.id]
- end
- if review_metrics.size>0 %>
- <tr>
- <td align="left" colspan="2" nowrap>
- <span class="comments">Metric (<%= link_to 'configure', {:controller => 'metrics', :action => 'index'}, {:class => 'action'} %>)</span><br/>
- <%= f.select( :metric_id, review_metrics, {}, {:onChange => "selectReviewMetric();"}) %></td>
- </tr>
- <tr>
- <td colspan="2">
- <% @review_types.each do |metric| %>
- <span id='review_description_<%= metric.id %>' style='display:none' class='review_description_update comments'>
- <%= metric.description %>
- </span>
- <% end %>
- <td>
- </tr>
- <tr>
- <td align="left"><span class="comments">Date*</span><br/>
- <%= f.date_select :measure_date %>
- </td>
- <td align="left" nowrap>
- <span class="comments">Value*</span>
- <% @review_types.each do |metric| -%>
- <span id='review_value_<%= metric.id %>' style='display:none' class='review_description_update comments'>
- (<%= metric.value_type_name -%>)
- </span>
- <% end -%>
- <br/>
- <%= f.text_field :value, :size => 10 %>
- </td>
- </tr>
- <tr>
- <td align="left" colspan="2"><span class="comments">Description</span><br/>
- <%= text_area_tag :description, '', :rows => 3, :cols => 40 %></td>
- </tr>
- <tr>
- <td align="left" colspan="2"><span class="comments">Link</span><br/>
- <%= text_field_tag :url, '', :size => 40 %>
- </td>
- </tr>
- <tr>
- <td align="left" colspan="2">
- <%= submit_tag( "Submit", :id => 'save_review' ) %>
- <%= link_to 'cancel', {:action => 'index', :id => @snapshot.project.id} ,
- {:id => 'cancel_add_review', :class => 'action'}%>
- </td>
- </tr>
- <tr>
- <td colspan="2"><span class="comments">* required fields</span></td>
- </tr>
- <% else %>
- <tr>
- <td align="left" colspan="2">
- <p><img src="../../images/controls/error.gif" />
- Please
- <%= link_to 'create metrics.', {:controller => 'metrics', :action => 'index'}, {:class => 'action'} %>
- </p>
- </td>
- </tr>
- <% end %>
- </table>
-<% end %>
-
-
-
-