Skip to content

Commit dc8806a

Browse files
rueckstiesskangas
authored andcommitted
connect: improved error handling, layout, labels
1 parent d89c2ac commit dc8806a

File tree

6 files changed

+54
-29
lines changed

6 files changed

+54
-29
lines changed

src/connect/index.jade

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
.page
1+
.page.connect
22
.content.with-sidebar
33
.container-fluid
44
form.form-horizontal
55
.message.alert(style='margin-top: 10px;', data-hook='message')
6-
hr
76
.form-group
87
label.col-sm-2.control-label Hostname
98
.col-sm-10
109
input.form-control(type='text', name='hostname', placeholder='localhost', data-hook='hostname')
1110
.form-group
1211
label.col-sm-2.control-label Port
1312
.col-sm-10
14-
input.form-control(type='number', name='port', placeholder='27017', data-hook='port')
13+
input.form-control(type='number', name='port', placeholder='27017', data-hook='port', min=0)
14+
hr
1515
.form-group
16-
label.col-sm-2.control-label Connection Name (optional)
17-
i.fa.fa-info-circle(tabindex="0", role="button", data-toggle="popover", data-trigger="focus", title="Connection Name", data-content="You can choose a friendly connection name for this connection, for example \"Development Server\". The connection will appear on the left side under this name.")
18-
16+
label.col-sm-2.control-label Save As... (optional)
17+
i.fa.fa-info-circle(tabindex="0", role="button", data-toggle="popover", data-trigger="focus", data-content="You can choose a friendly connection name for this connection, for example \"Development Server\". If you enter a name here, the connection will be saved and appears on the left side.")
1918
.col-sm-10
20-
input.form-control(type='text', name='name', placeholder='My Localhost', data-hook='name')
19+
input.form-control(type='text', name='name', placeholder='Connection Name', data-hook='name')
2120
.form-group
2221
.col-sm-offset-2.col-sm-10
2322
button.btn.btn-primary(type='submit') Connect

