UI will reload on navigation if the backend has been update

pull/4/head
Mark McDowall 11 years ago
parent 541cd0ce19
commit c286f1b18a

@ -29,49 +29,49 @@ define(
addSeries: function (action) {
this.setTitle('Add Series');
AppLayout.mainRegion.show(new AddSeriesLayout({action: action}));
this.showMainRegion(new AddSeriesLayout({action: action}));
},
calendar: function () {
this.setTitle('Calendar');
AppLayout.mainRegion.show(new CalendarLayout());
this.showMainRegion(new CalendarLayout());
},
settings: function (action) {
this.setTitle('Settings');
AppLayout.mainRegion.show(new SettingsLayout({ action: action }));
this.showMainRegion(new SettingsLayout({ action: action }));
},
missing: function () {
this.setTitle('Missing');
AppLayout.mainRegion.show(new MissingLayout());
this.showMainRegion(new MissingLayout());
},
history: function (action) {
this.setTitle('History');
AppLayout.mainRegion.show(new HistoryLayout({ action: action }));
this.showMainRegion(new HistoryLayout({ action: action }));
},
rss: function () {
this.setTitle('RSS');
AppLayout.mainRegion.show(new ReleaseLayout());
this.showMainRegion(new ReleaseLayout());
},
system: function (action) {
this.setTitle('System');
AppLayout.mainRegion.show(new SystemLayout({ action: action }));
this.showMainRegion(new SystemLayout({ action: action }));
},
seasonPass: function () {
this.setTitle('Season Pass');
AppLayout.mainRegion.show(new SeasonPassLayout());
this.showMainRegion(new SeasonPassLayout());
},
update: function () {
this.setTitle('Updates');
AppLayout.mainRegion.show(new UpdateLayout());
this.showMainRegion(new UpdateLayout());
}
});
});

@ -0,0 +1,6 @@
'use strict';
define(function () {
window.onbeforeunload = function () {
window.NzbDrone.unloading = true;
};
});

@ -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:
[

@ -8,7 +8,6 @@ define(
url: window.NzbDrone.ApiRoot + '/system/status'
});
var instance = new StatusModel();
instance.fetch();
return instance;

@ -191,7 +191,8 @@ define(
'Series/SeriesController',
'Router',
'Shared/Modal/Controller',
'Instrumentation/StringFormat'
'Instrumentation/StringFormat',
'LifeCycle'
], function ($, Backbone, Marionette, RouteBinder, SignalRBroadcaster, NavbarView, AppLayout, SeriesController, Router, ModalController) {
new SeriesController();

@ -11,7 +11,8 @@ define(
SeriesAdded : 'series:added',
SeriesDeleted : 'series:deleted',
SeasonRenamed : 'season:renamed',
CommandComplete: 'command:complete'
CommandComplete: 'command:complete',
ServerUpdated : 'server:updated'
};
vent.Commands = {

Loading…
Cancel
Save