diff options
author | David Gageot <david@gageot.net> | 2012-05-15 20:36:10 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-05-15 21:34:21 +0200 |
commit | 4d2eda6b07309dd871d1e2ad62e416b8d2240e18 (patch) | |
tree | c7b753e229e259afcf381d79c151e1b7004e9cab | |
parent | 19468c3b39f5b6cb8248920370775c354c0a49c6 (diff) | |
download | sonarqube-4d2eda6b07309dd871d1e2ad62e416b8d2240e18.tar.gz sonarqube-4d2eda6b07309dd871d1e2ad62e416b8d2240e18.zip |
Fix global dashboards
4 files changed, 35 insertions, 30 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/admin_dashboards_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/admin_dashboards_controller.rb index 06be304d77d..5f5abfd24b2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/admin_dashboards_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/admin_dashboards_controller.rb @@ -23,50 +23,56 @@ class AdminDashboardsController < ApplicationController verify :method => :post, :only => [:up, :down, :remove, :add, :delete], :redirect_to => {:action => :index} before_filter :admin_required - before_filter :load_default_dashboards def index - @default_dashboards=::Dashboard.find(:all, :conditions => {:shared => true}).sort { |a, b| a.name.downcase<=>b.name.downcase } - ids=@actives.map { |af| af.dashboard_id } - if !ids.nil? && !ids.empty? - @default_dashboards=@default_dashboards.reject! { |f| ids.include?(f.id) } - end + load_default_dashboards + ids=@actives.map { |a| a.dashboard_id } + @shared_dashboards=Dashboard.find(:all, :conditions => { :shared => true }).sort { |a, b| a.name.downcase<=>b.name.downcase } + @shared_dashboards.reject! { |s| ids.include?(s.id) } end def down position(+1) + + redirect_to :action => 'index' end def up position(-1) + + redirect_to :action => 'index' end def add - dashboard=::Dashboard.find(:first, :conditions => ['shared=? and id=?', true, params[:id].to_i()]) + load_default_dashboards + + dashboard=Dashboard.find(:first, :conditions => { :shared => true, :id => params[:id].to_i }) if dashboard - ActiveDashboard.create(:dashboard => dashboard, :user => nil, :order_index => (@actives.max_by(&:order_index).order_index+1)) + ActiveDashboard.create(:dashboard => dashboard, :user => nil, :order_index => @actives.max_by(&:order_index).order_index+1) flash[:notice]='Default dashboard added.' end + redirect_to :action => 'index' end - # Remove dashboard from defaults def remove + load_default_dashboards + if @actives.size<=1 flash[:error]='At least one dashboard must be defined as default.' else - active=@actives.to_a.find { |af| af.id==params[:id].to_i } + active=@actives.find { |af| af.id==params[:id].to_i } if active active.destroy flash[:notice]='Dashboard removed from default dashboards.' end end + redirect_to :action => 'index' end - # Completely delete dashboard def delete - dashboard=::Dashboard.find(params[:id]) + dashboard=Dashboard.find(params[:id]) bad_request('Bad dashboard') unless dashboard bad_request('This dashboard can not be deleted') unless dashboard.provided_programmatically? @@ -75,6 +81,7 @@ class AdminDashboardsController < ApplicationController else flash[:error]="Can't be deleted as long as it's used as default dashboard." end + redirect_to :action => 'index' end @@ -85,6 +92,8 @@ class AdminDashboardsController < ApplicationController end def position(offset) + load_default_dashboards + to_move = @actives.find { |a| a.id == params[:id].to_i} if to_move dashboards_same_type=@actives.select { |a| (a.global? == to_move.global?) }.sort_by(&:order_index) @@ -97,8 +106,6 @@ class AdminDashboardsController < ApplicationController a.save end end - - redirect_to :action => 'index' end end 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 88612ac5dc1..afe9b33a584 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 @@ -54,16 +54,14 @@ class DashboardsController < ApplicationController if active_dashboard flash[:error]=Api::Utils.message('dashboard.error_create_existing_name') redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource] + elsif @dashboard.save + add_default_dashboards_if_first_user_dashboard + last_active_dashboard=current_user.active_dashboards.max_by(&:order_index) + current_user.active_dashboards.create(:dashboard => @dashboard, :user_id => current_user.id, :order_index => (last_active_dashboard ? last_active_dashboard.order_index+1 : 1)) + redirect_to :controller => 'dashboard', :action => 'configure', :did => @dashboard.id, :id => (params[:resource] unless @dashboard.global) else - if @dashboard.save - add_default_dashboards_if_first_user_dashboard - last_active_dashboard=current_user.active_dashboards.max_by(&:order_index) - current_user.active_dashboards.create(:dashboard => @dashboard, :user_id => current_user.id, :order_index => (last_active_dashboard ? last_active_dashboard.order_index+1 : 1)) - redirect_to :controller => 'dashboard', :action => 'configure', :did => @dashboard.id, :id => (params[:resource] unless @dashboard.global) - else - flash[:error]=@dashboard.errors.full_messages.join('<br/>') - redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource] - end + flash[:error]=@dashboard.errors.full_messages.join('<br/>') + redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource] end end 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 9227ce61cf7..b902485966e 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, global=false) + def self.user_dashboards(user, global) result=nil if user && user.id - result=find(:all, :include => 'dashboard', :conditions => ['user_id=?', user.id], :order => 'order_index').select { |a| a.global? == global} + 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(global) + result=default_dashboards.select { |a| a.global? == global} end result end - def self.default_dashboards(global=false) - find(:all, :include => 'dashboard', :conditions => ['user_id IS NULL'], :order => 'order_index').select { |a| a.global? == global} + def self.default_dashboards() + find(:all, :include => 'dashboard', :conditions => {:user_id => nil}, :order => 'order_index') end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb index 469acd7b228..b140de47bc2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb @@ -25,12 +25,12 @@ </tr> </thead> <tbody> - <% if @default_dashboards.nil? || @default_dashboards.empty? %> + <% if @shared_dashboards.empty? %> <tr class="even"> <td colspan="4"><%= message('dashboard.no_dashboard') -%></td> </tr> <% else %> - <% @default_dashboards.each do |dashboard| %> + <% @shared_dashboards.each do |dashboard| %> <tr class="<%= cycle('even', 'odd') -%>"> <td> <div><%= h(dashboard.name(true)) -%></div> |