src/connect/index.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var ConnectionView = View.extend({
1919
}
2020
},
2121
events: {
22-
click: 'onClick',
22+
'click a': 'onClick',
2323
dblclick: 'onDoubleClick',
2424
mouseover: 'onMouseOver',
2525
mouseout: 'onMouseOut',
@@ -119,37 +119,47 @@ var ConnectView = View.extend({
119119
]
120120
},
121121
events: {
122-
'click .btn-info': 'onInfoClicked',
123122
'input [data-hook=name]': 'onNameChanged',
124123
'input [data-hook=port]': 'onPortChanged',
125124
'input [data-hook=hostname]': 'onHostNameChanged',
126125
'submit form': 'onSubmit'
127126
},
128-
onInfoClicked: function(evt) {
129-
evt.stopPropagation();
130-
// debug('info clicked');
131-
},
132127
onNameChanged: function(evt) {
133128
this.displayedConnection.name = evt.target.value;
134129
},
135130
onPortChanged: function(evt) {
136-
this.displayedConnection.port = parseInt(evt.target.value, 10);
131+
this.displayedConnection.portString = evt.target.value;
137132
},
138133
onHostNameChanged: function(evt) {
139134
this.displayedConnection.hostname = evt.target.value;
140135
},
141136
initialize: function() {
142137
document.title = 'Connect to MongoDB';
138+
this.displayedConnection.set({
139+
name: '',
140+
portString: '',
141+
hostname: ''
142+
});
143143
this.connections.fetch();
144144
},
145145
onSubmit: function(event) {
146146
event.stopPropagation();
147147
event.preventDefault();
148148

149+
// choose default connection values if unset
150+
if (!this.displayedConnection.hostname) {
151+
this.displayedConnection.unset('hostname');
152+
}
153+
if (!this.displayedConnection.portString) {
154+
this.displayedConnection.unset('portString');
155+
}
156+
149157
this.has_error = false;
150158

151159
var existingConnection = this.connections.get(this.displayedConnection.uri);
152-
if (existingConnection && existingConnection.name !== this.displayedConnection.name) {
160+
if (this.displayedConnection.name !== ''
161+
&& existingConnection
162+
&& existingConnection.name !== this.displayedConnection.name) {
153163
// the connection uri (`host:port`) exists already, but under a different name
154164
app.statusbar.hide();
155165
this.has_error = true;
@@ -162,19 +172,20 @@ var ConnectView = View.extend({
162172

163173
// now test if the connection name already exists with another uri
164174
existingConnection = this.connections.get(this.displayedConnection.name, 'name');
165-
if (existingConnection && existingConnection.uri !== this.displayedConnection.uri) {
175+
if (this.displayedConnection.name !== ''
176+
&& existingConnection
177+
&& existingConnection.uri !== this.displayedConnection.uri) {
166178
// the connection name exists already, but with a different uri
167179
app.statusbar.hide();
168180
this.has_error = true;
169-
this.message = format('A different connection with the name "%s" already exists. Please '
181+
this.message = format('Another connection with the name "%s" already exists. Please '
170182
+ 'choose a different name.',
171183
existingConnection.name);
172184
return;
173185
}
174186

175187
// now test if the server is reachable
176188
app.statusbar.show();
177-
this.message = format('Testing connection...');
178189
this.displayedConnection.test(this.onConnectionTested.bind(this));
179190
},
180191
onConnectionTested: function(err, model) {
@@ -184,15 +195,17 @@ var ConnectView = View.extend({
184195
this.message = format('Could not connect to %s, please check that a MongoDB instance '
185196
+ 'is running there.', model.uri);
186197
} else {
187-
model.save();
188-
this.connections.add(model);
189-
this.message = 'Connected!';
198+
if (model.name !== '') {
199+
// only store if the user chose a name to save the connection
200+
model.save();
201+
this.connections.add(model);
202+
}
190203
window.open(format('%s?uri=%s#schema', window.location.origin, model.uri));
191204

192205
setTimeout(this.set.bind(this, {
193206
message: ''
194207
}), 500);
195-
// setTimeout(window.close, 1000);
208+
setTimeout(window.close, 1000);
196209
}
197210
},
198211
render: function() {

src/connect/index.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.connect form {
2+
margin-top: 30px;
3+
}

src/connect/sidebar.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
div
22
.sidebar.panel
33
.panel-heading(style='padding: 10px;')
4-
.panel-title My Connections
4+
.panel-title Saved Connections
55
ul.list-group(data-hook='connection-list', style='top: 32px;')
66

77
.sidebar-bg

src/index.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Components
55
@import "./src/collection-stats/index.less";
6+
@import "./src/connect/index.less";
67
@import "./src/document-list/index.less";
78
@import "./src/field-list/index.less";
89
@import "./src/home/index.less";

src/models/connection.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,37 @@ module.exports = Model.extend({
1616
*/
1717
name: {
1818
type: 'string',
19-
default: 'Local'
19+
default: '',
20+
required: true
2021
},
2122
/**
2223
* Hostname or IP address of the Instance to connect to in the Deployment.
2324
*/
2425
hostname: {
2526
type: 'string',
26-
default: 'localhost'
27+
default: 'localhost',
28+
required: true
2729
},
2830
/**
2931
* Port the Instance to connect to in the Deployment is listening on.
3032
*/
31-
port: {
32-
type: 'number',
33-
default: 27017
33+
portString: {
34+
type: 'string',
35+
default: '27017',
36+
required: true
3437
},
3538
/**
3639
* Updated on each successful connection to the Deployment.
3740
*/
3841
last_used: 'date'
3942
},
4043
derived: {
44+
port: {
45+
deps: ['portString'],
46+
fn: function() {
47+
return parseInt(this.portString, 10);
48+
}
49+
},
4150
uri: {
4251
deps: ['hostname', 'port'],
4352
fn: function() {
@@ -47,7 +56,7 @@ module.exports = Model.extend({
4756
},
4857
use: function(uri) {
4958
var data = types.url(uri).data;
50-
this.port = data.hosts[0].port;
59+
this.portString = '' + data.hosts[0].port;
5160
this.hostname = data.hosts[0].host.toLowerCase();
5261
this.fetch();
5362
},

0 commit comments

Comments
 (0)