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
b98b81df
Commit
b98b81df
authored
Aug 10, 2013
by
Ujvari Gergely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving VS initialization from the services to App controller
and using $element.find() instead of $()
parent
a5b3dd15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
155 additions
and
160 deletions
+155
-160
controllers.coffee
h/js/controllers.coffee
+153
-7
services.coffee
h/js/services.coffee
+2
-153
No files found.
h/js/controllers.coffee
View file @
b98b81df
...
@@ -7,11 +7,11 @@ class App
...
@@ -7,11 +7,11 @@ class App
tab
:
null
tab
:
null
this
.
$inject
=
[
this
.
$inject
=
[
'$
element'
,
'$http'
,
'$location
'
,
'$scope'
,
'$timeout'
,
'$
compile'
,
'$element'
,
'$filter'
,
'$http'
,
'$location'
,
'$rootScope
'
,
'$scope'
,
'$timeout'
,
'annotator'
,
'authentication'
,
'drafts'
,
'flash'
'annotator'
,
'authentication'
,
'drafts'
,
'flash'
]
]
constructor
:
(
constructor
:
(
$
element
,
$http
,
$location
,
$scope
,
$timeout
$
compile
,
$element
,
$filter
,
$http
,
$location
,
$rootScope
,
$scope
,
$timeout
annotator
,
authentication
,
drafts
,
flash
annotator
,
authentication
,
drafts
,
flash
)
->
)
->
# Get the base URL from the base tag or the app location
# Get the base URL from the base tag or the app location
...
@@ -232,11 +232,157 @@ class App
...
@@ -232,11 +232,157 @@ class App
$scope
.
createUnattachedAnnotation
=
->
$scope
.
createUnattachedAnnotation
=
->
console
.
log
"Should create unattached annotation"
console
.
log
"Should create unattached annotation"
$scope
.
showSearchBar
=
=>
# Searchbar initialization
annotator
.
show_search
=
true
@
user_filter
=
$filter
(
'userName'
)
search_query
=
''
$scope
.
isSearchShown
=
=>
unless
typeof
(
localStorage
)
is
'undefined'
annotator
.
show_search
search_query
=
localStorage
.
getItem
(
"hyp_page_search_query"
)
console
.
log
'Loading back search query: '
+
search_query
@
visualSearch
=
VS
.
init
container
:
$element
.
find
(
'.visual-search'
)
query
:
search_query
callbacks
:
search
:
(
query
,
searchCollection
)
=>
unless
query
return
matched
=
[]
whole_document
=
true
in_body_text
=
''
for
searchItem
in
searchCollection
.
models
if
searchItem
.
attributes
.
category
is
'scope'
and
searchItem
.
attributes
.
value
is
'sidebar'
whole_document
=
false
if
searchItem
.
attributes
.
category
is
'text'
in_body_text
=
searchItem
.
attributes
.
value
.
toLowerCase
()
text_tokens
=
searchItem
.
attributes
.
value
.
split
' '
if
searchItem
.
attributes
.
category
is
'tag'
tag_search
=
searchItem
.
attributes
.
value
.
toLowerCase
()
if
whole_document
annotations
=
annotator
.
plugins
.
Store
.
annotations
else
annotations
=
$rootScope
.
annotations
for
annotation
in
annotations
matches
=
true
for
searchItem
in
searchCollection
.
models
category
=
searchItem
.
attributes
.
category
value
=
searchItem
.
attributes
.
value
switch
category
when
'user'
userName
=
@
user_filter
annotation
.
user
unless
userName
.
toLowerCase
()
is
value
.
toLowerCase
()
matches
=
false
break
when
'text'
unless
annotation
.
text
?
matches
=
false
break
for
token
in
text_tokens
unless
annotation
.
text
.
toLowerCase
().
indexOf
(
token
.
toLowerCase
())
>
-
1
matches
=
false
break
when
'tag'
unless
annotation
.
tags
?
matches
=
false
break
found
=
false
for
tag
in
annotation
.
tags
if
tag_search
is
tag
.
toLowerCase
()
found
=
true
break
unless
found
matches
=
false
break
when
'time'
delta
=
Math
.
round
((
+
new
Date
-
new
Date
(
annotation
.
updated
))
/
1000
)
switch
value
when
'5 min'
unless
delta
<=
60
*
5
matches
=
false
when
'30 min'
unless
delta
<=
60
*
30
matches
=
false
when
'1 hour'
unless
delta
<=
60
*
60
matches
=
false
when
'12 hours'
unless
delta
<=
60
*
60
*
12
matches
=
false
when
'1 day'
unless
delta
<=
60
*
60
*
24
matches
=
false
when
'1 week'
unless
delta
<=
60
*
60
*
24
*
7
matches
=
false
when
'1 month'
unless
delta
<=
60
*
60
*
24
*
31
matches
=
false
when
'1 year'
unless
delta
<=
60
*
60
*
24
*
366
matches
=
false
when
'group'
priv_public
=
'group:__world__'
in
(
annotation
.
permissions
.
read
or
[])
switch
value
when
'Public'
unless
priv_public
matches
=
false
when
'Private'
if
priv_public
matches
=
false
if
matches
matched
.
push
annotation
.
id
# Save query to localStorage
unless
typeof
(
localStorage
)
is
'undefined'
try
localStorage
.
setItem
"hyp_page_search_query"
,
query
catch
error
console
.
warn
'Cannot save query to localStorage!'
if
error
is
DOMException
.
QUOTA_EXCEEDED_ERR
console
.
warn
'localStorage quota exceeded!'
# Set the path
search
=
whole_document
:
whole_document
matched
:
matched
in_body_text
:
in_body_text
$location
.
path
(
'/page_search'
).
search
(
search
)
$rootScope
.
$digest
()
facetMatches
:
(
callback
)
=>
if
$scope
.
show_search
return
callback
[
'text'
,
'tag'
,
'scope'
,
'group'
,
'time'
,
'user'
],
{
preserveOrder
:
true
}
valueMatches
:
(
facet
,
searchTerm
,
callback
)
->
switch
facet
when
'group'
then
callback
[
'Public'
,
'Private'
]
when
'area'
then
callback
[
'sidebar'
,
'document'
]
when
'time'
callback
[
'5 min'
,
'30 min'
,
'1 hour'
,
'12 hours'
,
'1 day'
,
'1 week'
,
'1 month'
,
'1 year'
],
{
preserveOrder
:
true
}
clearSearch
:
(
original
)
=>
$scope
.
show_search
=
false
original
()
unless
typeof
(
localStorage
)
is
'undefined'
try
localStorage
.
setItem
"hyp_page_search_query"
,
""
catch
error
console
.
warn
'Cannot save query to localStorage!'
if
error
is
DOMException
.
QUOTA_EXCEEDED_ERR
console
.
warn
'localStorage quota exceeded!'
$location
.
path
(
'/viewer'
)
$rootScope
.
$digest
()
if
search_query
.
length
>
0
$timeout
=>
@
visualSearch
.
searchBox
.
searchEvent
(
''
)
,
1500
class
Annotation
class
Annotation
this
.
$inject
=
[
'$element'
,
'$location'
,
'$scope'
,
'annotator'
,
'drafts'
,
'$timeout'
]
this
.
$inject
=
[
'$element'
,
'$location'
,
'$scope'
,
'annotator'
,
'drafts'
,
'$timeout'
]
...
...
h/js/services.coffee
View file @
b98b81df
...
@@ -51,8 +51,8 @@ class Hypothesis extends Annotator
...
@@ -51,8 +51,8 @@ class Hypothesis extends Annotator
viewer
:
viewer
:
addField
:
(
->
)
addField
:
(
->
)
this
.
$inject
=
[
'$document'
,
'$
filter'
,
'$
location'
,
'$rootScope'
,
'$route'
,
'$timeout'
,
'drafts'
]
this
.
$inject
=
[
'$document'
,
'$location'
,
'$rootScope'
,
'$route'
,
'$timeout'
,
'drafts'
]
constructor
:
(
$document
,
$
filter
,
$
location
,
$rootScope
,
$route
,
$timeout
,
drafts
)
->
constructor
:
(
$document
,
$location
,
$rootScope
,
$route
,
$timeout
,
drafts
)
->
Gettext
.
prototype
.
parse_locale_data
annotator_locale_data
Gettext
.
prototype
.
parse_locale_data
annotator_locale_data
super
(
$document
.
find
'body'
)
super
(
$document
.
find
'body'
)
...
@@ -121,157 +121,6 @@ class Hypothesis extends Annotator
...
@@ -121,157 +121,6 @@ class Hypothesis extends Annotator
# Reload the route after annotations are loaded
# Reload the route after annotations are loaded
this
.
subscribe
'annotationsLoaded'
,
->
$route
.
reload
()
this
.
subscribe
'annotationsLoaded'
,
->
$route
.
reload
()
@
user_filter
=
$filter
(
'userName'
)
search_query
=
''
unless
typeof
(
localStorage
)
is
'undefined'
search_query
=
localStorage
.
getItem
(
"hyp_page_search_query"
)
console
.
log
'Loading back search query: '
+
search_query
@
visualSearch
=
VS
.
init
container
:
$
(
'.visual-search'
)
query
:
search_query
callbacks
:
search
:
(
query
,
searchCollection
)
=>
unless
query
return
matched
=
[]
whole_document
=
true
in_body_text
=
''
for
searchItem
in
searchCollection
.
models
if
searchItem
.
attributes
.
category
is
'scope'
and
searchItem
.
attributes
.
value
is
'sidebar'
whole_document
=
false
if
searchItem
.
attributes
.
category
is
'text'
in_body_text
=
searchItem
.
attributes
.
value
.
toLowerCase
()
text_tokens
=
searchItem
.
attributes
.
value
.
split
' '
if
searchItem
.
attributes
.
category
is
'tag'
tag_search
=
searchItem
.
attributes
.
value
.
toLowerCase
()
if
whole_document
annotations
=
@
plugins
.
Store
.
annotations
else
annotations
=
$rootScope
.
annotations
for
annotation
in
annotations
matches
=
true
for
searchItem
in
searchCollection
.
models
category
=
searchItem
.
attributes
.
category
value
=
searchItem
.
attributes
.
value
switch
category
when
'user'
userName
=
@
user_filter
annotation
.
user
unless
userName
.
toLowerCase
()
is
value
.
toLowerCase
()
matches
=
false
break
when
'text'
unless
annotation
.
text
?
matches
=
false
break
for
token
in
text_tokens
unless
annotation
.
text
.
toLowerCase
().
indexOf
(
token
.
toLowerCase
())
>
-
1
matches
=
false
break
when
'tag'
unless
annotation
.
tags
?
matches
=
false
break
found
=
false
for
tag
in
annotation
.
tags
if
tag_search
is
tag
.
toLowerCase
()
found
=
true
break
unless
found
matches
=
false
break
when
'time'
delta
=
Math
.
round
((
+
new
Date
-
new
Date
(
annotation
.
updated
))
/
1000
)
switch
value
when
'5 min'
unless
delta
<=
60
*
5
matches
=
false
when
'30 min'
unless
delta
<=
60
*
30
matches
=
false
when
'1 hour'
unless
delta
<=
60
*
60
matches
=
false
when
'12 hours'
unless
delta
<=
60
*
60
*
12
matches
=
false
when
'1 day'
unless
delta
<=
60
*
60
*
24
matches
=
false
when
'1 week'
unless
delta
<=
60
*
60
*
24
*
7
matches
=
false
when
'1 month'
unless
delta
<=
60
*
60
*
24
*
31
matches
=
false
when
'1 year'
unless
delta
<=
60
*
60
*
24
*
366
matches
=
false
when
'group'
priv_public
=
'group:__world__'
in
(
annotation
.
permissions
.
read
or
[])
switch
value
when
'Public'
unless
priv_public
matches
=
false
when
'Private'
if
priv_public
matches
=
false
if
matches
matched
.
push
annotation
.
id
#Save query to localStorage
unless
typeof
(
localStorage
)
is
'undefined'
try
localStorage
.
setItem
"hyp_page_search_query"
,
query
catch
error
console
.
warn
'Cannot save query to localStorage!'
if
error
is
DOMException
.
QUOTA_EXCEEDED_ERR
console
.
warn
'localStorage quota exceeded!'
# Set the path
search
=
whole_document
:
whole_document
matched
:
matched
in_body_text
:
in_body_text
$location
.
path
(
'/page_search'
).
search
(
search
)
$rootScope
.
$digest
()
facetMatches
:
(
callback
)
=>
if
@
show_search
return
callback
[
'text'
,
'tag'
,
'scope'
,
'group'
,
'time'
,
'user'
],
{
preserveOrder
:
true
}
valueMatches
:
(
facet
,
searchTerm
,
callback
)
->
switch
facet
when
'group'
then
callback
[
'Public'
,
'Private'
]
when
'area'
then
callback
[
'sidebar'
,
'document'
]
when
'time'
callback
[
'5 min'
,
'30 min'
,
'1 hour'
,
'12 hours'
,
'1 day'
,
'1 week'
,
'1 month'
,
'1 year'
],
{
preserveOrder
:
true
}
clearSearch
:
(
original
)
=>
@
show_search
=
false
original
()
unless
typeof
(
localStorage
)
is
'undefined'
try
localStorage
.
setItem
"hyp_page_search_query"
,
""
catch
error
console
.
warn
'Cannot save query to localStorage!'
if
error
is
DOMException
.
QUOTA_EXCEEDED_ERR
console
.
warn
'localStorage quota exceeded!'
$location
.
path
(
'/viewer'
)
$rootScope
.
$digest
()
if
search_query
.
length
>
0
$timeout
=>
@
visualSearch
.
searchBox
.
searchEvent
(
''
)
,
1500
_setupXDM
:
->
_setupXDM
:
->
$location
=
@
element
.
injector
().
get
'$location'
$location
=
@
element
.
injector
().
get
'$location'
$rootScope
=
@
element
.
injector
().
get
'$rootScope'
$rootScope
=
@
element
.
injector
().
get
'$rootScope'
...
...
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