mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-23 22:25:09 -04:00
UI will reload on navigation if the backend has been update
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
'use strict';
|
||||
define(
|
||||
[
|
||||
'vent',
|
||||
'AppLayout',
|
||||
'marionette',
|
||||
'Shared/NotFoundView'
|
||||
], function (AppLayout, Marionette, NotFoundView) {
|
||||
], function (vent, AppLayout, Marionette, NotFoundView) {
|
||||
return Marionette.AppRouter.extend({
|
||||
|
||||
initialize: function () {
|
||||
this.listenTo(vent, vent.Events.ServerUpdated, this._onServerUpdated);
|
||||
},
|
||||
|
||||
showNotFound: function () {
|
||||
this.setTitle('Not Found');
|
||||
AppLayout.mainRegion.show(new NotFoundView(this));
|
||||
this.showMainRegion(new NotFoundView(this));
|
||||
},
|
||||
|
||||
setTitle: function (title) {
|
||||
@@ -19,6 +24,21 @@ define(
|
||||
else {
|
||||
document.title = title + ' - NzbDrone';
|
||||
}
|
||||
},
|
||||
|
||||
_onServerUpdated: function () {
|
||||
this.pendingUpdate = true;
|
||||
},
|
||||
|
||||
showMainRegion: function (view) {
|
||||
if (this.pendingUpdate) {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
else {
|
||||
//AppLayout
|
||||
AppLayout.mainRegion.show(view);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,8 +4,9 @@ define(
|
||||
'vent',
|
||||
'jquery',
|
||||
'Shared/Messenger',
|
||||
'System/StatusModel',
|
||||
'signalR'
|
||||
], function (vent, $, Messenger) {
|
||||
], function (vent, $, Messenger, StatusModel) {
|
||||
return {
|
||||
|
||||
appInitializer: function () {
|
||||
@@ -39,48 +40,61 @@ define(
|
||||
vent.trigger('server:' + message.name, message.body);
|
||||
});
|
||||
|
||||
// this.signalRconnection.reconnecting(function() {
|
||||
// tryingToReconnect = true;
|
||||
//
|
||||
// Messenger.show({
|
||||
// id : messengerId,
|
||||
// type : 'info',
|
||||
// hideAfter : 0,
|
||||
// message : 'Connection to backend lost, attempting to reconnect'
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// this.signalRconnection.reconnected(function() {
|
||||
// tryingToReconnect = false;
|
||||
//
|
||||
// Messenger.show({
|
||||
// id : messengerId,
|
||||
// type : 'success',
|
||||
// hideAfter : 5,
|
||||
// message : 'Connection to backend restored'
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// this.signalRconnection.disconnected(function () {
|
||||
// if (tryingToReconnect) {
|
||||
// $('<div class="modal-backdrop"></div>').appendTo(document.body);
|
||||
//
|
||||
// Messenger.show({
|
||||
// id : messengerId,
|
||||
// type : 'error',
|
||||
// hideAfter : 0,
|
||||
// message : 'Connection to backend lost',
|
||||
// actions : {
|
||||
// cancel: {
|
||||
// label: 'Reload',
|
||||
// action: function() {
|
||||
// window.location.reload();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
this.signalRconnection.reconnecting(function() {
|
||||
if (window.NzbDrone.unloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
tryingToReconnect = true;
|
||||
|
||||
Messenger.show({
|
||||
id : messengerId,
|
||||
type : 'info',
|
||||
hideAfter : 0,
|
||||
message : 'Connection to backend lost, attempting to reconnect'
|
||||
});
|
||||
});
|
||||
|
||||
this.signalRconnection.reconnected(function() {
|
||||
tryingToReconnect = false;
|
||||
|
||||
var currentVersion = StatusModel.get('version');
|
||||
|
||||
var promise = StatusModel.fetch();
|
||||
promise.done(function () {
|
||||
if (StatusModel.get('version') !== currentVersion) {
|
||||
vent.trigger(vent.Events.ServerUpdated);
|
||||
}
|
||||
});
|
||||
|
||||
Messenger.show({
|
||||
id : messengerId,
|
||||
type : 'success',
|
||||
hideAfter : 5,
|
||||
message : 'Connection to backend restored'
|
||||
});
|
||||
});
|
||||
|
||||
this.signalRconnection.disconnected(function () {
|
||||
if (tryingToReconnect) {
|
||||
$('<div class="modal-backdrop"></div>').appendTo(document.body);
|
||||
|
||||
Messenger.show({
|
||||
id : messengerId,
|
||||
type : 'error',
|
||||
hideAfter : 0,
|
||||
message : 'Connection to backend lost',
|
||||
actions : {
|
||||
cancel: {
|
||||
label: 'Reload',
|
||||
action: function() {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.signalRconnection.start({ transport:
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user