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

Commit eef6065

Browse files
committed
on new connection only clearing the connection state of the active connection
1 parent 05eed61 commit eef6065

File tree

2 files changed

+8
-109
lines changed

2 files changed

+8
-109
lines changed

js/main.js

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -398,32 +398,6 @@ launchOnboarding = function(guidCreating) {
398398
});
399399
};
400400

401-
launchServerConnect = function() {
402-
// if (!serverConnectModal) {
403-
// serverConnectModal = new ServerConnectModal();
404-
405-
// serverConnectModal.on('connected', function(authenticated) {
406-
// $loadingModal.removeClass('hide');
407-
408-
// if (authenticated) {
409-
// serverConnectModal && serverConnectModal.remove();
410-
// serverConnectModal = null;
411-
// }
412-
// });
413-
414-
// serverConnectModal.render()
415-
// .open()
416-
// .start();
417-
// } else {
418-
// if (!serverConnectModal.isOpen()) {
419-
// serverConnectModal.open();
420-
// if (!serverConnectModal.isStarted()) serverConnectModal.start();
421-
// }
422-
// }
423-
424-
// !app.serverConnectModal.isOpen() && app.serverConnectModal.open().connect();
425-
};
426-
427401
app.connectHeartbeatSocket();
428402
app.serverConnectModal = new ServerConnectModal().render();
429403
app.serverConnectModal.on('connected', (authenticated) => {
@@ -488,26 +462,17 @@ app.getHeartbeatSocket().on('message', function(e) {
488462
launchOnboarding(guidCreating);
489463
break;
490464
case 'GUID generation complete':
491-
var creds = {
465+
app.serverConfigs.getActive().save({
492466
username: e.jsonData.username,
493467
password: e.jsonData.password
494-
};
495-
496-
if (app.serverConfigs.getActive().isLocalServer()) {
497-
creds.local_username = e.jsonData.username;
498-
creds.local_password = e.jsonData.password;
499-
}
500-
501-
serverConfigMd.save(creds);
468+
});
502469

503470
app.login().done(function() {
504471
guidCreating.resolve();
505472
});
506473

507474
break;
508475
case 'online':
509-
console.log(`1: ${!!loadProfileNeeded}, 2: ${!!guidCreating}`);
510-
511476
if (loadProfileNeeded && !guidCreating) {
512477
loadProfileNeeded = false;
513478

@@ -525,10 +490,8 @@ app.getHeartbeatSocket().on('message', function(e) {
525490
if (__.isEmpty(profile)) {
526491
launchOnboarding(guidCreating = $.Deferred().resolve().promise());
527492
} else {
528-
console.log('bu');
529493
app.serverConnectModal.succeedConnection(app.serverConfigs.getActive());
530494
loadProfile();
531-
console.log('lones');
532495
}
533496
});
534497
} else {

js/views/serverConnectModal.js

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ module.exports = BaseModal.extend({
2020
'click .js-msg-bar-close': 'hideMessageBar'
2121
},
2222

23-
// constructor: function (options) {
24-
// BaseModal.prototype.constructor.call(this,
25-
// __.extend({
26-
// showCloseButton: true
27-
// }, options));
28-
// },
29-
3023
initialize: function(options) {
3124
this.options = options || {};
3225

@@ -46,48 +39,6 @@ module.exports = BaseModal.extend({
4639
this.listenTo(this.serverConfigsVw, 'edit-config', this.onEditConfig);
4740
this.listenTo(this.serverConfigsVw, 'connect', this.onConnectClick);
4841
this.listenTo(this.serverConfigsVw, 'cancel', this.onCancelClick);
49-
50-
// In case connection drops outside of this modal's connect() flow.
51-
app.getHeartbeatSocket().on('close', (e) => {
52-
return;
53-
console.log('close detected');
54-
55-
if (!this.connectAttempt) {
56-
// console.log('you be bringin it straight fleece out style');
57-
this.failConnection(null, this.serverConfigs.getActive());
58-
59-
// !this.isOpen() && this.open();
60-
}
61-
});
62-
63-
$(document).ajaxComplete((this.onAjaxComplete = (e, jqXhr, settings) => {
64-
return;
65-
var failedConfig,
66-
activeConfig;
67-
68-
if (
69-
jqXhr.status === 401 ||
70-
(
71-
settings && settings.url.endsWith('/login') &&
72-
!(jqXhr.responseJSON && jqXhr.responseJSON.success)
73-
)
74-
) {
75-
// auth failed
76-
if (
77-
!this.connectAttempt &&
78-
(failedConfig = this.serverConfigs.get(jqXhr.serverConfig)) &&
79-
(activeConfig = this.serverConfigs.getActive()) &&
80-
activeConfig.id === failedConfig.id
81-
) {
82-
this.failConnection(
83-
jqXhr.responseJSON.reason === 'too many attempts' ?
84-
'failed-auth-too-many' : 'failed-auth',
85-
activeConfig
86-
);
87-
!this.isOpen() && this.open();
88-
}
89-
}
90-
}));
9142
},
9243

9344
remove: function() {
@@ -175,8 +126,6 @@ module.exports = BaseModal.extend({
175126

176127
if (this.connectAttempt && this.connectAttempt.state() === 'pending') return this;
177128

178-
console.log(`gonna succeed ${configMd.get('name')}`);
179-
180129
this.serverConfigsVw.setConnectionState({
181130
id: configMd.id,
182131
status: 'connected'
@@ -196,7 +145,6 @@ module.exports = BaseModal.extend({
196145

197146
var msg;
198147

199-
console.log(`you fail me, but the conny is ${this.connectAttempt ? this.connectAttempt.state() : ' no mo no mo no mo '}`);
200148
if (this.connectAttempt && this.connectAttempt.state() === 'pending') return this;
201149

202150
this.serverConfigsVw.setConnectionState({
@@ -228,36 +176,24 @@ module.exports = BaseModal.extend({
228176
}
229177

230178
this.connectAttempt && this.connectAttempt.cancel();
231-
this.serverConfigs.setActive(configMd.id);
232179
this.hideMessageBar();
233180

234181
this.serverConfigsVw.setConnectionState({
235-
id: configMd.id,
236-
status: 'connecting'
182+
id: this.serverConfigs.getActive().id,
183+
status: 'not-connected'
237184
});
238185

239-
this.serverConfigs.each((md) => {
240-
if (md.id !== configMd.id) {
241-
this.serverConfigsVw.setConnectionState({
242-
id: md.id,
243-
status: 'not-connected'
244-
});
245-
}
186+
this.serverConfigsVw.setConnectionState({
187+
id: configMd.id,
188+
status: 'connecting'
246189
});
247190

248191
this.setModalOptions({ showCloseButton: false });
192+
this.serverConfigs.setActive(configMd.id);
249193

250194
this.connectAttempt = this.attemptConnection().done(() => {
251-
console.log('great success');
252-
253-
// this.serverConfigsVw.setConnectionState({
254-
// id: configMd.id,
255-
// status: 'connected'
256-
// });
257-
258195
this.succeedConnection(configMd);
259196
}).fail((reason) => {
260-
console.log(`yuo be rejected because ${reason}`);
261197
this.failConnection(reason, configMd)
262198
}).always(() => {
263199
this.connectAttempt = null;

0 commit comments

Comments
 (0)