Commit 9ffe1bbc authored by Randall Leeds's avatar Randall Leeds

Consistently use q as the search query parameter

This unifies the stream and page_search query parameter usage. Both now
use the 'q' parameter. Additionally, the search string is passed to
`simpleSearch` directive and the `QueryParser` instead of an object
with a "query" or "q" key.

The clump of conditionals in the route update event handler is removed.
Instead, the viewer and page search redirect to one another and the
stream can be totally ignorant of the involvement of the location.

The views are updated to use ?q= for /u and /t shortcuts.
parent f038c8d2
...@@ -10,6 +10,7 @@ class App ...@@ -10,6 +10,7 @@ class App
frame: frame:
visible: false visible: false
ongoingHighlightSwitch: false ongoingHighlightSwitch: false
search: {}
sheet: {} sheet: {}
sorts: [ sorts: [
'Newest' 'Newest'
...@@ -40,7 +41,7 @@ class App ...@@ -40,7 +41,7 @@ class App
socialView: annotator.socialView socialView: annotator.socialView
ongoingHighlightSwitch: false ongoingHighlightSwitch: false
search: search:
query: $location.search() query: $location.search()['q']
session: session session: session
_reset() _reset()
...@@ -212,38 +213,23 @@ class App ...@@ -212,38 +213,23 @@ class App
$rootScope.applySort "Location" $rootScope.applySort "Location"
$scope.query = $location.search()
$scope.search = {}
$scope.search.update = angular.noop
$scope.search.clear = angular.noop
$rootScope.$on '$routeChangeSuccess', (event, next, current) -> $rootScope.$on '$routeChangeSuccess', (event, next, current) ->
unless next.$$route? then return unless next.$$route? then return
$scope.search.query = $location.search() $scope.search.query = $location.search()['q']
$rootScope.viewState.show = next.$$route.originalPath is '/viewer'
if next.$$route.originalPath is '/viewer'
$rootScope.viewState.show = true
else
$rootScope.viewState.show = false
unless next.$$route.originalPath is '/stream' unless next.$$route.originalPath is '/stream'
if current and next.$$route.originalPath is '/a/:id' if current and next.$$route.originalPath is '/a/:id'
$scope.reloadAnnotations() $scope.reloadAnnotations()
$scope.search.update = (searchCollection) ->
return unless annotator.discardDrafts()
query = {query: searchCollection}
unless angular.equals $location.search(), query
if $location.path() == '/viewer' or $location.path() == '/page_search'
$location.path('/page_search').search(query)
else
$location.path('/stream').search(query)
$scope.search.clear = -> $scope.search.clear = ->
$location.url('/viewer') $location.search('q', null)
$scope.search.update = (query) ->
unless angular.equals $location.search()['q'], query
if annotator.discardDrafts()
$location.search('q', query or null)
$scope.reloadAnnotations = -> $scope.reloadAnnotations = ->
Store = plugins.Store Store = plugins.Store
...@@ -720,6 +706,9 @@ class Viewer ...@@ -720,6 +706,9 @@ class Viewer
$location, $rootScope, $routeParams, $scope, $location, $rootScope, $routeParams, $scope,
annotator annotator
) -> ) ->
if $routeParams.q
return $location.path('/page_search').replace()
{providers, threading} = annotator {providers, threading} = annotator
$scope.activate = (annotation) -> $scope.activate = (annotation) ->
...@@ -746,12 +735,14 @@ class Search ...@@ -746,12 +735,14 @@ class Search
'annotator', 'viewFilter'] 'annotator', 'viewFilter']
constructor: ($filter, $location, $rootScope, $routeParams, $sce, $scope, constructor: ($filter, $location, $rootScope, $routeParams, $sce, $scope,
annotator, viewFilter) -> annotator, viewFilter) ->
unless $routeParams.q
return $location.path('/viewer').replace()
{providers, threading} = annotator {providers, threading} = annotator
$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 = []
$scope.search.query = $location.search()
$scope.render_order = {} $scope.render_order = {}
$scope.render_pos = {} $scope.render_pos = {}
$scope.ann_info = $scope.ann_info =
...@@ -823,7 +814,8 @@ class Search ...@@ -823,7 +814,8 @@ class Search
refresh() refresh()
refresh = => refresh = =>
[$scope.matches, $scope.filters] = viewFilter.filter $rootScope.annotations, $routeParams query = $routeParams.q
[$scope.matches, $scope.filters] = viewFilter.filter $rootScope.annotations, query
# Create the regexps for highlighting the matches inside the annotations' bodies # Create the regexps for highlighting the matches inside the annotations' bodies
$scope.text_tokens = $scope.filters.text.terms.slice() $scope.text_tokens = $scope.filters.text.terms.slice()
$scope.text_regexp = [] $scope.text_regexp = []
......
...@@ -412,8 +412,8 @@ simpleSearch = ['$parse', ($parse) -> ...@@ -412,8 +412,8 @@ simpleSearch = ['$parse', ($parse) ->
_clear(scope) if attr.onclear _clear(scope) if attr.onclear
scope.$watch attr.query, (query) -> scope.$watch attr.query, (query) ->
if query.query? if query?
scope.searchtext = query.query scope.searchtext = query
_search(scope, {"this": scope.searchtext}) _search(scope, {"this": scope.searchtext})
restrict: 'C' restrict: 'C'
......
...@@ -788,7 +788,7 @@ class ViewFilter ...@@ -788,7 +788,7 @@ class ViewFilter
# the faceted filters # the faceted filters
# ] # ]
filter: (annotations, query) => filter: (annotations, query) =>
filters = @searchfilter.generateFacetedFilter query.query filters = @searchfilter.generateFacetedFilter query
results = [] results = []
# Check for given limit # Check for given limit
......
...@@ -11,11 +11,11 @@ imports = [ ...@@ -11,11 +11,11 @@ imports = [
class StreamSearch class StreamSearch
this.inject = [ this.inject = [
'$location', '$scope', '$rootScope', '$scope', '$rootScope',
'queryparser', 'session', 'searchfilter', 'streamfilter' 'queryparser', 'session', 'searchfilter', 'streamfilter'
] ]
constructor: ( constructor: (
$location, $scope, $rootScope, $scope, $rootScope,
queryparser, session, searchfilter, streamfilter queryparser, session, searchfilter, streamfilter
) -> ) ->
# Initialize the base filter # Initialize the base filter
...@@ -25,8 +25,7 @@ class StreamSearch ...@@ -25,8 +25,7 @@ class StreamSearch
.setPastDataHits(50) .setPastDataHits(50)
# Apply query clauses # Apply query clauses
$scope.query = $location.search()['query'] terms = searchfilter.generateFacetedFilter $scope.search.query
terms = searchfilter.generateFacetedFilter $scope.query
queryparser.populateFilter streamfilter, terms queryparser.populateFilter streamfilter, terms
$scope.updater?.then (sock) -> $scope.updater?.then (sock) ->
...@@ -37,15 +36,6 @@ class StreamSearch ...@@ -37,15 +36,6 @@ class StreamSearch
$rootScope.applyView "Document" # Non-sensical, but best for the moment $rootScope.applyView "Document" # Non-sensical, but best for the moment
$rootScope.applySort "Newest" $rootScope.applySort "Newest"
$scope.search.query = $location.search()
$scope.search.update = (query) ->
unless angular.equals $location.search(query), query
$location.search {query:query}
$scope.search.clear = ->
$location.search({})
$scope.openDetails = (annotation) -> $scope.openDetails = (annotation) ->
$scope.loadMore = (number) => $scope.loadMore = (number) =>
# TODO: debounce # TODO: debounce
......
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