]> source.dussan.org Git - sonarqube.git/commitdiff
FIX A newly followed dashboard should always come last in the list
authorDavid Gageot <david@gageot.net>
Tue, 22 May 2012 17:10:34 +0000 (19:10 +0200)
committerDavid Gageot <david@gageot.net>
Tue, 22 May 2012 17:15:17 +0000 (19:15 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb

index b2ee37ba280accada9963739de2750c58baf4c74..587c81fc80f5c427193451be8367daa2235b6b84 100644 (file)
@@ -123,7 +123,8 @@ class DashboardsController < ApplicationController
       if active_dashboard
         flash[:error]=Api::Utils.message('dashboard.error_follow_existing_name')
       else
-        current_user.active_dashboards.create(:dashboard => dashboard, :user => current_user, :order_index => current_user.active_dashboards.size+1)
+        last_active_dashboard=current_user.active_dashboards.max_by(&:order_index)
+        current_user.active_dashboards.create(:dashboard => dashboard, :user => current_user, :order_index => (last_active_dashboard ? last_active_dashboard.order_index+1 : 1))
       end
     else
       bad_request('Unknown dashboard')