ref: refs/heads/backgroud_patches_bnc550934
commit 7f104b950a3ca5fb21461664665d7606e2229af8
Author: Ladislav Slezak
Date: Tue Dec 8 18:31:00 2009 +0100
read system status summary at background, display progress
---
.../status/app/controllers/status_controller.rb | 37 +++++++++++++++++---
.../app/views/status/_status_progress.html.erb | 26 ++++++++++++++
webclient/app/views/controlpanel/index.rhtml | 2 +-
3 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/plugins/status/app/controllers/status_controller.rb b/plugins/status/app/controllers/status_controller.rb
index 1202af1..1c7b698 100644
--- a/plugins/status/app/controllers/status_controller.rb
+++ b/plugins/status/app/controllers/status_controller.rb
@@ -93,17 +93,23 @@ class StatusController < ApplicationController
}
end
- def create_data
+ def create_data(from = nil, till = nil, background = false)
@limits_list = Hash.new
@limits_list[:reached] = String.new
@data_group = Hash.new
status = []
- till = Time.new
- from = till - 300 #last 5 minutes
+ till ||= Time.new
+ from ||= till - 300 #last 5 minutes
ActionController::Base.benchmark("Status data read from the server") do
- status = @client.find(:dummy_param, :params => { :start => from.to_i.to_s, :stop => till.to_i.to_s })
+ stat_params = { :start => from.to_i.to_s, :stop => till.to_i.to_s }
+ stat_params[:background] = "true" if background
+ status = @client.find(:dummy_param, :params => stat_params )
end
+
+ # this is a background status result
+ return status.attributes if status.attributes.keys.sort == ["progress", "status", "subprogress"]
+
create_data_map status
# logger.debug @data_group.inspect
@@ -176,7 +182,28 @@ class StatusController < ApplicationController
def show_summary
return unless client_permissions
begin
- if create_data
+ till = params['till']
+ from = params['from']
+
+ till ||= Time.new.to_i
+ from ||= till - 300 #last 5 minutes
+
+ result = create_data(from, till, !params['background'].nil?)
+
+ # is it a background progress?
+ if result.class == Hash
+ status_progress = result.symbolize_keys
+ Rails.logger.debug "Received background status progress: #{status_progress.inspect}"
+
+ respond_to do |format|
+ format.html { render :partial => 'status_progress', :locals => {:status => status_progress, :from => from, :till => till } }
+ format.json { render :json => status_progress }
+ end
+
+ return
+ end
+
+ if result
status = limits_reached
status = (_("Limits exceeded for %s") % status) unless status.empty?
else
diff --git a/plugins/status/app/views/status/_status_progress.html.erb b/plugins/status/app/views/status/_status_progress.html.erb
new file mode 100644
index 0000000..8624d9e
--- /dev/null
+++ b/plugins/status/app/views/status/_status_progress.html.erb
@@ -0,0 +1,26 @@
+
+<div class="status_summary">
+ <div style="float: left;">
+ <%= image_tag("/images/working.gif", :height=>"32", :width=>"32", :border=>"0") %>
+ </div>
+
+ <div style="float: left; padding-left: 1em; padding-top:10px">
+ <%= _("Reading system status") %>
+ </div>
+
+ <div style="float: left; padding-left: 1em; padding-top:10px">
+ <!-- TODO FIXME: put these styles to the stylesheet -->
+ <div style="float: left; width: 150px; text-align: center"><%= status[:progress].to_i -%>%</div>
+ <div style="border-style: solid; border-width: 1px; width: 150px; height: 1.2em;">
+ <div style="background: #66CC00; width: <%= status[:progress].to_i -%>%; height: 1.2em;"/>
+ </div>
+ </div>
+
+ <!-- refresh the status again after 2 seconds -->
+ <% javascript_tag do -%>
+ setTimeout(function() {
+ <%= remote_function(:update => "status_status",
+ :url => { :controller => :status, :action => :show_summary, :background => true, :from => from, :till => till }) %>
+ }, 2000);
+ <% end -%>
+</div>
diff --git a/webclient/app/views/controlpanel/index.rhtml b/webclient/app/views/controlpanel/index.rhtml
index 9c560b1..6247677 100644
--- a/webclient/app/views/controlpanel/index.rhtml
+++ b/webclient/app/views/controlpanel/index.rhtml
@@ -16,7 +16,7 @@
<% javascript_tag do -%>
$(document).ready( function() {
<%= remote_function(:update => "status_status",
- :url => { :controller => :status, :action => :show_summary }) %>
+ :url => { :controller => :status, :action => :show_summary, :background => true }) %>
});
<% end -%>
<% end %>
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org