Merge pull request #619 from samueldr/feature/lazy_errors

Adds error messages to lazy tabs
This commit is contained in:
Eelco Dolstra 2019-01-20 23:22:17 +01:00 committed by GitHub
commit e0d8dcfe2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View file

@ -237,7 +237,13 @@ sub end : ActionClass('RenderView') {
elsif (scalar @{$c->error}) { elsif (scalar @{$c->error}) {
$c->stash->{resource} = { error => join "\n", @{$c->error} }; $c->stash->{resource} = { error => join "\n", @{$c->error} };
$c->stash->{template} = 'error.tt'; if ($c->stash->{lazy}) {
$c->response->headers->header('X-Hydra-Lazy', 'Yes');
$c->stash->{template} = 'lazy_error.tt';
}
else {
$c->stash->{template} = 'error.tt';
}
$c->stash->{errors} = $c->error; $c->stash->{errors} = $c->error;
$c->response->status(500) if $c->response->status == 200; $c->response->status(500) if $c->response->status == 200;
if ($c->response->status >= 300) { if ($c->response->status >= 300) {

View file

@ -349,9 +349,10 @@ sub dashboard :Chained('dashboard_base') :PathPart('') :Args(0) {
sub my_jobs_tab :Chained('dashboard_base') :PathPart('my-jobs-tab') :Args(0) { sub my_jobs_tab :Chained('dashboard_base') :PathPart('my-jobs-tab') :Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
$c->stash->{lazy} = 1;
$c->stash->{template} = 'dashboard-my-jobs-tab.tt'; $c->stash->{template} = 'dashboard-my-jobs-tab.tt';
die unless $c->stash->{user}->emailaddress; error($c, "No email address is set for this user.") unless $c->stash->{user}->emailaddress;
# Get all current builds of which this user is a maintainer. # Get all current builds of which this user is a maintainer.
$c->stash->{builds} = [$c->model('DB::Builds')->search( $c->stash->{builds} = [$c->model('DB::Builds')->search(

5
src/root/lazy_error.tt Normal file
View file

@ -0,0 +1,5 @@
[% PROCESS common.tt %]
[% FOREACH error IN errors %]
<div class="alert alert-error">[% HTML.escape(error).replace('\n', '<br/>') %]</div>
[% END %]

View file

@ -108,9 +108,13 @@ function makeLazyTab(tabName, uri) {
if (id == '#' + tabName && !tabsLoaded[id]) { if (id == '#' + tabName && !tabsLoaded[id]) {
tabsLoaded[id] = 1; tabsLoaded[id] = 1;
$('#' + tabName).load(uri, function(response, status, xhr) { $('#' + tabName).load(uri, function(response, status, xhr) {
if (status == "error") { var lazy = xhr.getResponseHeader("X-Hydra-Lazy") === "Yes";
if (status == "error" && !lazy) {
$('#' + tabName).html("<div class='alert alert-error'>Error loading tab: " + xhr.status + " " + xhr.statusText + "</div>"); $('#' + tabName).html("<div class='alert alert-error'>Error loading tab: " + xhr.status + " " + xhr.statusText + "</div>");
} }
else {
$('#' + tabName).html(response);
}
}); });
} }
}); });