]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3570 Project "deletion" should run asynchronously
authorFabrice Bellingard <bellingard@gmail.com>
Thu, 5 Jul 2012 08:27:58 +0000 (10:27 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Thu, 5 Jul 2012 08:30:34 +0000 (10:30 +0200)
=> To prevent HTTP timeout.

plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb
sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/_pending_deletions_screen.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/pending_deletions.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/project/deletion.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/project/pending_deletion.html.erb [new file with mode: 0644]

index fdec6a9f57f2fcdfdc4c865bc989b541c93197e2..e3bd591bf6a1669c3a2ee64c15353ee0d0006062 100644 (file)
@@ -1275,6 +1275,11 @@ bulk_deletion.clear_selection=Clear selection of all {0} resources
 bulk_deletion.following_deletions_failed=The following resources could not be deleted. Please check the logs to know more about it.
 bulk_deletion.hide_message=Hide message
 bulk_deletion.sure_to_delete_the_resources=Are you sure you want to delete the selected resources?
+bulk_deletion.deletion_manager.deleting_resources=Deleting resources...
+bulk_deletion.deletion_manager.no_resource_to_delete=No resource to delete.
+bulk_deletion.deletion_manager.currently_deleting_x_out_of_x=Currently deleting resources... ({0} out of {1})
+bulk_deletion.deletion_manager.deletion_completed=Resource deletion completed.
+bulk_deletion.deletion_manager.however_failures_occurred=However, some failures occurred.
 
 
 #------------------------------------------------------------------------------
index a7d74f7887d177b7063994a96c302e77b28b39cd..46a8055b2686e26eef9887718f85096f7e5c8c98 100644 (file)
@@ -76,7 +76,7 @@ class BulkDeletionController < ApplicationController
     if deletion_manager.currently_deleting_resources? || 
       (!deletion_manager.currently_deleting_resources? && deletion_manager.deletion_failures_occured?)
       # display the same page again and again
-      @deletion_manager = deletion_manager
+      # => implicit render "pending_deletions.html.erb"
     else
       redirect_to :action => 'index'
     end
index 1391edd4ac02ff7a3eb5073918785c308ded30f5..cf5af3ed82da52d59e22c6adc2a84dca42136be6 100644 (file)
@@ -31,21 +31,48 @@ class ProjectController < ApplicationController
   def deletion
     @project = get_current_project(params[:id])
 
-    unless java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'deletable')
+    if java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'deletable')
+      deletion_manager = ResourceDeletionManager.instance
+      if deletion_manager.currently_deleting_resources? || 
+        (!deletion_manager.currently_deleting_resources? && deletion_manager.deletion_failures_occured?)
+        # a deletion is happening or it has just finished with errors => display the message from the Resource Deletion Manager
+        render :template => 'project/pending_deletion'
+      else    
+        @snapshot=@project.last_snapshot
+      end
+    else
       redirect_to :action => 'index', :id => params[:id]
     end
-    
-    @snapshot=@project.last_snapshot
   end
 
   def delete
-    if params[:id]
-      @project = Project.by_key(params[:id])
-      if @project && is_admin?(@project)
-        Project.delete_resource_tree(@project)
-      end
+    @project = get_current_project(params[:id])
+    
+    # Ask the resource deletion manager to start the migration
+    # => this is an asynchronous AJAX call
+    ResourceDeletionManager.instance.delete_resources([@project.id])
+    
+    # and return some text that will actually never be displayed
+    render :text => ResourceDeletionManager.instance.message
+  end
+  
+  def pending_deletion
+    deletion_manager = ResourceDeletionManager.instance
+    
+    if deletion_manager.currently_deleting_resources? || 
+      (!deletion_manager.currently_deleting_resources? && deletion_manager.deletion_failures_occured?)
+      # display the same page again and again
+      # => implicit render "pending_deletion.html.erb"
+    else
+      redirect_to_default
     end
-    redirect_to_default
+  end
+  
+  def dismiss_deletion_message
+    # It is important to reinit the ResourceDeletionManager so that the deletion screens can be available again
+    ResourceDeletionManager.instance.reinit
+    
+    redirect_to :action => 'deletion', :id => params[:id]
   end
   
   def quality_profile
index f828cc3e0854048560f82e926de73246c47c16a2..dbdcd73a34899675b9fa18fa5cac401c03ca6232 100644 (file)
@@ -75,7 +75,7 @@ class ResourceDeletionManager
       unless currently_deleting_resources?
         reinit()
         @status = WORKING
-        @message = "Deleting resources..."
+        @message = Api::Utils.message('bulk_deletion.deletion_manager.deleting_resources')
         can_start_deletion = true
       end
     end
@@ -83,13 +83,13 @@ class ResourceDeletionManager
     if can_start_deletion
       if resource_ids.empty?
         @status = AVAILABLE
-        @message = "No resource to delete."
+        @message = Api::Utils.message('bulk_deletion.deletion_manager.no_resource_to_delete')
       else
         java_facade = Java::OrgSonarServerUi::JRubyFacade.getInstance()
         # launch the deletion
         resource_ids.each_with_index do |resource_id, index|
           resource = Project.find(:first, :conditions => {:id => resource_id.to_i})
