Mailinglist Archive: yast-commit (1771 mails)

< Previous Next >
[yast-commit] <web-client> master : Error handling improved
  • From: Duncan Mac-Vicar P <dmacvicar@xxxxxxx>
  • Date: Tue, 1 Sep 2009 16:21:44 +0200
  • Message-id: <E1MiUGW-0007MK-DT@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 993389704da3c72b43754ac3cbc2bd8bbd35dda0
Author: Duncan Mac-Vicar P <dmacvicar@xxxxxxx>
Date: Tue Sep 1 16:21:44 2009 +0200

Error handling improved

See http://en.opensuse.org/YaST/Web/Development/Error_Handling
for more information.

New features:
- unhandled ajax errors are displayed in the standard flash messages
facility, using standard jquery.ui styles
- provide helper report_error to put an exception into the flash
message area
- popup to examine backtrace and copy to clipboard facility
---
.../app/controllers/patch_updates_controller.rb | 10 +-
.../views/patch_updates/_patch_summary.html.erb | 9 +-
.../app/controllers/application_controller.rb | 2 +-
webclient/app/helpers/view_helpers/html_helper.rb | 100 ++++++++++++++++++++
webclient/app/views/controlpanel/index.rhtml | 4 +
webclient/app/views/layouts/main.rhtml | 33 +++++--
.../app/views/shared/_exception_trap.html.erb | 34 +-------
webclient/app/views/shared/exception_trap.html.erb | 10 +-
webclient/public/flash/clippy.swf | Bin 0 -> 5380 bytes
webclient/public/stylesheets/style.css | 13 +++
10 files changed, 158 insertions(+), 57 deletions(-)

diff --git a/plugins/patch_updates/app/controllers/patch_updates_controller.rb
b/plugins/patch_updates/app/controllers/patch_updates_controller.rb
index 02623fe..ce42430 100644
--- a/plugins/patch_updates/app/controllers/patch_updates_controller.rb
+++ b/plugins/patch_updates/app/controllers/patch_updates_controller.rb
@@ -14,10 +14,12 @@ class PatchUpdatesController < ApplicationController

# this action is rendered as a partial, so it can't throw
def show_summary
+ error = nil
patch_updates = nil
begin
patch_updates = load_proxy 'org.opensuse.yast.system.patches', :all
- rescue
+ rescue Exception => e
+ error = e
patch_updates = nil
end

@@ -36,11 +38,9 @@ class PatchUpdatesController < ApplicationController
end

respond_to do |format|
- format.html { render :partial => "patch_summary", :locals => { :patch =>
patches_summary } }
+ format.html { render :partial => "patch_summary", :locals => { :patch =>
patches_summary, :error => error } }
format.json { render :json => patches_summary }
- end
-
-
+ end
end

def load_filtered
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
index de7d9fb..88e3bde 100644
--- a/plugins/patch_updates/app/views/patch_updates/_patch_summary.html.erb
+++ b/plugins/patch_updates/app/views/patch_updates/_patch_summary.html.erb
@@ -1,8 +1,9 @@
-<div class="status_patches">
- <% unless patch %>
- <div class="status-icon warning"></div>
- <%= _("An error occured when loading patch information.") %>
+<%= report_error(error, _("An error occured when loading patch information."))
if error %>

+<div class="status_patches">
+ <% unless patch %>
+ <div class="status-icon warning"></div>
+ <%= _("No information about patches available") %>
<% else %>
<% link_to "patch_updates" do %>
<% if patch[:security]+patch[:important] > 0 %>
diff --git a/webclient/app/controllers/application_controller.rb
b/webclient/app/controllers/application_controller.rb
index d66d802..cfe4e97 100644
--- a/webclient/app/controllers/application_controller.rb
+++ b/webclient/app/controllers/application_controller.rb
@@ -29,7 +29,7 @@ class ApplicationController < ActionController::Base
begin
settings_url =
YaST::ServiceResource::Session.site.merge("/vendor_settings/bugzilla_url.json")
@bug_url = ActiveSupport::JSON.decode(open(settings_url).read)
- rescue Exception => e
+ rescue Exception => vendor_excp
@bug_url =
"https://bugzilla.novell.com/enter_bug.cgi?classification=7340&product=openSUSE+11.2&submit=Use+This+Product&component=WebYaST&format=guided";
# there was a problem or the setting does not exist
# Here we should handle this always as an error
diff --git a/webclient/app/helpers/view_helpers/html_helper.rb
b/webclient/app/helpers/view_helpers/html_helper.rb
index 6fbce27..f02a7a7 100644
--- a/webclient/app/helpers/view_helpers/html_helper.rb
+++ b/webclient/app/helpers/view_helpers/html_helper.rb
@@ -91,6 +91,106 @@ module ViewHelpers::HtmlHelper
return ret
end

+ # clipboard icon for a predefined text
+ def clippy(text, bgcolor='#FFFFFF')
+ html = <<-EOF
+ <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
+ width="110"
+ height="14"
+ id="clippy" >
+ <param name="movie" value="/flash/clippy.swf"/>
+ <param name="allowScriptAccess" value="always" />
+ <param name="quality" value="high" />
+ <param name="scale" value="noscale" />
+ <param NAME="FlashVars" value="text=#{text}">
+ <param name="bgcolor" value="#{bgcolor}">
+ <embed src="/flash/clippy.swf"
+ width="110"
+ height="14"
+ name="clippy"
+ quality="high"
+ allowScriptAccess="always"
+ type="application/x-shockwave-flash"
+ pluginspage="http://www.macromedia.com/go/getflashplayer";
+ FlashVars="text=#{text}"
+ bgcolor="#{bgcolor}"
+ />
+ </object>
+ EOF
+ end
+
+ # report an exception to the flash messages zone
+ # a flash error message will be appended to the
+ # element with id "flashes" with standard jquery
+ # ui styles. A link with more information that
+ # display a popup is also automatically created
+ def report_error(error, message=nil)
+ # get the id of the error, or use a random id
+ error_id = error.nil? ? rand(10000) : error.object_id
+ # get the backtrace, or create a message saying there is none
+ backtrace_text = (error.nil? || error.backtrace.nil? ||
error.backtrace.blank?) ? "No information available" :
error.backtrace.join("\n")
+
+ # the summary message
+ if message.nil?
+ message = "There was a problem retrieving information from the server."
+ end
+
+ # build the html
+ html =<<-EOF2
+ <div id="error-#{error_id}-content">
+ <div>
+ <p><strong>Error message:</strong>#{error.message}</p>
+ <p><a href="#{@bug_url}">Report bug</a></p>
+ <p><a href="#" id="error-#{error_id}-show-backtrace-link">Show
details</a>#{clippy(backtrace_text)}</p></p>
+ <pre id="error-#{error_id}-backtrace" style="display: none">
+ #{backtrace_text}
+ </pre>
+ </div>
+ </div>
+
+ <div class="ui-state-error ui-corner-all" style="margin-top: 20px;
padding: 0 .7em;" id="error-#{error_id}-summary">
+ <p><span class="ui-icon ui-icon-alert"/>#{message} (<a href="#"
id="error-#{error_id}-details-link">more..</a>)</p>
+ </div>
+
+ <script type="text/javascript">
+ $(document).ready(
+ function() {
+ //$('#error-#{error_id}-summary').hide();
+
+ // hide the exception details
+ $('#error-#{error_id}-content').hide();
+
+ // put the error summary with the other flashes
+ // and not where the output should go
+ $('#flash-messages').prepend($('#error-#{error_id}-summary'));
+
+ //$('#error-#{error_id}-content').show();
+
+ // define a dialog with the error details
+ $('#error-#{error_id}-content').dialog(
+ {
+ bgiframe: true,
+ autoOpen: false,
+ height: 300,
+ modal: true
+ });
+
+ // make the More link to open the dialog with details
+ $('#error-#{error_id}-details-link').click( function() {
+ $('#error-#{error_id}-content').dialog('open');
+ });
+
+ // make the Show details links show the backtrace
+ $('#error-#{error_id}-show-backtrace-link').click(function() {
+ $('#error-#{error_id}-backtrace').hide();
+ $('#error-#{error_id}-backtrace').show();
+ return false;
+ });
+ });
+ </script>
+EOF2
+ end
+
end

# vim: ft=ruby
diff --git a/webclient/app/views/controlpanel/index.rhtml
b/webclient/app/views/controlpanel/index.rhtml
index da28c60..5e4ea21 100644
--- a/webclient/app/views/controlpanel/index.rhtml
+++ b/webclient/app/views/controlpanel/index.rhtml
@@ -1,4 +1,8 @@
+
+<% content_for :head do %>
<%= javascript_include_tag :defaults %>
+<% end %>
+
<% if ActionController::Routing.possible_controllers.include?("patch_updates")
%>
<% javascript_tag do -%>
$(document).ready( function() {
diff --git a/webclient/app/views/layouts/main.rhtml
b/webclient/app/views/layouts/main.rhtml
index 44141ac..b8e78a2 100644
--- a/webclient/app/views/layouts/main.rhtml
+++ b/webclient/app/views/layouts/main.rhtml
@@ -9,7 +9,6 @@
<link rel="stylesheet" href="/stylesheets/jquery.jqplot.css" type="text/css"
media="screen" title="default" charset="utf-8" />
<link rel="stylesheet" href="/stylesheets/jquery-ui-1.7.2.custom.css"
type="text/css" media="screen" title="default" charset="utf-8" />

-
<script type="text/javascript" charset="utf-8" src="/inc/jquery.js"></script>
<script type="text/javascript" charset="utf-8"
src="/inc/jquery.query.js"></script>
<script type="text/javascript" charset="utf-8"
src="/inc/jquery.timers.js"></script>
@@ -30,7 +29,6 @@
<script type="text/javascript" charset="utf-8"
src="/inc/shortcut.js"></script>
<script type="text/javascript" charset="utf-8"
src="/inc/yast.widgets.js"></script>
<script type="text/javascript" charset="utf-8"
src="/inc/yast.helpers.js"></script>
-
<!-- custom page scripts and css -->
<%= yield :head %>

@@ -63,18 +61,33 @@
</div>

<div id="content" class="content">
+ <!-- here both flash and dynamic notifications should be added -->
+ <div id="flash-messages">
<!-- show the flash messages -->
- <% [:error, :warning, :notice, :message].each do |name| %>
- <% if flash[name] %>
- <%= "<div class=\"notifications\"
id=\"#{name}\">#{flash[name]}</div>" %>
- <% flash.delete name -%>
- <% end %>
- <% end %>

- <div id="progress" style="display:none;">
- <%= image_tag("/images/working.gif") %><%=_("...Wait...")%>
+ <% flash.each do |flash_type, message| %>
+ <%
+ flash_icon = case flash_type
+ when :error then "ui-icon-alert"
+ else "ui-icon-info"
+ end
+ flash_style = case flash_type
+ when :error then "ui-state-error"
+ else "ui-state-highlight"
+ end
+ %>
+
+ <div class="flash-message <%= flash_style %> ui-corner-all"
style="margin-top: 20px; padding: .7em;">
+ <p><span class="ui-icon <%= flash_icon %>" style="float: left;
margin-right: .3em;"></span><strong><%= message %></strong></p>
</div>
+ <% flash.delete flash_type -%>
+ <% end %>
+ </div> <!-- flash messages -->

+ <div id="progress" style="display:none;">
+ <%= image_tag("/images/working.gif") %><%=_("...Wait...")%>
+ </div>
+
<%= yield %>
</div>

diff --git a/webclient/app/views/shared/_exception_trap.html.erb
b/webclient/app/views/shared/_exception_trap.html.erb
index be67075..bd0d9c5 100644
--- a/webclient/app/views/shared/_exception_trap.html.erb
+++ b/webclient/app/views/shared/_exception_trap.html.erb
@@ -1,36 +1,4 @@

-<% error_id = error.nil? ? rand(10000) : error.object_id %>
+<%= report_error(error) %>

-<script type="text/javascript">
-$(document).ready(
- function() {
- $('#error-<%= error_id %>-balloon-content').hide();
- $('#error-<%= error_id %>-balloon-content').dialog(
- {
- bgiframe: true,
- autoOpen: false,
- height: 300,
- modal: true
- });
-
- $('#error-<%= error_id %>-details-link').click( function() {
- $('#error-<%= error_id %>-balloon-content').dialog('open');
- });
- $('#error-<%= error_id %>-show-backtrace-link').click(function() {
$('#error-<%= error_id %>-backtrace').hide();$('#error-<%= error_id
%>-backtrace').show();return false; });
- });
-
-</script>
-
-<div id="error-<%= error_id %>-balloon-content">
- <p><strong>Error message:</strong>: <%= error.message %></p>
- <p><a href="<%= @bug_url %>">Report bug</a></p>
- <p><a href="#" id="error-<%= error_id %>-show-backtrace-link">Show
details</a>
- <pre id="error-<%= error_id %>-backtrace" style="display: none"><%=
(error.nil? || error.backtrace.nil? || error.backtrace.blank?) ? "No
information available" : error.backtrace.join("\n") %></pre>
-</div>
-
-<div class="status-icon error"></div><div>There was a problem retrieving the
information (<a href="#" id="error-<%= error_id
%>-details-link">more..</a>)</div>
-
-<pre id="backtrace-<%= error_id %>" style="display: none">
-<%= (error.nil? || error.backtrace.nil? || error.backtrace.blank?) ? "No
information available" : error.backtrace.join("\n") %>
-</pre>

diff --git a/webclient/app/views/shared/exception_trap.html.erb
b/webclient/app/views/shared/exception_trap.html.erb
index e79d7ee..50ff941 100644
--- a/webclient/app/views/shared/exception_trap.html.erb
+++ b/webclient/app/views/shared/exception_trap.html.erb
@@ -1,7 +1,7 @@

<script type="text/javascript">
$(document).ready(function() {
- $('#details-link').click(function() {
$('#backtrace').hide();$(this).next().show();return false; });
+ $('#details-link').click(function() {
$('#backtrace').hide();$('#backtrace').show();return false; });
});
</script>

@@ -9,16 +9,18 @@ $(document).ready(function() {

<p>We are sorry, but WebYaST is still in alpha and there are some problems.</p>

-<h2>Error Message:</h2>
+<h3>Problem:</h3>

<p><pre><%= h error.to_s %></pre></p>

<p>Please <a href="<%= @bug_url %>">Report a bug so we can fix the
problem!.</a> Don't forget to include the bug details.</p>

-<a href="#" id="details-link">Show details...</a>
+<% backtrace = (error.nil? || error.backtrace.nil? || error.backtrace.blank?)
? _("No information available") : error.backtrace.join("\n") %>
+
+<p><a href="#" id="details-link">Show details...</a><%= clippy(backtrace) %><p>

<pre id="backtrace" style="display: none">
-<%= (error.nil? || error.backtrace.nil? || error.backtrace.blank?) ? "No
information available" : error.backtrace.join("\n") %>
+<%= backtrace %>
</pre>


diff --git a/webclient/public/flash/clippy.swf
b/webclient/public/flash/clippy.swf
new file mode 100644
index 0000000..e46886c
Binary files /dev/null and b/webclient/public/flash/clippy.swf differ
diff --git a/webclient/public/stylesheets/style.css
b/webclient/public/stylesheets/style.css
index 0e094e3..bbb8ab5 100644
--- a/webclient/public/stylesheets/style.css
+++ b/webclient/public/stylesheets/style.css
@@ -446,3 +446,16 @@ th.checkbox {
text-align: center;
}

+.clipboard {
+ display: block;
+ width: 14px;
+ height: 14px;
+ background: transparent url(images/clipboard/button_up.png) no-repeat scroll
0 0;
+ float: left;
+}
+.clipboard:hover {
+ background: transparent url(images/clipboard/button_over.png) no-repeat
scroll 0 0;
+}
+.clipboard:active {
+ background: transparent url(images/clipboard/button_down.png) no-repeat
scroll 0 0;
+}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages