@@ -7,10 +7,6 @@ var debug = require('debug')('scout:field-list');
7
7
var _ = require ( 'lodash' ) ;
8
8
var raf = require ( 'raf' ) ;
9
9
var SampledSchema = require ( '../models/sampled-schema' ) ;
10
- var app = require ( 'ampersand-app' ) ;
11
-
12
- var LeafClause = require ( 'mongodb-language-model' ) . LeafClause ;
13
- var Query = require ( 'mongodb-language-model' ) . Query ;
14
10
15
11
function handleCaret ( el ) {
16
12
var $el = $ ( el ) ;
@@ -41,9 +37,6 @@ var FieldView = View.extend({
41
37
fieldListView : 'view' ,
42
38
arrayFieldListView : 'view'
43
39
} ,
44
- children : {
45
- refineClause : LeafClause
46
- } ,
47
40
bindings : {
48
41
'model.name' : {
49
42
hook : 'name'
@@ -93,7 +86,6 @@ var FieldView = View.extend({
93
86
} ) , {
94
87
silent : true
95
88
} ) ;
96
- this . listenTo ( this . fieldListView , 'change:refineQuery' , this . onRefineClause ) ;
97
89
return this . fieldListView ;
98
90
}
99
91
} ,
@@ -108,64 +100,26 @@ var FieldView = View.extend({
108
100
} ) , {
109
101
silent : true
110
102
} ) ;
111
- this . listenTo ( this . arrayFieldListView , 'change:refineQuery' , this . onRefineClause ) ;
112
103
return this . arrayFieldListView ;
113
104
}
114
105
}
115
106
} ,
116
107
initialize : function ( ) {
117
108
this . listenTo ( this , 'change:visible' , this . renderMinicharts ) ;
118
- this . refineClause . key . content = this . model . name ;
119
109
} ,
120
110
render : function ( ) {
121
111
this . renderWithTemplate ( this ) ;
122
112
this . viewSwitcher = new ViewSwitcher ( this . queryByHook ( 'minichart-container' ) ) ;
123
113
} ,
124
- onRefineClause : function ( who ) {
125
- if ( who . getType ( ) === 'MinichartView' ) {
126
- this . refineClause . value = who . refineValue ;
127
- }
128
- this . parent . trigger ( 'refine' , this ) ;
129
- } ,
130
- prefixClauseKey : function ( clause ) {
131
- var newClause = new LeafClause ( ) ;
132
- newClause . key . content = this . model . name + '.' + clause . key . buffer ;
133
- newClause . value = clause . value ;
134
- return newClause ;
135
- } ,
136
- getClauses : function ( ) {
137
- var clauses = [ ] ;
138
- if ( this . fieldListView ) {
139
- this . fieldListView . refineQuery . clauses . each ( function ( clause ) {
140
- if ( clause . valid ) {
141
- clauses . push ( this . prefixClauseKey ( clause ) ) ;
142
- }
143
- } . bind ( this ) ) ;
144
- }
145
- if ( this . arrayFieldListView ) {
146
- this . arrayFieldListView . refineQuery . clauses . each ( function ( clause ) {
147
- if ( clause . valid ) {
148
- clauses . push ( this . prefixClauseKey ( clause ) ) ;
149
- }
150
- } . bind ( this ) ) ;
151
- }
152
- if ( this . refineClause . valid ) {
153
- clauses . push ( this . refineClause ) ;
154
- }
155
- return clauses ;
156
- } ,
157
114
renderMinicharts : function ( ) {
158
115
if ( ! this . type_model ) {
159
116
this . type_model = this . model . types . at ( 0 ) ;
160
117
}
161
-
162
118
debug ( 'setting miniview for type_model_id `%s`' , this . type_model . getId ( ) ) ;
163
119
this . minichartView = new MinichartView ( {
164
120
model : this . type_model ,
165
121
parent : this
166
122
} ) ;
167
- this . refineClause . value = this . minichartView . refineValue ;
168
- this . listenTo ( this . minichartView , 'change:refineValue' , this . onRefineClause ) ;
169
123
this . viewSwitcher . set ( this . minichartView ) ;
170
124
} ,
171
125
click : function ( evt ) {
@@ -178,15 +132,7 @@ var FieldView = View.extend({
178
132
FieldListView = View . extend ( {
179
133
modelType : 'FieldListView' ,
180
134
session : {
181
- fieldCollectionView : 'view' ,
182
- refineQuery : {
183
- type : 'state' ,
184
- required : true ,
185
- default : function ( ) {
186
- return new Query ( ) ;
187
- }
188
- } ,
189
- queryContext : 'object'
135
+ fieldCollectionView : 'view'
190
136
} ,
191
137
template : require ( './index.jade' ) ,
192
138
initialize : function ( ) {
@@ -195,36 +141,8 @@ FieldListView = View.extend({
195
141
} else {
196
142
this . listenTo ( this . parent , 'change:visible' , this . makeFieldVisible ) ;
197
143
}
198
- this . on ( 'refine' , this . onRefineQuery ) ;
199
- if ( this . parent . getType ( ) === 'Collection' ) {
200
- // I'm the global FieldListView, remembering query context
201
- this . queryContext = _ . clone ( app . queryOptions . query ) ;
202
- }
203
- } ,
204
- onRefineQuery : function ( ) {
205
- var views = this . fieldCollectionView . views ;
206
- var clauses = _ . flatten ( _ . map ( views , function ( view ) {
207
- return view . getClauses ( ) ;
208
- } ) ) ;
209
- this . refineQuery = new Query ( {
210
- clauses : clauses
211
- } ) ;
212
- if ( this . parent . getType ( ) === 'Collection' ) {
213
- // fill clauses with query context unless they are further refined by user
214
- this . queryContext . clauses . each ( function ( clause ) {
215
- this . refineQuery . clauses . add ( clause ) ;
216
- // if (!_.find(clauses, function(cl) {
217
- // return cl.id === clause.id;
218
- // })) {
219
- // clauses.push(clause);
220
- // }
221
- } . bind ( this ) ) ;
222
- // I'm the global FieldListView, changing query in app
223
- app . queryOptions . query = this . refineQuery ;
224
- }
225
144
} ,
226
145
makeFieldVisible : function ( ) {
227
- this . queryContext = _ . clone ( app . queryOptions . query ) ;
228
146
var views = this . fieldCollectionView . views ;
229
147
_ . each ( views , function ( field_view ) {
230
148
raf ( function ( ) {
0 commit comments