From d70b5b532fed1bffc6c8744e5b99ee5065c76679 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 14 May 2012 17:25:10 +0200 Subject: [PATCH] SONAR-3460 Improve dashboard migration We should create one dashboard per filter and one active dashboard per active filter. --- .../app/controllers/dashboard_controller.rb | 8 ++-- .../app/controllers/dashboards_controller.rb | 4 +- .../WEB-INF/app/models/active_dashboard.rb | 10 ++--- .../app/views/layouts/_layout.html.erb | 4 +- ...302_create_global_dashboards_for_filter.rb | 37 ++++++++++++++----- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb index 5cd31a3d311..e1e9fffd571 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb @@ -151,9 +151,9 @@ class DashboardController < ApplicationController elsif params[:name] @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['dashboards.name=? AND active_dashboards.user_id=?', params[:name], current_user.id]) elsif params[:id] - @active=ActiveDashboard.user_dashboards(current_user).find { |a| !a.global? } + @active=ActiveDashboard.user_dashboards(current_user, false).first else - @active=ActiveDashboard.user_dashboards(current_user).find { |a| a.global? } + @active=ActiveDashboard.user_dashboards(current_user, true).first end end @@ -164,9 +164,9 @@ class DashboardController < ApplicationController elsif params[:name] @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['dashboards.name=? AND active_dashboards.user_id IS NULL', params[:name]]) elsif params[:id] - @active=ActiveDashboard.user_dashboards(nil).find { |a| !a.global? } + @active=ActiveDashboard.user_dashboards(nil, false).first else - @active=ActiveDashboard.user_dashboards(nil).find { |a| a.global? } + @active=ActiveDashboard.user_dashboards(nil, true).first end end @dashboard=(@active ? @active.dashboard : nil) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb index 0cf468771ee..88612ac5dc1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb @@ -27,9 +27,7 @@ class DashboardsController < ApplicationController def index @global = !params[:resource] - @actives=ActiveDashboard.user_dashboards(current_user) - @actives.reject! { |a| a.global? != @global} - + @actives=ActiveDashboard.user_dashboards(current_user, @global) @shared_dashboards=Dashboard.find(:all, :conditions => ['(user_id<>? OR user_id IS NULL) AND shared=?', current_user.id, true], :order => 'name ASC') active_dashboard_ids=@actives.map(&:dashboard_id) @shared_dashboards.reject! { |d| active_dashboard_ids.include?(d.id) } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/active_dashboard.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/active_dashboard.rb index 6dd4a976e3d..9227ce61cf7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/active_dashboard.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/active_dashboard.rb @@ -51,18 +51,18 @@ class ActiveDashboard < ActiveRecord::Base user_id.nil? end - def self.user_dashboards(user) + def self.user_dashboards(user, global=false) result=nil if user && user.id - result=find(:all, :include => 'dashboard', :conditions => ['user_id=?', user.id], :order => 'order_index') + result=find(:all, :include => 'dashboard', :conditions => ['user_id=?', user.id], :order => 'order_index').select { |a| a.global? == global} end if result.nil? || result.empty? - result=default_dashboards + result=default_dashboards(global) end result end - def self.default_dashboards - find(:all, :include => 'dashboard', :conditions => ['user_id IS NULL'], :order => 'order_index') + def self.default_dashboards(global=false) + find(:all, :include => 'dashboard', :conditions => ['user_id IS NULL'], :order => 'order_index').select { |a| a.global? == global} end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index b9da26594a3..3039a5a1570 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -35,7 +35,7 @@