]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1927 GUI to manage global dashboards
authorDavid Gageot <david@gageot.net>
Fri, 4 May 2012 15:28:18 +0000 (17:28 +0200)
committerDavid Gageot <david@gageot.net>
Fri, 4 May 2012 16:14:28 +0000 (18:14 +0200)
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/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/_create.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_edit.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb

index ca2d9141c9b8fee3ee39767b3bd82fa43fae656c..6df53e1107f647aa522884f281372f320d9f172e 100644 (file)
@@ -30,15 +30,17 @@ class DashboardsController < ApplicationController
     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?
+    if params[:resource]
+      @resource=Project.by_key(params[:resource])
+      if @resource.nil?
       # TODO display error page
-      redirect_to home_path
-      return false
+        redirect_to home_path
+        return false
+      end
+      access_denied unless has_role?(:user, @resource)
+      @snapshot = @resource.last_snapshot
+      @project=@resource # variable name used in old widgets
     end
-    access_denied unless has_role?(:user, @resource)
-    @snapshot = @resource.last_snapshot
-    @project=@resource # variable name used in old widgets
   end
 
   def create
@@ -54,7 +56,7 @@ class DashboardsController < ApplicationController
         add_default_dashboards_if_first_user_dashboard
         last_active_dashboard=current_user.active_dashboards.max { |x, y| x.order_index<=>y.order_index }
         current_user.active_dashboards.create(:dashboard => @dashboard, :user_id => current_user.id, :order_index => (last_active_dashboard ? last_active_dashboard.order_index+1 : 1))
-        redirect_to :controller => 'dashboard', :action => 'configure', :did => @dashboard.id, :id => params[:resource]
+        redirect_to :controller => 'dashboard', :action => 'configure', :did => @dashboard.id, :id => (params[:resource] unless @dashboard.global)
       else
         flash[:error]=@dashboard.errors.full_messages.join('<br/>')
         redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource]
@@ -171,7 +173,7 @@ class DashboardsController < ApplicationController
   def load_dashboard_from_params(dashboard)
     dashboard.name=params[:name]
     dashboard.description=params[:description]
-    dashboard.global=(params[:global].present?)
+    dashboard.is_global=(params[:global].present?)
     dashboard.shared=(params[:shared].present? && is_admin?)
     dashboard.user_id=current_user.id
     dashboard.column_layout=Dashboard::DEFAULT_LAYOUT if !dashboard.column_layout
index 2fde1aa85440e698f7db6382e045495c710ca381..1dfdc522b579eea5df6bf998a79bbcd5d952f997 100644 (file)
@@ -46,8 +46,12 @@ class Dashboard < ActiveRecord::Base
        read_attribute(:shared) || false
   end
 
-  def global?
-    read_attribute(:is_global) || false
+  def global=(global)
+    write_attribute(:is_global, global)
+  end
+
+  def global
+    read_attribute(:is_global)
   end
 
   def layout
index 9590cd4ef353b01a7fef51c2941ec292da05e329..ef900b49c1e95520a20d3a7c9005e89819bdcfbd 100644 (file)
@@ -3,12 +3,12 @@
 
 <table class="data" id="admin_console">
   <thead>
-  <tr>
-    <th>Name</th>
-    <th>Shared by</th>
-    <th>Order</th>
-    <th class="right">Operations</th>
-  </tr>
+    <tr>
+      <th><%= message('name') -%></th>
+      <th><%= message('global') -%></th>
+      <th><%= message('shared_by') -%></th>
+      <th colspan="2" class="right"><%= message('operations') -%></th>
+    </tr>
   </thead>
   <tbody>
   <% if @actives.empty? %>
@@ -23,6 +23,9 @@
           <br>
           <span style="font-size: 85%;font-weight: normal;"><%= active.dashboard.description %></span>
         </td>
+        <td>
+          <%= boolean_icon(active.dashboard.global) -%>
+        </td>
         <td><%= h(active.dashboard.user.name) if active.dashboard.user %></td>
         <td>
           <% if index>0 %>
 <table class="data" id="shared">
   <thead>
   <tr>
-    <th>Name</th>
-    <th>Shared by</th>
-    <th colspan="2" class="right">Operations</th>
+    <th><%= message('name') -%></th>
+    <th><%= message('global') -%></th>
+    <th><%= message('shared_by') -%></th>
+    <th colspan="2" class="right"><%= message('operations') -%></th>
   </tr>
   </thead>
   <tbody>
