Skip to content

Commit 371933b

Browse files
committed
Merge pull request #203 from 10gen/INT-780-save-ssl-cert-paths
INT-780 save ssl cert paths, removing debug msgs
2 parents d6d2bb7 + 176941e commit 371933b

File tree

10 files changed

+210
-79
lines changed

10 files changed

+210
-79
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"ampersand-collection-filterable": "^0.2.1",
8989
"ampersand-collection-lodash-mixin": "^2.0.1",
9090
"ampersand-collection-rest-mixin": "^5.0.0",
91+
"ampersand-dom-bindings": "^3.7.0",
9192
"ampersand-filtered-subcollection": "^2.0.4",
9293
"ampersand-form-view": "^5.1.1",
9394
"ampersand-input-view": "^5.0.0",

src/connect/behavior.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
var State = require('ampersand-state');
2-
var debug = require('debug')('scout:connect:behavior');
32
var assert = require('assert');
43
var Connection = require('../models/connection');
54
var _ = require('lodash');
65

6+
// var debug = require('debug')('scout:connect:behavior');
7+
78
module.exports = State.extend({
89
props: {
910
view: 'any',
@@ -79,9 +80,9 @@ module.exports = State.extend({
7980
},
8081
dispatch: function(action) {
8182
var newState = this.reduce(this.state, action);
82-
if (newState !== this.state) {
83-
debug('transition: (%s, %s) ==> %s', this.state, action, newState);
84-
}
83+
// if (newState !== this.state) {
84+
// debug('transition: (%s, %s) ==> %s', this.state, action, newState);
85+
// }
8586
this.state = newState;
8687
return this.state;
8788
},
@@ -100,7 +101,7 @@ module.exports = State.extend({
100101

101102
// check if the current state allows the given action
102103
if (this.validTransitions[state].indexOf(action) === -1) {
103-
debug('ignoring action `%s` in state `%s`', action, state);
104+
// debug('ignoring action `%s` in state `%s`', action, state);
104105
return state;
105106
}
106107
// general actions, independent of state

src/connect/connect-form-view.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var SelectView = require('ampersand-select-view');
44
var authOptions = require('./authentication');
55
var sslOptions = require('./ssl');
66
var FilteredCollection = require('ampersand-filtered-subcollection');
7-
var debug = require('debug')('scout:connect:connect-form-view');
7+
// var debug = require('debug')('scout:connect:connect-form-view');
88

99

1010
require('bootstrap/js/popover');
@@ -66,7 +66,6 @@ var ConnectFormView = FormView.extend({
6666
return;
6767
}
6868
var name = obj.hostname + ':' + obj.port;
69-
debug('obj', obj);
7069
if (obj.authentication === 'MONGODB') {
7170
if (obj.mongodb_username) {
7271
name = obj.mongodb_username + '@' + name;
@@ -189,7 +188,7 @@ var ConnectFormView = FormView.extend({
189188
el: this.parent.queryByHook('saveas-subview'),
190189
name: 'name',
191190
label: 'Name',
192-
placeholder: 'e.g. Shared Dev, Stats Box, PRODUCTION',
191+
placeholder: 'e.g. Shared Dev, QA Box, PRODUCTION',
193192
required: false
194193
})
195194
];

src/connect/filereader-default.jade

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
.message.message-below.message-error(data-hook='message-container')
44
p(data-hook='message-text')
55
.form-item-file
6-
input(type="file", name="uploadKeyFile", multiple)
6+
.btn.btn-default(data-hook='load-file-button', style='text-transform: none;')
7+
i.fa.fa-file
8+
|  
9+
span(data-hook='button-label')= buttonTitle

src/connect/filereader-view.js

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
var InputView = require('./input-view');
2+
var _ = require('lodash');
3+
var path = require('path');
4+
var remote = window.require('remote');
5+
var dialog = remote.require('dialog');
6+
var format = require('util').format;
7+
var bindings = require('ampersand-dom-bindings');
8+
var fileReaderTemplate = require('./filereader-default.jade');
9+
10+
// var debug = require('debug')('scout:connect:filereader-view');
11+
12+
module.exports = InputView.extend({
13+
template: fileReaderTemplate,
14+
props: {
15+
inputValue: {
16+
type: 'array',
17+
required: true,
18+
default: function() {
19+
return [];
20+
}
21+
},
22+
removed: {
23+
type: 'boolean',
24+
required: true,
25+
default: false
26+
}
27+
},
28+
derived: {
29+
buttonTitle: {
30+
deps: ['inputValue'],
31+
fn: function() {
32+
if (this.inputValue.length === 0) {
33+
return 'Choose certificate(s)';
34+
} else if (this.inputValue.length === 1) {
35+
return path.basename(this.inputValue[0]);
36+
}
37+
return format('%d files selected', this.inputValue.length);
38+
}
39+
},
40+
numSelectedFiles: {
41+
deps: ['inputValue'],
42+
fn: function() {
43+
return this.inputValue.length;
44+
}
45+
}
46+
},
47+
events: {
48+
'click [data-hook=load-file-button]': 'loadFileButtonClicked'
49+
},
50+
bindings: {
51+
buttonTitle: {
52+
type: 'text',
53+
hook: 'button-label'
54+
},
55+
'label': [
56+
{
57+
hook: 'label'
58+
},
59+
{
60+
type: 'toggle',
61+
hook: 'label'
62+
}
63+
],
64+
'message': {
65+
type: 'text',
66+
hook: 'message-text'
67+
},
68+
'showMessage': {
69+
type: 'toggle',
70+
hook: 'message-container'
71+
}
72+
},
73+
/**
74+
* Set value to empty array in spec, instead of '', set appropriate
75+
* invalidClass and validityClassSelector and always validate.
76+
* @param {Object} spec the spec to set up this input view
77+
*/
78+
initialize: function(spec) {
79+
spec = spec || {};
80+
_.defaults(spec, {value: []});
81+
this.invalidClass = 'has-error';
82+
this.validityClassSelector = '.form-item-file';
83+
InputView.prototype.initialize.call(this, spec);
84+
},
85+
/**
86+
* @todo (thomasr)
87+
* Because ampersand-input-view still uses [email protected] where
88+
* the render/remove/render cycle doesn't correctly set up the bindings
89+
* again, we need to re-initialize the bindings manually here. Once they
90+
* upgrade to [email protected] we can probably remove this entire
91+
* render method.
92+
*
93+
* @return {Object} this
94+
*/
95+
render: function() {
96+
this.renderWithTemplate(this);
97+
this.input = this.queryByHook('load-file-button');
98+
if (this.removed) {
99+
this._parsedBindings = bindings(this.bindings, this);
100+
this._initializeBindings();
101+
this.removed = false;
102+
}
103+
this.setValue(this.inputValue, !this.required);
104+
return this;
105+
},
106+
/**
107+
* Turn into no-op, as we don't work on input elements
108+
* @see ampersand-input-view.js#handleTypeChange
109+
*/
110+
handleTypeChange: function() {
111+
},
112+
/**
113+
* Turn into identity, as we don't need to trim the value
114+
* @param {Array} val the value to pass through
115+
* @return {Array} return the unchanged value
116+
*/
117+
clean: function(val) {
118+
return val;
119+
},
120+
/**
121+
* Turn into no-op, as we don't work on input elements
122+
* @see ampersand-input-view.js#initInputBindings
123+
*/
124+
// initInputBindings: function() {
125+
// },
126+
/**
127+
* Only call ampersand-view's remove, we don't need to remove event listeners
128+
* @see ampersand-input-view.js#remove
129+
*/
130+
remove: function() {
131+
this.removed = true;
132+
InputView.prototype.remove.apply(this, arguments);
133+
},
134+
/**
135+
* Not setting this.input.value here because our this.input is a div
136+
* @param {Array} value the value to assign to this.inputValue
137+
* @param {Boolean} skipValidation whether it should be validated or not
138+
* @see ampersand-input-view.js#setValue
139+
*/
140+
setValue: function(value, skipValidation) {
141+
this.inputValue = value;
142+
if (!skipValidation && !this.getErrorMessage()) {
143+
this.shouldValidate = true;
144+
} else if (skipValidation) {
145+
this.shouldValidate = false;
146+
}
147+
},
148+
/**
149+
* Need to change the value empty check to empty arrays instead
150+
* @return {String} error message
151+
* @see ampersand-input-view.js#getErrorMessage
152+
*/
153+
getErrorMessage: function() {
154+
var message = '';
155+
if (this.required && this.value.length === 0) {
156+
return this.requiredMessage;
157+
}
158+
(this.tests || []).some(function(test) {
159+
message = test.call(this, this.value) || '';
160+
return message;
161+
}, this);
162+
return message;
163+
},
164+
/**
165+
* Don't access this.input.value as we don't work on input elements
166+
* @see ampersand-input-view.js#beforeSubmit
167+
*/
168+
beforeSubmit: function() {
169+
// at the point where we've tried to submit, we want to validate
170+
// everything from now on.
171+
this.shouldValidate = true;
172+
this.runTests();
173+
},
174+
loadFileButtonClicked: function() {
175+
dialog.showOpenDialog({
176+
properties: ['openFile', 'multiSelections']
177+
}, function(filenames) {
178+
this.inputValue = filenames || [];
179+
this.handleChange();
180+
}.bind(this));
181+
}
182+
});

src/connect/index.jade

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
- if (!method.enabled) classNames.push('hidden')
2222
- if (i === 0) classNames.push('active')
2323
div(class=classNames, id='auth-#{method._id}')
24-
24+
25+
hr
26+
2527
div(data-hook='sslselect-subview')
2628

2729
- for method, i in sslMethods

src/connect/index.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ var ConnectView = View.extend({
9494
'input input[name=name]': 'onNameInputChanged',
9595
'change input[name=name]': 'onNameInputChanged',
9696
'input input': 'onAnyInputChanged',
97-
'change select': 'onAnyInputChanged'
97+
'change input': 'onAnyInputChanged',
98+
'change select': 'onAnyInputChanged',
99+
'click div.btn': 'onAnyInputChanged'
98100
},
99101

100102
/**
@@ -292,14 +294,8 @@ var ConnectView = View.extend({
292294
*/
293295
updateConnection: function() {
294296
if (this.connection) {
295-
debug('updating existing connection from form data');
296-
// set previous auth fields
297-
var authFields = Connection.getFieldNames(this.previousAuthMethod);
298-
debug('authFields', authFields);
299297
this.connection.set(this.form.data);
300-
debug('after', this.connection.serialize());
301298
} else {
302-
debug('creating new connection from form data');
303299
this.connection = new Connection(this.form.data);
304300
}
305301
this.connection.is_favorite = true;
@@ -339,10 +335,6 @@ var ConnectView = View.extend({
339335
return;
340336
}
341337
app.statusbar.show();
342-
debug('trying to connect with URL %s and options %j',
343-
connection.driver_url,
344-
connection.driver_options
345-
);
346338

347339
connection.test(function(err) {
348340
app.statusbar.hide();

src/connect/index.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@
139139
overflow: auto;
140140
}
141141
label {
142-
width: 32%;
142+
width: 35%;
143143
text-align: right;
144144
padding: 5px 15px 0 0;
145145
}
146146
input, select, .form-item-file {
147-
width: 68%;
147+
width: 65%;
148148
}
149149
.form-item-file {
150150
input {

src/connect/input-view.js

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
var InputView = require('ampersand-input-view');
2-
var _ = require('lodash');
3-
42
// var debug = require('debug')('scout:connect:input-view');
53

64
/**
7-
* Need to overwrite render() method and pass in `this` for renderWithTemplate(), so that
8-
* label gets correctly rendered on subsequent render() calls.
5+
* Need to overwrite render() method and pass in `this` for renderWithTemplate()
6+
* so that label gets correctly rendered on subsequent render() calls.
97
*/
108
module.exports = InputView.extend({
119
initialize: function() {
@@ -23,38 +21,5 @@ module.exports = InputView.extend({
2321
// if the field is not required
2422
this.setValue(this.inputValue, !this.required);
2523
return this;
26-
},
27-
clean: function(val) {
28-
if (this.type === 'number') {
29-
return Number(val);
30-
} else if (this.type === 'string') {
31-
return val.trim();
32-
}
33-
return val;
34-
},
35-
/**
36-
* overwriting InputView#beforeSubmit to handle `file` type correctly.
37-
* For `file` type, the input view returns the actual path (provided by
38-
* electron) rather than the browser fake path.
39-
* @see https://github.com/atom/electron/blob/master/docs/api/file-object.md
40-
*/
41-
beforeSubmit: function() {
42-
var value;
43-
if (this.type === 'file') {
44-
value = _.chain(this.input.files)
45-
.map(function(file) {
46-
return _.get(file, 'path', null);
47-
})
48-
.filter()
49-
.value();
50-
if (value.length === 0) {
51-
value = '';
52-
}
53-
} else {
54-
value = this.input.value;
55-
}
56-
this.inputValue = this.clean(value);
57-
this.shouldValidate = true;
58-
this.runTests();
5924
}
6025
});

0 commit comments

Comments
 (0)