We should create one dashboard per filter and one active dashboard per active filter.
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
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)
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) }
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
<div id="sidebar">
<ul>
<% if selected_section==Navigation::SECTION_HOME %>
- <% ActiveDashboard.user_dashboards(current_user).select(&:global?).each do |active_dashboard| %>
+ <% ActiveDashboard.user_dashboards(current_user, true).each do |active_dashboard| %>
<li class="<%= 'selected' if @dashboard && controller.controller_path=='dashboard' && active_dashboard.dashboard_id==@dashboard.id -%>">
<a href="<%= ApplicationController.root_context -%>/dashboard/?did=<%= active_dashboard.dashboard_id -%>"><%= active_dashboard.dashboard.name(true) -%></a>
</li>
<% end %>
<% elsif selected_section==Navigation::SECTION_RESOURCE %>
- <% ActiveDashboard.user_dashboards(current_user).reject(&:global?).each do |active_dashboard| %>
+ <% ActiveDashboard.user_dashboards(current_user, false).each do |active_dashboard| %>
<li class="<%= 'selected' if @dashboard && controller.controller_path=='dashboard' && active_dashboard.dashboard_id==@dashboard.id -%>">
<a href="<%= ApplicationController.root_context -%>/dashboard/index/<%= @project.id -%>?did=<%= active_dashboard.dashboard_id -%><%= "&"+period_param if period_param -%>"><%= active_dashboard.dashboard.name(true) -%></a>
</li>
end
def self.up
- ActiveFilter.find(:all).each do |activeFilter|
- filter = ::Filter.find(activeFilter.filter_id)
+ dashboard_per_filter = create_global_dahboards()
+ activate_dashboards(dashboard_per_filter)
+ drop_table('active_filters')
+ end
- dashboard = Dashboard.create(:user_id => activeFilter.user_id,
+ def self.create_global_dahboards
+ dashboards = {}
+
+ ::Filter.find(:all).each do |filter|
+ dashboard = Dashboard.create(:user_id => filter.user_id,
:name => filter.name,
:description => '',
:column_layout => '100%',
:shared => filter.shared,
:is_global => true)
- if !filter.favourites || activeFilter.user_id
- ActiveDashboard.create(:dashboard_id => dashboard.id,
- :user_id => activeFilter.user_id,
- :order_index => activeFilter.order_index)
- end
-
widget = Widget.create(:dashboard_id => dashboard.id,
:widget_key => 'filter',
:name => 'Filter',
WidgetProperty.create(:widget_id => widget.id,
:kee => 'filter',
:text_value => filter.id)
+
+ dashboards[filter.id] = dashboard
end
- drop_table('active_filters')
+ dashboards
end
+
+ def self.activate_dashboards(dashboard_per_filter)
+ ActiveFilter.find(:all).each do |activeFilter|
+ filter = ::Filter.find(activeFilter.filter_id)
+
+ dashboard = dashboard_per_filter[filter.id]
+
+ if !filter.favourites || activeFilter.user_id
+ ActiveDashboard.create(:dashboard_id => dashboard.id,
+ :user_id => activeFilter.user_id,
+ :order_index => activeFilter.order_index)
+ end
+ end
+ end
+
end