From: Simon Brandhof Date: Mon, 26 Nov 2012 14:05:12 +0000 (+0100) Subject: SONAR-2835 ability to copy measure filters X-Git-Tag: 3.4~271 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fafa2a93ae7df5ffed66ead68ce07500a45b96c1;p=sonarqube.git SONAR-2835 ability to copy measure filters --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb index e99fb71704a..1b47de87cd9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb @@ -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/ + def copy_form + require_parameters :id + @filter = find_filter(params[:id]) + render :partial => 'measures/copy_form' + end + + # POST /measures/copy/?name=&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/ def delete verify_post_request diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/user.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/user.rb index 5be2a51c417..c89ae10fef9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/user.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/user.rb @@ -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 index 00000000000..85cc0ee3fbf --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb @@ -0,0 +1,29 @@ +
+ +
+
+

Copy Filter: <%= h @filter.name -%>

+
+
+ <% @filter.errors.each do |attr, msg| %> +

<%= h msg -%>

+ <% end %> +
+ + +
+
+ + +
+
+ +
+
+ \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_cloud.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_cloud.html.erb index 517dae4aa0b..7f48beb44d2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_cloud.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_cloud.html.erb @@ -18,18 +18,13 @@ 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 %> - <%= result.snapshot.resource.name %> + <%= result.snapshot.resource.name %> <% end end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_edit_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_edit_form.html.erb index 1708e9552c5..530cfefd2e4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_edit_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_edit_form.html.erb @@ -29,5 +29,5 @@ \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_save_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_save_form.html.erb index 0390f579c0d..f848acdbd07 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_save_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_save_form.html.erb @@ -33,5 +33,5 @@ $j("#save-filter-form").modalForm({success:function (data) { window.location = baseUrl + '/measures/filter/' + data; }}); - $j('#name').focus(); + $j('#name').select(); \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb index 695bd565d8b..48e5a3fc889 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb @@ -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 %>

My Measure Filters

- +
@@ -60,6 +60,8 @@
<%= message('edit') -%>   + <%= message('copy') -%> +   <%= 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 @@
-
+

Shared Measure Filters

@@ -83,12 +85,13 @@ + <% if @shared_filters.empty? %> - + <% else %> <% @shared_filters.each do |filter| %> @@ -105,6 +108,9 @@ + <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb index ca88e75f055..e27ee1e0307 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb @@ -133,7 +133,7 @@ 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) %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb index d1303cb1896..2eb09d52d3e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb @@ -25,5 +25,5 @@ \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb index 56af1937060..e5a74cd22ba 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_rename_form.html.erb @@ -24,5 +24,5 @@ \ No newline at end of file
<%= message('name') -%> <%= message('shared_by') -%><%= message('operations') -%>
<%= message('filters.no_filters') -%><%= message('filters.no_filters') -%>
<%= h filter.user.name -%> + <%= message('copy') -%> +