Skip to content

Commit 2c53601

Browse files
committed
INT-780 save ssl cert paths, removing debug msgs
1 parent d6d2bb7 commit 2c53601

File tree

6 files changed

+79
-63
lines changed

6 files changed

+79
-63
lines changed

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: 1 addition & 2 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;

src/connect/filereader-view.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var InputView = require('./input-view');
2+
var _ = require('lodash');
3+
// var path = require('path');
4+
var fileReaderTemplate = require('./filereader-default.jade');
5+
6+
// var debug = require('debug')('scout:connect:filereader-view');
7+
8+
module.exports = InputView.extend({
9+
template: fileReaderTemplate,
10+
clean: function() {
11+
var value;
12+
value = _.chain(this.input.files)
13+
.map(function(file) {
14+
return _.get(file, 'path', null);
15+
})
16+
.filter()
17+
.value();
18+
if (value.length === 0) {
19+
value = '';
20+
}
21+
return value;
22+
},
23+
setValue: function(value, skipValidation) {
24+
if (!this.input) {
25+
this.inputValue = value;
26+
return;
27+
}
28+
this.input.value = '';
29+
/**
30+
* Cannot set input value for file types. @see INT-780
31+
*/
32+
// if (value || value === 0) {
33+
// if (!_.isArray(value)) {
34+
// value = [value];
35+
// }
36+
// if (value.length <= 1) {
37+
// this.input.value = path.basename(value);
38+
// } else {
39+
// this.input.value = 'multiple files';
40+
// }
41+
// this.input.files = _.map(value, function(f) {
42+
// return {
43+
// name: path.basename(f),
44+
// path: f
45+
// };
46+
// });
47+
// }
48+
this.inputValue = this.clean();
49+
if (!skipValidation && !this.getErrorMessage()) {
50+
this.shouldValidate = true;
51+
} else if (skipValidation) {
52+
this.shouldValidate = false;
53+
}
54+
},
55+
handleChange: function() {
56+
if (this.inputValue && this.changed) {
57+
this.shouldValidate = true;
58+
}
59+
// for `file` type input fields, this is the only event and we need
60+
// to set this.inputValue here again.
61+
this.inputValue = this.clean();
62+
this.runTests();
63+
}
64+
});

src/connect/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ var ConnectView = View.extend({
9494
'input input[name=name]': 'onNameInputChanged',
9595
'change input[name=name]': 'onNameInputChanged',
9696
'input input': 'onAnyInputChanged',
97+
'change input': 'onAnyInputChanged',
9798
'change select': 'onAnyInputChanged'
9899
},
99100

@@ -292,14 +293,8 @@ var ConnectView = View.extend({
292293
*/
293294
updateConnection: function() {
294295
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);
299296
this.connection.set(this.form.data);
300-
debug('after', this.connection.serialize());
301297
} else {
302-
debug('creating new connection from form data');
303298
this.connection = new Connection(this.form.data);
304299
}
305300
this.connection.is_favorite = true;
@@ -339,10 +334,6 @@ var ConnectView = View.extend({
339334
return;
340335
}
341336
app.statusbar.show();
342-
debug('trying to connect with URL %s and options %j',
343-
connection.driver_url,
344-
connection.driver_options
345-
);
346337

347338
connection.test(function(err) {
348339
app.statusbar.hide();

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
});

src/connect/ssl.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
var SSLOptionCollection = require('./models/ssl-option-collection');
77

88
var InputView = require('./input-view');
9+
var FileReaderView = require('./filereader-view');
910
var inputTemplate = require('./input-default.jade');
10-
var fileReaderTemplate = require('./filereader-default.jade');
1111

1212
// var debug = require('debug')('scout:connect:ssl');
1313

@@ -37,8 +37,7 @@ var SERVER = {
3737
// enabled: app.isFeatureEnabled('Connect with SSL SERVER'),
3838
enabled: true,
3939
fields: [
40-
new InputView({
41-
template: fileReaderTemplate,
40+
new FileReaderView({
4241
name: 'ssl_ca',
4342
type: 'file',
4443
label: 'Certificate Authority',
@@ -57,24 +56,21 @@ var ALL = {
5756
// enabled: app.isFeatureEnabled('Connect with SSL ALL'),
5857
enabled: true,
5958
fields: [
60-
new InputView({
61-
template: fileReaderTemplate,
59+
new FileReaderView({
6260
name: 'ssl_ca',
6361
type: 'file',
6462
label: 'Certificate Authority',
6563
placeholder: '',
6664
required: true
6765
}),
68-
new InputView({
69-
template: fileReaderTemplate,
66+
new FileReaderView({
7067
name: 'ssl_private_key',
7168
type: 'file',
7269
label: 'Certificate Key',
7370
placeholder: '',
7471
required: true
7572
}),
76-
new InputView({
77-
template: fileReaderTemplate,
73+
new FileReaderView({
7874
name: 'ssl_certificate',
7975
type: 'file',
8076
label: 'Certificate',

0 commit comments

Comments
 (0)