@@ -68,6 +72,9 @@
           <br>
           <span class="small"><%= dashboard.description %></span>
         </td>
+        <td>
+          <%= boolean_icon(dashboard.global) -%>
+        </td>
         <td><%= h(dashboard.user.name) if dashboard.user %></td>
         <td class="thin nowrap right">
           <%= link_to 'Add to defaults', {:action => 'add', :id => dashboard.id}, {:method => :post, :id => "add-#{u dashboard.name}", :class => 'link-action'} %>
index 20963d490eb4a8c65168364c394956d220962d8f..88350d6c99cea3c6c3087d9543e0eb6a79317643 100644 (file)
@@ -8,9 +8,7 @@
           <li><%= link_to message('dashboard.configure_widgets'), dashboard_action(:configure) -%></li>
           <li><%= link_to message('dashboard.edit_layout'), dashboard_action(:edit_layout) -%></li>
         <% end %>
-        <% if @resource %>
-          <li class="last"><%= link_to message('dashboard.manage_dashboards'), {:controller => :dashboards, :action => :index, :resource => @resource.id} -%></li>
-        <% end %>
+        <li class="last"><%= link_to message('dashboard.manage_dashboards'), {:controller => :dashboards, :action => :index, :resource => (@resource.id if @resource)} -%></li>
       <% end %>
     </ul>
   <% end %>
index 57e76dfc193739eff1323a4908196f0832c4eb82..ce07999c2f46060dcd3801700f225971613939f0 100644 (file)
@@ -5,12 +5,12 @@
       <td colspan="2"><h1><%= message('dashboard.create_dashboard') -%></h1></td>
     </tr>
     <tr>
-      <td class="left" valign="top">
+      <td class="left" valign="top" colspan="2">
         <%= message('name') -%>:<br/><input type="text" name="name" size="30" maxlength="256">
       </td>
     </tr>
     <tr>
-      <td class="left" valign="top">
+      <td class="left" valign="top" colspan="2">
         <%= message('description') -%>:<br/><input type="text" name="description" size="30" maxlength="1000">
       </td>
     </tr>
       <td class="left" valign="top">
         <%= message('global') -%>:<br/><input type="checkbox" name="global" value="true">
       </td>
-    </tr>
-    <% if is_admin? %>
-      <tr>
+      <% if is_admin? %>
         <td class="left" valign="top">
           <%= message('shared') -%>:<br/><input type="checkbox" name="shared" value="true">
         </td>
-      </tr>
-    <% end %>
+      <% end %>
+    </tr>
     <tr>
-      <td class="left" valign="top">
+      <td class="left" valign="top" colspan="2">
         <input type="submit" value="<%= message('dashboard.create_dashboard') -%>" id="submit-create-dashboard"/>
       </td>
     </tr>
index 38a5c31c7325905c76372e01f057a27b8f67ec8b..2b616de9166eb8955fbcc3b6a1fa63a974e78ae4 100644 (file)
@@ -5,28 +5,31 @@
         <td colspan="2"><h1><%= message('dashboard.edit_dashboard') -%></h1></td>
       </tr>
       <tr>
-        <td class="left" valign="top">
+        <td class="left" valign="top" colspan="2">
         <%= message('name') -%>:<br/><input type="text" name="name" size="30" maxlength="256" value="<%= @dashboard.name -%>">
         </td>
       </tr>
       <tr>
-        <td class="left" valign="top">
+        <td class="left" valign="top" colspan="2">
         <%= message('description') -%>:<br/><input type="text" name="description" size="30" maxlength="1000" value="<%= @dashboard.description -%>">
         </td>
       </tr>
-      <% if is_admin? %>
       <tr>
         <td class="left" valign="top">
-        <%= message('shared') -%>:<br/><input type="checkbox" name="shared" value="true" <%= 'checked' if @dashboard.shared -%>>
+          <%= message('global') -%>:<br/><input type="checkbox" name="global" value="true" <%= 'checked' if @dashboard.global -%>>
         </td>
+        <% if is_admin? %>
+          <td class="left" valign="top">
+            <%= message('shared') -%>:<br/><input type="checkbox" name="shared" value="true" <%= 'checked' if @dashboard.shared -%>>
+          </td>
       </tr>
       <% end %>
       <tr>
