Commit fdc79de8 authored by Nick Stenning's avatar Nick Stenning

Give comments/page notes a single target with source field

In order for comments (AKA "page notes") to be discoverable with the
search logic implemented in #2413 (cc4ca35), they need to have at least
one target with a source field.

Previously a comment was defined as an annotation

- with a `uri`
- without any targets
- without any references (no targets but with references == a reply)

Now comments have a single target with a single field, `source`. This
finally puts us in a position where we can consider deprecating the
`uri` field.
parent 29fd17c6
......@@ -296,6 +296,22 @@ module.exports = class Guest extends Annotator
createHighlight: ->
return this.createAnnotation({$highlight: true})
# Create a blank comment (AKA "page note")
createComment: () ->
annotation = {}
self = this
prepare = (info) ->
annotation.document = info.metadata
annotation.uri = info.uri
annotation.target = [{source: info.uri}]
this.getDocumentInfo()
.then(prepare)
.then(-> self.publish('beforeAnnotationCreated', [annotation]))
annotation
showAnnotations: (annotations) ->
tags = (a.$$tag for a in annotations)
@crossframe?.call('showAnnotations', tags)
......
......@@ -57,7 +57,7 @@ module.exports = class Toolbar extends Annotator.Plugin
"click": (event) =>
event.preventDefault()
event.stopPropagation()
@annotator.createAnnotation()
@annotator.createComment()
@annotator.show()
]
@buttons = $(makeButton(item) for item in items)
......
......@@ -240,6 +240,46 @@ describe 'Guest', ->
annotation = guest.createAnnotation(annotation)
assert.equal(annotation.foo, 'bar')
it 'triggers a beforeAnnotationCreated event', (done) ->
guest = createGuest()
guest.subscribe('beforeAnnotationCreated', -> done())
guest.createAnnotation()
describe 'createComment()', ->
it 'adds metadata to the annotation object', ->
guest = createGuest()
sinon.stub(guest, 'getDocumentInfo').returns(Promise.resolve({
metadata: {title: 'hello'}
uri: 'http://example.com/'
}))
annotation = guest.createComment()
timeoutPromise()
.then ->
assert.equal(annotation.uri, 'http://example.com/')
assert.deepEqual(annotation.document, {title: 'hello'})
it 'adds a single target with a source property', ->
guest = createGuest()
sinon.stub(guest, 'getDocumentInfo').returns(Promise.resolve({
metadata: {title: 'hello'}
uri: 'http://example.com/'
}))
annotation = guest.createComment()
timeoutPromise()
.then ->
assert.deepEqual(annotation.target, [{source: 'http://example.com/'}])
it 'triggers a beforeAnnotationCreated event', (done) ->
guest = createGuest()
guest.subscribe('beforeAnnotationCreated', -> done())
guest.createComment()
describe 'anchor()', ->
el = null
range = null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment