]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3825 better error handling during copy of measure filter
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 13 Dec 2012 10:57:43 +0000 (11:57 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 13 Dec 2012 10:57:43 +0000 (11:57 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb

index a63af45542aea34e4fd64020f3f4284ebe164fca..391c759f859d681f49ada75ac58591bf9ff26bb2 100644 (file)
@@ -138,18 +138,21 @@ class MeasuresController < ApplicationController
     access_denied unless logged_in?
     require_parameters :id
 
-    to_clone = find_filter(params[:id])
-    @filter = MeasureFilter.new
-    @filter.name = params[:name]
-    @filter.description = params[:description]
-    @filter.user_id = current_user.id
-    @filter.shared = to_clone.shared
-    @filter.data = to_clone.data
-    @filter.shared = false
-    if @filter.save
-      current_user.favourited_measure_filters << @filter
-      render :text => @filter.id.to_s, :status => 200
+    source = find_filter(params[:id])
+    target = MeasureFilter.new
+    target.name = params[:name]
+    target.description = params[:description]
+    target.user_id = current_user.id
+    target.shared = source.shared
+    target.data = source.data
+    target.shared = false
+    if target.save
+      current_user.favourited_measure_filters << target
+      render :text => target.id.to_s, :status => 200
     else
+      # keep the id (from source) and errors (from target) in the copy form
+      target.id= source.id
+      @filter = target
       render :partial => 'measures/copy_form', :status => 400
     end
   end
index 68eef6d414cd35e4bcaf6d7c10e0fc538cca8af4..89d14fa379c219bf6136a9cf2f77a32ce5968fc7 100644 (file)
@@ -2,15 +2,19 @@
   <input type="hidden" name="id" value="<%= @filter.id -%>">
   <fieldset>
     <div class="form-head">
-      <h2>Copy Filter: <%= h @filter.name -%></h2>
+      <h2>Copy Filter</h2>
     </div>
     <div class="form-body">
       <% @filter.errors.each do |attr, msg| %>
         <p class="error"><%= h msg -%></p>
       <% end %>
+      <div class="form-field">
+        <label>Copy</label>
+        <input type="text" size="50" maxlength="100" value="<%= h @filter.name -%>" disabled="disabled"/>
+      </div>
       <div class="form-field">
         <label for="name">Name <em class="mandatory">*</em></label>
-        <input id="name" name="name" type="text" size="50" maxlength="100" value="<%= h @filter.name -%>"/>
+        <input id="name" name="name" type="text" size="50" maxlength="100" value=""/>
       </div>
       <div class="form-field">
         <label for="description">Description</label>
@@ -24,8 +28,8 @@
   </fieldset>
 </form>
 <script>
-  $j("#copy-filter-form").modalForm({success:function (data) {
-      window.location = baseUrl + '/measures/filter/' + data;
-    }});
+  $j("#copy-filter-form").modalForm({success: function (data) {
+    window.location = baseUrl + '/measures/filter/' + data;
+  }});
   $j('#name').select();
 </script>
\ No newline at end of file
index 242bb0e6f4eccd646aba588d1457e943850902fd..045cb0ac4d1b7f3cfa60a7d8ad814d857ba7260b 100644 (file)
@@ -35,7 +35,7 @@
               <% end %>
             <% end %>
           </ul>
-          <div class="page_title">
+          <div class="page_title" id="filter-title">
             <% if @filter.name.present? %>
               <span class="h3"><%= h @filter.name -%></span>
               <span class="note">