From: simonbrandhof Date: Thu, 28 Oct 2010 13:53:19 +0000 (+0000) Subject: SONAR-1643 follow shared dashboards X-Git-Tag: 2.6~735 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8793034838a4c4e54652b5a48466212c02f016d4;p=sonarqube.git SONAR-1643 follow shared dashboards --- 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 a2d7f67dcf0..ae5ad686711 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 @@ -21,11 +21,14 @@ class DashboardsController < ApplicationController 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? @@ -126,6 +129,18 @@ class DashboardsController < ApplicationController 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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb index a36f6aa1066..bbcc70ee061 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb @@ -32,12 +32,8 @@ class Dashboard < ActiveRecord::Base read_attribute(:shared) || false end - def author - dashboard.user - end - - def author_name - author ? author.name : nil + def user_name + user_id ? user.name : nil end def editable_by?(user) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb index 913b361d6a2..aff8b9578a0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb @@ -4,7 +4,7 @@

My dashboards

- +
@@ -58,7 +58,41 @@ %>
Name
- +

+

Shared dashboards

+ + + + + + + + + + <% if @shared_dashboards.nil? || @shared_dashboards.empty? %> + + <% + else + @shared_dashboards.each do |dashboard| %> + + + + + + <% end + end + %> + +
NameShared byOperations
No dashboards
+ <%= link_to dashboard.name, {:controller => :dashboard, :action => :index, :id => dashboard.id, :resource => params[:resource]} -%> + <% if dashboard.description.present? %> +

<%= h dashboard.description -%>

+ <% end %> +
+ <%= dashboard.user_name -%> + + <%= link_to 'Follow', {:action => 'follow', :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}" %> +