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
20a89fea
Commit
20a89fea
authored
Aug 01, 2014
by
gergely-ujvari
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1368 from hypothesis/search-callback-routing-cleanup
Search callback routing cleanup
parents
13161352
0adec576
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
67 deletions
+37
-67
controllers.coffee
h/static/scripts/controllers.coffee
+18
-37
directives.coffee
h/static/scripts/directives.coffee
+2
-2
searchfilters.coffee
h/static/scripts/searchfilters.coffee
+3
-3
services.coffee
h/static/scripts/services.coffee
+6
-5
streamsearch.coffee
h/static/scripts/streamsearch.coffee
+3
-14
directives-test.coffee
tests/js/directives-test.coffee
+5
-6
No files found.
h/static/scripts/controllers.coffee
View file @
20a89fea
...
@@ -10,6 +10,7 @@ class App
...
@@ -10,6 +10,7 @@ class App
frame
:
frame
:
visible
:
false
visible
:
false
ongoingHighlightSwitch
:
false
ongoingHighlightSwitch
:
false
search
:
{}
sheet
:
{}
sheet
:
{}
sorts
:
[
sorts
:
[
'Newest'
'Newest'
...
@@ -40,8 +41,7 @@ class App
...
@@ -40,8 +41,7 @@ class App
socialView
:
annotator
.
socialView
socialView
:
annotator
.
socialView
ongoingHighlightSwitch
:
false
ongoingHighlightSwitch
:
false
search
:
search
:
query
:
$location
.
search
()
query
:
$location
.
search
()[
'q'
]
show
:
not
angular
.
equals
(
$location
.
search
(),
{})
session
:
session
session
:
session
_reset
()
_reset
()
...
@@ -105,12 +105,6 @@ class App
...
@@ -105,12 +105,6 @@ class App
$scope
.
reloadAnnotations
()
$scope
.
reloadAnnotations
()
$scope
.
initUpdater
()
$scope
.
initUpdater
()
$scope
.
$watch
'search.show'
,
(
visible
)
->
if
visible
$timeout
->
$element
.
find
(
'.visual-search'
).
find
(
'input'
).
last
().
focus
()
,
10
$scope
.
$watch
'socialView.name'
,
(
newValue
,
oldValue
)
->
$scope
.
$watch
'socialView.name'
,
(
newValue
,
oldValue
)
->
return
if
newValue
is
oldValue
return
if
newValue
is
oldValue
console
.
log
"Social View changed to '"
+
newValue
+
"'. Reloading annotations."
console
.
log
"Social View changed to '"
+
newValue
+
"'. Reloading annotations."
...
@@ -219,41 +213,23 @@ class App
...
@@ -219,41 +213,23 @@ class App
$rootScope
.
applySort
"Location"
$rootScope
.
applySort
"Location"
$scope
.
query
=
$location
.
search
()
$scope
.
search
=
{}
$scope
.
search
.
update
=
angular
.
noop
$scope
.
search
.
clear
=
angular
.
noop
#$scope.show_search = Object.keys($scope.query).length > 0
$rootScope
.
$on
'$routeChangeSuccess'
,
(
event
,
next
,
current
)
->
$rootScope
.
$on
'$routeChangeSuccess'
,
(
event
,
next
,
current
)
->
unless
next
.
$
$route
?
then
return
unless
next
.
$
$route
?
then
return
$scope
.
search
.
query
=
$location
.
search
()
$scope
.
search
.
query
=
$location
.
search
()[
'q'
]
$scope
.
search
.
show
=
not
angular
.
equals
(
$location
.
search
(),
{})
$rootScope
.
viewState
.
show
=
next
.
$
$route
.
originalPath
is
'/viewer'
if
next
.
$
$route
.
originalPath
is
'/viewer'
$rootScope
.
viewState
.
show
=
true
else
$rootScope
.
viewState
.
show
=
false
unless
next
.
$
$route
.
originalPath
is
'/stream'
unless
next
.
$
$route
.
originalPath
is
'/stream'
if
current
and
next
.
$
$route
.
originalPath
is
'/a/:id'
if
current
and
next
.
$
$route
.
originalPath
is
'/a/:id'
$scope
.
reloadAnnotations
()
$scope
.
reloadAnnotations
()
$scope
.
search
.
update
=
(
searchCollection
)
->
$scope
.
search
.
clear
=
->
return
unless
annotator
.
discardDrafts
()
$location
.
search
(
'q'
,
null
)
query
=
{
query
:
searchCollection
}
unless
angular
.
equals
$location
.
search
(),
query
if
$location
.
path
()
==
'/viewer'
or
$location
.
path
()
==
'/page_search'
$location
.
path
(
'/page_search'
).
search
(
query
)
else
$location
.
path
(
'/stream'
).
search
(
query
)
$scope
.
search
.
clear
=
->
$scope
.
search
.
update
=
(
query
)
->
$location
.
url
(
'/viewer'
)
unless
angular
.
equals
$location
.
search
()[
'q'
],
query
if
annotator
.
discardDrafts
()
$location
.
search
(
'q'
,
query
or
null
)
$scope
.
reloadAnnotations
=
->
$scope
.
reloadAnnotations
=
->
Store
=
plugins
.
Store
Store
=
plugins
.
Store
...
@@ -730,6 +706,9 @@ class Viewer
...
@@ -730,6 +706,9 @@ class Viewer
$location
,
$rootScope
,
$routeParams
,
$scope
,
$location
,
$rootScope
,
$routeParams
,
$scope
,
annotator
annotator
)
->
)
->
if
$routeParams
.
q
return
$location
.
path
(
'/page_search'
).
replace
()
{
providers
,
threading
}
=
annotator
{
providers
,
threading
}
=
annotator
$scope
.
activate
=
(
annotation
)
->
$scope
.
activate
=
(
annotation
)
->
...
@@ -756,13 +735,14 @@ class Search
...
@@ -756,13 +735,14 @@ class Search
'annotator'
,
'viewFilter'
]
'annotator'
,
'viewFilter'
]
constructor
:
(
$filter
,
$location
,
$rootScope
,
$routeParams
,
$sce
,
$scope
,
constructor
:
(
$filter
,
$location
,
$rootScope
,
$routeParams
,
$sce
,
$scope
,
annotator
,
viewFilter
)
->
annotator
,
viewFilter
)
->
unless
$routeParams
.
q
return
$location
.
path
(
'/viewer'
).
replace
()
{
providers
,
threading
}
=
annotator
{
providers
,
threading
}
=
annotator
$scope
.
highlighter
=
'<span class="search-hl-active">$&</span>'
$scope
.
highlighter
=
'<span class="search-hl-active">$&</span>'
$scope
.
filter_orderBy
=
$filter
(
'orderBy'
)
$scope
.
filter_orderBy
=
$filter
(
'orderBy'
)
$scope
.
matches
=
[]
$scope
.
matches
=
[]
$scope
.
search
.
query
=
$location
.
search
()
$scope
.
search
.
show
=
true
$scope
.
render_order
=
{}
$scope
.
render_order
=
{}
$scope
.
render_pos
=
{}
$scope
.
render_pos
=
{}
$scope
.
ann_info
=
$scope
.
ann_info
=
...
@@ -834,7 +814,8 @@ class Search
...
@@ -834,7 +814,8 @@ class Search
refresh
()
refresh
()
refresh
=
=>
refresh
=
=>
[
$scope
.
matches
,
$scope
.
filters
]
=
viewFilter
.
filter
$rootScope
.
annotations
,
$routeParams
query
=
$routeParams
.
q
[
$scope
.
matches
,
$scope
.
filters
]
=
viewFilter
.
filter
$rootScope
.
annotations
,
query
# Create the regexps for highlighting the matches inside the annotations' bodies
# Create the regexps for highlighting the matches inside the annotations' bodies
$scope
.
text_tokens
=
$scope
.
filters
.
text
.
terms
.
slice
()
$scope
.
text_tokens
=
$scope
.
filters
.
text
.
terms
.
slice
()
$scope
.
text_regexp
=
[]
$scope
.
text_regexp
=
[]
...
...
h/static/scripts/directives.coffee
View file @
20a89fea
...
@@ -412,8 +412,8 @@ simpleSearch = ['$parse', ($parse) ->
...
@@ -412,8 +412,8 @@ simpleSearch = ['$parse', ($parse) ->
_clear
(
scope
)
if
attr
.
onclear
_clear
(
scope
)
if
attr
.
onclear
scope
.
$watch
attr
.
query
,
(
query
)
->
scope
.
$watch
attr
.
query
,
(
query
)
->
if
query
.
query
?
if
query
?
scope
.
searchtext
=
query
.
query
scope
.
searchtext
=
query
_search
(
scope
,
{
"this"
:
scope
.
searchtext
})
_search
(
scope
,
{
"this"
:
scope
.
searchtext
})
restrict
:
'C'
restrict
:
'C'
...
...
h/static/scripts/searchfilters.coffee
View file @
20a89fea
...
@@ -162,13 +162,13 @@ class QueryParser
...
@@ -162,13 +162,13 @@ class QueryParser
exact_match
:
false
exact_match
:
false
case_sensitive
:
false
case_sensitive
:
false
and_or
:
'and'
and_or
:
'and'
tag
s
:
tag
:
path
:
'/tags'
path
:
'/tags'
exact_match
:
false
exact_match
:
false
case_sensitive
:
false
case_sensitive
:
false
and_or
:
'or'
and_or
:
'or'
quote
:
quote
:
path
:
"/quote"
path
:
'/quote'
exact_match
:
false
exact_match
:
false
case_sensitive
:
false
case_sensitive
:
false
and_or
:
'and'
and_or
:
'and'
...
@@ -212,7 +212,7 @@ class QueryParser
...
@@ -212,7 +212,7 @@ class QueryParser
query_type
:
'multi_match'
query_type
:
'multi_match'
match_type
:
'cross_fields'
match_type
:
'cross_fields'
and_or
:
'and'
and_or
:
'and'
fields
:
[
'quote'
,
'tag
s
'
,
'text'
,
'uri'
,
'user'
]
fields
:
[
'quote'
,
'tag'
,
'text'
,
'uri'
,
'user'
]
parseModels
:
(
models
)
->
parseModels
:
(
models
)
->
...
...
h/static/scripts/services.coffee
View file @
20a89fea
...
@@ -736,12 +736,13 @@ class ViewFilter
...
@@ -736,12 +736,13 @@ class ViewFilter
matches
=
true
matches
=
true
# Make copy for filtering
# Make copy for filtering
copy
=
value
.
slice
()
copy
=
value
.
slice
()
copy
.
filter
(
e
)
->
not
match
filter
.
terms
,
e
if
(
filter
.
operator
is
'and'
and
copy
.
length
<
value
.
length
)
or
copy
=
copy
.
filter
(
e
)
->
match
filter
.
terms
,
e
if
(
filter
.
operator
is
'and'
and
copy
.
length
<
filter
.
terms
.
length
)
or
(
filter
.
operator
is
'or'
and
not
copy
.
length
)
(
filter
.
operator
is
'or'
and
not
copy
.
length
)
matches
=
false
matches
=
false
matches
matches
_anyMatches
:
(
filter
,
value
,
match
)
->
_anyMatches
:
(
filter
,
value
,
match
)
->
...
@@ -788,7 +789,7 @@ class ViewFilter
...
@@ -788,7 +789,7 @@ class ViewFilter
# the faceted filters
# the faceted filters
# ]
# ]
filter
:
(
annotations
,
query
)
=>
filter
:
(
annotations
,
query
)
=>
filters
=
@
searchfilter
.
generateFacetedFilter
query
.
query
filters
=
@
searchfilter
.
generateFacetedFilter
query
results
=
[]
results
=
[]
# Check for given limit
# Check for given limit
...
...
h/static/scripts/streamsearch.coffee
View file @
20a89fea
...
@@ -11,11 +11,11 @@ imports = [
...
@@ -11,11 +11,11 @@ imports = [
class
StreamSearch
class
StreamSearch
this
.
inject
=
[
this
.
inject
=
[
'$
location'
,
'$
scope'
,
'$rootScope'
,
'$scope'
,
'$rootScope'
,
'queryparser'
,
'session'
,
'searchfilter'
,
'streamfilter'
'queryparser'
,
'session'
,
'searchfilter'
,
'streamfilter'
]
]
constructor
:
(
constructor
:
(
$
location
,
$
scope
,
$rootScope
,
$scope
,
$rootScope
,
queryparser
,
session
,
searchfilter
,
streamfilter
queryparser
,
session
,
searchfilter
,
streamfilter
)
->
)
->
# Initialize the base filter
# Initialize the base filter
...
@@ -25,8 +25,7 @@ class StreamSearch
...
@@ -25,8 +25,7 @@ class StreamSearch
.
setPastDataHits
(
50
)
.
setPastDataHits
(
50
)
# Apply query clauses
# Apply query clauses
$scope
.
query
=
$location
.
search
()[
'query'
]
terms
=
searchfilter
.
generateFacetedFilter
$scope
.
search
.
query
terms
=
searchfilter
.
generateFacetedFilter
$scope
.
query
queryparser
.
populateFilter
streamfilter
,
terms
queryparser
.
populateFilter
streamfilter
,
terms
$scope
.
updater
?
.
then
(
sock
)
->
$scope
.
updater
?
.
then
(
sock
)
->
...
@@ -37,16 +36,6 @@ class StreamSearch
...
@@ -37,16 +36,6 @@ class StreamSearch
$rootScope
.
applyView
"Document"
# Non-sensical, but best for the moment
$rootScope
.
applyView
"Document"
# Non-sensical, but best for the moment
$rootScope
.
applySort
"Newest"
$rootScope
.
applySort
"Newest"
$scope
.
search
.
query
=
$location
.
search
()
$scope
.
search
.
show
=
not
angular
.
equals
(
$location
.
search
(),
{})
$scope
.
search
.
update
=
(
query
)
->
unless
angular
.
equals
$location
.
search
(
query
),
query
$location
.
search
{
query
:
query
}
$scope
.
search
.
clear
=
->
$location
.
search
({})
$scope
.
openDetails
=
(
annotation
)
->
$scope
.
openDetails
=
(
annotation
)
->
$scope
.
loadMore
=
(
number
)
=>
$scope
.
loadMore
=
(
number
)
=>
# TODO: debounce
# TODO: debounce
...
...
tests/js/directives-test.coffee
View file @
20a89fea
...
@@ -136,7 +136,6 @@ describe 'h.directives', ->
...
@@ -136,7 +136,6 @@ describe 'h.directives', ->
describe
'.simpleSearch'
,
->
describe
'.simpleSearch'
,
->
$element
=
null
$element
=
null
beforeEach
->
beforeEach
->
$scope
.
query
=
{}
$scope
.
update
=
sinon
.
spy
()
$scope
.
update
=
sinon
.
spy
()
$scope
.
clear
=
sinon
.
spy
()
$scope
.
clear
=
sinon
.
spy
()
...
@@ -152,12 +151,12 @@ describe 'h.directives', ->
...
@@ -152,12 +151,12 @@ describe 'h.directives', ->
$scope
.
$digest
()
$scope
.
$digest
()
it
'updates the search-bar'
,
->
it
'updates the search-bar'
,
->
$scope
.
query
=
{
query
:
"Test query"
}
$scope
.
query
=
"Test query"
$scope
.
$digest
()
$scope
.
$digest
()
assert
.
equal
(
$scope
.
searchtext
,
$scope
.
query
.
query
)
assert
.
equal
(
$scope
.
searchtext
,
$scope
.
query
)
it
'calls the given search function'
,
->
it
'calls the given search function'
,
->
$scope
.
query
=
{
query
:
"Test query"
}
$scope
.
query
=
"Test query"
$scope
.
$digest
()
$scope
.
$digest
()
$element
.
trigger
(
'submit'
)
$element
.
trigger
(
'submit'
)
sinon
.
assert
.
calledWith
(
$scope
.
update
,
"Test query"
)
sinon
.
assert
.
calledWith
(
$scope
.
update
,
"Test query"
)
...
@@ -167,7 +166,7 @@ describe 'h.directives', ->
...
@@ -167,7 +166,7 @@ describe 'h.directives', ->
assert
(
$scope
.
clear
.
called
)
assert
(
$scope
.
clear
.
called
)
it
'clears the search-bar'
,
->
it
'clears the search-bar'
,
->
$scope
.
query
=
{
query
:
"Test query"
}
$scope
.
query
=
"Test query"
$scope
.
$digest
()
$scope
.
$digest
()
$element
.
find
(
'.simple-search-clear'
).
click
()
$element
.
find
(
'.simple-search-clear'
).
click
()
assert
.
equal
(
$scope
.
searchtext
,
''
)
assert
.
equal
(
$scope
.
searchtext
,
''
)
...
@@ -177,7 +176,7 @@ describe 'h.directives', ->
...
@@ -177,7 +176,7 @@ describe 'h.directives', ->
assert
.
include
(
$form
.
prop
(
'className'
),
'simple-search-inactive'
)
assert
.
include
(
$form
.
prop
(
'className'
),
'simple-search-inactive'
)
it
'removes the class from the form when there is an input value'
,
->
it
'removes the class from the form when there is an input value'
,
->
$scope
.
query
=
{
query
:
"Test query"
}
$scope
.
query
=
"Test query"
$scope
.
$digest
()
$scope
.
$digest
()
$form
=
$element
.
find
(
'.simple-search-form'
)
$form
=
$element
.
find
(
'.simple-search-form'
)
...
...
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