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

Commit 5c7c6d4

Browse files
committed
multiple tweaks to switching server connections
1 parent 74a39f0 commit 5c7c6d4

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

js/main.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,36 +94,48 @@ user.on('change:language', function(md, lang) {
9494
app.serverConfigs = new ServerConfigsCl();
9595
app.serverConfigs.fetch().done(() => {
9696
var oldConfig,
97-
defaultConfig;
97+
defaultConfig,
98+
defaultConfigFlat;
9899

99100
if (!app.serverConfigs.getActive()) {
100101
defaultConfig = app.serverConfigs.create({
101102
name: polyglot.t('serverConnectModal.defaultServerName'),
102103
default: true
103-
})
104+
});
105+
defaultConfigFlat = defaultConfig.toJSON();
104106

105107
// migrate any existing connection from the
106108
// old single config set-up (_serverConfig-1)
107109
if (oldConfig = localStorage['_serverConfig-1']) {
108110
oldConfig = JSON.parse(oldConfig);
109111

110-
app.serverConfigs.setActive(
111-
app.serverConfigs.create(
112-
__.extend(
113-
{},
114-
__.omit(oldConfig, ['local_username', 'local_password', 'id']),
115-
{ name: polyglot.t('serverConnectModal.portedConnectionName') }
116-
)
117-
).id
118-
);
119-
120-
if (oldConfig.local_username && oldConfig.local_password) {
121-
defaultConfig.save({
122-
local_username: oldConfig.local_username,
123-
local_password: oldConfig.local_password
124-
});
112+
// don't create a ported connection if it's the same as the default one
113+
if (
114+
oldConfig.server_ip +
115+
oldConfig.rest_api_port +
116+
oldConfig.api_socket_port +
117+
oldConfig.SSL !==
118+
defaultConfig.get('server_ip') +
119+
defaultConfig.get('rest_api_port') +
120+
defaultConfig.get('api_socket_port') +
121+
defaultConfig.get('SSL')
122+
) {
123+
app.serverConfigs.setActive(
124+
app.serverConfigs.create(
125+
__.extend(
126+
{},
127+
__.omit(oldConfig, ['local_username', 'local_password', 'id']),
128+
{ name: polyglot.t('serverConnectModal.portedConnectionName') }
129+
)
130+
).id
131+
);
125132
}
126133

134+
defaultConfig.save({
135+
username: oldConfig.username,
136+
password: oldConfig.password
137+
});
138+
127139
localStorage.removeItem('_serverConfig-1');
128140
} else {
129141
app.serverConfigs.setActive(defaultConfig.id);
@@ -455,7 +467,7 @@ app.connectHeartbeatSocket();
455467
app.serverConnectModal = new ServerConnectModal().render();
456468
app.serverConnectModal.on('connected', () => {
457469
if (profileLoaded) {
458-
// If we've already loaded called loadProfile() and then, we connect
470+
// If we've already called loadProfile() and then, we connect
459471
// to a new server (or reconnect to the same server) we'll reload the
460472
// app since some of the "global" components (Router, PageNav,
461473
// SocketView...) were not designed to handle a new connection.

js/views/serverConnectModal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,13 @@ module.exports = BaseModal.extend({
280280
loginRequest = app.login().done(function(data) {
281281
if (data.success) {
282282
conclude(false, data);
283+
self.trigger('connected');
283284
} else {
284285
if (data.reason === 'too many attempts') {
285286
conclude(true, 'failed-auth-too-many');
286287
} else {
287288
conclude(true, 'failed-auth');
288289
}
289-
290-
self.trigger('connected', false);
291290
}
292291
}).fail(function(jqxhr) {
293292
if (jqxhr.statusText === 'abort') return;

0 commit comments

Comments
 (0)