-          @message = "Currently deleting resources... (" + (index+1).to_s + " out of " + resource_ids.size.to_s + ")"
+          @message = Api::Utils.message('bulk_deletion.deletion_manager.currently_deleting_x_out_of_x', :params => [(index+1).to_s, resource_ids.size.to_s])
           if resource && 
             # next line add 'VW' and 'DEV' tests because those resource types don't have the 'deletable' property yet...
             (java_facade.getResourceTypeBooleanProperty(resource.qualifier, 'deletable') || resource.qualifier=='VW' || resource.qualifier=='DEV')
@@ -102,7 +102,8 @@ class ResourceDeletionManager
           end
         end
         @status = AVAILABLE
-        @message = "Resource deletion completed."
+        @message = Api::Utils.message('bulk_deletion.deletion_manager.deletion_completed')
+        @message += ' ' + Api::Utils.message('bulk_deletion.deletion_manager.however_failures_occurred') unless @failed_deletions.empty?
       end
     end    
   end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/_pending_deletions_screen.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/_pending_deletions_screen.html.erb
new file mode 100644 (file)
index 0000000..27895eb
--- /dev/null
@@ -0,0 +1,35 @@
+<%
+  deletion_manager = ResourceDeletionManager.instance
+  pending_deletions = deletion_manager.currently_deleting_resources?
+  failed_deletions = deletion_manager.failed_deletions
+%>
+
+<% if pending_deletions %>
+  <meta http-equiv='refresh' content='5;'>
+<% end %>
+
+<h1 class="marginbottom10"><%= message('bulk_deletion.page') -%></h1>
+
+<div class="<%= pending_deletions ? 'admin' : 'error' -%>" style="padding:10px">
+  <% if pending_deletions %>
+    <%= image_tag 'loading.gif' -%>
+  <% end %>
+  
+  <b><%= deletion_manager.message -%></b>
+  <br/>
+  <br/>
+  
+  <% if !pending_deletions && !failed_deletions.empty? %>
+    <p>
+      <%= message('bulk_deletion.following_deletions_failed') -%>
+      <ul style="list-style: none outside; padding-left: 30px;">
+      <% failed_deletions.each do |name| %>
+        <li style="list-style: disc outside; padding: 2px;"><%= name -%></li>
+      <% end %>
+      </ul>
+    </p>
+    <p>
+      <a href="<%= url_after_dismiss -%>"><%= message('bulk_deletion.hide_message') -%></a>
+    </p>
+  <% end %>
+</div>
\ No newline at end of file
index e5e67a6d57d234495e8f9f9be9640f76c5dec2a3..505c243e48a8db60db065985f3c2781aaa492b9a 100644 (file)
@@ -1,34 +1,2 @@
-<%
-  pending_deletions = @deletion_manager.currently_deleting_resources?
-  failed_deletions = @deletion_manager.failed_deletions
-%>
-
-<% if pending_deletions %>
-  <meta http-equiv='refresh' content='5;'>
-<% end %>
-
-<h1 class="marginbottom10"><%= message('bulk_deletion.page') -%></h1>
-
-<div class="<%= pending_deletions ? 'admin' : 'error' -%>" style="padding:10px">
-  <% if pending_deletions %>
-    <%= image_tag 'loading.gif' -%>
-  <% end %>
-  
-  <b><%= @deletion_manager.message -%></b>
-  <br/>
-  <br/>
-  
-  <% if !pending_deletions && !failed_deletions.empty? %>
-    <p>
-      <%= message('bulk_deletion.following_deletions_failed') -%>
-      <ul style="list-style: none outside; padding-left: 30px;">
-      <% failed_deletions.each do |name| %>
-        <li style="list-style: disc outside; padding: 2px;"><%= name -%></li>
-      <% end %>
-      </ul>
-    </p>
-    <p>
-      <%= link_to message('bulk_deletion.hide_message'), :action => 'dismiss_message' -%>
-    </p>
-  <% end %>
-</div>
\ No newline at end of file
+<%= render :partial => 'pending_deletions_screen', 
+           :locals => {:url_after_dismiss => url_for(:action => 'dismiss_message')} -%>
\ No newline at end of file
index ea5493f8a4baaa08a98d7796ccf0d1d5f2fb06ac..fb02aa939158dbbdd0f4714f047933b331be8e61 100644 (file)
@@ -7,10 +7,13 @@
 <br/>
 <div class="yui-g widget" id="widget_delete_project">
   <div class="warning">
+    <% form_remote_tag( :url => {:action => 'delete', :id => @project.id}, :method => :delete, 
+                        :loading => "window.location='#{url_for :action => 'pending_deletion', :id => @project.id}';") do %>
     <%= message('project_deletion.operation_cannot_be_undone') -%>
-    <%= button_to( delete_resource_message, { :action => "delete", :id => @project.id }, 
-                   :class => 'action red-button', :method => :delete, 
-                   :confirm => message('project_deletion.delete_resource_confirmation', :params => resource_name)) %>
+    <br/>
+    <%= submit_tag delete_resource_message, :id => 'delete_resource', :class => 'action red-button', 
+                   :confirm => message('project_deletion.delete_resource_confirmation', :params => resource_name) %>
+    <% end %>
   </div>
 </div>
 <% end %>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/pending_deletion.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/pending_deletion.html.erb
new file mode 100644 (file)
index 0000000..7d96f93
--- /dev/null
@@ -0,0 +1,2 @@
+<%= render :partial => 'bulk_deletion/pending_deletions_screen', 
+           :locals => {:url_after_dismiss => url_for(:action => 'dismiss_deletion_message', :id => params[:id])} -%>
\ No newline at end of file