SECTION=Navigation::SECTION_RESOURCE
- verify :method => :post, :only => [:create, :update, :delete, :up, :down, :unfollow], :redirect_to => {:action => :index}
+ verify :method => :post, :only => [:create, :update, :delete, :up, :down, :follow, :unfollow], :redirect_to => {:action => :index}
before_filter :login_required
def index
@actives=ActiveDashboard.user_dashboards(current_user)
+ @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{|a| a.dashboard_id}
+ @shared_dashboards.reject!{|d| active_dashboard_ids.include?(d.id)}
@resource=Project.by_key(params[:resource])
if @resource.nil?
redirect_to :action => 'index', :resource => params[:resource]
end
+ def follow
+ add_default_dashboards_if_first_user_dashboard()
+ 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
+ active=current_user.active_dashboards.to_a.find{|a| a.dashboard_id==params[:id].to_i}
+ if active.nil?
+ current_user.active_dashboards.create(:dashboard => dashboard, :user => current_user, :order_index => current_user.active_dashboards.size+1)
+ end
+ end
+ redirect_to :action => :index, :resource => params[:resource]
+ end
+
def unfollow
active_dashboard=ActiveDashboard.find(:first, :conditions => ['user_id=? AND dashboard_id=?', current_user.id, params[:id].to_i])
if active_dashboard
<td valign="top">
<h1 class="marginbottom10">My dashboards</h1>
- <table class="data" id="dashboards">
+ <table class="data marginbottom10" id="dashboards">
<thead>
<tr>
<th>Name</th>
%>
</tbody>
</table>
-
+ <br/><br/>
+ <h1 class="marginbottom10">Shared dashboards</h1>
+ <table class="data" id="shared-dashboards">
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Shared by</th>
+ <th>Operations</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% if @shared_dashboards.nil? || @shared_dashboards.empty? %>
+ <tr class="even"><td colspan="5">No dashboards</td></tr>
+ <%
+ else
+ @shared_dashboards.each do |dashboard| %>
+ <tr id="shared-dashboard-<%= u dashboard.name -%>" class="<%= cycle('even','odd', :name => 'shared') -%>">
+ <td>
+ <%= link_to dashboard.name, {:controller => :dashboard, :action => :index, :id => dashboard.id, :resource => params[:resource]} -%>
+ <% if dashboard.description.present? %>
+ <p class="small"><%= h dashboard.description -%></p>
+ <% end %>
+ </td>
+ <td>
+ <%= dashboard.user_name -%>
+ </td>
+ <td>
+ <%= link_to 'Follow', {:action => 'follow', :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}" %>
+ </td>
+ </tr>
+ <% end
+ end
+ %>
+ </tbody>
+ </table>
</td>
<td class="sep"> </td>
<td width="210" valign="top" align="right">