From 02b91e5a17f512921d58952e0f446ce23937b76a Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 23 May 2012 13:49:22 +0200 Subject: [PATCH] Revert "Fix Pagination and sorting in filter widget" This reverts commit a0e00c5f0a63b81226c2b04271df07fdeff6a5f7. --- .../app/controllers/filters_controller.rb | 10 +-- .../WEB-INF/app/helpers/filters_helper.rb | 83 +++++++++---------- .../WEB-INF/app/views/filters/_list.html.erb | 31 ++----- 3 files changed, 46 insertions(+), 78 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb index 95fadc7bf4a..f06a27a086e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb @@ -25,7 +25,7 @@ class FiltersController < ApplicationController SECTION=Navigation::SECTION_CONFIGURATION verify :method => :post, :only => [:create, :delete, :up, :down, :activate, :deactivate, :up_column, :down_column, :add_column, :delete_column, :set_sorted_column, :set_view, :set_columns, :set_page_size], :redirect_to => {:action => :index} - before_filter :login_required, :except => %w(index treemap list) + before_filter :login_required, :except => %w(index treemap) def manage if is_admin? @@ -36,14 +36,6 @@ class FiltersController < ApplicationController @filters.sort! { |a,b| a.name.downcase <=> b.name.downcase } end - def list - @widget=Widget.find(params[:widget]) - @filter=::Filter.find(params[:id]) - @filter_context=Filters.execute(@filter, self, params) - - render :partial => 'list', :locals => {:edit_mode => params[:edit_mode], :widget => @widget} - end - def new @filter=::Filter.new() @filter.criteria< "filter-#{@widget.id}", :url => params.merge({:controller => :filters, :action => :list, :id => filter.id, :edit_mode => @edit_mode, :widget => @widget.id}.merge(override))} - end - def column_title(column, filter) - if column.sortable? - html=goto_page(h(column.display_name), filter, {:asc => (!(column.ascending?)).to_s, :sort => column.id}) - else - html=h(column.display_name) - end - if column.variation - html=" #{html}" - end + if column.sortable? + html=link_to h(column.display_name), url_for(:overwrite_params => {:asc => (!(column.ascending?)).to_s, :sort => column.id}) + else + html=h(column.display_name) + end + if column.variation + html=" #{html}" + end - if filter.sorted_column==column - html << (column.ascending? ? image_tag("asc12.png") : image_tag("desc12.png")) - end - html + if filter.sorted_column==column + html << (column.ascending? ? image_tag("asc12.png") : image_tag("desc12.png")) + end + html end def column_align(column) - (column.on_name? || column.on_key?) ? 'left' : 'right' + (column.on_name? || column.on_key?) ? 'left' : 'right' end def treemap_metrics(filter) - metrics=filter.measure_columns.map { |col| col.metric } - size_metric=(metrics.size>=1 ? metrics[0] : Metric.by_key('ncloc')) - color_metric=nil - if metrics.size>=2 - color_metric=metrics[1] - end - if color_metric.nil? || !color_metric.treemap_color? - color_metric=Metric.by_key('violations_density') - end - [size_metric, color_metric] + metrics=filter.measure_columns.map{|col| col.metric} + size_metric=(metrics.size>=1 ? metrics[0] : Metric.by_key('ncloc')) + color_metric=nil + if metrics.size>=2 + color_metric=metrics[1] + end + if color_metric.nil? || !color_metric.treemap_color? + color_metric=Metric.by_key('violations_density') + end + [size_metric, color_metric] end def period_names - p1=Property.value('sonar.timemachine.period1', nil, 'previous_analysis') - p2=Property.value('sonar.timemachine.period2', nil, '5') - p3=Property.value('sonar.timemachine.period3', nil, '30') - [period_name(p1), period_name(p2), period_name(p3)] + p1=Property.value('sonar.timemachine.period1', nil, 'previous_analysis') + p2=Property.value('sonar.timemachine.period2', nil, '5') + p3=Property.value('sonar.timemachine.period3', nil, '30') + [period_name(p1), period_name(p2), period_name(p3)] end private def period_name(property) - if property=='previous_analysis' - message('delta_since_previous_analysis') - elsif property =~ /^[\d]+(\.[\d]+){0,1}$/ - # is integer - message('delta_over_x_days', :params => property) - elsif property =~ /\d{4}-\d{2}-\d{2}/ - message('delta_since', :params => property) - elsif !property.blank? - message('delta_since_version', :params => property) - else - nil - end + if property=='previous_analysis' + message('delta_since_previous_analysis') + elsif property =~ /^[\d]+(\.[\d]+){0,1}$/ + # is integer + message('delta_over_x_days', :params => property) + elsif property =~ /\d{4}-\d{2}-\d{2}/ + message('delta_since', :params => property) + elsif !property.blank? + message('delta_since_version', :params => property) + else + nil + end end - end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb index e40ef84b61c..679e9c5c9fe 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb @@ -1,8 +1,5 @@ <% filter=@filter_context.filter %> -<% @edit_mode=edit_mode %> -<% @widget=widget if widget %> - -
+
@@ -52,31 +49,15 @@ %> | <% if max_pages > 20 && start_page > 1 %> - <%= goto_page message('paging_previous'), filter, :page_id => 1 %> - <% end %> - - <% if current_page>start_page %> - <%= goto_page message('paging_previous'), filter, :page_id => current_page-1 %> - <% else %> - <%= message('paging_previous') -%> + <%= link_to message('paging_first'), {:overwrite_params => {:page_id => 1}} -%> <% end %> - + <%= link_to_if current_page>start_page, message('paging_previous'), {:overwrite_params => {:page_id => current_page-1}} %> <% for index in start_page..end_page %> - <% unless index==current_page %> - <%= goto_page index.to_s, filter, :page_id => index %> - <% else %> - <%= index.to_s -%> - <% end %> + <%= link_to_unless index==current_page, index.to_s, {:overwrite_params => {:page_id => index}} %> <% end %> - - <% if current_page - <%= goto_page message('paging_next'), filter, :page_id => current_page+1 %> - <% else %> - <%= message('paging_next') -%> - <% end %> - + <%= link_to_if current_page {:page_id => 1+current_page}} %> <% if max_pages > 20 && end_page < max_pages %> - <%= goto_page message('paging_last'), filter, :page_id => max_pages %> + <%= link_to message('paging_last'), {:overwrite_params => {:page_id => max_pages}} -%> <% end %> <% end %> -- 2.39.5