]> source.dussan.org Git - sonarqube.git/commitdiff
First draft of administration console of manual measures
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 19 Jul 2011 16:02:00 +0000 (18:02 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 19 Jul 2011 16:03:44 +0000 (18:03 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/metric.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 [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/_row.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/manual_measures/index.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/project/_dashboard_edit_review.html.erb [deleted file]

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
new file mode 100644 (file)
index 0000000..12dcf57
--- /dev/null
@@ -0,0 +1,67 @@
+#
+# 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
index 1b839e29a8430832d5b9ea6f2dd3cbe8a7961d11..fffd7a91f253c94a3c516b840b86d10fae926602 100644 (file)
@@ -259,7 +259,7 @@ module ApplicationHelper
   #
   def format_measure(metric_or_measure, options={})
     html=''
-
+    m=nil
     if metric_or_measure.is_a? ProjectMeasure
       m = metric_or_measure
     elsif @snapshot
index 22bfb6f2ff03d4cb97a61e88bbfe09fff2acda93..91bbef9068dc73ae2188e025c1faba7377be4f0c 100644 (file)
@@ -239,10 +239,6 @@ class Metric < ActiveRecord::Base
     [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|
index 004552333e9c3e05a726c5dd72c349cbc983a5f2..a8585dfb75c2077d1cac9e3dc536f191deb7b9f5 100644 (file)
@@ -1,4 +1,7 @@
-<% selected_section = controller.class::SECTION %>
+<%
+   selected_section = controller.class::SECTION
+   @project=@resource unless @project
+%>
 <div id="container">
   <div id="hd">
     <%= render :partial => 'layouts/breadcrumb' %>
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
new file mode 100644 (file)
index 0000000..80209c1
--- /dev/null
@@ -0,0 +1,14 @@
+<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>
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
new file mode 100644 (file)
index 0000000..399bceb
--- /dev/null
@@ -0,0 +1,18 @@
+<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>
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
new file mode 100644 (file)
index 0000000..c9de933
--- /dev/null
@@ -0,0 +1,54 @@
+<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 %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/_dashboard_edit_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/_dashboard_edit_review.html.erb
deleted file mode 100644 (file)
index 4f9e450..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-<%= 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" />&nbsp;
-                Please
-                <%= link_to 'create metrics.', {:controller => 'metrics', :action => 'index'}, {:class => 'action'} %>
-            </p>
-          </td>
-        </tr>
-      <% end %>
-  </table>
-<% end %>
-
-
-
-