-        <td class="left" valign="top">
-        <input type="submit" value="<%= message('dashboard.update_dashboard') -%>" id="submit-update-dashboard"/>
-        <a href="<%= url_for :action => 'index', :resource => params[:resource] -%>"><%= message('cancel') -%></a>
+        <td class="left" valign="top" colspan="2">
+          <input type="submit" value="<%= message('dashboard.update_dashboard') -%>" id="submit-update-dashboard"/>
+          <a href="<%= url_for :action => 'index', :resource => params[:resource] -%>"><%= message('cancel') -%></a>
         </td>
       </tr>
     </tbody>
 </table>
-</form>
\ No newline at end of file
+</form>
index e876fad2cc1b91f49bb08b01567775ee97e016b8..1398baf8de2a220942af83937308533631c804eb 100644 (file)
              @actives.each_with_index do |active, index| %>
             <tr id="dashboard-<%= u active.name -%>" class="<%= cycle('even', 'odd', :name => 'dashboards') -%>">
               <td>
-                <%= link_to active.name(true), {:controller => :dashboard, :action => :index, :did => active.dashboard_id, :id => params[:resource]} -%>
+                <%= link_to active.name(true), {:controller => :dashboard, :action => :index, :did => active.dashboard_id, :id => (params[:resource] unless active.dashboard.global) } -%>
                 <% if active.dashboard.description.present? %>
                   <p class="small"><%= h active.dashboard.description -%></p>
                 <% end %>
               </td>
               <td>
-                <%= boolean_icon(active.dashboard.global?) -%>
+                <%= boolean_icon(active.dashboard.global) -%>
               </td>
               <% if is_admin %>
                 <td>
-                  <%= boolean_icon(active.dashboard.shared?) -%>
+                  <%= boolean_icon(active.dashboard.shared) -%>
                 </td>
               <% end %>
               <td>
@@ -51,7 +51,7 @@
               </td>
               <td class="thin nowrap right">
                 <% if active.owner?(current_user) %>
-                  <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => 'configure', :did => active.dashboard_id, :id => params[:resource]},
+                  <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => 'configure', :did => active.dashboard_id, :id => (params[:resource] unless active.dashboard.global)},
                               :id => "configure-#{u active.name}", :class => 'link-action' %>
                   |
                   <%= link_to_remote message('edit'), {:update => "admin_form", :url => {:action => "edit", :id => active.dashboard_id, :resource => params[:resource]}},
@@ -77,6 +77,7 @@
         <thead>
         <tr>
           <th><%= message('name') -%></th>
+          <th><%= message('global') -%></th>
           <th><%= message('shared_by') -%></th>
           <th><%= message('operations') -%></th>
         </tr>
@@ -96,6 +97,9 @@
                   <p class="small"><%= h dashboard.description -%></p>
                 <% end %>
               </td>
+              <td>
+                <%= boolean_icon(dashboard.global) -%>
+              </td>
               <td>
                 <%= dashboard.user_name -%>
               </td>
index d9be65e9e0b14c8ed66115696725dee814d1e757..9c1d3a854c8b145552411c48a38f7e34395ae635 100644 (file)
@@ -42,9 +42,9 @@
             <li class="<%= 'selected' if controller.controller_path=='dependencies' -%>">
               <a href="<%= ApplicationController.root_context -%>/dependencies/index"><%= message('dependencies.page') -%></a></li>
 
-            <% ActiveDashboard.user_dashboards(current_user).select { |active_dashboard| active_dashboard.dashboard.global? }.each do |active_dashboard| %>
+            <% ActiveDashboard.user_dashboards(current_user).select { |active_dashboard| active_dashboard.dashboard.global }.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/?did=<%= active_dashboard.dashboard_id -%>"><%= active_dashboard.dashboard.name(true) -%></a>
+                <a href="<%= ApplicationController.root_context -%>/dashboard/?did=<%= active_dashboard.dashboard_id -%>"><%= active_dashboard.dashboard.name(true) -%></a>
               </li>
             <% end %>
 
@@ -57,7 +57,7 @@
             <% end %>
 
           <% elsif selected_section==Navigation::SECTION_RESOURCE %>
-            <% ActiveDashboard.user_dashboards(current_user).select { |active_dashboard| !active_dashboard.dashboard.global? }.each do |active_dashboard| %>
+            <% ActiveDashboard.user_dashboards(current_user).select { |active_dashboard| !active_dashboard.dashboard.global }.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>