]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1643 follow shared dashboards
authorsimonbrandhof <simon.brandhof@gmail.com>
Thu, 28 Oct 2010 13:53:19 +0000 (13:53 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Thu, 28 Oct 2010 13:53:19 +0000 (13:53 +0000)
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb

index a2d7f67dcf01bf1d843319e5a794d7e04c527227..ae5ad686711e864eb5d035db7678bd3de285b0e8 100644 (file)
@@ -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
index a36f6aa1066a7b62e06d9888ecf8d4265db34ef6..bbcc70ee061ade30febc274d2ddda5534e27c292 100644 (file)
@@ -32,12 +32,8 @@ class Dashboard < ActiveRecord::Base
     read_attribute(:shared) || false\r
   end\r
 \r
-  def author\r
-    dashboard.user\r
-  end\r
-\r
-  def author_name\r
-    author ? author.name : nil\r
+  def user_name\r
+    user_id ? user.name : nil\r
   end\r
 \r
   def editable_by?(user)\r
index 913b361d6a2dbe8dea6edfd16fc54f1b92169187..aff8b9578a0e1d7554b37c538159780a39e38d1b 100644 (file)
@@ -4,7 +4,7 @@
     <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">