Commit 5736d80b authored by Randall Leeds's avatar Randall Leeds

Combine Viewer and PageSearch controllers

No longer change routes when the query changes between the Viewer
and the PageSearch controller so that the filtering is near instant.
parent 42c8ac83
...@@ -23,9 +23,7 @@ configure = [ ...@@ -23,9 +23,7 @@ configure = [
$routeProvider.when '/viewer', $routeProvider.when '/viewer',
controller: 'ViewerController' controller: 'ViewerController'
templateUrl: 'viewer.html' templateUrl: 'viewer.html'
$routeProvider.when '/page_search', reloadOnSearch: false
controller: 'SearchController'
templateUrl: 'viewer.html'
$routeProvider.when '/stream', $routeProvider.when '/stream',
controller: 'StreamSearchController' controller: 'StreamSearchController'
templateUrl: 'viewer.html' templateUrl: 'viewer.html'
......
...@@ -358,12 +358,13 @@ class AnnotationViewer ...@@ -358,12 +358,13 @@ class AnnotationViewer
class Viewer class Viewer
this.$inject = [ this.$inject = [
'$location', '$routeParams', '$scope', 'annotator' '$filter', '$routeParams', '$sce', '$scope',
'annotator', 'viewFilter'
] ]
constructor: ($location, $routeParams, $scope, annotator) -> constructor: (
if $routeParams.q $filter, $routeParams, $sce, $scope,
return $location.path('/page_search').replace() annotator, viewFilter
) ->
# 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 $scope.isStream = true
...@@ -383,26 +384,15 @@ class Viewer ...@@ -383,26 +384,15 @@ class Viewer
params: highlights params: highlights
$scope.shouldShowAnnotation = (id) -> $scope.shouldShowAnnotation = (id) ->
if $routeParams.q
shownAnnotations = $scope.ann_info.shown
(shownAnnotations[id] or $scope.render_order[id])
else
selectedAnnotations = $scope.selectedAnnotations selectedAnnotations = $scope.selectedAnnotations
!selectedAnnotations or selectedAnnotations?[id] (!selectedAnnotations or selectedAnnotations?[id])
class Search
this.$inject = ['$filter', '$location', '$routeParams', '$sce', '$scope',
'annotator', 'viewFilter']
constructor: ($filter, $location, $routeParams, $sce, $scope,
annotator, viewFilter) ->
unless $routeParams.q
return $location.path('/viewer').replace()
{plugins, providers} = 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.render_order = {} $scope.render_order = {}
$scope.render_pos = {} $scope.render_pos = {}
$scope.ann_info = $scope.ann_info =
...@@ -413,10 +403,6 @@ class Search ...@@ -413,10 +403,6 @@ 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] or $scope.render_order[id]
buildRenderOrder = (threadid, threads) => buildRenderOrder = (threadid, threads) =>
unless threads?.length unless threads?.length
return return
...@@ -452,20 +438,13 @@ class Search ...@@ -452,20 +438,13 @@ class Search
result = true result = true
result result
$scope.activate = (annotation) -> refresh = =>
if angular.isObject annotation if $routeParams.q
highlights = [annotation.$$tag] delete $scope.selectedAnnotations
else else
highlights = [] delete $scope.matches
for p in providers return
p.channel.notify
method: 'setActiveHighlights'
params: highlights
$scope.$watch 'annotations', (nVal, oVal) =>
refresh()
refresh = =>
query = $routeParams.q query = $routeParams.q
annotations = $scope.threading.root.flattenChildren() annotations = $scope.threading.root.flattenChildren()
[$scope.matches, $scope.filters] = viewFilter.filter annotations, query [$scope.matches, $scope.filters] = viewFilter.filter annotations, query
...@@ -552,7 +531,6 @@ class Search ...@@ -552,7 +531,6 @@ class Search
target.highlightQuote = target.quote target.highlightQuote = target.quote
$scope.ann_info.show_quote[thread.message.id] = false $scope.ann_info.show_quote[thread.message.id] = false
children = thread.flattenChildren() children = thread.flattenChildren()
if children? if children?
for child in children for child in children
...@@ -569,7 +547,6 @@ class Search ...@@ -569,7 +547,6 @@ class Search
$scope.ann_info.show_quote[child.id] = false $scope.ann_info.show_quote[child.id] = false
# Calculate the number of hidden annotations for <x> more labels # Calculate the number of hidden annotations for <x> more labels
for threadid, order of $scope.render_order for threadid, order of $scope.render_order
hidden = 0 hidden = 0
...@@ -611,7 +588,6 @@ class Search ...@@ -611,7 +588,6 @@ class Search
$scope.ann_info.shown[prev_id] = true $scope.ann_info.shown[prev_id] = true
pos -= 1 pos -= 1
$scope.clickMoreBottom = (id, $event) -> $scope.clickMoreBottom = (id, $event) ->
$event?.stopPropagation() $event?.stopPropagation()
threadid = $scope.getThreadId id threadid = $scope.getThreadId id
...@@ -637,4 +613,3 @@ angular.module('h.controllers', imports) ...@@ -637,4 +613,3 @@ angular.module('h.controllers', imports)
.controller('AppController', App) .controller('AppController', App)
.controller('ViewerController', Viewer) .controller('ViewerController', Viewer)
.controller('AnnotationViewerController', AnnotationViewer) .controller('AnnotationViewerController', AnnotationViewer)
.controller('SearchController', Search)
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