From fd40613d8ebae128ef72576ff6243fe2da37b06a Mon Sep 17 00:00:00 2001 From: m3ntalsp00n Date: Sat, 4 Feb 2017 15:47:09 +1000 Subject: [PATCH 1/3] showUpdate funciton allows updated messages Signed-off-by: m3ntalsp00n --- core/js/js.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/core/js/js.js b/core/js/js.js index 3651635541a..0576dcc3357 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -780,8 +780,18 @@ var OCP = {}, // sometimes "beforeunload" happens later, so need to defer the reload a bit setTimeout(function() { if (!self._userIsNavigatingAway && !self._reloadCalled) { - OC.Notification.show(t('core', 'Problem loading page, reloading in 5 seconds')); - setTimeout(OC.reload, 5000); + var timer = 0; + var seconds = 5; + var interval = setInterval( function() { + OC.Notification.showUpdate(t('core', 'Problem loading page, reloading in ' + (seconds - timer) + ' seconds')); + if (timer >= seconds) { + clearInterval(interval); + OC.reload(); + } + timer++; + }, 1000 // 1 second interval + ); + // only call reload once self._reloadCalled = true; } @@ -1173,6 +1183,30 @@ OC.Notification={ return this.showHtml($('
').text(text).html(), options); }, + /** + * Updates (replaces) a sanitized notification. + * + * @param {string} text Message to display + * @return {jQuery} JQuery element for notificaiton row + */ + showUpdate: function(text) { + var $notification = $('#notification'); + // sanitise + var $html = $('
').text(text).html(); + + // new notification + if (text && $notification.find('.row').length == 0) { + return this.showHtml($html); + } + + var $row = $('
').prepend($html); + + // just update html in notification + $notification.html($row); + + return $row; + }, + /** * Shows a notification that disappears after x seconds, default is * 7 seconds From dd9ee2db6f981d0a1f1623af831b3eb2239a5990 Mon Sep 17 00:00:00 2001 From: m3ntalsp00n Date: Sat, 4 Feb 2017 18:51:52 +1000 Subject: [PATCH 2/3] fix tests, longer wait time, update notification stub Signed-off-by: m3ntalsp00n --- core/js/tests/specs/coreSpec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index d83c0cd9a38..3380b6be420 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -1000,7 +1000,7 @@ describe('Core base tests', function() { describe('global ajax errors', function() { var reloadStub, ajaxErrorStub, clock; var notificationStub; - var waitTimeMs = 6000; + var waitTimeMs = 6500; var oldCurrentUser; beforeEach(function() { @@ -1075,10 +1075,12 @@ describe('Core base tests', function() { it('displays notification', function() { var xhr = { status: 401 }; + notificationUpdateStub = sinon.stub(OC.Notification, 'showUpdate'); + $(document).trigger(new $.Event('ajaxError'), xhr); clock.tick(waitTimeMs); - expect(notificationStub.calledOnce).toEqual(true); + expect(notificationUpdateStub.notCalled).toEqual(false); }); it('shows a temporary notification if the connection is lost', function() { var xhr = { status: 0 }; From 01963b4d7226c1768d3f95dc75eb01ed715706c2 Mon Sep 17 00:00:00 2001 From: m3ntalsp00n Date: Wed, 8 Feb 2017 16:55:31 +1000 Subject: [PATCH 3/3] Fix indentation and l10n compliance. Signed-off-by: m3ntalsp00n --- core/js/js.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/js/js.js b/core/js/js.js index 0576dcc3357..5ef5c72f625 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -783,11 +783,11 @@ var OCP = {}, var timer = 0; var seconds = 5; var interval = setInterval( function() { - OC.Notification.showUpdate(t('core', 'Problem loading page, reloading in ' + (seconds - timer) + ' seconds')); + OC.Notification.showUpdate(n('core', 'Problem loading page, reloading in %n second', 'Problem loading page, reloading in %n seconds', seconds - timer)); if (timer >= seconds) { - clearInterval(interval); + clearInterval(interval); OC.reload(); - } + } timer++; }, 1000 // 1 second interval );