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
e131a3bb
Commit
e131a3bb
authored
Oct 09, 2013
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor drafts service to add discard callbacks
This change may affect #803 and #805.
parent
a7ddb6d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
21 deletions
+41
-21
controllers.coffee
h/js/controllers.coffee
+6
-6
services.coffee
h/js/services.coffee
+35
-15
No files found.
h/js/controllers.coffee
View file @
e131a3bb
...
...
@@ -8,11 +8,11 @@ class App
this
.
$inject
=
[
'$element'
,
'$filter'
,
'$http'
,
'$location'
,
'$rootScope'
,
'$scope'
,
'$timeout'
,
'annotator'
,
'authentication'
,
'
drafts'
,
'
flash'
,
'streamfilter'
'annotator'
,
'authentication'
,
'flash'
,
'streamfilter'
]
constructor
:
(
$element
,
$filter
,
$http
,
$location
,
$rootScope
,
$scope
,
$timeout
annotator
,
authentication
,
drafts
,
flash
,
streamfilter
annotator
,
authentication
,
flash
,
streamfilter
)
->
# Get the base URL from the base tag or the app location
baseUrl
=
angular
.
element
(
'head base'
)[
0
]
?
.
href
...
...
@@ -111,7 +111,7 @@ class App
,
10
$scope
.
$on
'back'
,
->
return
unless
drafts
.
discard
()
return
unless
annotator
.
discardDrafts
()
if
$location
.
path
()
==
'/viewer'
and
$location
.
search
()
?
.
id
?
$location
.
search
(
'id'
,
null
).
replace
()
else
...
...
@@ -180,7 +180,7 @@ class App
$scope
.
toggleHighlightingMode
=
->
# Check for drafts
return
unless
drafts
.
discard
()
return
unless
annotator
.
discardDrafts
()
# Check login state first
unless
plugins
.
Auth
?
and
plugins
.
Auth
.
haveValidToken
()
...
...
@@ -204,7 +204,7 @@ class App
params
:
$scope
.
highlightingMode
$scope
.
createUnattachedAnnotation
=
->
return
unless
drafts
.
discard
()
# Invoke draft support
return
unless
annotator
.
discardDrafts
()
provider
.
notify
method
:
'addComment'
@
user_filter
=
$filter
(
'userName'
)
...
...
@@ -586,7 +586,7 @@ class Annotation
$scope
.
editing
=
true
$scope
.
origText
=
$scope
.
model
.
$modelValue
.
text
$scope
.
origTags
=
$scope
.
model
.
$modelValue
.
tags
drafts
.
add
$scope
.
model
.
$modelValue
drafts
.
add
$scope
.
model
.
$modelValue
,
->
$scope
.
cancel
()
$scope
.
delete
=
(
$event
)
->
$event
?
.
stopPropagation
()
...
...
h/js/services.coffee
View file @
e131a3bb
...
...
@@ -152,7 +152,7 @@ class Hypothesis extends Annotator
# Register it with the draft service, except when it's an injection
unless
annotation
.
inject
drafts
.
add
annotation
drafts
.
add
annotation
,
=>
this
.
deleteAnnotation
annotation
else
# This is an injection. Delete the marker.
delete
annotation
.
inject
...
...
@@ -192,7 +192,6 @@ class Hypothesis extends Annotator
_setupXDM
:
(
options
)
->
$rootScope
=
@
element
.
injector
().
get
'$rootScope'
drafts
=
@
element
.
injector
().
get
'drafts'
provider
=
Channel
.
build
options
# Dodge toolbars [DISABLE]
...
...
@@ -207,10 +206,9 @@ class Hypothesis extends Annotator
.
bind
(
'publish'
,
(
ctx
,
args
...)
=>
this
.
publish
args
...)
.
bind
(
'back'
,
=>
# This guy does stuff when you "back out" of the interface.
# (Currently triggered by a click on the source page.)
# Navigate "back" out of the interface.
$rootScope
.
$apply
=>
return
unless
drafts
.
discard
()
return
unless
this
.
discardDrafts
()
this
.
hide
()
)
...
...
@@ -227,10 +225,12 @@ class Hypothesis extends Annotator
this
.
updateViewer
((
@
threading
.
getContainer
id
).
message
for
id
in
ids
)
)
.
bind
(
'setTool'
,
(
ctx
,
name
)
=>
this
.
setTool
name
)
.
bind
(
'setTool'
,
(
ctx
,
name
)
=>
$rootScope
.
$apply
=>
this
.
setTool
name
)
.
bind
(
'setVisibleHighlights'
,
(
ctx
,
state
)
=>
this
.
setVisibleHighlights
state
$rootScope
.
$apply
=>
this
.
setVisibleHighlights
state
)
_setupWrapper
:
->
...
...
@@ -470,6 +470,11 @@ class Hypothesis extends Annotator
# No targets and no references means that this is a comment
not
(
annotation
.
references
?
.
length
or
annotation
.
target
?
.
length
)
# Discard all drafts, deleting unsaved annotations from the annotator
discardDrafts
:
->
return
@
element
.
injector
().
get
(
'drafts'
).
discard
()
class
AuthenticationProvider
constructor
:
->
@
actions
=
...
...
@@ -499,29 +504,44 @@ class AuthenticationProvider
class
DraftProvider
drafts
:
[]
drafts
:
null
constructor
:
->
this
.
drafts
=
[]
$get
:
->
this
add
:
(
draft
)
->
@
drafts
.
push
draft
unless
this
.
contains
draft
remove
:
(
draft
)
->
@
drafts
=
(
d
for
d
in
@
drafts
when
d
isnt
draft
)
contains
:
(
draft
)
->
(
@
drafts
.
indexOf
draft
)
!=
-
1
add
:
(
draft
,
cb
)
->
@
drafts
.
push
{
draft
,
cb
}
remove
:
(
draft
)
->
remove
=
[]
for
d
,
i
in
@
drafts
remove
.
push
i
if
d
.
draft
is
draft
while
remove
.
length
@
drafts
.
splice
(
remove
.
pop
(),
1
)
contains
:
(
draft
)
->
for
d
in
@
drafts
if
d
.
draft
is
draft
then
return
true
return
false
discard
:
->
count
=
(
d
for
d
in
@
drafts
when
d
.
text
?
.
length
).
length
text
=
switch
count
switch
@
drafts
.
length
when
0
then
null
when
1
"""You have an unsaved reply.
Do you really want to discard this draft?"""
else
"""You have
#{
count
}
unsaved replies.
"""You have
#{
@
drafts
.
length
}
unsaved replies.
Do you really want to discard these drafts?"""
if
count
==
0
or
confirm
text
if
@
drafts
.
length
is
0
or
confirm
text
discarded
=
@
drafts
.
slice
()
@
drafts
=
[]
d
.
cb
?
()
for
d
in
discarded
true
else
false
...
...
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