Commit 03ade9e7 authored by Aron Carroll's avatar Aron Carroll Committed by Randall Leeds

Fix display of page search results

Each controller for the viewer template must now define a
shouldShowAnnotation method that accepts an annotation id and determines
whether it should be displayed. This moves the logic out of the template
and into the controllers.
parent 957ad49c
...@@ -295,6 +295,7 @@ class App ...@@ -295,6 +295,7 @@ class App
$scope.clearSelection = -> $scope.clearSelection = ->
$scope.search.query = '' $scope.search.query = ''
$scope.selectedAnnotations = null $scope.selectedAnnotations = null
$scope.selectedAnnotationsCount = 0
$scope.frame = visible: false $scope.frame = visible: false
$scope.id = identity $scope.id = identity
...@@ -321,11 +322,14 @@ class AnnotationViewer ...@@ -321,11 +322,14 @@ class AnnotationViewer
constructor: ($routeParams, $scope, streamfilter) -> constructor: ($routeParams, $scope, streamfilter) ->
# Tells the view that these annotations are standalone # Tells the view that these annotations are standalone
$scope.isEmbedded = false $scope.isEmbedded = false
$scope.isStream = false
# Provide no-ops until these methods are moved elsewere. They only apply # Provide no-ops until these methods are moved elsewere. They only apply
# to annotations loaded into the stream. # to annotations loaded into the stream.
$scope.activate = angular.noop $scope.activate = angular.noop
$scope.shouldShowAnnotation = (id) -> true
$scope.$watch 'updater', (updater) -> $scope.$watch 'updater', (updater) ->
if updater? if updater?
updater.then (sock) -> updater.then (sock) ->
...@@ -340,18 +344,15 @@ class AnnotationViewer ...@@ -340,18 +344,15 @@ class AnnotationViewer
class Viewer class Viewer
this.$inject = [ this.$inject = [
'$location', '$routeParams', '$scope', '$location', '$routeParams', '$scope', 'annotator'
'annotator'
] ]
constructor: ( constructor: ($location, $routeParams, $scope, annotator) ->
$location, $routeParams, $scope,
annotator
) ->
if $routeParams.q if $routeParams.q
return $location.path('/page_search').replace() return $location.path('/page_search').replace()
# Tells the view that these annotations are embedded into the owner doc # Tells the view that these annotations are embedded into the owner doc
$scope.isEmbedded = true $scope.isEmbedded = true
$scope.isStream = true
{providers, threading} = annotator {providers, threading} = annotator
...@@ -367,6 +368,10 @@ class Viewer ...@@ -367,6 +368,10 @@ class Viewer
method: 'setActiveHighlights' method: 'setActiveHighlights'
params: highlights params: highlights
$scope.shouldShowAnnotation = (id) ->
selectedAnnotations = $scope.selectedAnnotations
!selectedAnnotations or selectedAnnotations?[id]
class Search class Search
this.$inject = ['$filter', '$location', '$routeParams', '$sce', '$scope', this.$inject = ['$filter', '$location', '$routeParams', '$sce', '$scope',
...@@ -378,6 +383,9 @@ class Search ...@@ -378,6 +383,9 @@ class Search
{providers, threading} = annotator {providers, threading} = annotator
$scope.isEmbedded = true
$scope.isStream = true
$scope.highlighter = '<span class="search-hl-active">$&</span>' $scope.highlighter = '<span class="search-hl-active">$&</span>'
$scope.filter_orderBy = $filter('orderBy') $scope.filter_orderBy = $filter('orderBy')
$scope.matches = [] $scope.matches = []
...@@ -391,6 +399,10 @@ class Search ...@@ -391,6 +399,10 @@ class Search
more_top_num : {} more_top_num : {}
more_bottom_num: {} more_bottom_num: {}
$scope.shouldShowAnnotation = (id) ->
shownAnnotations = $scope.ann_info?.shown or {}
!!shownAnnotations[id]
buildRenderOrder = (threadid, threads) => buildRenderOrder = (threadid, threads) =>
unless threads?.length unless threads?.length
return return
......
...@@ -259,16 +259,22 @@ class Hypothesis extends Annotator ...@@ -259,16 +259,22 @@ class Hypothesis extends Annotator
toggleViewerSelection: (annotations=[]) => toggleViewerSelection: (annotations=[]) =>
scope = @element.scope() scope = @element.scope()
selected = scope.selectedAnnotations or {} selected = scope.selectedAnnotations or {}
for a in annotations for a in annotations
if selected[a.id] if selected[a.id]
delete selected[a.id] delete selected[a.id]
else else
selected[a.id] = true selected[a.id] = true
if Object.keys(selected).length
count = Object.keys(selected).length
scope.selectedAnnotationsCount = count
if count
scope.selectedAnnotations = selected scope.selectedAnnotations = selected
else else
scope.selectedAnnotations = null scope.selectedAnnotations = null
this this
updateViewer: (annotations=[]) => updateViewer: (annotations=[]) =>
...@@ -281,6 +287,7 @@ class Hypothesis extends Annotator ...@@ -281,6 +287,7 @@ class Hypothesis extends Annotator
for a in annotations for a in annotations
selected[a.id] = true selected[a.id] = true
scope.selectedAnnotations = selected scope.selectedAnnotations = selected
scope.selectedAnnotationsCount = Object.keys(selected).length
this.show() this.show()
this this
......
...@@ -26,6 +26,9 @@ class StreamSearch ...@@ -26,6 +26,9 @@ class StreamSearch
terms = searchfilter.generateFacetedFilter $scope.search.query terms = searchfilter.generateFacetedFilter $scope.search.query
queryparser.populateFilter streamfilter, terms queryparser.populateFilter streamfilter, terms
$scope.isEmbedded = false
$scope.isStream = true
$scope.sort.name = 'Newest' $scope.sort.name = 'Newest'
......
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