]> source.dussan.org Git - sonarqube.git/commitdiff
Better links in 'Manage Dashboards' section
authorDavid Gageot <david@gageot.net>
Fri, 18 May 2012 14:49:04 +0000 (16:49 +0200)
committerDavid Gageot <david@gageot.net>
Fri, 18 May 2012 14:49:04 +0000 (16:49 +0200)
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

index f012d8b8edb10e6f6d196ff2e8cf2df537634368..b2ee37ba280accada9963739de2750c58baf4c74 100644 (file)
@@ -48,12 +48,13 @@ class DashboardsController < ApplicationController
 
   def create
     @dashboard=Dashboard.new()
+    @dashboard.user_id=current_user.id
     load_dashboard_from_params(@dashboard)
 
     active_dashboard = current_user.active_dashboards.to_a.find { |ad| ad.name==@dashboard.name }
     if active_dashboard
       flash[:error]=Api::Utils.message('dashboard.error_create_existing_name')
-      redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource]
+      redirect_to :action => 'index', :resource => params[:resource]
     elsif @dashboard.save
       add_default_dashboards_if_first_user_dashboard
       last_active_dashboard=current_user.active_dashboards.max_by(&:order_index)
@@ -61,22 +62,22 @@ class DashboardsController < ApplicationController
       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]
+      redirect_to :action => 'index', :resource => params[:resource]
     end
   end
 
   def edit
     @dashboard=Dashboard.find(params[:id])
-    if @dashboard.owner?(current_user)
+    if @dashboard.editable_by?(current_user)
       render :partial => 'edit'
     else
-      redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource]
+      redirect_to :action => 'index', :resource => params[:resource]
     end
   end
 
   def update
     dashboard=Dashboard.find(params[:id])
-    if dashboard.owner?(current_user)
+    if dashboard.editable_by?(current_user)
       load_dashboard_from_params(dashboard)
 
       if dashboard.save
@@ -95,10 +96,10 @@ class DashboardsController < ApplicationController
   def delete
     dashboard=Dashboard.find(params[:id])
     bad_request('Unknown dashboard') unless dashboard
-    access_denied unless dashboard.owner?(current_user)
+    access_denied unless dashboard.editable_by?(current_user)
 
     if dashboard.destroy
-      flash[:error]=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
@@ -127,7 +128,7 @@ class DashboardsController < ApplicationController
     else
       bad_request('Unknown dashboard')
     end
-    redirect_to :action => :index, :resource => params[:resource]
+    redirect_to :action => 'index', :resource => params[:resource]
   end
 
   def unfollow
@@ -138,7 +139,7 @@ class DashboardsController < ApplicationController
     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]
+    redirect_to :action => 'index', :resource => params[:resource]
   end
 
   private
@@ -169,7 +170,6 @@ class DashboardsController < ApplicationController
     dashboard.description=params[:description]
     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
   end
 
index 982db2f7ad35071238589efc532fe45f641da3b8..6a569b88118f093d02da0e439aa325b43d313c5a 100644 (file)
@@ -32,7 +32,7 @@
         </td>
         <td class="thin nowrap right">
           <% if active_dashboards.size() > 1 %>
-            <%= link_to 'Remove from defaults', {:action => 'remove', :id => active.id}, {:confirm => 'Are you sure to remove it from default dashboards ?', :method => :post, :id => "remove-#{u active.name}", :class => 'link-action'} %>
+            <%= link_to 'Remove from defaults', {:action => :remove, :id => active.id}, {:confirm => 'Are you sure to remove it from default dashboards ?', :method => :post, :id => "remove-#{u active.name}", :class => 'link-action'} %>
           <% end %>
         </td>
       </tr>
index b140de47bc2f9046c3dc00ae51324dccf034211c..b59d91b8a1285397d94a98e95c443739c6397d7f 100644 (file)
           </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'} %>
-            <% if dashboard.provided_programmatically? %>
-              |
-              <%= link_to 'Delete', {:action => 'delete', :id => dashboard.id}, {:confirm => "Do you want to delete the dashboard #{dashboard.name(true)}?", :method => :post, :id => "delete-#{u dashboard.name}", :class => 'link-action'} %>
-            <% end %>
           </td>
         </tr>
       <% end %>
index 705f7d27e0d1131a0a4abdc75228bdc7b358eef7..23cb6fcbf608c0db0f8b07be8d23965aec7c4566 100644 (file)
                 <%= 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 %>
-                    |
-                  <% if active.owner?(current_user) %>
-                      <%= 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' %>
-                  <% else %>
-                      <%= link_to message('unfollow'), {:action => :unfollow, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post,
-                                  :id => "unfollow-#{u active.name}", :class => 'link-action' %>
-                  <% end %>
+                  |
+                  <%= 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 %>
-              <% elsif !active.owner?(current_user) && (@actives.size() > 1) %>
+              <% 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 %>
               <%= dashboard.user_name -%>
             </td>
             <td class="thin nowrap right">
-              <%= link_to message('follow'), {:action => 'follow', :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %>
+              <% 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