1
1
var View = require ( 'ampersand-view' ) ;
2
- var format = require ( 'util' ) . format ;
2
+ // var format = require('util').format;
3
3
// var IdentifyView = require('../identify');
4
4
var CollectionView = require ( './collection' ) ;
5
5
var { NamespaceStore } = require ( 'hadron-reflux-store' ) ;
@@ -55,9 +55,10 @@ var HomeView = View.extend({
55
55
* TODO (imlucas) Handle state when rtss permissions not available.
56
56
*/
57
57
this . serverStatsView = app . appRegistry . getComponent ( 'RTSS.ServerStats' ) ;
58
+ this . collectionsTable = app . appRegistry . getComponent ( 'Database.CollectionsTable' ) ;
58
59
this . listenTo ( app . instance , 'sync' , this . onInstanceFetched ) ;
59
60
this . listenTo ( app . connection , 'change:name' , this . updateTitle ) ;
60
- NamespaceStore . listen ( this . onNamespaceChange . bind ( this ) ) ;
61
+ NamespaceStore . listen ( this . switchMainContent . bind ( this ) ) ;
61
62
ipc . on ( 'window:show-compass-tour' , this . showTour . bind ( this , true ) ) ;
62
63
ipc . on ( 'window:show-network-optin' , this . showOptIn . bind ( this ) ) ;
63
64
@@ -68,15 +69,6 @@ var HomeView = View.extend({
68
69
} ,
69
70
render : function ( ) {
70
71
this . renderWithTemplate ( this ) ;
71
- var containerNode = this . queryByHook ( 'report-zero-state' ) ;
72
- ReactDOM . render (
73
- React . createElement ( this . serverStatsView , { interval : 1000 } ) ,
74
- containerNode
75
- ) ;
76
- NamespaceStore . listen ( ( ) => {
77
- ReactDOM . unmountComponentAtNode ( containerNode ) ;
78
- } ) ;
79
-
80
72
const SideBarComponent = app . appRegistry . getComponent ( 'Sidebar.Component' ) ;
81
73
ReactDOM . render (
82
74
React . createElement ( SideBarComponent ) ,
@@ -88,6 +80,34 @@ var HomeView = View.extend({
88
80
} else {
89
81
this . tourClosed ( ) ;
90
82
}
83
+ this . switchMainContent ( '' ) ;
84
+ } ,
85
+ switchMainContent : function ( namespace ) {
86
+ if ( namespace === this . ns ) {
87
+ debug ( 'already selected namespace' , namespace ) ;
88
+ return ;
89
+ }
90
+ this . ns = namespace ;
91
+ const ns = toNS ( namespace ) ;
92
+ var containerNode = this . queryByHook ( 'report-zero-state' ) ;
93
+
94
+ if ( ns . database === '' ) {
95
+ // neither database nor collection are present, top level instance view
96
+ ReactDOM . render (
97
+ React . createElement ( this . serverStatsView , { interval : 1000 } ) ,
98
+ containerNode
99
+ ) ;
100
+ } else if ( ns . collection === '' ) {
101
+ // a database was clicked, render collections table
102
+ ReactDOM . render (
103
+ React . createElement ( this . collectionsTable ) ,
104
+ containerNode
105
+ ) ;
106
+ } else {
107
+ // unmount instance/databases view and switch to collection view
108
+ ReactDOM . unmountComponentAtNode ( containerNode ) ;
109
+ }
110
+ this . updateTitle ( namespace ) ;
91
111
} ,
92
112
showTour : function ( force ) {
93
113
var tourView = new TourView ( { force : force } ) ;
@@ -146,10 +166,10 @@ var HomeView = View.extend({
146
166
}
147
167
}
148
168
} ,
149
- updateTitle : function ( model ) {
169
+ updateTitle : function ( ns ) {
150
170
var title = 'MongoDB Compass - ' + app . connection . instance_id ;
151
- if ( model ) {
152
- title += '/' + model . getId ( ) ;
171
+ if ( ns ) {
172
+ title += '/' + ns ;
153
173
}
154
174
document . title = title ;
155
175
} ,
@@ -170,26 +190,27 @@ var HomeView = View.extend({
170
190
171
191
return database . collections . get ( ns . ns ) ;
172
192
} ,
173
- onNamespaceChange : function ( ) {
174
- const model = this . _getCollection ( ) ;
175
-
176
- if ( ! model ) {
177
- app . navigate ( '/' ) ;
178
- return ;
179
- }
180
-
181
- const collection = app . instance . collections ;
182
- if ( ! collection . select ( model ) ) {
183
- return debug ( 'already selected %s' , model ) ;
184
- }
185
-
186
- this . updateTitle ( model ) ;
187
- this . showNoCollectionsZeroState = false ;
188
- this . showDefaultZeroState = false ;
189
- app . navigate ( format ( 'schema/%s' , model . getId ( ) ) , {
190
- silent : true
191
- } ) ;
192
- } ,
193
+ // onNamespaceChange: function(ns) {
194
+ // const model = this._getCollection();
195
+ //
196
+ // // if (!model) {
197
+ // // app.navigate('/');
198
+ // // return;
199
+ // // }
200
+ //
201
+ // const collection = app.instance.collections;
202
+ // if (!collection.select(model)) {
203
+ // return debug('already selected %s', model);
204
+ // }
205
+ //
206
+ // this.updateTitle(model);
207
+ // this.showNoCollectionsZeroState = false;
208
+ // this.showDefaultZeroState = false;
209
+ //
210
+ // // app.navigate(format('schema/%s', model.getId()), {
211
+ // // silent: true
212
+ // // });
213
+ // },
193
214
onClickShowConnectWindow : function ( ) {
194
215
// code to close current connection window and open connect dialog
195
216
ipc . call ( 'app:show-connect-window' ) ;
0 commit comments