Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 2919e59

Browse files
committed
tweaked connection flow
1 parent 9f7167f commit 2919e59

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

js/main.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,14 @@ var loadProfile = function(landingRoute, onboarded) {
399399
$(document).ajaxSend(function(e, jqXhr, settings) {
400400
// With this we could map ajax responses to the server config
401401
// that was active when they were initiated.
402-
jqXhr.serverConfig = app.serverConfigs.getActive().id;
402+
jqXhr.serverConfig = app.serverConfigs.getActive();
403+
});
404+
405+
$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
406+
if (jqxhr.status === 401 && jqxhr.serverConfig.id === app.serverConfigs.getActive().id) {
407+
app.serverConnectModal.failConnection('failed-auth', jqxhr.serverConfig)
408+
.open();
409+
}
403410
});
404411

405412
launchOnboarding = function(guidCreating) {
@@ -447,24 +454,26 @@ pageConnectModal.on('cancel', () => {
447454
app.connectHeartbeatSocket();
448455
app.serverConnectModal = new ServerConnectModal().render();
449456
app.serverConnectModal.on('connected', (authenticated) => {
450-
$loadingModal.removeClass('hide');
451-
452-
if (authenticated) {
453-
profileLoaded && location.reload();
457+
if (profileLoaded) {
458+
// If we've already loaded called loadProfile() and then, we connect
459+
// to a new server (or reconnect to the same server) we'll reload the
460+
// app since some of the "global" components (Router, PageNav,
461+
// SocketView...) were not designed to handle a new connection.
462+
authenticated && location.reload();
463+
} else {
464+
// clear some flags so the heartbeat events will
465+
// appropriatally loadProfile or launch onboarding
466+
guidCreating = null;
467+
loadProfileNeeded = true;
454468
app.serverConnectModal.close();
469+
$loadingModal.removeClass('hide');
455470
}
456471
});
457472

458473
app.getHeartbeatSocket().on('open', function(e) {
459474
removeStartupRetry();
460475
pageConnectModal.remove();
461476
$loadingModal.removeClass('hide');
462-
onboardingModal && onboardingModal.remove();
463-
464-
// clear some flags so the heartbeat events will
465-
// appropriatally loadProfile or launch onboarding
466-
guidCreating = null;
467-
loadProfileNeeded = true;
468477
});
469478

470479
app.getHeartbeatSocket().on('close', (startUpRetry = function(e) {
@@ -518,6 +527,7 @@ app.getHeartbeatSocket().on('message', function(e) {
518527
case 'online':
519528
if (loadProfileNeeded && !guidCreating) {
520529
loadProfileNeeded = false;
530+
onboardingModal && onboardingModal.remove();
521531

522532
app.login().done(function(data) {
523533
if (data.success) {

js/views/pageNavServersVw.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,21 @@ module.exports = BaseVw.extend({
5353
app.serverConnectModal.open();
5454
}).open();
5555

56-
app.serverConnectModal.connect(serverConfig);
57-
// .done(() => {
58-
// alert('im done');
59-
// this.pageConnectModal.remove();
60-
// }).fail(() => {
61-
// alert('ive failed');
62-
// return;
63-
// alert('china town');
64-
// this.pageConnectModal.remove();
65-
// app.serverConnectModal.open();
66-
// });
56+
app.serverConnectModal.connect(serverConfig)
57+
.done(() => {
58+
this.pageConnectModal.remove();
59+
}).fail(() => {
60+
this.pageConnectModal.remove();
61+
app.serverConnectModal.open();
62+
});
6763
},
6864

6965
render: function() {
66+
var connectedServerConfig = app.serverConnectModal.getConnectedServer();
67+
7068
loadTemplate('./js/templates/pageNavServersMenu.html', (t) => {
7169
this.$el.html(t({
72-
connectedServer: this.collection.at(0).id,
70+
connectedServer: connectedServerConfig && connectedServerConfig.id,
7371
servers: this.collection.toJSON()
7472
}));
7573
});

js/views/serverConnectModal.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ module.exports = BaseModal.extend({
129129

130130
if (this.connectAttempt && this.connectAttempt.state() === 'pending') return this;
131131

132-
this.connectedServer = configMd;
132+
this._connectedServer = configMd;
133133

134134
this.serverConfigsVw.setConnectionState({
135135
id: configMd.id,
@@ -151,7 +151,7 @@ module.exports = BaseModal.extend({
151151
var msg;
152152

153153
if (this.connectAttempt && this.connectAttempt.state() === 'pending') return this;
154-
if (this.connectedServer && this.connectedServer.id === configMd.id) this.connectedServer = null;
154+
if (this._connectedServer && this._connectedServer.id === configMd.id) this._connectedServer = null;
155155

156156
this.serverConfigsVw.setConnectionState({
157157
id: configMd.id,
@@ -187,13 +187,13 @@ module.exports = BaseModal.extend({
187187
this.connectAttempt && this.connectAttempt.cancel();
188188
this.hideMessageBar();
189189

190-
if (this.connectedServer) {
190+
if (this._connectedServer) {
191191
this.serverConfigsVw.setConnectionState({
192-
id: this.connectedServer.id,
192+
id: this._connectedServer.id,
193193
status: 'not-connected'
194194
});
195195

196-
this.connectedServer = null;
196+
this._connectedServer = null;
197197
}
198198

199199
this.serverConfigsVw.setConnectionState({
@@ -309,6 +309,10 @@ module.exports = BaseModal.extend({
309309
return promise;
310310
},
311311

312+
getConnectedServer: function() {
313+
return this._connectedServer;
314+
},
315+
312316
close: function() {
313317
this.closeConfigForm();
314318
BaseModal.prototype.close.apply(this, arguments);

0 commit comments

Comments
 (0)