Commit d25b5981 authored by Nick Stenning's avatar Nick Stenning

Use the "HTML" link for the annotation timestamp

The timestamp wasn't originally specified to be switched to the
"in-context" link, so this commit makes sure that it always points to
the "HTML" representation of the annotation, if that link is available.
parent 23b3020f
...@@ -120,11 +120,13 @@ function updateViewModel($scope, time, domainModel, ...@@ -120,11 +120,13 @@ function updateViewModel($scope, time, domainModel,
}; };
if (domainModel.links) { if (domainModel.links) {
vm.annotationURI = domainModel.links.incontext || vm.linkInContext = domainModel.links.incontext ||
domainModel.links.html || domainModel.links.html ||
''; '';
vm.linkHTML = domainModel.links.html || '';
} else { } else {
vm.annotationURI = ''; vm.linkInContext = '';
vm.linkHTML = '';
} }
vm.isPrivate = permissions.isPrivate( vm.isPrivate = permissions.isPrivate(
......
...@@ -1424,30 +1424,54 @@ describe('annotation', function() { ...@@ -1424,30 +1424,54 @@ describe('annotation', function() {
}); });
}); });
describe('annotation metadata', function () { describe('annotation links', function () {
function findLink(directive) { it('linkInContext uses the in-context links when available', function () {
var links = directive.element[0] var annotation = Object.assign({}, fixtures.defaultAnnotation(), {
.querySelectorAll('header .annotation-header__timestamp'); links: {
return links[links.length-1]; html: 'https://test.hypothes.is/a/deadbeef',
} incontext: 'https://hpt.is/deadbeef'
},
});
var controller = createDirective(annotation).controller;
assert.equal(controller.linkInContext, annotation.links.incontext);
});
it('displays HTML links when in-context links are not available', function () { it('linkInContext falls back to the HTML link when in-context links are missing', function () {
var annotation = Object.assign({}, fixtures.defaultAnnotation(), { var annotation = Object.assign({}, fixtures.defaultAnnotation(), {
links: {html: 'https://test.hypothes.is/a/deadbeef'}, links: {
html: 'https://test.hypothes.is/a/deadbeef',
},
}); });
var directive = createDirective(annotation); var controller = createDirective(annotation).controller;
assert.equal(findLink(directive).href, annotation.links.html);
assert.equal(controller.linkInContext, annotation.links.html);
}); });
it('displays in-context links when available', function () { it('linkHTML uses the HTML link when available', function () {
var annotation = Object.assign({}, fixtures.defaultAnnotation(), { var annotation = Object.assign({}, fixtures.defaultAnnotation(), {
links: { links: {
html: 'https://test.hypothes.is/a/deadbeef', html: 'https://test.hypothes.is/a/deadbeef',
incontext: 'https://hpt.is/deadbeef' incontext: 'https://hpt.is/deadbeef'
}, },
}); });
var directive = createDirective(annotation); var controller = createDirective(annotation).controller;
assert.equal(findLink(directive).href, annotation.links.incontext);
assert.equal(controller.linkHTML, annotation.links.html);
});
it('linkInContext is blank when unknown', function () {
var annotation = fixtures.defaultAnnotation();
var controller = createDirective(annotation).controller;
assert.equal(controller.linkInContext, '');
});
it('linkHTML is blank when unknown', function () {
var annotation = fixtures.defaultAnnotation();
var controller = createDirective(annotation).controller;
assert.equal(controller.linkHTML, '');
}); });
}); });
}); });
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
target="_blank" target="_blank"
title="{{vm.absoluteTimestamp}}" title="{{vm.absoluteTimestamp}}"
ng-if="!vm.editing() && vm.updated()" ng-if="!vm.editing() && vm.updated()"
ng-href="{{vm.annotationURI}}" ng-href="{{vm.linkHTML}}"
>{{vm.relativeTimestamp}}</a> >{{vm.relativeTimestamp}}</a>
</header> </header>
...@@ -183,7 +183,7 @@ ...@@ -183,7 +183,7 @@
</button> </button>
<annotation-share-dialog <annotation-share-dialog
group="vm.group()" group="vm.group()"
uri="vm.annotationURI" uri="vm.linkInContext"
is-private="vm.isPrivate" is-private="vm.isPrivate"
is-open="vm.showShareDialog" is-open="vm.showShareDialog"
on-close="vm.showShareDialog = false"> on-close="vm.showShareDialog = false">
......
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