Commit f1e316c9 authored by Randall Leeds's avatar Randall Leeds Committed by Sean Hammond

Show orphans and sort by text position selector

The positions of the anchors are no longer needed.
parent 66d7b2cf
...@@ -197,10 +197,11 @@ module.exports = class Guest extends Annotator ...@@ -197,10 +197,11 @@ module.exports = class Guest extends Annotator
sync = (anchors) -> sync = (anchors) ->
# Store the results of anchoring. # Store the results of anchoring.
annotation.$orphan = anchors.length > 0 annotation.$anchored = anchors.length is 0
for anchor in anchors for anchor in anchors
if anchor.range? if anchor.range?
annotation.$orphan = false annotation.$anchored = true
break
# Add the anchors for this annotation to instance storage. # Add the anchors for this annotation to instance storage.
self.anchors = self.anchors.concat(anchors) self.anchors = self.anchors.concat(anchors)
......
...@@ -249,28 +249,28 @@ describe 'Guest', -> ...@@ -249,28 +249,28 @@ describe 'Guest', ->
afterEach -> afterEach ->
document.body.removeChild(el) document.body.removeChild(el)
it "doesn't declare annotation without targets as orphans", (done) -> it "declares annotations without targets as anchored", (done) ->
guest = createGuest() guest = createGuest()
annotation = target: [] annotation = target: []
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.isFalse(annotation.$orphan) assert.isTrue(annotation.$anchored)
done() .then(done, done)
it "doesn't declare annotations with a working target as orphans", (done) -> it "declares annotations with a working target anchored", (done) ->
guest = createGuest() guest = createGuest()
annotation = target: [{selector: "test"}] annotation = target: [{selector: "test"}]
sandbox.stub(anchoring, 'anchor').returns(Promise.resolve(range)) sandbox.stub(anchoring, 'anchor').returns(Promise.resolve(range))
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.isFalse(annotation.$orphan) assert.isTrue(annotation.$anchored)
done() .then(done, done)
it "declares annotations with broken targets as orphans", (done) -> it "declares annotations with broken targets not anchored", (done) ->
guest = createGuest() guest = createGuest()
annotation = target: [{selector: 'broken selector'}] annotation = target: [{selector: 'broken selector'}]
sandbox.stub(anchoring, 'anchor').returns(Promise.reject()) sandbox.stub(anchoring, 'anchor').returns(Promise.reject())
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.isTrue(annotation.$orphan) assert.isFalse(annotation.$anchored)
done() .then(done, done)
it 'updates the cross frame and bucket bar plugins', (done) -> it 'updates the cross frame and bucket bar plugins', (done) ->
guest = createGuest() guest = createGuest()
...@@ -282,7 +282,7 @@ describe 'Guest', -> ...@@ -282,7 +282,7 @@ describe 'Guest', ->
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.called(guest.plugins.BucketBar.update) assert.called(guest.plugins.BucketBar.update)
assert.called(guest.plugins.CrossFrame.sync) assert.called(guest.plugins.CrossFrame.sync)
done() .then(done, done)
it 'returns a promise of the anchors for the annotation', (done) -> it 'returns a promise of the anchors for the annotation', (done) ->
guest = createGuest() guest = createGuest()
...@@ -292,7 +292,7 @@ describe 'Guest', -> ...@@ -292,7 +292,7 @@ describe 'Guest', ->
target = [{selector: []}] target = [{selector: []}]
guest.anchor({target: [target]}).then (anchors) -> guest.anchor({target: [target]}).then (anchors) ->
assert.equal(anchors.length, 1) assert.equal(anchors.length, 1)
done() .then(done, done)
it 'adds the anchor to the "anchors" instance property"', (done) -> it 'adds the anchor to the "anchors" instance property"', (done) ->
guest = createGuest() guest = createGuest()
...@@ -307,7 +307,7 @@ describe 'Guest', -> ...@@ -307,7 +307,7 @@ describe 'Guest', ->
assert.strictEqual(guest.anchors[0].target, target) assert.strictEqual(guest.anchors[0].target, target)
assert.strictEqual(guest.anchors[0].range, range) assert.strictEqual(guest.anchors[0].range, range)
assert.strictEqual(guest.anchors[0].highlights, highlights) assert.strictEqual(guest.anchors[0].highlights, highlights)
done() .then(done, done)
it 'destroys targets that have been removed from the annotation', (done) -> it 'destroys targets that have been removed from the annotation', (done) ->
annotation = {} annotation = {}
...@@ -321,7 +321,7 @@ describe 'Guest', -> ...@@ -321,7 +321,7 @@ describe 'Guest', ->
assert.equal(guest.anchors.length, 0) assert.equal(guest.anchors.length, 0)
assert.calledOnce(removeHighlights, highlights) assert.calledOnce(removeHighlights, highlights)
assert.calledWith(removeHighlights, highlights) assert.calledWith(removeHighlights, highlights)
done() .then(done, done)
it 'does not reanchor targets that are already anchored', (done) -> it 'does not reanchor targets that are already anchored', (done) ->
guest = createGuest() guest = createGuest()
...@@ -331,7 +331,7 @@ describe 'Guest', -> ...@@ -331,7 +331,7 @@ describe 'Guest', ->
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.equal(guest.anchors.length, 1) assert.equal(guest.anchors.length, 1)
assert.calledOnce(stub) assert.calledOnce(stub)
done() .then(done, done)
describe 'detach()', -> describe 'detach()', ->
it 'removes the anchors from the "anchors" instance variable', -> it 'removes the anchors from the "anchors" instance variable', ->
......
...@@ -18,7 +18,7 @@ module.exports = class CrossFrame ...@@ -18,7 +18,7 @@ module.exports = class CrossFrame
new Discovery($window, options) new Discovery($window, options)
createAnnotationSync = -> createAnnotationSync = ->
whitelist = ['$highlight', '$orphan','target', 'document', 'uri'] whitelist = ['$anchored', '$highlight', 'target', 'document', 'uri']
options = options =
formatter: (annotation) -> formatter: (annotation) ->
formatted = {} formatted = {}
......
...@@ -57,12 +57,27 @@ module.exports = class WidgetController ...@@ -57,12 +57,27 @@ module.exports = class WidgetController
crossframe.call('scrollToAnnotation', annotation.$$tag) crossframe.call('scrollToAnnotation', annotation.$$tag)
$scope.shouldShowThread = (container) -> $scope.shouldShowThread = (container) ->
if annotationUI.hasSelectedAnnotations() and not container.parent.parent # Show stubs
annotationUI.isAnnotationSelected(container.message?.id) if not container?.message?
else return true
true
# Show replies
if container.message.references?.length
return true
# Show selected threads
if annotationUI.hasSelectedAnnotations()
return annotationUI.isAnnotationSelected(container.message.id)
# Show regardless of $anchored if that feature is turned on
if $scope.feature('show_unanchored_annotations')
return true
# Show anchored threads
if container.message.$anchored
return true
return false
$scope.hasFocus = (annotation) -> $scope.hasFocus = (annotation) ->
!!($scope.focusedAnnotations ? {})[annotation?.$$tag] !!($scope.focusedAnnotations ? {})[annotation?.$$tag]
$scope.notOrphan = (container) -> !container?.message?.$orphan
...@@ -71,3 +71,11 @@ $thread-padding: 1em; ...@@ -71,3 +71,11 @@ $thread-padding: 1em;
.thread-load-more { .thread-load-more {
clear: both; clear: both;
} }
.thread-anchor-notice {
// XXX: negative margins here make me sad; maybe refactor container
background-color: lighten($gray-light, 38%);
border-top: solid 1px $gray-lighter;
margin: 0 -1em -1em -1em;
padding: 1em;
}
...@@ -45,3 +45,7 @@ ...@@ -45,3 +45,7 @@
ng-show="vm.shouldShowAsReply()"> ng-show="vm.shouldShowAsReply()">
</li> </li>
</ul> </ul>
<footer class="thread-anchor-notice" ng-if="!vm.container.message.$anchored">
<em>We can't find the exact position of this annotation.</em>
</footer>
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
ng-mouseenter="focus(child.message)" ng-mouseenter="focus(child.message)"
ng-click="scrollTo(child.message)" ng-click="scrollTo(child.message)"
ng-mouseleave="focus()" ng-mouseleave="focus()"
ng-repeat="child in threadRoot.children | filter:notOrphan | orderBy : sort.predicate" ng-repeat="child in threadRoot.children | orderBy : sort.predicate"
ng-show="shouldShowThread(child) && (count('edit') || count('match') || !threadFilter.active()) || vm.isNew()"> ng-show="shouldShowThread(child) && (count('edit') || count('match') || !threadFilter.active()) || vm.isNew()">
</li> </li>
</ul> </ul>
......
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