]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3512 Make it possible to share a dashboard without following it
authorDavid Gageot <david@gageot.net>
Mon, 18 Jun 2012 14:46:35 +0000 (16:46 +0200)
committerDavid Gageot <david@gageot.net>
Tue, 19 Jun 2012 08:57:19 +0000 (10:57 +0200)
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/_list.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/admin_dashboards/index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb
sonar-server/src/main/webapp/stylesheets/dashboard.css

index b973de86df5230a5ad5b8a6ae6f803bc9e75d4dc..74b8ddaf5185b6b6c0c5ac63a9425d711ee190fa 100644 (file)
@@ -12,27 +12,27 @@ alerts=Alerts
 all=All
 and=And
 any=Any
+ascending=Ascending
 assignee=Assignee
 author=Author
-ascending=Ascending
 back=Back
 backup_verb=Backup
 blocker=Blocker
 bold=Bold
 build_date=Build date
 build_time=Build time
+calendar=Calendar
 cancel=Cancel
 category=Category
-calendar=Calendar
-change_verb=Change
 changelog=Changelog
-configure=Configure
+change_verb=Change
 class=Class
 classes=Classes
 closed=Closed
 code=Code
 color=Color
 compare=Compare
+configure=Configure
 copy=Copy
 create=Create
 created=Created
@@ -44,8 +44,8 @@ default=Default
 delete=Delete
 descending=Descending
 description=Description
-directory=Directory
 directories=Directories
+directory=Directory
 display=Display
 download_verb=Download
 edit=Edit
@@ -58,8 +58,8 @@ follow=Follow
 global=Global
 hide=Hide
 identifier_abbreviated=Id
-info=Info
 inactive=Inactive
+info=Info
 inheritance=Inheritance
 key=Key
 language=Language
@@ -82,6 +82,7 @@ open_verb=Open
 operations=Operations
 optional=Optional
 order=Order
+owner=Owner
 package=Package
 packages=Packages
 parameters=Parameters
@@ -92,19 +93,19 @@ plugin=Plugin
 project=Project
 projects=Projects
 raw=Raw
+rename=Rename
 reset_verb=Reset
 result=Result
 results=Results
-rule=Rule
-rules=Rules
-rename=Rename
 review=Review
 reviews=Reviews
 review_verb=Review
+rule=Rule
+rules=Rules
 save=Save
 search_verb=Search
-select_verb=Select
 select_all=Select all
+select_verb=Select
 severity=Severity
 severity_abbreviated=Se.
 shared=Shared
@@ -122,20 +123,20 @@ title=Title
 to=To
 treemap=Treemap
 true=True
-update_verb=Update
-updated=Updated
 unfollow=Unfollow
 unit_test=Unit test
 unit_tests=Unit tests
-unselect_verb=Unselect
 unselect_all=Unselect all
+unselect_verb=Unselect
+updated=Updated
+update_verb=Update
 user=User
 value=Value
 variation=Variation
+version=Version
 view=View
 views=Views
 violations=Violations
-version=Version
 
 
 #------------------------------------------------------------------------------
@@ -529,6 +530,7 @@ dashboard.my_global_dashboards=My global dashboards
 dashboard.my_project_dashboards=My project dashboards
 dashboard.no_dashboard=No dashboard
 dashboard.do_you_want_to_delete_dashboard=Do you want to delete this dashboard ?
+dashboard.available_dashboards=Available dashboards
 dashboard.shared_dashboards=Shared dashboards
 dashboard.create_dashboard=New dashboard
 dashboard.create_project_dashboard=Create project dashboard
index 3d2d0a4d6a02b9ad541225b9e6a6037da7d89910..b07c19fc1c5f3a233fee0da1abb5b6cd3f2f6caf 100644 (file)
@@ -28,9 +28,10 @@ class DashboardsController < ApplicationController
     @global = !params[:resource]
 
     @actives=ActiveDashboard.user_dashboards(current_user, @global)
-    @shared_dashboards=Dashboard.find(:all, :conditions => ['(user_id<>? OR user_id IS NULL) AND shared=? AND is_global=?', current_user.id, true, @global]).sort { |a, b| a.name.downcase<=>b.name.downcase }
+    @shared_dashboards=Dashboard.find(:all, :conditions => ['(shared=? or user_id=?) and is_global=?', true, current_user.id, @global])
     active_ids=@actives.map(&:dashboard_id)
     @shared_dashboards.reject! { |d| active_ids.include?(d.id) }
+    @shared_dashboards=Api::Utils.insensitive_sort(@shared_dashboards, &:name)
 
     if params[:resource]
       @resource=Project.by_key(params[:resource])
@@ -58,9 +59,8 @@ class DashboardsController < ApplicationController
     elsif @dashboard.save
       add_default_dashboards_if_first_user_dashboard(@dashboard.global?)
       last_index=current_user.active_dashboards.max_by(&:order_index).order_index
-      current_user.active_dashboards.create(:dashboard => @dashboard, :user_id => current_user.id, :order_index => last_index+1)
 
-      redirect_to :controller => 'dashboard', :action => 'configure', :did => @dashboard.id, :id => (params[:resource] unless @dashboard.global)
+      redirect_to :action => 'index', :resource => params[:resource], :highlight => @dashboard.id
     else
       flash[:error]=@dashboard.errors.full_messages.join('<br/>')
 
@@ -84,29 +84,28 @@ class DashboardsController < ApplicationController
 
       if dashboard.save
         unless dashboard.shared?
-          ActiveDashboard.destroy_all(['dashboard_id = ? and (user_id<>? OR user_id IS NULL)', dashboard.id, current_user.id])
+          ActiveDashboard.destroy_all(:dashboard_id => dashboard.id)
         end
       else
         flash[:error]=dashboard.errors.full_messages.join('<br/>')
       end
-    else
-      # TODO explicit error
     end
+
     redirect_to :action => 'index', :resource => params[:resource]
   end
 
   def delete
     dashboard=Dashboard.find(params[:id])
-    bad_request('Unknown dashboard') unless dashboard
+
     access_denied unless dashboard.editable_by?(current_user)
 
     if dashboard.destroy
-      flash[:warning]=Api::Utils.message('dashboard.default_restored') if ActiveDashboard.count(:conditions => ['user_id=?', current_user.id])==0
+      flash[:warning]=Api::Utils.message('dashboard.default_restored') if ActiveDashboard.count(:conditions => {:user_id => current_user.id})==0
     else
       flash[:error]=Api::Utils.message('dashboard.error_delete_default')
     end
-    redirect_to :action => 'index', :resource => params[:resource]
 
+    redirect_to :action => 'index', :resource => params[:resource]
   end
 
   def down
@@ -118,58 +117,51 @@ class DashboardsController < ApplicationController
   end
 
   def follow
-    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
-      add_default_dashboards_if_first_user_dashboard(dashboard.global?)
+    dashboard=Dashboard.find(params[:id])
 
-      active_dashboard = current_user.active_dashboards.to_a.find { |ad| ad.name==dashboard.name }
-      if active_dashboard
-        flash[:error]=Api::Utils.message('dashboard.error_follow_existing_name')
-      else
-        last_active_dashboard=current_user.active_dashboards.max_by(&:order_index)
-        current_user.active_dashboards.create(:dashboard => dashboard, :user => current_user, :order_index => (last_active_dashboard ? last_active_dashboard.order_index+1 : 1))
-      end
+    add_default_dashboards_if_first_user_dashboard(dashboard.global?)
+    active_dashboard = current_user.active_dashboards.to_a.find { |ad| ad.name==dashboard.name }
+    if active_dashboard
+      flash[:error]=Api::Utils.message('dashboard.error_follow_existing_name')
     else
-      bad_request('Unknown dashboard')
+      last_active_dashboard=current_user.active_dashboards.max_by(&:order_index)
+      current_user.active_dashboards.create(:dashboard => dashboard, :user => current_user, :order_index => (last_active_dashboard ? last_active_dashboard.order_index+1 : 1))
     end
+
     redirect_to :action => 'index', :resource => params[:resource]
   end
 
   def unfollow
-    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
-      add_default_dashboards_if_first_user_dashboard(dashboard.global?)
+    dashboard=Dashboard.find(params[:id])
 
-      ActiveDashboard.destroy_all(['user_id=? AND dashboard_id=?', current_user.id, params[:id].to_i])
+    add_default_dashboards_if_first_user_dashboard(dashboard.global?)
+    ActiveDashboard.destroy_all(:user_id => current_user.id, :dashboard_id => params[:id].to_i)
 
-      if ActiveDashboard.count(:conditions => ['user_id=?', current_user.id])==0
-        flash[:notice]=Api::Utils.message('dashboard.default_restored')
-      end
+    if ActiveDashboard.count(:conditions => {:user_id => current_user.id})==0
+      flash[:notice]=Api::Utils.message('dashboard.default_restored')
     end
+
     redirect_to :action => 'index', :resource => params[:resource]
   end
 
   private
 
   def position(offset)
-    dashboard=Dashboard.find(params[:id].to_i)
-    if dashboard
-      add_default_dashboards_if_first_user_dashboard(dashboard.global?)
+    dashboard=Dashboard.find(params[:id])
 
-      actives=current_user.active_dashboards.select { |a| a.global? == dashboard.global? }.sort_by(&:order_index)
+    add_default_dashboards_if_first_user_dashboard(dashboard.global?)
+    actives=current_user.active_dashboards.select { |a| a.global? == dashboard.global? }.sort_by(&:order_index)
 
