1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#
# Sonar, entreprise quality control tool.
# Copyright (C) 2008-2011 SonarSource
# mailto:contact AT sonarsource DOT com
#
# Sonar is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# Sonar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with Sonar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
class AdminDashboardsController < ApplicationController
SECTION=Navigation::SECTION_CONFIGURATION
verify :method => :post, :only => [:up, :down, :remove, :add], :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
end
def up
dashboard_index=-1
dashboard=nil
@actives.each_index do |index|
if @actives[index].id==params[:id].to_i
dashboard_index=index
dashboard=@actives[index]
end
end
if dashboard && dashboard_index>0
@actives[dashboard_index]=@actives[dashboard_index-1]
@actives[dashboard_index-1]=dashboard
@actives.each_index do |index|
@actives[index].order_index=index+1
@actives[index].save
end
end
redirect_to :action => 'index'
end
def down
dashboard_index=-1
dashboard=nil
@actives.each_index do |index|
if @actives[index].id==params[:id].to_i
dashboard_index=index
dashboard=@actives[index]
end
end
if dashboard && dashboard_index<@actives.size-1
@actives[dashboard_index]=@actives[dashboard_index+1]
@actives[dashboard_index+1]=dashboard
@actives.each_index do |index|
@actives[index].order_index=index+1
@actives[index].save
end
end
redirect_to :action => 'index'
end
def add
dashboard=::Dashboard.find(:first, :conditions => ['shared=? and id=?', true, params[:id].to_i()])
if dashboard
ActiveDashboard.create(:dashboard => dashboard, :user => nil, :order_index => @actives.size+1)
flash[:notice]='Default dashboard added.'
end
redirect_to :action => 'index'
end
def remove
if @actives.size<=1
flash[:error]='At least one dashboard must be defined.'
else
active=@actives.to_a.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
private
def load_default_dashboards
@actives=ActiveDashboard.default_dashboards
end
end
|