628b2310 by Adam Heath

Major rework, uses a builder pattern now.

1 parent 2b235279
......@@ -61,7 +61,6 @@ module.exports = function(grunt) {
var _ = require('lodash');
function genJasmineConfig(withCoverage, options) {
var template, templateOptions;
var src = [
'src/scripts/{,**/}*.js',
'!src/scripts/main.js',
......@@ -103,7 +102,7 @@ module.exports = function(grunt) {
}
}
url = parts.join('/');
if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.spec\.js$/)) {
if (0) if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.spec\.js$/)) {
url = './.grunt/grunt-contrib-jasmine/' + url;
} else if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.js$/)) {
url = './.grunt/grunt-contrib-jasmine/' + url;
......@@ -149,7 +148,7 @@ module.exports = function(grunt) {
template: template,
templateOptions: templateOptions,
},
}
};
return jasmineConfig;
}
......
......@@ -2,6 +2,7 @@ define(function(require) {
'use strict';
var _ = require('underscore');
var Util = require('./Util');
var Facet = require('./Facet');
var Facets = require('./Facets');
var Solr = require('./Solr');
......@@ -19,23 +20,26 @@ define(function(require) {
return solrData;
}
function makeSolrResponseMixedCase(solrData) {
var facetCounts = Util.getField(solrData, 'facet_counts');
function makeSolrResponseMixedCase(solrResponse) {
var facetCounts = Util.getField(solrResponse, 'facet_counts');
return {
facetCounts: facetCounts,
facetRanges: Util.getField(facetCounts, 'facet_ranges'),
facetFields: Util.getField(facetCounts, 'facet_fields'),
facetQueries: Util.getField(facetCounts, 'facet_queries'),
statsFields: Util.getField(solrData.stats, 'stats_fields'),
statsFields: Util.getField(solrResponse.stats, 'stats_fields'),
};
}
function createStaticSolrResponse(has, toMerge) {
var solrResponse = createSolrResponse({stats: true});
var solrData = makeSolrResponseMixedCase(solrResponse);
if (_.isFunction(toMerge)) {
toMerge = toMerge(solrData);
} else {
_.each(solrData, function(value, key) {
_.extend(value, toMerge[key]);
});
}
return solrResponse;
}
......@@ -45,26 +49,26 @@ define(function(require) {
expect(item.get('checked')).toEqual(checked);
}
var facetsBuilder = function facetsBuilder() {
return {
model: new Facets.Facet({
var definedFacets = {
model: [
{
formName: 'model',
label: 'Model',
},
{
}, {
queryField: 'model_s',
facetType: 'field',
bins: {
misc: ['saturn', 'jeep'],
startsWithB: ['buick'],
},
}),
year: new Facets.Facet({
},
],
year: [
{
formName: 'year',
orderByDirection: 'desc',
label: 'Year',
},
{
}, {
queryField: 'year_dt',
comparator: 'date',
facetType: 'year-field',
......@@ -80,8 +84,10 @@ define(function(require) {
var year = new Date(value).getUTCFullYear();
return year + ' - ' + (year + 2);
},
}),
dateOfBirth: new Facets.Facet({
},
],
dateOfBirth: [
{
formName: 'dateOfBirth',
label: 'Birthday',
}, {
......@@ -91,8 +97,10 @@ define(function(require) {
facetStats: true,
other: 'before',
start: 'NOW/YEAR-25YEAR',
}),
value: new Facets.Facet({
},
],
value: [
{
formName: 'value',
label: 'Value',
}, {
......@@ -104,15 +112,53 @@ define(function(require) {
var value = parseInt(item.get('key'));
return '$' + value + ' - $' + (value + 1000);
},
}),
},
],
bodyType: [
{
label: 'Type'
}, {
facetType: 'field',
labelMap: {
aluminum: 'Aluminum',
plastic: 'Plastic',
carbonComposite: 'Carbon Composite',
steel: 'Steel',
},
},
],
};
var facetsBuilder = function facetsBuilder(facetName) {
if (facetName) {
return new Facet(definedFacets[facetName][0], definedFacets[facetName][1]);
}
var result = {};
_.each(_.keys(definedFacets), function(facetName) {
result[facetName] = new Facet(definedFacets[facetName][0], definedFacets[facetName][1]);
});
return result;
};
var responses = {
sequential: [
createStaticSolrResponse({stats: true}, {
facetRanges: {
function createSolrDataMerger(modelData) {
return function(solrData) {
_.each(solrData, function(solrValue, solrKey) {
_.each(modelData, function(modelObj, modelKey) {
var modelValue = modelObj[solrKey];
if (modelValue) {
if (solrKey === 'facetQueries') {
_.extend(solrValue, modelValue);
} else {
solrValue[modelKey] = modelValue;
}
}
});
});
};
}
var defaultModelData = {
dateOfBirth: {
facetRanges: {
counts: [
'1974-01-01T00:00:00.000Z', 1,
'1972-01-01T00:00:00.000Z', 1,
......@@ -120,9 +166,18 @@ define(function(require) {
],
before: 5,
},
statsFields: {min: '2000', max: '2010'},
},
facetFields: {
model: [
bodyType: {
facetFields: [
'aluminum', 14,
'carbonComposite', 66,
'steel', 2,
],
},
model: {
facetFields: [
'ford', 23,
'chevy', 18,
'toyota', 5,
......@@ -131,12 +186,21 @@ define(function(require) {
'buick', 0, // keep here to test the bin/exclude feature
'dodge', 0,
],
value: [
facetQueries: {
'model:misc': 26,
'model:startsWithB': 0,
},
},
value: {
facetFields: [
'23456', 1,
'5678', 2,
'1234', 3,
],
year: [
statsFields: {min: '1234', max: '23456'},
},
year: {
facetFields: [
'2000-01-01T00:00:00.000Z', 1,
'2001-01-01T00:00:00.000Z', 4,
'2002-01-01T00:00:00.000Z', 0,
......@@ -149,17 +213,12 @@ define(function(require) {
'2009-01-01T00:00:00.000Z', 0,
'2010-01-01T00:00:00.000Z', 1,
],
statsFields: {min: '2000-01-01T00:00:00.000Z', max: '2010-01-01T00:00:00.000Z'},
},
facetQueries: {
'model:misc': 26,
'model:startsWithB': 0,
},
statsFields: {
year: {min: '2000', max: '2010'},
dateOfBirth: {min: '2000', max: '2010'},
value: {min: '1234', max: '23456'},
},
}),
};
var responses = {
sequential: [
createStaticSolrResponse({stats: true}, createSolrDataMerger(defaultModelData)),
],
suggestions: [
createStaticSolrResponse({stats: true}, {
......
......@@ -29,7 +29,8 @@ define(function(require) {
return obj[key];
},
setField: function getField(obj, key, value) {
return obj[key] = value;
obj[key] = value;
return value;
},
getItemKeyAccessor: function getItemKeyAccessor(item) {
return item.get('key');
......