Fixed nprogress nesting

This commit is contained in:
Marcin Kurczewski 2014-10-20 20:01:37 +02:00
parent 25080fd977
commit 88dfc0eb96
4 changed files with 42 additions and 10 deletions

View file

@ -106,6 +106,7 @@
<script type="text/javascript" src="/js/Presenters/PagerPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/MessagePresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/HttpErrorPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/ProgressPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/LoginPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/LogoutPresenter.js"></script>

View file

@ -1,6 +1,6 @@
var App = App || {};
App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboard, nprogress) {
App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboard, progress) {
var lastContentPresenter = null;
@ -15,7 +15,7 @@ App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboar
}
function switchContentPresenter(presenter, args) {
nprogress.start();
progress.start();
if (lastContentPresenter === null || lastContentPresenter.name !== presenter.name) {
if (lastContentPresenter !== null && lastContentPresenter.deinit) {
@ -24,10 +24,10 @@ App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboar
keyboard.reset();
topNavigationPresenter.changeTitle(null);
topNavigationPresenter.focus();
presenter.init.call(presenter, args, nprogress.done);
presenter.init.call(presenter, args, progress.done);
lastContentPresenter = presenter;
} else if (lastContentPresenter.reinit) {
lastContentPresenter.reinit.call(lastContentPresenter, args, nprogress.done);
lastContentPresenter.reinit.call(lastContentPresenter, args, progress.done);
}
}
@ -54,4 +54,4 @@ App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboar
};
App.DI.registerSingleton('presenterManager', ['jQuery', 'promise', 'topNavigationPresenter', 'keyboard', 'nprogress'], App.PresenterManager);
App.DI.registerSingleton('presenterManager', ['jQuery', 'promise', 'topNavigationPresenter', 'keyboard', 'progress'], App.PresenterManager);

View file

@ -11,7 +11,7 @@ App.Presenters.PagerPresenter = function(
pager,
messagePresenter,
browsingSettings,
nprogress) {
progress) {
var $target;
var $pageList;
@ -85,11 +85,12 @@ App.Presenters.PagerPresenter = function(
function retrieve() {
messagePresenter.hideMessages($messages);
nprogress.start();
progress.start();
return promise.make(function(resolve, reject) {
promise.wait(pager.retrieve())
.then(function(response) {
progress.done();
updateCallback(response, forceClear || !endlessScroll);
forceClear = false;
if (!response.entities.length) {
@ -107,12 +108,11 @@ App.Presenters.PagerPresenter = function(
attachNextPageLoader();
}
refreshPageList();
nprogress.done();
resolve();
}).fail(function(response) {
progress.done();
clearContent();
hidePageList();
nprogress.done();
messagePresenter.showError($messages, response.json && response.json.error || response);
reject();
@ -223,4 +223,4 @@ App.Presenters.PagerPresenter = function(
};
App.DI.register('pagerPresenter', ['_', 'jQuery', 'util', 'promise', 'keyboard', 'router', 'pager', 'messagePresenter', 'browsingSettings', 'nprogress'], App.Presenters.PagerPresenter);
App.DI.register('pagerPresenter', ['_', 'jQuery', 'util', 'promise', 'keyboard', 'router', 'pager', 'messagePresenter', 'browsingSettings', 'progress'], App.Presenters.PagerPresenter);

View file

@ -0,0 +1,31 @@
var App = App || {};
App.Controls = App.Controls || {};
App.Presenters.ProgressPresenter = function(nprogress) {
var nesting = 0;
function start() {
nesting ++;
if (nesting === 1) {
nprogress.start();
}
}
function done() {
nesting --;
if (nesting === 0) {
nprogress.done();
} else {
nprogress.inc();
}
}
return {
start: start,
done: done,
};
}
App.DI.registerSingleton('progress', ['nprogress'], App.Presenters.ProgressPresenter);