]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3512 Make it possible to share a dashboard without following it
authorDavid Gageot <david@gageot.net>
Tue, 19 Jun 2012 12:46:02 +0000 (14:46 +0200)
committerDavid Gageot <david@gageot.net>
Tue, 19 Jun 2012 13:14:47 +0000 (15:14 +0200)
Any dashboard can be edited or configured

sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb

index 5729a5283ee33d714f7db55630ea8329c2e8ebce..eedcb926c5d522e3b09bd94ea6b56fe30c9fc973 100644 (file)
@@ -143,33 +143,38 @@ class DashboardController < ApplicationController
   private
 
   def load_dashboard
-    @active=nil
+    active=nil
+    @dashboard=nil
 
     if logged_in?
       if params[:did]
-        @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['active_dashboards.dashboard_id=? AND active_dashboards.user_id=?', params[:did].to_i, current_user.id])
+        @dashboard=Dashboard.find(:first, :conditions => ['id=? AND user_id=?', params[:did].to_i, current_user.id])
       elsif params[:name]
-        @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['dashboards.name=? AND active_dashboards.user_id=?', params[:name], current_user.id])
+        @dashboard=Dashboard.find(:first, :conditions => ['name=? AND user_id=?', params[:name], current_user.id])
       elsif params[:id]
-        @active=ActiveDashboard.user_dashboards(current_user, false).first
+        active=ActiveDashboard.user_dashboards(current_user, false).first
       else
-        @active=ActiveDashboard.user_dashboards(current_user, true).first
+        active=ActiveDashboard.user_dashboards(current_user, true).first
       end
     end
 
-    if @active.nil?
+    unless active or @dashboard
       # anonymous or not found in user dashboards
       if params[:did]
-        @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['active_dashboards.dashboard_id=? AND active_dashboards.user_id IS NULL', params[:did].to_i])
+        @dashboard=Dashboard.find(:first, :conditions => ['id=? AND shared=?', params[:did].to_i, true])
       elsif params[:name]
-        @active=ActiveDashboard.find(:first, :include => 'dashboard', :conditions => ['dashboards.name=? AND active_dashboards.user_id IS NULL', params[:name]])
+        @dashboard=Dashboard.find(:first, :conditions => ['name=? AND shared=?', params[:name], true])
       elsif params[:id]
-        @active=ActiveDashboard.user_dashboards(nil, false).first
+        active=ActiveDashboard.user_dashboards(nil, false).first
       else
-        @active=ActiveDashboard.user_dashboards(nil, true).first
+        active=ActiveDashboard.user_dashboards(nil, true).first
       end
     end
-    @dashboard=(@active ? @active.dashboard : nil)
+
+    unless @dashboard
+      @dashboard=(active ? active.dashboard : nil)
+    end
+
     @dashboard_configuration=Api::DashboardConfiguration.new(@dashboard, :period_index => params[:period], :snapshot => @snapshot) if @dashboard && @snapshot
   end
 
index 786ca5a2a732bfa0f2e1adf32a18d739a5cae86b..2a6c7dabc7800ec501f5bf18b26e8b682d690948 100644 (file)
@@ -1,18 +1,15 @@
 <div class="admin_page">
   <h1><%= message('dashboard.global_dashboards') -%></h1>
-
   <p><%= message('dashboard.global_dashboards.description') -%></p>
 
   <%= render :partial => 'list', :locals => {:active_dashboards => @actives.select(&:global?), :group => 'activeGlobal'} %>
 
   <h1><%= message('dashboard.project_dashboards') -%></h1>
-
   <p><%= message('dashboard.project_dashboards.description') -%></p>
 
   <%= render :partial => 'list', :locals => {:active_dashboards => @actives.reject(&:global?), :group => 'activeProject'} %>
 
   <h1><%= message('dashboard.shared_dashboards') -%></h1>
-
   <p><%= message('dashboard.shared_dashboards.description') -%></p>
 
   <table class="data" id="shared">
index 2bce07ee61c6fb725923f78753e52221f1972ce2..4293e203b7ccb75b7071d59276b56ae3e8374140 100644 (file)
@@ -2,13 +2,13 @@
   <% if logged_in? %>
     <ul class="operations">
       <% if back %>
-        <li class="last"><%= link_to message('dashboard.back_to_dashboard'), dashboard_action(:index) -%></li>
+        <li><%= link_to message('dashboard.back_to_dashboard'), dashboard_action(:index) -%></li>
       <% else %>
         <% if @dashboard.editable_by?(current_user) %>
           <li><%= link_to message('dashboard.configure_widgets'), dashboard_action(:configure) -%></li>
         <% end %>
-        <li class="last"><%= link_to message('dashboard.manage_dashboards'), {:controller => :dashboards, :action => :index, :resource => (@resource.id if @resource) } -%></li>
       <% end %>
+      <li class="last"><%= link_to message('dashboard.manage_dashboards'), {:controller => :dashboards, :action => :index, :resource => (@resource.id if @resource) } -%></li>
     </ul>
   <% end %>
 
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb
new file mode 100644 (file)
index 0000000..ca88843
--- /dev/null
@@ -0,0 +1,51 @@
+<table class="data" id="shared-dashboards">
+  <thead>
+  <tr>
+    <th class="name"><%= message('name') -%></th>
+    <th class="shared"><%= message('shared') -%></th>
+    <th class="owner"><%= message('owner') -%></th>
+    <th class="order">&nbsp;</th>
+    <th class="operations"><%= message('operations') -%></th>
+  </tr>
+  </thead>
+  <tbody>
+  <% if @shared_dashboards.nil? || @shared_dashboards.empty? %>
+    <tr class="even">
+      <td colspan="5" class="empty"><%= message('dashboard.no_dashboard') -%></td>
+    </tr>
+  <%
+     else
+       @shared_dashboards.each do |dashboard| %>
+      <tr id="dashboard-<%= dashboard.id -%>" class="<%= cycle('even', 'odd', :name => 'shared') -%>">
+        <td>
+          <%= link_to h(dashboard.name(true)), {:controller => :dashboard, :action => :index, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)},
+                      :id => "view-#{u dashboard.name}", :class => 'link-action' %>
+          <div class="description"><%= h dashboard.description -%></div>
+        </td>
+        <td class="shared">
+          <%= boolean_icon(dashboard.shared) -%>
+        </td>
+        <td class="owner">
+          <%= h(dashboard.user_name || message('dashboard.username.default')) -%>
+        </td>
+        <td class="order">&nbsp;</td>
+        <td class="thin nowrap operations">
+          <% if dashboard.editable_by?(current_user) %>
+            <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)},
+                        :id => "configure-#{u dashboard.name}", :class => 'link-action' %>
+            |
+            <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => dashboard.id, :resource => params[:resource]}},
+                               {:id => "edit-#{u dashboard.name}", :method => :get, :class => 'link-action'} %>
+            |
+            <%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post,
+                        :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u dashboard.name}", :class => 'link-action' %>
+            |
+          <% end %>
+          <%= link_to message('follow'), {:action => :follow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %>
+        </td>
+      </tr>
+    <% end
+       end
+    %>
+  </tbody>
+</table>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb
new file mode 100644 (file)
index 0000000..f6cd8d7
--- /dev/null
@@ -0,0 +1,66 @@
+<table class="data" id="dashboards">
+  <thead>
+  <tr>
+    <th class="name"><%= message('name') -%></th>
+    <th class="shared"><%= message('shared') -%></th>
+    <th class="owner"><%= message('owner') -%></th>
+    <th class="order"><%= message('order') -%></th>
+    <th class="operations"><%= message('operations') -%></th>
+  </tr>
+  </thead>
+  <tbody>
+  <% if @actives.nil? || @actives.empty? %>
+    <tr class="even">
+      <td colspan="5" class="empty"><%= message('dashboard.no_dashboard') -%></td>
+    </tr>
+  <% else %>
+    <% @actives.map(&:dashboard).each_with_index do |dashboard, index| %>
+      <tr id="dashboard-<%= dashboard.id -%>" class="<%= cycle('even', 'odd', :name => 'dashboard') -%>">
+        <td>
+          <%= link_to h(dashboard.name(true)), {:controller => :dashboard, :action => :index, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)},
+                      :id => "view-#{u dashboard.name}", :class => 'link-action' %>
+          <div class="description"><%= h dashboard.description -%></div>
+        </td>
+        <td class="shared">
+          <%= boolean_icon(dashboard.shared) -%>
+        </td>
+        <td class="owner">
+          <%= h(dashboard.user_name || message('dashboard.username.default')) -%>
+        </td>
+        <td class="order">
+          <% if index > 0 %>
+            <%= link_to image_tag('blue-up.png'), {:action => :up, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "up-#{u dashboard.name}" %>
+          <% else %>
+            <%= image_tag('transparent_16.gif') %>
+          <% end %>
+          <% if index < @actives.size-1 %>
+            <%= link_to image_tag('blue-down.png'), {:action => :down, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "down-#{u dashboard.name}" %>
+          <% else %>
+            <%= image_tag('transparent_16.gif') %>
+        <% end %>
+        </td>
+        <td class="thin nowrap operations">
+          <% if dashboard.editable_by?(current_user) %>
+            <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)},
+                        :id => "configure-#{u dashboard.name}", :class => 'link-action' %>
+            |
+            <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => dashboard.id, :resource => params[:resource]}},
+                               {:id => "edit-#{u dashboard.name}", :method => :get, :class => 'link-action'} %>
+            <% if @actives.size() > 1 %>
+              |
+              <%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post,
+                          :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u dashboard.name}", :class => 'link-action' %>
+              |
+            <% end %>
+          <% end %>
+          <% if @actives.size() > 1 %>
+            <%= link_to message('unfollow'), {:action => :unfollow, :id => dashboard.id, :resource => params[:resource]}, :method => :post,
+                        :id => "unfollow-#{u dashboard.name}", :class => 'link-action' %>
+          <% end %>
+        </td>
+      </tr>
+    <% end
+       end
+    %>
+  </tbody>
+</table>
index 8a34a2cab7240440351bc7ad99e2fde882e358df..2fda8e73f69b868f4bf277cc943bf9bd4162adee 100644 (file)
-<% is_admin=is_admin? %>
-
 <div class="admin_page">
   <div id="my_dasboards">
     <h1><%= message(@global ? 'dashboard.my_global_dashboards' : 'dashboard.my_project_dashboards') -%></h1>
-
-    <table class="data" id="dashboards">
-      <thead>
-      <tr>
-        <th class="name"><%= message('name') -%></th>
-        <th class="shared"><%= message('shared') -%></th>
-        <th class="owner"><%= message('owner') -%></th>
-        <th class="order"><%= message('order') -%></th>
-        <th class="operations"><%= message('operations') -%></th>
-      </tr>
-      </thead>
-      <tbody>
-      <% if @actives.nil? || @actives.empty? %>
-        <tr class="even">
-          <td colspan="4"><%= message('dashboard.no_dashboard') -%></td>
-        </tr>
-      <% else %>
-        <% @actives.each_with_index do |active, index| %>
-          <tr id="dashboard-<%= active.id -%>" class="<%= cycle('even', 'odd', :name => 'dashboard') -%>">
-            <td>
-              <%= active.name(true) -%>
-              <div class="description"><%= h active.dashboard.description -%></div>
-            </td>
-            <td class="shared">
-              <%= boolean_icon(active.dashboard.shared) -%>
-            </td>
-            <td class="owner">
-              <%= h(active.dashboard.user_name || message('dashboard.username.default')) -%>
-            </td>
-            <td class="order">
-              <% if index > 0 %>
-                <%= link_to image_tag('blue-up.png'), {:action => :up, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, :id => "up-#{u active.name}" %>
-              <% else %>
-                <%= image_tag('transparent_16.gif') %>
-              <% end %>
-              <% if index < @actives.size-1 %>
-                <%= link_to image_tag('blue-down.png'), {:action => :down, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, :id => "down-#{u active.name}" %>
-              <% else %>
-                <%= image_tag('transparent_16.gif') %>
-            <% end %>
-            </td>
-            <td class="thin nowrap operations">
-              <% if active.editable_by?(current_user) %>
-                <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => active.dashboard_id, :id => (params[:resource] unless active.global?)},
-                            :id => "configure-#{u active.name}", :class => 'link-action' %>
-                |
-                <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => active.dashboard_id, :resource => params[:resource]}},
-                                   {:id => "edit-#{u active.name}", :method => :get, :class => 'link-action'} %>
-                <% if @actives.size() > 1 %>
-                  |
-                  <%= link_to message('delete'), {:action => :delete, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post,
-                              :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u active.name}", :class => 'link-action' %>
-                  |
-                <% end %>
-              <% end %>
-              <% if @actives.size() > 1 %>
-                <%= link_to message('unfollow'), {:action => :unfollow, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post,
-                            :id => "unfollow-#{u active.name}", :class => 'link-action' %>
-              <% end %>
-            </td>
-          </tr>
-        <% end
-           end
-        %>
-      </tbody>
-    </table>
+    <%= render_partial :partial => 'my_dashboards', :locals => { :is_admin => is_admin? } %>
 
     <h1><%= message('dashboard.available_dashboards') -%></h1>
-
-    <table class="data" id="shared-dashboards">
-      <thead>
-      <tr>
-        <th class="name"><%= message('name') -%></th>
-        <th class="shared"><%= message('shared') -%></th>
-        <th class="owner"><%= message('owner') -%></th>
-        <th class="order">&nbsp;</th>
-        <th class="operations"><%= message('operations') -%></th>
-      </tr>
-      </thead>
-      <tbody>
-      <% if @shared_dashboards.nil? || @shared_dashboards.empty? %>
-        <tr class="even">
-          <td colspan="5" class="empty"><%= message('dashboard.no_dashboard') -%></td>
-        </tr>
-      <%
-         else
-           @shared_dashboards.each do |dashboard| %>
-          <tr id="dashboard-<%= dashboard.id -%>" class="<%= cycle('even', 'odd', :name => 'shared') -%>">
-            <td>
-              <%= dashboard.name(true) -%>
-              <div class="description"><%= h dashboard.description -%></div>
-            </td>
-            <td class="shared">
-              <%= boolean_icon(dashboard.shared) -%>
-            </td>
-            <td class="owner">
-              <%= h(dashboard.user_name || message('dashboard.username.default')) -%>
-            </td>
-            <td class="order">&nbsp;</td>
-            <td class="thin nowrap operations">
-              <% if dashboard.editable_by?(current_user) %>
-                <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => dashboard.id, :resource => params[:resource]}},
-                                   {:id => "edit-#{u dashboard.name}", :method => :get, :class => 'link-action'} %>
-                |
-                <%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post,
-                            :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u dashboard.name}", :class => 'link-action' %>
-                |
-              <% end %>
-              <%= link_to message('follow'), {:action => :follow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %>
-            </td>
-          </tr>
-        <% end
-           end
-        %>
-      </tbody>
-    </table>
+    <%= render_partial :partial => 'available_dashboards', :locals => { :is_admin => is_admin? } %>
   </div>
 
   <div id="create_dashboard">