]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3460 Fix dashboard ordering when the user is using the default dashboards
authorDavid Gageot <david@gageot.net>
Thu, 24 May 2012 12:28:49 +0000 (14:28 +0200)
committerDavid Gageot <david@gageot.net>
Thu, 24 May 2012 12:28:49 +0000 (14:28 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb

index 2706f3125fcb4c82a3445defc66164ca0c7b2a12..66c8ba7a15b1f92b17f07b09d47769e0b2e98599 100644 (file)
@@ -121,6 +121,7 @@ class DashboardsController < ApplicationController
     dashboard=Dashboard.find(:first, :conditions => ['shared=? and id=? and (user_id is null or user_id<>?)', true, params[:id].to_i, current_user.id])
     if dashboard
       add_default_dashboards_if_first_user_dashboard(dashboard.global?)
+
       active_dashboard = current_user.active_dashboards.to_a.find { |ad| ad.name==dashboard.name }
       if active_dashboard
         flash[:error]=Api::Utils.message('dashboard.error_follow_existing_name')
@@ -138,6 +139,7 @@ class DashboardsController < ApplicationController
     dashboard=Dashboard.find(:first, :conditions => ['shared=? and id=? and (user_id is null or user_id<>?)', true, params[:id].to_i, current_user.id])
     if dashboard
       add_default_dashboards_if_first_user_dashboard(dashboard.global?)
+
       ActiveDashboard.destroy_all(['user_id=? AND dashboard_id=?', current_user.id, params[:id].to_i])
 
       if ActiveDashboard.count(:conditions => ['user_id=?', current_user.id])==0
@@ -150,22 +152,24 @@ class DashboardsController < ApplicationController
   private
 
   def position(offset)
-    dashboards=current_user.active_dashboards.to_a
+    dashboard=Dashboard.find(:first, :conditions => ['shared=? and id=? and (user_id is null or user_id<>?)', true, params[:id].to_i, current_user.id])
+    if dashboard
+      add_default_dashboards_if_first_user_dashboard(dashboard.global?)
 
-    to_move = dashboards.find { |a| a.id == params[:id].to_i }
-    if to_move
-      add_default_dashboards_if_first_user_dashboard(to_move.global?)
-      dashboards_same_type=dashboards.select { |a| (a.global? == to_move.global?) }.sort_by(&:order_index)
+      actives=current_user.active_dashboards.select { |a| a.global? == dashboard.global? }.sort_by(&:order_index)
 
-      index = dashboards_same_type.index(to_move)
-      dashboards_same_type[index], dashboards_same_type[index + offset] = dashboards_same_type[index + offset], dashboards_same_type[index]
+      index = actives.index { |a| a.dashboard_id == dashboard.id }
+      if index
+        actives[index], actives[index + offset] = actives[index + offset], actives[index]
 
-      dashboards_same_type.each_with_index do |a, i|
-        a.order_index=i+1
-        a.save
+        actives.each_with_index do |a, i|
+          a.order_index=i+1
+          a.save
+        end
       end
     end
 
+
     redirect_to :action => 'index', :resource => params[:resource]
   end
 
index 91353957c0ba1d9e5f42130c53317c9e594908b5..c840892f3461b240278eccb4666b080482ca0ef9 100644 (file)
             <% end %>
             <td>
               <% if index > 0 %>
-                <%= link_to image_tag('blue-up.png'), {:action => :up, :id => active.id, :resource => params[:resource]}, :method => :post, :id => "up-#{u active.name}" %>
+                <%= link_to image_tag('blue-up.png'), {:action => :up, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, :id => "up-#{u active.name}" %>
               <% else %>
                 <%= image_tag('transparent_16.gif') %>
               <% end %>
               <% if index < @actives.size-1 %>
-                <%= link_to image_tag('blue-down.png'), {:action => :down, :id => active.id, :resource => params[:resource]}, :method => :post, :id => "down-#{u active.name}" %>
+                <%= link_to image_tag('blue-down.png'), {:action => :down, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, :id => "down-#{u active.name}" %>
               <% end %>
             </td>
             <td class="thin nowrap right">