@@ -7,10 +7,6 @@ var debug = require('debug')('scout:field-list');
77var _ = require ( 'lodash' ) ;
88var raf = require ( 'raf' ) ;
99var 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 ;
1410
1511function handleCaret ( el ) {
1612 var $el = $ ( el ) ;
@@ -41,9 +37,6 @@ var FieldView = View.extend({
4137 fieldListView : 'view' ,
4238 arrayFieldListView : 'view'
4339 } ,
44- children : {
45- refineClause : LeafClause
46- } ,
4740 bindings : {
4841 'model.name' : {
4942 hook : 'name'
@@ -93,7 +86,6 @@ var FieldView = View.extend({
9386 } ) , {
9487 silent : true
9588 } ) ;
96- this . listenTo ( this . fieldListView , 'change:refineQuery' , this . onRefineClause ) ;
9789 return this . fieldListView ;
9890 }
9991 } ,
@@ -108,64 +100,26 @@ var FieldView = View.extend({
108100 } ) , {
109101 silent : true
110102 } ) ;
111- this . listenTo ( this . arrayFieldListView , 'change:refineQuery' , this . onRefineClause ) ;
112103 return this . arrayFieldListView ;
113104 }
114105 }
115106 } ,
116107 initialize : function ( ) {
117108 this . listenTo ( this , 'change:visible' , this . renderMinicharts ) ;
118- this . refineClause . key . content = this . model . name ;
119109 } ,
120110 render : function ( ) {
121111 this . renderWithTemplate ( this ) ;
122112 this . viewSwitcher = new ViewSwitcher ( this . queryByHook ( 'minichart-container' ) ) ;
123113 } ,
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- } ,
157114 renderMinicharts : function ( ) {
158115 if ( ! this . type_model ) {
159116 this . type_model = this . model . types . at ( 0 ) ;
160117 }
161-
162118 debug ( 'setting miniview for type_model_id `%s`' , this . type_model . getId ( ) ) ;
163119 this . minichartView = new MinichartView ( {
164120 model : this . type_model ,
165121 parent : this
166122 } ) ;
167- this . refineClause . value = this . minichartView . refineValue ;
168- this . listenTo ( this . minichartView , 'change:refineValue' , this . onRefineClause ) ;
169123 this . viewSwitcher . set ( this . minichartView ) ;
170124 } ,
171125 click : function ( evt ) {
@@ -178,15 +132,7 @@ var FieldView = View.extend({
178132FieldListView = View . extend ( {
179133 modelType : 'FieldListView' ,
180134 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'
190136 } ,
191137 template : require ( './index.jade' ) ,
192138 initialize : function ( ) {
@@ -195,36 +141,8 @@ FieldListView = View.extend({
195141 } else {
196142 this . listenTo ( this . parent , 'change:visible' , this . makeFieldVisible ) ;
197143 }
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- }
225144 } ,
226145 makeFieldVisible : function ( ) {
227- this . queryContext = _ . clone ( app . queryOptions . query ) ;
228146 var views = this . fieldCollectionView . views ;
229147 _ . each ( views , function ( field_view ) {
230148 raf ( function ( ) {
0 commit comments