Commit 109acb2b authored by gergely-ujvari's avatar gergely-ujvari

Make page search play nice with scopes

Page search can now search within all the scopes. Even dynamic mode works when search results are recalculated during scrolling.

Fixes #1094
parent b1605eeb
...@@ -228,13 +228,6 @@ class App ...@@ -228,13 +228,6 @@ class App
@visualSearch.searchBox.disableFacets(); @visualSearch.searchBox.disableFacets();
@visualSearch.searchBox.value(''); @visualSearch.searchBox.value('');
@visualSearch.searchBox.flags.allSelected = false; @visualSearch.searchBox.flags.allSelected = false;
# Set host/guests into dynamic bucket mode
if $rootScope.viewState.view is "Sceeen"
for p in annotator.providers
p.channel.notify
method: 'setDynamicBucketMode'
params: true
$scope.$on '$routeChangeStart', (current, next) -> $scope.$on '$routeChangeStart', (current, next) ->
return unless next.$$route? return unless next.$$route?
...@@ -272,7 +265,6 @@ class App ...@@ -272,7 +265,6 @@ class App
return unless annotator.discardDrafts() return unless annotator.discardDrafts()
matched = [] matched = []
whole_document = true
parsedQuery = parsedQuery =
text: '' text: ''
...@@ -280,10 +272,6 @@ class App ...@@ -280,10 +272,6 @@ class App
quote: [] quote: []
for searchItem in searchCollection.models for searchItem in searchCollection.models
if searchItem.attributes.category is 'scope' and
searchItem.attributes.value is 'sidebar'
whole_document = false
category = searchItem.attributes.category category = searchItem.attributes.category
value = searchItem.attributes.value value = searchItem.attributes.value
...@@ -298,38 +286,26 @@ class App ...@@ -298,38 +286,26 @@ class App
if category in ['quote'] if category in ['quote']
parsedQuery[category].push val.toLowerCase() for val in value.split ' ' parsedQuery[category].push val.toLowerCase() for val in value.split ' '
if whole_document annotations = $rootScope.annotations
annotations = annotator.plugins.Store.annotations
else
annotations = $rootScope.annotations
matchingIDs = viewFilter.filter annotations, parsedQuery matchingIDs = viewFilter.filter annotations, parsedQuery
# Set the path # Set the path
# TODO: do we really need this data in the location? # TODO: do we really need this data in the location?
search = search =
whole_document : whole_document query: parsedQuery
matched : matchingIDs matched : matchingIDs
in_body_text: parsedQuery.text in_body_text: parsedQuery.text
quote: parsedQuery.quote quote: parsedQuery.quote
$location.path('/page_search').search(search) $location.path('/page_search').search(search)
unless $scope.inSearch # If we are entering search right now
# Turn dynamic bucket mode off for host/guests
for p in annotator.providers
p.channel.notify
method: 'setDynamicBucketMode'
params: false
$rootScope.$digest() $rootScope.$digest()
facetMatches: (callback) => facetMatches: (callback) =>
if $scope.show_search if $scope.show_search
return callback ['text','tag', 'quote', 'scope', 'group','time','user'], {preserveOrder: true} return callback ['text','tag', 'quote', 'group','time','user'], {preserveOrder: true}
valueMatches: (facet, searchTerm, callback) -> valueMatches: (facet, searchTerm, callback) ->
switch facet switch facet
when 'group' then callback ['Public', 'Private'] when 'group' then callback ['Public', 'Private']
when 'scope' then callback ['sidebar', 'document']
when 'time' when 'time'
callback ['5 min', '30 min', '1 hour', '12 hours', '1 day', '1 week', '1 month', '1 year'], {preserveOrder: true} callback ['5 min', '30 min', '1 hour', '12 hours', '1 day', '1 week', '1 month', '1 year'], {preserveOrder: true}
clearSearch: (original) => clearSearch: (original) =>
...@@ -790,8 +766,10 @@ class Viewer ...@@ -790,8 +766,10 @@ class Viewer
class Search class Search
this.$inject = ['$filter', '$location', '$rootScope', '$routeParams', '$sce', '$scope', 'annotator'] this.$inject = ['$filter', '$location', '$rootScope', '$routeParams', '$sce', '$scope',
constructor: ($filter, $location, $rootScope, $routeParams, $sce, $scope, annotator) -> 'annotator', 'viewFilter']
constructor: ($filter, $location, $rootScope, $routeParams, $sce, $scope,
annotator, viewFilter) ->
{providers, threading} = annotator {providers, threading} = annotator
$scope.highlighter = '<span class="search-hl-active">$&</span>' $scope.highlighter = '<span class="search-hl-active">$&</span>'
...@@ -863,6 +841,10 @@ class Search ...@@ -863,6 +841,10 @@ class Search
method: 'scrollTo' method: 'scrollTo'
params: annotation.$$tag params: annotation.$$tag
$scope.$watchCollection 'annotations', (nVal, oVal) =>
$routeParams.matched = viewFilter.filter $rootScope.annotations, $routeParams.query
refresh()
refresh = => refresh = =>
$scope.search_filter = $routeParams.matched $scope.search_filter = $routeParams.matched
...@@ -887,12 +869,15 @@ class Search ...@@ -887,12 +869,15 @@ class Search
threads = [] threads = []
roots = {} roots = {}
$scope.render_order = {} $scope.render_order = {}
# Choose the root annotations to work with # Choose the root annotations to work with
for id, thread of annotator.threading.idTable when thread.message? for id, thread of annotator.threading.idTable when thread.message?
annotation = thread.message annotation = thread.message
annotation_root = if annotation.references? then annotation.references[0] else annotation.id annotation_root = if annotation.references? then annotation.references[0] else annotation.id
# Already handled thread # Already handled thread
if roots[annotation_root]? then continue if roots[annotation_root]? then continue
root_annotation = (annotator.threading.getContainer annotation_root).message
unless root_annotation in $rootScope.annotations then continue
if annotation.id in $scope.search_filter if annotation.id in $scope.search_filter
# We have a winner, let's put its root annotation into our list and build the rendering # We have a winner, let's put its root annotation into our list and build the rendering
......
...@@ -160,7 +160,7 @@ class Annotator.Guest extends Annotator ...@@ -160,7 +160,7 @@ class Annotator.Guest extends Annotator
annotations.push anchor.annotation annotations.push anchor.annotation
# Show all the annotations # Show all the annotations
@showViewer "Document", annotations @updateViewer "Document", annotations
) )
.bind('setTool', (ctx, name) => .bind('setTool', (ctx, name) =>
......
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