ref: refs/heads/master commit 32db64914021cc2f0d547d20ed2a4a26a2d0658a Author: Josef Reidinger <jreidinger@suse.cz> Date: Thu Jul 16 09:48:00 2009 +0200 get information about patches as AJAX call, so don't delay loading of initial page --- .../app/controllers/patch_updates_controller.rb | 24 +++++++++ .../views/patch_updates/_patch_summary.html.erb | 33 ++++++++++++ .../app/controllers/system_time_controller.rb | 3 +- .../app/controllers/controlpanel_controller.rb | 54 -------------------- webclient/app/views/controlpanel/index.rhtml | 17 ++++-- 5 files changed, 71 insertions(+), 60 deletions(-) diff --git a/plugins/patch_updates/app/controllers/patch_updates_controller.rb b/plugins/patch_updates/app/controllers/patch_updates_controller.rb index d315adc..ce4c0de 100644 --- a/plugins/patch_updates/app/controllers/patch_updates_controller.rb +++ b/plugins/patch_updates/app/controllers/patch_updates_controller.rb @@ -12,6 +12,30 @@ class PatchUpdatesController < ApplicationController logger.debug "Available patches: #{@patch_updates.inspect}" end + def show_summary + patch_updates = load_proxy 'org.opensuse.yast.system.patches', :all + + unless patch_updates + flash.clear #no flash from load_proxy + render :partial => "patch_summary", :locals => { :patch => nil } + return false + end + + patches = { :security => 0, :important => 0, :optional => 0} + + patch_updates.each do |patch| + case patch.kind + when "security": patches[:security] += 1 + when "important": patches[:important] += 1 + when "optional": patches[:optional] += 1 + else + logger.warn "unknown patch kind #{patch.kind}" + end + end + + render :partial => "patch_summary", :locals => { :patch => patches } + end + def load_filtered @patch_updates = load_proxy 'org.opensuse.yast.system.patches', :all kind = params[:value] diff --git a/plugins/patch_updates/app/views/patch_updates/_patch_summary.html.erb b/plugins/patch_updates/app/views/patch_updates/_patch_summary.html.erb new file mode 100644 index 0000000..571ca7d --- /dev/null +++ b/plugins/patch_updates/app/views/patch_updates/_patch_summary.html.erb @@ -0,0 +1,33 @@ +<div> + <% unless patch %> + <img src="/images/button_warning.png" alt="warning icon" /> + <%= _("Error occur during loading patch information.") %> + <% else %> + <% link_to "patch_updates" do %> + <% if patch[:security]+patch[:important] > 0 %> + <img src="/images/button_critical.png" alt="System need update"/> + <% elsif patch[:optional] %> + <img src="/images/button_warning.png" alt="System contains any update" /> + <% else %> + <img src="/images/button_ok.png" alt="No updates available"/> + <% end %> + + <% any_update = false %> + <% if patch[:security] > 0 %> + <%= _("Security Updates: #{patch[:security]} ") %> + <% any_update = true %> + <% end %> + <% if patch[:important] > 0 %> + <%= _("Important Updates: #{patch[:important]} ") %> + <% any_update = true %> + <% end %> + <% if patch[:optional] > 0 %> + <%= _("Optional Updates: #{patch[:optional]} ") %> + <% any_update = true %> + <% end %> + <% unless any_update %> + <%= _("Your system is up to date.") %> + <% end %> + <% end %> + <% end %> +</div> diff --git a/plugins/systemtime/app/controllers/system_time_controller.rb b/plugins/systemtime/app/controllers/system_time_controller.rb index 4be17b2..9ce4fe9 100644 --- a/plugins/systemtime/app/controllers/system_time_controller.rb +++ b/plugins/systemtime/app/controllers/system_time_controller.rb @@ -37,7 +37,8 @@ class SystemTimeController < ApplicationController public - # FIXME: should go to initialize() + # FIXME: should go to initialize(), even better move it to singleton which + # holds informations about available timezones @@timezones = {} # FIXME: should go to initialize() diff --git a/webclient/app/controllers/controlpanel_controller.rb b/webclient/app/controllers/controlpanel_controller.rb index 4850b23..f7d67df 100644 --- a/webclient/app/controllers/controlpanel_controller.rb +++ b/webclient/app/controllers/controlpanel_controller.rb @@ -12,8 +12,6 @@ class ControlpanelController < ApplicationController def index @shortcuts = shortcuts_data - res = check_update - @update_label, @update_image = res if res.is_a? Array end def show_all @@ -38,58 +36,6 @@ class ControlpanelController < ApplicationController protected - # FIXME: refactor out to updates_controller ! - # - # Check patches - def check_update - proxy = YaST::ServiceResource.proxy_for('org.opensuse.yast.system.patches') - unless proxy - logger.warn "Couldn't find proxy for org.opensuse.yast.system.patches" - return - end - begin - patch_updates = proxy.find(:all) || [] - rescue ActiveResource::ClientError => e - flash[:error] = YaST::ServiceResource.error(e) - return - rescue Exception => e - flash[:error] = "An exception was raised. Check the logs." - logger.error e - logger.info e.backtrace.join("\n") - return - end - - security = 0 - important = 0 - optional = 0 - patch_updates.each do |patch| - case patch.kind - when "security": security += 1 - when "important": important += 1 - when "optional": optional += 1 - end - end - # FIXME: Don't create label, create a partial view instead - # FIXME: translations ! - label = "" - label += "Security Updates: #{security} " if security>0 - label += "Important Updates: #{important} " if important>0 - label += "Optional Updates: #{optional} " if optional>0 - - label = _("Your system is up to date.") if label.blank? - - # FIMXE: Images are defined by CSS, don't hardcode them here - if security>0 || important>0 - img = "/images/button_critical.png" - elsif optional>0 - img = "/images/button_warning.png" - else - img = "/images/button_ok.png" - end - logger.debug "evaluated patches #{patch_updates.inspect} ==> security:#{security}; important:#{important}; optional:#{optional}" - [ label, img ] - end - # reads the shortcuts and returns the # hash with the data def shortcuts_data diff --git a/webclient/app/views/controlpanel/index.rhtml b/webclient/app/views/controlpanel/index.rhtml index bedd50e..af562c6 100644 --- a/webclient/app/views/controlpanel/index.rhtml +++ b/webclient/app/views/controlpanel/index.rhtml @@ -1,11 +1,16 @@ +<%= javascript_include_tag :defaults %> + +<% javascript_tag do -%> + $(document).ready( function() { + <%= remote_function(:update => "status_patches", + :url => { :controller => :patch_updates, :action => :show_summary }) %> + }); +<% end -%> <h3><img src="/images/monitoring.png" height="23" width="23" border="0" /> <%= _("Status") %></h3> -<div id="status_patches_icon"> - <img src= <%=@update_image%> height="32" width="32" border="0" /> -</div> -<div id="status_patches_msg"> - <a href="patch_updates"><%=@update_label%></a> +<div id="status_patches"> + Loading information about patches </div> <br /> <div id="status_health_icon"> @@ -53,3 +58,5 @@ </div> </div> + + -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org