=> To prevent HTTP timeout.
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.
#------------------------------------------------------------------------------
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
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
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
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')
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
--- /dev/null
+<%
+ 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
-<%
- 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
<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
--- /dev/null
+<%= 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