Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
6419c9a5
Commit
6419c9a5
authored
Feb 02, 2015
by
Randall Leeds
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1896 from hypothesis/improve-viewfilter
Improve viewfilter
parents
5f01d136
b4b68c69
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
177 additions
and
11 deletions
+177
-11
services.coffee
h/static/scripts/services.coffee
+6
-11
services-test.coffee
tests/js/services-test.coffee
+171
-0
No files found.
h/static/scripts/services.coffee
View file @
6419c9a5
...
...
@@ -365,7 +365,7 @@ class ViewFilter
uri
:
autofalse
:
(
annotation
)
->
return
not
annotation
.
uri
?
value
:
(
annotation
)
->
return
annotation
.
uri
match
:
(
term
,
value
)
->
return
value
is
term
match
:
(
term
,
value
)
->
return
value
.
indexOf
(
term
)
>
-
1
user
:
autofalse
:
(
annotation
)
->
return
not
annotation
.
user
?
value
:
(
annotation
)
->
return
annotation
.
user
...
...
@@ -373,9 +373,8 @@ class ViewFilter
any
:
fields
:
[
'quote'
,
'text'
,
'tag'
,
'user'
]
this
.
$inject
=
[
'searchfilter'
,
'stringHelpers'
]
constructor
:
(
searchfilter
,
stringHelpers
)
->
@
searchfilter
=
searchfilter
this
.
$inject
=
[
'stringHelpers'
]
constructor
:
(
stringHelpers
)
->
@
_normalize
=
(
e
)
->
if
typeof
e
is
'string'
...
...
@@ -399,10 +398,10 @@ class ViewFilter
_arrayMatches
:
(
filter
,
value
,
match
)
->
matches
=
true
# Make copy for filtering
copy
=
value
.
slice
()
copy
=
filter
.
terms
.
slice
()
copy
=
copy
.
filter
(
e
)
->
match
filter
.
terms
,
e
match
value
,
e
if
(
filter
.
operator
is
'and'
and
copy
.
length
<
filter
.
terms
.
length
)
or
(
filter
.
operator
is
'or'
and
not
copy
.
length
)
...
...
@@ -436,11 +435,7 @@ class ViewFilter
# value: a function to extract to facet value for the annotation.
# match: a function to check if the extracted value matches with the facet value
#
# Returns a two-element list:
# [
# matched annotation IDs list,
# the faceted filters
# ]
# Returns the matched annotation IDs list,
filter
:
(
annotations
,
filters
)
->
limit
=
Math
.
min
((
filters
.
result
?
.
terms
or
[])...)
count
=
0
...
...
tests/js/services-test.coffee
0 → 100644
View file @
6419c9a5
assert
=
chai
.
assert
sinon
.
assert
.
expose
assert
,
prefix
:
null
poem
=
tiger
:
'Tiger! Tiger! burning bright
In the forest of the night
What immortal hand or eye
Could frame thy fearful symmetry?'
raven
:
'Once upon a midnight dreary, while I pondered, weak and weary,
Over many a quaint and curious volume of forgotten lore—
While I nodded, nearly napping, suddenly there came a tapping,
As of some one gently rapping, rapping at my chamber door.
“’Tis some visitor,” I muttered, “tapping at my chamber door—
Only this and nothing more.”'
describe
'h'
,
->
sandbox
=
null
beforeEach
module
(
'h'
)
beforeEach
module
(
$provide
)
->
sandbox
=
sinon
.
sandbox
.
create
()
return
afterEach
->
sandbox
.
restore
()
describe
'viewFilter service'
,
->
viewFilter
=
null
stringHelpers
=
null
beforeEach
inject
(
_stringHelpers_
,
_viewFilter_
)
->
stringHelpers
=
_stringHelpers_
viewFilter
=
_viewFilter_
describe
'filter'
,
->
it
'normalizes the filter terms'
,
->
stringHelpers
.
uniFold
=
sandbox
.
spy
()
filters
=
text
:
terms
:
[
'Tiger'
]
operator
:
'and'
viewFilter
.
filter
[],
filters
assert
.
calledWith
stringHelpers
.
uniFold
,
'tiger'
describe
'filter operators'
,
->
annotations
=
null
beforeEach
->
annotations
=
[
{
id
:
1
,
text
:
poem
.
tiger
},
{
id
:
2
,
text
:
poem
.
raven
}
]
it
'all terms must match for "and" operator'
,
->
filters
=
text
:
terms
:
[
'Tiger'
,
'burning'
,
'bright'
]
operator
:
'and'
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
equal
result
.
length
,
1
assert
.
equal
result
[
0
],
1
it
'only one term must match for "or" operator'
,
->
filters
=
text
:
terms
:
[
'Tiger'
,
'quaint'
]
operator
:
'or'
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
equal
result
.
length
,
2
describe
'checkers'
,
->
describe
'autofalse'
,
->
it
'consider auto false function'
,
->
viewFilter
.
checkers
=
test
:
autofalse
:
sandbox
.
stub
().
returns
(
true
)
value
:
(
annotation
)
->
return
annotation
.
test
match
:
(
term
,
value
)
->
return
value
.
indexOf
(
term
)
>
-
1
filters
=
test
:
terms
:
[
'Tiger'
]
operator
:
'and'
annotations
=
[{
id
:
1
,
test
:
poem
.
tiger
}]
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
called
viewFilter
.
checkers
.
test
.
autofalse
assert
.
equal
result
.
length
,
0
it
'uses the value function to extract data from the annotation'
,
->
viewFilter
.
checkers
=
test
:
autofalse
:
(
annotation
)
->
return
false
value
:
sandbox
.
stub
().
returns
(
'test'
)
match
:
(
term
,
value
)
->
return
value
.
indexOf
(
term
)
>
-
1
filters
=
test
:
terms
:
[
'test'
]
operator
:
'and'
annotations
=
[{
id
:
1
,
test
:
poem
.
tiger
}]
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
called
viewFilter
.
checkers
.
test
.
value
assert
.
equal
result
.
length
,
1
it
'the match function determines the matching'
,
->
viewFilter
.
checkers
=
test
:
autofalse
:
(
annotation
)
->
return
false
value
:
(
annotation
)
->
return
annotation
.
test
match
:
sandbox
.
stub
().
returns
(
false
)
filters
=
test
:
terms
:
[
'Tiger'
]
operator
:
'and'
annotations
=
[{
id
:
1
,
test
:
poem
.
tiger
}]
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
called
viewFilter
.
checkers
.
test
.
match
assert
.
equal
result
.
length
,
0
viewFilter
.
checkers
.
test
.
match
.
returns
(
true
)
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
called
viewFilter
.
checkers
.
test
.
match
assert
.
equal
result
.
length
,
1
describe
'any field'
,
->
it
'finds matches across many fields'
,
->
annotation1
=
{
id
:
1
,
text
:
poem
.
tiger
}
annotation2
=
{
id
:
2
,
user
:
poem
.
tiger
}
annotation3
=
{
id
:
3
,
tags
:
[
'Tiger'
]}
annotations
=
[
annotation1
,
annotation2
,
annotation3
]
filters
=
any
:
terms
:
[
'Tiger'
]
operator
:
'and'
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
equal
result
.
length
,
3
it
'can find terms across different fields'
,
->
annotation
=
id
:
1
text
:
poem
.
tiger
target
:
[
selector
:
[{
"type"
:
"TextQuoteSelector"
,
"exact"
:
"The Tiger by William Blake"
,
}]
user
:
"acct:poe@edgar.com"
tags
:
[
"poem"
,
"Blake"
,
"Tiger"
]
]
filters
=
any
:
terms
:
[
'burning'
,
'William'
,
'poem'
,
'bright'
]
operator
:
'and'
result
=
viewFilter
.
filter
[
annotation
],
filters
assert
.
equal
result
.
length
,
1
assert
.
equal
result
[
0
],
1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment