From: David Gageot Date: Wed, 23 May 2012 06:19:43 +0000 (+0200) Subject: Fix Pagination and sorting in filter widget X-Git-Tag: 3.1~108 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a0e00c5f0a63b81226c2b04271df07fdeff6a5f7;p=sonarqube.git Fix Pagination and sorting in filter widget --- 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 f06a27a086e..95fadc7bf4a 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) + before_filter :login_required, :except => %w(index treemap list) def manage if is_admin? @@ -36,6 +36,14 @@ 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=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 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 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 679e9c5c9fe..e40ef84b61c 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,5 +1,8 @@ <% filter=@filter_context.filter %> -
+<% @edit_mode=edit_mode %> +<% @widget=widget if widget %> + +
@@ -49,15 +52,31 @@ %> | <% if max_pages > 20 && start_page > 1 %> - <%= link_to message('paging_first'), {:overwrite_params => {:page_id => 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') -%> <% 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 %> - <%= link_to_unless index==current_page, index.to_s, {:overwrite_params => {:page_id => index}} %> + <% unless index==current_page %> + <%= goto_page index.to_s, filter, :page_id => index %> + <% else %> + <%= index.to_s -%> + <% end %> <% end %> - <%= link_to_if current_page {:page_id => 1+current_page}} %> + + <% if current_page + <%= goto_page message('paging_next'), filter, :page_id => current_page+1 %> + <% else %> + <%= message('paging_next') -%> + <% end %> + <% if max_pages > 20 && end_page < max_pages %> - <%= link_to message('paging_last'), {:overwrite_params => {:page_id => max_pages}} -%> + <%= goto_page message('paging_last'), filter, :page_id => max_pages %> <% end %> <% end %>