-      index = actives.index { |a| a.dashboard_id == dashboard.id }
-      if index
-        actives[index], actives[index + offset] = actives[index + offset], actives[index]
+    index = actives.index { |a| a.dashboard_id == dashboard.id }
+    if index
+      actives[index], actives[index + offset] = actives[index + offset], actives[index]
 
-        actives.each_with_index do |a, i|
-          a.order_index=i+1
-          a.save
-        end
+      actives.each_with_index do |a, i|
+        a.order_index=i+1
+        a.save
       end
     end
 
-
     redirect_to :action => 'index', :resource => params[:resource]
   end
 
index d903d2d4f1159818b22d8ab6b096cae148e00870..682cfc6497902ef33cbf5ae10281cbd306ad53a5 100644 (file)
@@ -2,7 +2,7 @@
   <thead>
   <tr>
     <th class="name"><%= message('name') -%></th>
-    <th class="shared"><%= message('shared_by') -%></th>
+    <th class="owner"><%= message('shared_by') -%></th>
     <th class="order"><%= message('order') -%></th>
     <th class="operations"><%= message('operations') -%></th>
   </tr>
           <div><%= h(active.name(true)) -%></div>
           <div class="description"><%= active.dashboard.description -%></div>
         </td>
-        <td class="shared">
-          <% if active.dashboard.shared %>
-            <%= h(active.dashboard.user_name || message('dashboard.username.default')) -%>
-          <% end %>
+        <td class="owner">
+          <%= h(active.dashboard.user_name || message('dashboard.username.default')) -%>
         </td>
         <td class="order">
           <% if index > 0 %>
index 32bc6ad7aa6b0bce3fbb675aba02a15278cbae52..786ca5a2a732bfa0f2e1adf32a18d739a5cae86b 100644 (file)
@@ -19,7 +19,7 @@
     <thead>
     <tr>
       <th class="name"><%= message('name') -%></th>
-      <th class="shared"><%= message('shared_by') -%></th>
+      <th class="owner"><%= message('shared_by') -%></th>
       <th class="global"><%= message('global') -%></th>
       <th class="operations"><%= message('operations') -%></th>
     </tr>
             <div><%= h(dashboard.name(true)) -%></div>
             <div class="description"><%= dashboard.description -%></div>
           </td>
-          <td class="shared">
-            <% if dashboard.shared %>
-              <%= h(dashboard.user_name || message('dashboard.username.default')) -%>
-            <% end %>
+          <td class="owner">
+            <%= h(dashboard.user_name || message('dashboard.username.default')) -%>
           </td>
           <td class="global">
             <%= boolean_icon(dashboard.global) -%>
index 500e94de9d2adb2c13ce95628ea81d4f36b08839..8a34a2cab7240440351bc7ad99e2fde882e358df 100644 (file)
@@ -8,7 +8,8 @@
       <thead>
       <tr>
         <th class="name"><%= message('name') -%></th>
-        <th class="shared"><%= message('shared_by') -%></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>
         </tr>
       <% else %>
         <% @actives.each_with_index do |active, index| %>
-          <tr id="dashboard-<%= u active.name -%>" class="<%= cycle('even', 'odd', :name => 'dashboard') -%>">
+          <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">
-              <% if active.dashboard.shared %>
-                <%= h(active.dashboard.user_name || message('dashboard.username.default')) -%>
-              <% end %>
+              <%= 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 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 and active.shared? and !active.dashboard.owner?(current_user) %>
-                <% if active.editable_by?(current_user) %>
-                |
-                <% 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 %>
       </tbody>
     </table>
 
-    <h1><%= message('dashboard.shared_dashboards') -%></h1>
+    <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_by') -%></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>
       <%
          else
            @shared_dashboards.each do |dashboard| %>
-          <tr id="shared-dashboard-<%= u dashboard.name -%>" class="<%= cycle('even', 'odd', :name => 'shared') -%>">
+          <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">
-              <% if dashboard.shared %>
-                <%= h(dashboard.user_name || message('dashboard.username.default')) -%>
-              <% end %>
+              <%= 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">
                 <%= 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 %>
               <%= link_to message('follow'), {:action => :follow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %>
             </td>
           </tr>
     <%= render :partial => 'dashboards/create' %>
   </div>
 </div>
+
+<% if params[:highlight] %>
+<script type="text/javascript">
+  new Effect.Highlight('dashboard-<%= h params[:highlight] -%>', {duration: 2, startcolor: '#cae3f2'});
+</script>
+<% end %>
index 4c3d4187add1d912cdb1a213611e7050d4e39635..b548d9fc502aa9a0c2b9281e331480bf1bf707f0 100644 (file)
   text-align: right;
 }
 
-.admin_page .shared {
+.admin_page .owner {
   width: 140px;
   text-align: center;
 }
 
+.admin_page .shared {
+  width: 40px;
+  text-align: center;
+}
+
 .admin_page .order, .admin_page .global {
-  width: 60px;
+  width: 45px;
   text-align: center;
 }