]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2835 ability to copy measure filters
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 26 Nov 2012 14:05:12 +0000 (15:05 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 26 Nov 2012 14:05:12 +0000 (15:05 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/user.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_cloud.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_edit_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_save_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb

index e99fb71704a03c6adf4ec3e8c147c7edddc736bc..1b47de87cd9fd50931222aecf642fa5dd05016f0 100644 (file)
@@ -74,7 +74,7 @@ class MeasuresController < ApplicationController
     @filter.shared=(params[:shared]=='true')
     @filter.data=URI.unescape(params[:data])
     if @filter.save
-      current_user.favourited_measure_filters<<@filter
+      current_user.favourited_measure_filters<<@filter if add_to_favourites
       render :text => @filter.id.to_s, :status => 200
     else
       render :partial => 'measures/save_form', :status => 400
@@ -116,6 +116,34 @@ class MeasuresController < ApplicationController
     end
   end
 
+  # GET /measures/copy_form/<filter id>
+  def copy_form
+    require_parameters :id
+    @filter = find_filter(params[:id])
+    render :partial => 'measures/copy_form'
+  end
+
+  # POST /measures/copy/<filter id>?name=<copy name>&description=<copy description>
+  def copy
+    verify_post_request
+    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
+      render :text => @filter.id.to_s, :status => 200
+    else
+      render :partial => 'measures/copy_form', :status => 400
+    end
+  end
+
   # POST /measures/delete/<filter id>
   def delete
     verify_post_request
index 5be2a51c417b3950db164d6ec9b24a11b305f923..c89ae10fef9082c16153581a08903b9c20093d00 100644 (file)
@@ -30,10 +30,10 @@ class User < ActiveRecord::Base
   has_many :filters, :dependent => :destroy
   has_many :active_dashboards, :dependent => :destroy, :order => 'order_index'
   has_many :dashboards, :dependent => :destroy
-  has_many :measure_filters, :class_name => 'MeasureFilter', :dependent => :delete_all
+  has_many :measure_filters, :class_name => 'MeasureFilter', :dependent => :delete_all, :order => 'name asc'
 
   # measure filters that are marked as favourites
-  has_many :favourited_measure_filters, :class_name => 'MeasureFilter', :through => :measure_filter_favourites, :source => :measure_filter
+  has_many :favourited_measure_filters, :class_name => 'MeasureFilter', :through => :measure_filter_favourites, :source => :measure_filter, :order => 'name asc'
 
   # the join table MEASURE_FILTER_FAVOURITES
   has_many :measure_filter_favourites, :class_name => 'MeasureFilterFavourite', :dependent => :delete_all
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb
new file mode 100644 (file)
index 0000000..85cc0ee
--- /dev/null
@@ -0,0 +1,29 @@
+<form id="copy-filter-form" method="post" action="<%= ApplicationController.root_context -%>/measures/copy">
+  <input type="hidden" name="id" value="<%= @filter.id -%>">
+  <fieldset>
+    <div class="form-head">
+      <h2>Copy Filter: <%= h @filter.name -%></h2>
+    </div>
+    <div class="form-body">
+      <% @filter.errors.each do |attr, msg| %>
+        <p class="error"><%= h msg -%></p>
+      <% end %>
+      <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 -%>"/>
+      </div>
+      <div class="form-field">
+        <label for="description">Description</label>
+        <input id="description" name="description" type="text" size="50" maxlength="4000" value="<%= h @filter.description -%>"/>
+      </div>
+    </div>
+    <div class="form-foot">
+      <input type="submit" value="<%= h message('copy') -%>" id="copy-submit"/>
+      <a href="#" onclick="return closeModalWindow()" id="copy-cancel"><%= h message('cancel') -%></a>
+    </div>
+  </fieldset>
+</form>
+<script>
+  $j("#copy-filter-form").modalForm();
+  $j('#name').select();
+</script>
\ No newline at end of file
index 517dae4aa0b9f8eb8d38bacdd0362a96e92e4551..7f48beb44d2d01094ed9eec5c36bc45ccc757b20 100644 (file)
        size_measure=result.measure(@filter.display.size_metric)
        if size_measure && size_measure.value
          color_measure=result.measure(@filter.display.color_metric)
-         if result.snapshot.source_code?
-          link="of(#{result.snapshot.project_id})"
-         else
-           link="ov(#{result.snapshot.project_id})"
-         end
 
          title="#{result.snapshot.resource.long_name} | #{@filter.display.size_metric.short_name}: #{size_measure.formatted_value}"
          if color_measure && color_measure.value
            title += " | #{@filter.display.color_metric.short_name}: #{color_measure.formatted_value}"
          end
   %>
-      <a href="#" onclick="<%= link -%>" title="<%= title -%>"><span style="font-size: <%= cloud_font_size(size_measure.value, min_size_value, max_size_value) -%>%;color: <%= MeasureColor.color(color_measure, color_options).html -%>"><%= result.snapshot.resource.name %></span></a>
+      <a href="<%= ApplicationController.root_context -%>/dashboard/index/<%= result.snapshot.resource_id -%>" title="<%= title -%>"><span style="font-size: <%= cloud_font_size(size_measure.value, min_size_value, max_size_value) -%>%;color: <%= MeasureColor.color(color_measure, color_options).html -%>"><%= result.snapshot.resource.name %></span></a>
     <% end
        end %>
 </div>
\ No newline at end of file
index 1708e9552c524e90759ef86a56bbe06305a2b887..530cfefd2e4a74a071e9df4c764376acc7b325e7 100644 (file)
@@ -29,5 +29,5 @@
 </form>
 <script>
   $j("#edit-filter-form").modalForm();
-  $j('#name').focus();
+  $j('#name').select();
 </script>
\ No newline at end of file
index 0390f579c0da71c0a8d3728bae12dcab45564273..f848acdbd07b00006d0a4f29fa1b39fdc3d50f9d 100644 (file)
@@ -33,5 +33,5 @@
   $j("#save-filter-form").modalForm({success:function (data) {
     window.location = baseUrl + '/measures/filter/' + data;
   }});
-  $j('#name').focus();
+  $j('#name').select();
 </script>
\ No newline at end of file
index 695bd565d8b126c0a74428d39f2def138c49dcdc..48e5a3fc889fd853af13e22ffccf42ca1db8b0ee 100644 (file)
@@ -5,11 +5,11 @@
         var filterId = $j(this).attr('filter-id');
         var star = $j(this);
         $j.ajax({
-          type: 'POST',
+          type:'POST',
           url:baseUrl + "/measures/toggle_fav",
-          data:{id: filterId},
+          data:{id:filterId},
           success:function (data) {
-            if (data=='true') {
+            if (data == 'true') {
               star.removeClass('notfav').addClass('fav');
               star.attr('title', '<%= escape_javascript message('click_to_remove_from_favourites') -%>');
             } else {
@@ -24,7 +24,7 @@
 <% end %>
 
 <h2>My Measure Filters</h2>
-<table class="data" id="my-filters">
+<table class="data marginbottom10" id="my-filters">
   <thead>
   <tr>
     <th class="thin"></th>
@@ -60,6 +60,8 @@
         <td class="thin nowrap right">
           <a id="edit_<%= filter.name.parameterize -%>" href="<%= ApplicationController.root_context -%>/measures/edit_form/<%= filter.id -%>" class="link-action open-modal"><%= message('edit') -%></a>
           &nbsp;
+          <a id="copy-<%= filter.name.parameterize -%>" href="<%= ApplicationController.root_context -%>/measures/copy_form/<%= filter.id -%>" class="link-action open-modal"><%= message('copy') -%></a>
+          &nbsp;
           <%= link_to_action message('delete'), "#{ApplicationController.root_context}/measures/delete/#{filter.id}",
                              :class => 'link-action link-red',
                              :id => "delete_#{filter.name.parameterize}",
@@ -74,7 +76,7 @@
   </tbody>
 </table>
 
-<br>
+<br/>
 
 <h2>Shared Measure Filters</h2>
 <table class="data" id="shared-filters">
     <th class="thin"></th>
     <th><%= message('name') -%></th>
     <th><%= message('shared_by') -%></th>
+    <th class="right"><%= message('operations') -%></th>
   </tr>
   </thead>
   <tbody>
   <% if @shared_filters.empty? %>
     <tr class="even">
-      <td colspan="3"><%= message('filters.no_filters') -%></td>
+      <td colspan="4"><%= message('filters.no_filters') -%></td>
     </tr>
   <% else %>
     <% @shared_filters.each do |filter| %>
         <td>
           <%= h filter.user.name -%>
         </td>
+        <td class="thin nowrap right">
+          <a id="copy-<%= filter.name.parameterize -%>" href="<%= ApplicationController.root_context -%>/measures/copy_form/<%= filter.id -%>" class="link-action open-modal"><%= message('copy') -%></a>
+        </td>
       </tr>
 
     <% end %>
index ca88e75f055989617dfa7d252b431a202fdcacb2..e27ee1e0307cc827629540237d750f93e5267a74 100644 (file)
 
       Display as:
       <% MeasureFilter::DISPLAYS.each do |display_class| %>
-        <%= link_to_if display_class::KEY!=@filter.display.class::KEY, display_class::KEY, params.merge(:action => 'search', :display => display_class::KEY, :id => nil) -%>
+        <%= link_to_if display_class::KEY!=@filter.display.class::KEY, display_class::KEY, params.merge(:action => 'search', :display => display_class::KEY, :id => @filter.id) -%>
       <% end %>
 
       <% if logged_in? && (@filter.user_id==nil || @filter.user_id==current_user.id) %>
index d1303cb1896681633433119afd7a8bef62c3be13..2eb09d52d3e6a038157265290089d3183f7a9ddd 100644 (file)
@@ -25,5 +25,5 @@
 </form>
 <script>
   $j("#copy-profile-form").modalForm();
-  $j('#copy-name').focus();
+  $j('#copy-name').select();
 </script>
\ No newline at end of file
index 56af193706044d98303d50caff19c94c61c782df..e5a74cd22ba1d488092aa0f9e742e17e3baffd70 100644 (file)
@@ -24,5 +24,5 @@
 </form>
 <script>
   $j("#rename-profile-form").modalForm();
-  $j('#new-name').focus();
+  $j('#new-name').select();
 </script>
\ No newline at end of file