mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
Merge pull request #1453 from nextcloud/do-not-reload-if-connection-lost
do not reload the page if the server is (temporarily) unreachable
This commit is contained in:
commit
6d688e89c1
2 changed files with 29 additions and 2 deletions
|
|
@ -729,6 +729,17 @@ var OC={
|
|||
return oc_isadmin;
|
||||
},
|
||||
|
||||
/**
|
||||
* Warn users that the connection to the server was lost temporarily
|
||||
*
|
||||
* This function is throttled to prevent stacked notfications.
|
||||
* After 7sec the first notification is gone, then we can show another one
|
||||
* if necessary.
|
||||
*/
|
||||
_ajaxConnectionLostHandler: _.throttle(function() {
|
||||
OC.Notification.showTemporary(t('core', 'Connection to server lost'));
|
||||
}, 7 * 1000, {trailing: false}),
|
||||
|
||||
/**
|
||||
* Process ajax error, redirects to main page
|
||||
* if an error/auth error status was returned.
|
||||
|
|
@ -742,7 +753,7 @@ var OC={
|
|||
return;
|
||||
}
|
||||
|
||||
if (_.contains([0, 302, 303, 307, 401], xhr.status)) {
|
||||
if (_.contains([302, 303, 307, 401], xhr.status)) {
|
||||
// sometimes "beforeunload" happens later, so need to defer the reload a bit
|
||||
setTimeout(function() {
|
||||
if (!self._userIsNavigatingAway && !self._reloadCalled) {
|
||||
|
|
@ -752,6 +763,13 @@ var OC={
|
|||
self._reloadCalled = true;
|
||||
}
|
||||
}, 100);
|
||||
} else if(xhr.status === 0) {
|
||||
// Connection lost (e.g. WiFi disconnected or server is down)
|
||||
setTimeout(function() {
|
||||
if (!self._userIsNavigatingAway && !self._reloadCalled) {
|
||||
self._ajaxConnectionLostHandler();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -924,7 +924,7 @@ describe('Core base tests', function() {
|
|||
var dataProvider = [
|
||||
[200, false],
|
||||
[400, false],
|
||||
[0, true],
|
||||
[0, false],
|
||||
[401, true],
|
||||
[302, true],
|
||||
[303, true],
|
||||
|
|
@ -979,5 +979,14 @@ describe('Core base tests', function() {
|
|||
clock.tick(waitTimeMs);
|
||||
expect(notificationStub.calledOnce).toEqual(true);
|
||||
});
|
||||
it('shows a temporary notification if the connection is lost', function() {
|
||||
var xhr = { status: 0 };
|
||||
spyOn(OC, '_ajaxConnectionLostHandler');
|
||||
|
||||
$(document).trigger(new $.Event('ajaxError'), xhr);
|
||||
clock.tick(101);
|
||||
|
||||
expect(OC._ajaxConnectionLostHandler.calls.count()).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue