Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
solr-frontend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
8534addb
authored
2016-02-05 17:11:41 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Much more testing of Facet, getting closer to 100%.
1 parent
2cc67ace
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
18 deletions
src/scripts/solr/model/Facet.js
test/specs/Facet.js
src/scripts/solr/model/Facet.js
View file @
8534add
...
...
@@ -33,6 +33,7 @@ define(function(require) {
var
Facet
=
Backbone
.
Model
.
extend
({
defaults
:
function
defaults
()
{
return
{
checkedKeys
:
[],
formName
:
null
,
query
:
null
,
suggestions
:
[],
...
...
@@ -110,7 +111,7 @@ define(function(require) {
var
newChecked
=
checkedKeys
[
facetItem
.
get
(
'key'
)];
var
currentChecked
=
facetItem
.
get
(
'checked'
);
if
(
newChecked
!==
currentChecked
)
{
facetItem
.
set
(
'checked'
,
newChecked
);
facetItem
.
set
(
'checked'
,
!!
newChecked
);
}
if
(
facetItem
.
get
(
'checked'
))
{
checkedCount
++
;
...
...
@@ -128,19 +129,6 @@ define(function(require) {
if
(
!
sortKeyExtractor
)
{
sortKeyExtractor
=
getItemKeyAccessor
;
}
var
comparator
=
options
.
comparator
;
if
(
!
comparator
)
{
comparator
=
Sort
.
standard
;
}
else
if
(
typeof
comparator
===
'string'
)
{
comparator
=
Sort
[
comparator
];
}
switch
(
options
.
facetType
)
{
case
'year'
:
case
'range'
:
case
'interval'
:
comparator
=
wrapComparatorForAllBeforeAfter
(
comparator
,
[
'all'
,
'before'
].
indexOf
(
options
.
other
)
!==
-
1
,
[
'all'
,
'after'
].
indexOf
(
options
.
other
)
!==
-
1
);
break
;
}
var
formatter
=
options
.
formatter
;
if
(
!
formatter
)
{
var
labelMap
=
options
.
labelMap
;
...
...
@@ -155,21 +143,46 @@ define(function(require) {
}
}
this
.
formatter
=
formatter
;
this
.
on
(
'change:comparator change:orderByDirection'
,
function
()
{
var
comparator
=
this
.
get
(
'comparator'
);
if
(
!
comparator
)
{
comparator
=
Sort
.
standard
;
}
else
if
(
typeof
comparator
===
'string'
)
{
comparator
=
Sort
[
comparator
];
}
switch
(
options
.
facetType
)
{
case
'year'
:
case
'range'
:
case
'interval'
:
comparator
=
wrapComparatorForAllBeforeAfter
(
comparator
,
[
'all'
,
'before'
].
indexOf
(
options
.
other
)
!==
-
1
,
[
'all'
,
'after'
].
indexOf
(
options
.
other
)
!==
-
1
);
break
;
}
var
facet
=
this
;
comparator
=
(
function
(
comparator
)
{
return
function
facetItemValue
(
a
,
b
)
{
var
keyA
=
sortKeyExtractor
(
a
);
var
keyB
=
sortKeyExtractor
(
b
);
switch
(
this
.
get
(
'orderByDirection'
))
{
switch
(
facet
.
get
(
'orderByDirection'
))
{
case
'desc'
:
var
tmp
=
keyA
;
keyA
=
keyB
;
keyB
=
tmp
;
break
;
}
return
comparator
.
call
(
this
,
sortKeyExtractor
(
a
),
sortKeyExtractor
(
b
)
);
return
comparator
.
call
(
facet
,
keyA
,
keyB
);
};
})(
comparator
);
this
.
set
(
'items'
,
new
ItemCollection
([],
{
comparator
:
comparator
}));
var
items
=
this
.
get
(
'items'
);
items
.
comparator
=
comparator
;
items
.
sort
();
},
this
);
this
.
set
(
'items'
,
new
ItemCollection
([]));
this
.
set
(
'comparator'
,
options
.
comparator
,
{
silent
:
true
});
this
.
trigger
(
'change:comparator'
);
this
.
get
(
'items'
).
on
(
'item-change'
,
function
()
{
this
.
trigger
(
'item-change'
);
},
this
);
this
.
facetType
=
options
.
facetType
;
this
.
facetStats
=
options
.
facetStats
;
this
.
other
=
options
.
other
;
...
...
@@ -243,7 +256,7 @@ define(function(require) {
checked
:
false
,
hidden
:
false
,
},
_
initialize
:
function
(
data
,
options
)
{
initialize
:
function
(
data
,
options
)
{
this
.
on
(
'add'
,
function
(
model
,
parent
,
options
)
{
// added to a collection
this
.
on
(
'change:checked'
,
function
()
{
...
...
test/specs/Facet.js
View file @
8534add
This diff is collapsed.
Click to expand it.
Please
register
or
sign in
to post a comment