]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1902 After removing a column in a filter, the move left functions jumps two...
authorsimonbrandhof <simon.brandhof@gmail.com>
Mon, 13 Jun 2011 21:09:05 +0000 (23:09 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Mon, 13 Jun 2011 21:09:17 +0000 (23:09 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb

index 0522b63a71823c8b0b702d063972391bfaee945e..ee254338008da40f8ad6cacabee428b538ab657a 100644 (file)
@@ -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<filter.columns.size-1
-      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<filter.columns.size
+      target_column.order_index+=1
+      target_column.save
+      old_right_col=filter.columns[target_column.order_index-1]
+      old_right_col.order_index-=1
+      old_right_col.save
     end
     redirect_to :action => 'edit', :id => filter.id
   end
index 34c50e1034f081e2ce5a8e7f8cb62161ba97779c..b1bf557b18d0e9664591f48087785066ed27ab9e 100644 (file)
@@ -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