1
1
var pkg = require ( '../package.json' ) ;
2
2
var app = require ( 'ampersand-app' ) ;
3
3
app . extend ( {
4
+ // @todo (imlucas) Move to config
5
+ // `scout-server` to point at.
6
+ endpoint : 'http://localhost:29017' ,
4
7
meta : {
5
8
'App Version' : pkg . version
6
9
}
@@ -145,9 +148,9 @@ var Application = View.extend({
145
148
} ) ;
146
149
147
150
var params = qs . parse ( window . location . search . replace ( '?' , '' ) ) ;
148
- var uri = params . uri || 'mongodb://localhost:27017' ;
151
+ var connection_id = params . connection_id ;
149
152
var state = new Application ( {
150
- uri : uri
153
+ connection_id : connection_id
151
154
} ) ;
152
155
153
156
var QueryOptions = require ( './models/query-options' ) ;
@@ -156,23 +159,41 @@ var MongoDBInstance = require('./models/mongodb-instance');
156
159
var Router = require ( './router' ) ;
157
160
var Statusbar = require ( './statusbar' ) ;
158
161
162
+ function start ( ) {
163
+ state . router = new Router ( ) ;
164
+ domReady ( state . _onDOMReady . bind ( state ) ) ;
165
+ }
166
+
159
167
app . extend ( {
160
168
client : null ,
161
169
init : function ( ) {
162
- state . statusbar = new Statusbar ( ) ;
163
- this . connection = new Connection ( ) ;
164
- this . connection . use ( uri ) ;
165
- this . queryOptions = new QueryOptions ( ) ;
166
- this . volatileQueryOptions = new QueryOptions ( ) ;
167
- this . instance = new MongoDBInstance ( ) ;
168
-
169
170
// feature flags
170
171
this . features = {
171
172
querybuilder : true
172
173
} ;
174
+ state . statusbar = new Statusbar ( ) ;
173
175
174
- state . router = new Router ( ) ;
175
-
176
+ if ( connection_id ) {
177
+ state . connection = new Connection ( {
178
+ _id : connection_id
179
+ } ) ;
180
+
181
+
182
+ debug ( 'looking up connection `%s`...' , connection_id ) ;
183
+ state . connection . fetch ( {
184
+ success : function ( ) {
185
+ debug ( 'got connection `%j`...' , state . connection . serialize ( ) ) ;
186
+ app . client = getOrCreateClient ( app . endpoint , state . connection . serialize ( ) ) ;
187
+
188
+ state . queryOptions = new QueryOptions ( ) ;
189
+ state . volatileQueryOptions = new QueryOptions ( ) ;
190
+ state . instance = new MongoDBInstance ( ) ;
191
+ start ( ) ;
192
+ }
193
+ } ) ;
194
+ } else {
195
+ start ( ) ;
196
+ }
176
197
// set up ipc
177
198
ipc . on ( 'message' , state . onMessageReceived . bind ( this ) ) ;
178
199
} ,
@@ -185,20 +206,37 @@ Object.defineProperty(app, 'statusbar', {
185
206
}
186
207
} ) ;
187
208
188
- Object . defineProperty ( app , 'client ' , {
209
+ Object . defineProperty ( app , 'instance ' , {
189
210
get : function ( ) {
190
- return getOrCreateClient ( {
191
- seed : app . connection . uri
192
- } ) ;
211
+ return state . instance ;
193
212
}
194
213
} ) ;
195
- app . init ( ) ;
196
214
197
- function render_app ( ) {
198
- state . _onDOMReady ( ) ;
199
- }
215
+ Object . defineProperty ( app , 'queryOptions' , {
216
+ get : function ( ) {
217
+ return state . queryOptions ;
218
+ }
219
+ } ) ;
200
220
201
- domReady ( render_app ) ;
221
+ Object . defineProperty ( app , 'volatileQueryOptions' , {
222
+ get : function ( ) {
223
+ return state . volatileQueryOptions ;
224
+ }
225
+ } ) ;
226
+
227
+ Object . defineProperty ( app , 'connection' , {
228
+ get : function ( ) {
229
+ return state . connection ;
230
+ }
231
+ } ) ;
232
+
233
+ Object . defineProperty ( app , 'router' , {
234
+ get : function ( ) {
235
+ return state . router ;
236
+ }
237
+ } ) ;
238
+
239
+ app . init ( ) ;
202
240
203
241
// expose app globally for debugging purposes
204
242
window . app = app ;
0 commit comments