Commit 39e85a0d authored by Nick Stenning's avatar Nick Stenning

Merge pull request #2118 from hypothesis/1542-source-url-not-visible-on-older-annotations

Use domain as citation title if no document
parents 7e06bdfb 05e0cd83
...@@ -211,15 +211,15 @@ AnnotationController = [ ...@@ -211,15 +211,15 @@ AnnotationController = [
@annotationURI = new URL("/a/#{@annotation.id}", this.baseURI).href @annotationURI = new URL("/a/#{@annotation.id}", this.baseURI).href
# Extract the document metadata. # Extract the document metadata.
uri = model.uri
domain = new URL(uri).hostname
if model.document if model.document
uri = model.uri
if uri.indexOf("urn") is 0 if uri.indexOf("urn") is 0
# This URI is not clickable, see if we have something better # This URI is not clickable, see if we have something better
for link in model.document.link when link.href.indexOf("urn") for link in model.document.link when link.href.indexOf("urn")
uri = link.href uri = link.href
break break
domain = new URL(uri).hostname
documentTitle = if Array.isArray(model.document.title) documentTitle = if Array.isArray(model.document.title)
model.document.title[0] model.document.title[0]
else else
...@@ -229,11 +229,14 @@ AnnotationController = [ ...@@ -229,11 +229,14 @@ AnnotationController = [
uri: uri uri: uri
domain: domain domain: domain
title: documentTitle or domain title: documentTitle or domain
if @document.title.length > 30
@document.title = @document.title[0..29] + '…'
else else
@document = null @document =
uri: uri
domain: domain
title: domain
if @document.title.length > 30
@document.title = @document.title[0..29] + '…'
# Form the tags for ngTagsInput. # Form the tags for ngTagsInput.
@annotation.tags = ({text} for text in (model.tags or [])) @annotation.tags = ({text} for text in (model.tags or []))
......
...@@ -209,10 +209,20 @@ describe 'annotation', -> ...@@ -209,10 +209,20 @@ describe 'annotation', ->
controller.render() controller.render()
assert.equal(controller.document.title, 'example.com') assert.equal(controller.document.title, 'example.com')
it 'skips the document object if no document is present on the annotation', -> it 'still sets the uri correctly if the annotation has no document', ->
delete annotation.document delete annotation.document
controller.render() controller.render()
assert.isNull(controller.document) assert(controller.document.uri == $scope.annotation.uri)
it 'still sets the domain correctly if the annotation has no document', ->
delete annotation.document
controller.render()
assert(controller.document.domain == 'example.com')
it 'uses the domain for the title when the annotation has no document', ->
delete annotation.document
controller.render()
assert(controller.document.title == 'example.com')
describe 'when there are no targets', -> describe 'when there are no targets', ->
beforeEach -> beforeEach ->
......
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