Major rework, uses a builder pattern now.
Showing
4 changed files
with
99 additions
and
40 deletions
... | @@ -61,7 +61,6 @@ module.exports = function(grunt) { | ... | @@ -61,7 +61,6 @@ module.exports = function(grunt) { |
61 | var _ = require('lodash'); | 61 | var _ = require('lodash'); |
62 | 62 | ||
63 | function genJasmineConfig(withCoverage, options) { | 63 | function genJasmineConfig(withCoverage, options) { |
64 | var template, templateOptions; | ||
65 | var src = [ | 64 | var src = [ |
66 | 'src/scripts/{,**/}*.js', | 65 | 'src/scripts/{,**/}*.js', |
67 | '!src/scripts/main.js', | 66 | '!src/scripts/main.js', |
... | @@ -103,7 +102,7 @@ module.exports = function(grunt) { | ... | @@ -103,7 +102,7 @@ module.exports = function(grunt) { |
103 | } | 102 | } |
104 | } | 103 | } |
105 | url = parts.join('/'); | 104 | url = parts.join('/'); |
106 | if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.spec\.js$/)) { | 105 | if (0) if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.spec\.js$/)) { |
107 | url = './.grunt/grunt-contrib-jasmine/' + url; | 106 | url = './.grunt/grunt-contrib-jasmine/' + url; |
108 | } else if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.js$/)) { | 107 | } else if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.js$/)) { |
109 | url = './.grunt/grunt-contrib-jasmine/' + url; | 108 | url = './.grunt/grunt-contrib-jasmine/' + url; |
... | @@ -149,7 +148,7 @@ module.exports = function(grunt) { | ... | @@ -149,7 +148,7 @@ module.exports = function(grunt) { |
149 | template: template, | 148 | template: template, |
150 | templateOptions: templateOptions, | 149 | templateOptions: templateOptions, |
151 | }, | 150 | }, |
152 | } | 151 | }; |
153 | return jasmineConfig; | 152 | return jasmineConfig; |
154 | } | 153 | } |
155 | 154 | ... | ... |
This diff is collapsed.
Click to expand it.
... | @@ -2,6 +2,7 @@ define(function(require) { | ... | @@ -2,6 +2,7 @@ define(function(require) { |
2 | 'use strict'; | 2 | 'use strict'; |
3 | var _ = require('underscore'); | 3 | var _ = require('underscore'); |
4 | var Util = require('./Util'); | 4 | var Util = require('./Util'); |
5 | var Facet = require('./Facet'); | ||
5 | var Facets = require('./Facets'); | 6 | var Facets = require('./Facets'); |
6 | var Solr = require('./Solr'); | 7 | var Solr = require('./Solr'); |
7 | 8 | ||
... | @@ -19,23 +20,26 @@ define(function(require) { | ... | @@ -19,23 +20,26 @@ define(function(require) { |
19 | return solrData; | 20 | return solrData; |
20 | } | 21 | } |
21 | 22 | ||
22 | function makeSolrResponseMixedCase(solrData) { | 23 | function makeSolrResponseMixedCase(solrResponse) { |
23 | var facetCounts = Util.getField(solrData, 'facet_counts'); | 24 | var facetCounts = Util.getField(solrResponse, 'facet_counts'); |
24 | return { | 25 | return { |
25 | facetCounts: facetCounts, | ||
26 | facetRanges: Util.getField(facetCounts, 'facet_ranges'), | 26 | facetRanges: Util.getField(facetCounts, 'facet_ranges'), |
27 | facetFields: Util.getField(facetCounts, 'facet_fields'), | 27 | facetFields: Util.getField(facetCounts, 'facet_fields'), |
28 | facetQueries: Util.getField(facetCounts, 'facet_queries'), | 28 | facetQueries: Util.getField(facetCounts, 'facet_queries'), |
29 | statsFields: Util.getField(solrData.stats, 'stats_fields'), | 29 | statsFields: Util.getField(solrResponse.stats, 'stats_fields'), |
30 | }; | 30 | }; |
31 | } | 31 | } |
32 | 32 | ||
33 | function createStaticSolrResponse(has, toMerge) { | 33 | function createStaticSolrResponse(has, toMerge) { |
34 | var solrResponse = createSolrResponse({stats: true}); | 34 | var solrResponse = createSolrResponse({stats: true}); |
35 | var solrData = makeSolrResponseMixedCase(solrResponse); | 35 | var solrData = makeSolrResponseMixedCase(solrResponse); |
36 | if (_.isFunction(toMerge)) { | ||
37 | toMerge = toMerge(solrData); | ||
38 | } else { | ||
36 | _.each(solrData, function(value, key) { | 39 | _.each(solrData, function(value, key) { |
37 | _.extend(value, toMerge[key]); | 40 | _.extend(value, toMerge[key]); |
38 | }); | 41 | }); |
42 | } | ||
39 | return solrResponse; | 43 | return solrResponse; |
40 | } | 44 | } |
41 | 45 | ||
... | @@ -45,26 +49,26 @@ define(function(require) { | ... | @@ -45,26 +49,26 @@ define(function(require) { |
45 | expect(item.get('checked')).toEqual(checked); | 49 | expect(item.get('checked')).toEqual(checked); |
46 | } | 50 | } |
47 | 51 | ||
48 | var facetsBuilder = function facetsBuilder() { | 52 | var definedFacets = { |
49 | return { | 53 | model: [ |
50 | model: new Facets.Facet({ | 54 | { |
51 | formName: 'model', | 55 | formName: 'model', |
52 | label: 'Model', | 56 | label: 'Model', |
53 | }, | 57 | }, { |
54 | { | ||
55 | queryField: 'model_s', | 58 | queryField: 'model_s', |
56 | facetType: 'field', | 59 | facetType: 'field', |
57 | bins: { | 60 | bins: { |
58 | misc: ['saturn', 'jeep'], | 61 | misc: ['saturn', 'jeep'], |
59 | startsWithB: ['buick'], | 62 | startsWithB: ['buick'], |
60 | }, | 63 | }, |
61 | }), | 64 | }, |
62 | year: new Facets.Facet({ | 65 | ], |
66 | year: [ | ||
67 | { | ||
63 | formName: 'year', | 68 | formName: 'year', |
64 | orderByDirection: 'desc', | 69 | orderByDirection: 'desc', |
65 | label: 'Year', | 70 | label: 'Year', |
66 | }, | 71 | }, { |
67 | { | ||
68 | queryField: 'year_dt', | 72 | queryField: 'year_dt', |
69 | comparator: 'date', | 73 | comparator: 'date', |
70 | facetType: 'year-field', | 74 | facetType: 'year-field', |
... | @@ -80,8 +84,10 @@ define(function(require) { | ... | @@ -80,8 +84,10 @@ define(function(require) { |
80 | var year = new Date(value).getUTCFullYear(); | 84 | var year = new Date(value).getUTCFullYear(); |
81 | return year + ' - ' + (year + 2); | 85 | return year + ' - ' + (year + 2); |
82 | }, | 86 | }, |
83 | }), | 87 | }, |
84 | dateOfBirth: new Facets.Facet({ | 88 | ], |
89 | dateOfBirth: [ | ||
90 | { | ||
85 | formName: 'dateOfBirth', | 91 | formName: 'dateOfBirth', |
86 | label: 'Birthday', | 92 | label: 'Birthday', |
87 | }, { | 93 | }, { |
... | @@ -91,8 +97,10 @@ define(function(require) { | ... | @@ -91,8 +97,10 @@ define(function(require) { |
91 | facetStats: true, | 97 | facetStats: true, |
92 | other: 'before', | 98 | other: 'before', |
93 | start: 'NOW/YEAR-25YEAR', | 99 | start: 'NOW/YEAR-25YEAR', |
94 | }), | 100 | }, |
95 | value: new Facets.Facet({ | 101 | ], |
102 | value: [ | ||
103 | { | ||
96 | formName: 'value', | 104 | formName: 'value', |
97 | label: 'Value', | 105 | label: 'Value', |
98 | }, { | 106 | }, { |
... | @@ -104,15 +112,53 @@ define(function(require) { | ... | @@ -104,15 +112,53 @@ define(function(require) { |
104 | var value = parseInt(item.get('key')); | 112 | var value = parseInt(item.get('key')); |
105 | return '$' + value + ' - $' + (value + 1000); | 113 | return '$' + value + ' - $' + (value + 1000); |
106 | }, | 114 | }, |
107 | }), | 115 | }, |
116 | ], | ||
117 | bodyType: [ | ||
118 | { | ||
119 | label: 'Type' | ||
120 | }, { | ||
121 | facetType: 'field', | ||
122 | labelMap: { | ||
123 | aluminum: 'Aluminum', | ||
124 | plastic: 'Plastic', | ||
125 | carbonComposite: 'Carbon Composite', | ||
126 | steel: 'Steel', | ||
127 | }, | ||
128 | }, | ||
129 | ], | ||
108 | }; | 130 | }; |
131 | var facetsBuilder = function facetsBuilder(facetName) { | ||
132 | if (facetName) { | ||
133 | return new Facet(definedFacets[facetName][0], definedFacets[facetName][1]); | ||
134 | } | ||
135 | var result = {}; | ||
136 | _.each(_.keys(definedFacets), function(facetName) { | ||
137 | result[facetName] = new Facet(definedFacets[facetName][0], definedFacets[facetName][1]); | ||
138 | }); | ||
139 | return result; | ||
109 | }; | 140 | }; |
110 | 141 | ||
111 | var responses = { | 142 | function createSolrDataMerger(modelData) { |
112 | sequential: [ | 143 | return function(solrData) { |
113 | createStaticSolrResponse({stats: true}, { | 144 | _.each(solrData, function(solrValue, solrKey) { |
114 | facetRanges: { | 145 | _.each(modelData, function(modelObj, modelKey) { |
146 | var modelValue = modelObj[solrKey]; | ||
147 | if (modelValue) { | ||
148 | if (solrKey === 'facetQueries') { | ||
149 | _.extend(solrValue, modelValue); | ||
150 | } else { | ||
151 | solrValue[modelKey] = modelValue; | ||
152 | } | ||
153 | } | ||
154 | }); | ||
155 | }); | ||
156 | }; | ||
157 | } | ||
158 | |||
159 | var defaultModelData = { | ||
115 | dateOfBirth: { | 160 | dateOfBirth: { |
161 | facetRanges: { | ||
116 | counts: [ | 162 | counts: [ |
117 | '1974-01-01T00:00:00.000Z', 1, | 163 | '1974-01-01T00:00:00.000Z', 1, |
118 | '1972-01-01T00:00:00.000Z', 1, | 164 | '1972-01-01T00:00:00.000Z', 1, |
... | @@ -120,9 +166,18 @@ define(function(require) { | ... | @@ -120,9 +166,18 @@ define(function(require) { |
120 | ], | 166 | ], |
121 | before: 5, | 167 | before: 5, |
122 | }, | 168 | }, |
169 | statsFields: {min: '2000', max: '2010'}, | ||
123 | }, | 170 | }, |
124 | facetFields: { | 171 | bodyType: { |
125 | model: [ | 172 | facetFields: [ |
173 | 'aluminum', 14, | ||
174 | 'carbonComposite', 66, | ||
175 | 'steel', 2, | ||
176 | ], | ||
177 | }, | ||
178 | |||
179 | model: { | ||
180 | facetFields: [ | ||
126 | 'ford', 23, | 181 | 'ford', 23, |
127 | 'chevy', 18, | 182 | 'chevy', 18, |
128 | 'toyota', 5, | 183 | 'toyota', 5, |
... | @@ -131,12 +186,21 @@ define(function(require) { | ... | @@ -131,12 +186,21 @@ define(function(require) { |
131 | 'buick', 0, // keep here to test the bin/exclude feature | 186 | 'buick', 0, // keep here to test the bin/exclude feature |
132 | 'dodge', 0, | 187 | 'dodge', 0, |
133 | ], | 188 | ], |
134 | value: [ | 189 | facetQueries: { |
190 | 'model:misc': 26, | ||
191 | 'model:startsWithB': 0, | ||
192 | }, | ||
193 | }, | ||
194 | value: { | ||
195 | facetFields: [ | ||
135 | '23456', 1, | 196 | '23456', 1, |
136 | '5678', 2, | 197 | '5678', 2, |
137 | '1234', 3, | 198 | '1234', 3, |
138 | ], | 199 | ], |
139 | year: [ | 200 | statsFields: {min: '1234', max: '23456'}, |
201 | }, | ||
202 | year: { | ||
203 | facetFields: [ | ||
140 | '2000-01-01T00:00:00.000Z', 1, | 204 | '2000-01-01T00:00:00.000Z', 1, |
141 | '2001-01-01T00:00:00.000Z', 4, | 205 | '2001-01-01T00:00:00.000Z', 4, |
142 | '2002-01-01T00:00:00.000Z', 0, | 206 | '2002-01-01T00:00:00.000Z', 0, |
... | @@ -149,17 +213,12 @@ define(function(require) { | ... | @@ -149,17 +213,12 @@ define(function(require) { |
149 | '2009-01-01T00:00:00.000Z', 0, | 213 | '2009-01-01T00:00:00.000Z', 0, |
150 | '2010-01-01T00:00:00.000Z', 1, | 214 | '2010-01-01T00:00:00.000Z', 1, |
151 | ], | 215 | ], |
216 | statsFields: {min: '2000-01-01T00:00:00.000Z', max: '2010-01-01T00:00:00.000Z'}, | ||
152 | }, | 217 | }, |
153 | facetQueries: { | 218 | }; |
154 | 'model:misc': 26, | 219 | var responses = { |
155 | 'model:startsWithB': 0, | 220 | sequential: [ |
156 | }, | 221 | createStaticSolrResponse({stats: true}, createSolrDataMerger(defaultModelData)), |
157 | statsFields: { | ||
158 | year: {min: '2000', max: '2010'}, | ||
159 | dateOfBirth: {min: '2000', max: '2010'}, | ||
160 | value: {min: '1234', max: '23456'}, | ||
161 | }, | ||
162 | }), | ||
163 | ], | 222 | ], |
164 | suggestions: [ | 223 | suggestions: [ |
165 | createStaticSolrResponse({stats: true}, { | 224 | createStaticSolrResponse({stats: true}, { | ... | ... |
... | @@ -29,7 +29,8 @@ define(function(require) { | ... | @@ -29,7 +29,8 @@ define(function(require) { |
29 | return obj[key]; | 29 | return obj[key]; |
30 | }, | 30 | }, |
31 | setField: function getField(obj, key, value) { | 31 | setField: function getField(obj, key, value) { |
32 | return obj[key] = value; | 32 | obj[key] = value; |
33 | return value; | ||
33 | }, | 34 | }, |
34 | getItemKeyAccessor: function getItemKeyAccessor(item) { | 35 | getItemKeyAccessor: function getItemKeyAccessor(item) { |
35 | return item.get('key'); | 36 | return item.get('key'); | ... | ... |
-
Please register or sign in to post a comment