Commit c1da56b7 authored by Aron Carroll's avatar Aron Carroll

Merge pull request #1635 from hypothesis/1591-clear-filter-if-selection-is-empty

Update selectedAnnotations at annotationUpdate event.
parents ed6406ae b7b448f6
...@@ -30,7 +30,7 @@ class Hypothesis extends Annotator ...@@ -30,7 +30,7 @@ class Hypothesis extends Annotator
events: events:
'beforeAnnotationCreated': 'digest' 'beforeAnnotationCreated': 'digest'
'annotationCreated': 'digest' 'annotationCreated': 'digest'
'annotationDeleted': 'digest' 'annotationDeleted': 'annotationDeleted'
'annotationUpdated': 'digest' 'annotationUpdated': 'digest'
'annotationsLoaded': 'digest' 'annotationsLoaded': 'digest'
...@@ -205,6 +205,17 @@ class Hypothesis extends Annotator ...@@ -205,6 +205,17 @@ class Hypothesis extends Annotator
# Do nothing in the app frame, let the host handle it. # Do nothing in the app frame, let the host handle it.
setupAnnotation: (annotation) -> annotation setupAnnotation: (annotation) -> annotation
# Properly set the selectedAnnotations- and the Count variables
_setSelectedAnnotations: (selected) ->
scope = @element.scope()
count = Object.keys(selected).length
scope.selectedAnnotationsCount = count
if count
scope.selectedAnnotations = selected
else
scope.selectedAnnotations = null
toggleViewerSelection: (annotations=[]) -> toggleViewerSelection: (annotations=[]) ->
scope = @element.scope() scope = @element.scope()
scope.search.query = '' scope.search.query = ''
...@@ -215,15 +226,7 @@ class Hypothesis extends Annotator ...@@ -215,15 +226,7 @@ class Hypothesis extends Annotator
delete selected[a.id] delete selected[a.id]
else else
selected[a.id] = true selected[a.id] = true
@_setSelectedAnnotations selected
count = Object.keys(selected).length
scope.selectedAnnotationsCount = count
if count
scope.selectedAnnotations = selected
else
scope.selectedAnnotations = null
this this
updateViewer: (annotations=[]) -> updateViewer: (annotations=[]) ->
...@@ -236,8 +239,7 @@ class Hypothesis extends Annotator ...@@ -236,8 +239,7 @@ class Hypothesis extends Annotator
selected = {} selected = {}
for a in annotations for a in annotations
selected[a.id] = true selected[a.id] = true
scope.selectedAnnotations = selected @_setSelectedAnnotations selected
scope.selectedAnnotationsCount = Object.keys(selected).length
this.show() this.show()
this this
...@@ -255,6 +257,13 @@ class Hypothesis extends Annotator ...@@ -255,6 +257,13 @@ class Hypothesis extends Annotator
digest: -> digest: ->
@element.scope().$evalAsync angular.noop @element.scope().$evalAsync angular.noop
annotationDeleted: (annotation) ->
scope = @element.scope()
if scope.selectedAnnotations?[annotation.id]
delete scope.selectedAnnotations[annotation.id]
@_setSelectedAnnotations scope.selectedAnnotations
@digest()
patch_store: -> patch_store: ->
scope = @element.scope() scope = @element.scope()
Store = Annotator.Plugin.Store Store = Annotator.Plugin.Store
......
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