From 75027beeae4a95769fb068a1091329e77bda38ec Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Mon, 13 Jun 2011 23:09:05 +0200 Subject: [PATCH] SONAR-1902 After removing a column in a filter, the move left functions jumps two columns --- .../app/controllers/filters_controller.rb | 35 +++++++++---------- .../main/webapp/WEB-INF/app/models/filter.rb | 15 ++++++++ 2 files changed, 32 insertions(+), 18 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 0522b63a718..ee254338008 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 @@ -235,6 +235,7 @@ class FiltersController < ApplicationController unless editable_filter?(filter) return access_denied end + filter.clean_columns_order() # clean the columns which are badly ordered (see SONAR-1902) fields=params[:column].split(',') family=fields[0] @@ -254,15 +255,14 @@ class FiltersController < ApplicationController return access_denied end - column_index=-1 - filter.columns.each_index do |index| - column_index=index if filter.columns[index]==column - end - if column_index>0 - filter.columns[column_index-1].order_index=column_index - filter.columns[column_index-1].save - filter.columns[column_index].order_index=column_index-1 - filter.columns[column_index].save + filter.clean_columns_order() # clean the columns which are badly ordered (see SONAR-1902) + target_column=filter.column_by_id(params[:id].to_i) + if target_column.order_index>1 + target_column.order_index-=1 + target_column.save + old_left_col=filter.columns[target_column.order_index-1] + old_left_col.order_index+=1 + old_left_col.save end redirect_to :action => 'edit', :id => filter.id end @@ -275,15 +275,14 @@ class FiltersController < ApplicationController return access_denied end - column_index=-1 - filter.columns.each_index do |index| - column_index=index if filter.columns[index]==column - end - if column_index>=0 && column_index=1 && target_column.order_index 'edit', :id => filter.id end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb index 34c50e1034f..b1bf557b18d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb @@ -140,6 +140,21 @@ class Filter < ActiveRecord::Base def period? period_index && period_index>0 end + + def column_by_id(col_id) + columns.each do |col| + return col if col.id==col_id + end + return nil + end + + def clean_columns_order + columns.each_with_index do |col, index| + col.order_index=index+1 + col.save + end + reload + end protected -- 2.39.5