Skip to content

Commit

Permalink
fix bug in initFromSettingsJSON when no facets are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
francesko committed Jan 14, 2016
1 parent 87e9483 commit 5ac5a29
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 85 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Backbone.Facetr",
"version": "0.4.1",
"version": "0.4.2",
"main": "dist/backbone.facetr.js",
"ignore": [
"**/.*",
Expand Down
83 changes: 42 additions & 41 deletions dist/backbone.facetr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// backbone.facetr 0.4.1
// backbone.facetr 0.4.2
// Copyright (c)2012 Arillo GmbH
// Author: Francesco Macri
// Distributed under MIT license
Expand Down Expand Up @@ -30,7 +30,7 @@
return _getCollection(collection);
};

Backbone.Facetr.VERSION = '0.4.1';
Backbone.Facetr.VERSION = '0.4.2';

// facet collections cache
var _collections = {};
Expand Down Expand Up @@ -1180,54 +1180,55 @@
};

this.initFromSettingsJSON = function(json) {
var facetCollection, facetr, facets, sort, filter, facetData, attr,
var facetCollection, facetr, facets, sort, facetData, attr,
eop, iop, fsort, cust, values, facet, i, j, k, len, len2;

facetr = Backbone.Facetr;
facetCollection = facetr(collection);
facets = json.facets;
sort = json.sort;
filter = json.search;

for(i = 0, len = facets.length; i < len; i += 1) {
facetData = facets[i];
attr = facetData.attr;
eop = facetData.eop;
iop = facetData.iop;
fsort = facetData.sort;
cust = facetData.cust;
values = facetData.vals;

facet = facetCollection.facet(attr, eop);

switch(fsort.by){
case 'count' : {
facet.sortByCount();
} break;
case 'activeCount' : {
facet.sortByActiveCount();
} break;
default:{
facet.sortByValue();
}
}

facet[fsort.direction]();

if(cust){
for(k in cust){
if(cust.hasOwnProperty(k)){
facet.customData(k, cust[k]);
}
}
}

for(j = 0, len2 = values.length; j < len2; j += 1) {
facet.value(values[j], iop);
}
if(facets != null) {
for(i = 0, len = facets.length; i < len; i += 1) {
facetData = facets[i];
attr = facetData.attr;
eop = facetData.eop;
iop = facetData.iop;
fsort = facetData.sort;
cust = facetData.cust;
values = facetData.vals;

facet = facetCollection.facet(attr, eop);

switch(fsort.by){
case 'count' : {
facet.sortByCount();
} break;
case 'activeCount' : {
facet.sortByActiveCount();
} break;
default:{
facet.sortByValue();
}
}

facet[fsort.direction]();

if(cust){
for(k in cust){
if(cust.hasOwnProperty(k)){
facet.customData(k, cust[k]);
}
}
}

for(j = 0, len2 = values.length; j < len2; j += 1) {
facet.value(values[j], iop);
}
}
}

if(sort) {
if(sort != null) {
var sattr = sort.by,
sdir = sort.dir;

Expand Down
4 changes: 2 additions & 2 deletions dist/backbone.facetr.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "backbone.facetr",
"description": "A library to perform faceted search on Backbone collections",
"version": "0.4.1",
"version": "0.4.2",
"homepage": "https://github.com/arillo/Backbone.Facetr",
"license": "MIT",
"keywords": [
Expand Down
79 changes: 40 additions & 39 deletions src/facetr.facetcollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,54 +450,55 @@ var FacetCollection = function(collection) {
};

this.initFromSettingsJSON = function(json) {
var facetCollection, facetr, facets, sort, filter, facetData, attr,
var facetCollection, facetr, facets, sort, facetData, attr,
eop, iop, fsort, cust, values, facet, i, j, k, len, len2;

facetr = Backbone.Facetr;
facetCollection = facetr(collection);
facets = json.facets;
sort = json.sort;
filter = json.search;

for(i = 0, len = facets.length; i < len; i += 1) {
facetData = facets[i];
attr = facetData.attr;
eop = facetData.eop;
iop = facetData.iop;
fsort = facetData.sort;
cust = facetData.cust;
values = facetData.vals;

facet = facetCollection.facet(attr, eop);

switch(fsort.by){
case 'count' : {
facet.sortByCount();
} break;
case 'activeCount' : {
facet.sortByActiveCount();
} break;
default:{
facet.sortByValue();
}
}

facet[fsort.direction]();

if(cust){
for(k in cust){
if(cust.hasOwnProperty(k)){
facet.customData(k, cust[k]);
}
}
}

for(j = 0, len2 = values.length; j < len2; j += 1) {
facet.value(values[j], iop);
}
if(facets != null) {
for(i = 0, len = facets.length; i < len; i += 1) {
facetData = facets[i];
attr = facetData.attr;
eop = facetData.eop;
iop = facetData.iop;
fsort = facetData.sort;
cust = facetData.cust;
values = facetData.vals;

facet = facetCollection.facet(attr, eop);

switch(fsort.by){
case 'count' : {
facet.sortByCount();
} break;
case 'activeCount' : {
facet.sortByActiveCount();
} break;
default:{
facet.sortByValue();
}
}

facet[fsort.direction]();

if(cust){
for(k in cust){
if(cust.hasOwnProperty(k)){
facet.customData(k, cust[k]);
}
}
}

for(j = 0, len2 = values.length; j < len2; j += 1) {
facet.value(values[j], iop);
}
}
}

if(sort) {
if(sort != null) {
var sattr = sort.by,
sdir = sort.dir;

Expand Down
2 changes: 1 addition & 1 deletion src/facetr.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
return _getCollection(collection);
};

Backbone.Facetr.VERSION = '0.4.1';
Backbone.Facetr.VERSION = '0.4.2';

//= facetr.helpers.js
//= facetr.facet.js
Expand Down

0 comments on commit 5ac5a29

Please sign in to comment.