Commit 254a069a authored by Nick Stenning's avatar Nick Stenning

Merge pull request #1937 from hypothesis/load_all_annotations

Load all annotations
parents 82fbab54 8375bdb6
...@@ -187,8 +187,24 @@ class ViewerController ...@@ -187,8 +187,24 @@ class ViewerController
loaded = [] loaded = []
_loadAnnotationsFrom = (query, offset) ->
queryCore =
limit: 20
offset: offset
sort: 'created'
order: 'asc'
q = angular.extend(queryCore, query)
store.SearchResource.get q, (results) ->
total = results.total
offset += results.rows.length
if offset < total
_loadAnnotationsFrom query, offset
annotationMapper.loadAnnotations(results.rows)
loadAnnotations = -> loadAnnotations = ->
query = limit: 200 query = {}
if annotationUI.tool is 'highlight' if annotationUI.tool is 'highlight'
return unless auth.user return unless auth.user
query.user = auth.user query.user = auth.user
...@@ -196,8 +212,8 @@ class ViewerController ...@@ -196,8 +212,8 @@ class ViewerController
for p in crossframe.providers for p in crossframe.providers
for e in p.entities when e not in loaded for e in p.entities when e not in loaded
loaded.push e loaded.push e
r = store.SearchResource.get angular.extend(uri: e, query), (results) -> q = angular.extend(uri: e, query)
annotationMapper.loadAnnotations(results.rows) _loadAnnotationsFrom q, 0
streamfilter.resetFilter().addClause('/uri', 'one_of', loaded) streamfilter.resetFilter().addClause('/uri', 'one_of', loaded)
......
assert = chai.assert assert = chai.assert
sinon.assert.expose assert, prefix: null sinon.assert.expose assert, prefix: null
fakeStore =
SearchResource:
get: sinon.spy()
describe 'h', -> describe 'h', ->
$scope = null $scope = null
fakeAuth = null
fakeIdentity = null fakeIdentity = null
fakeLocation = null fakeLocation = null
fakeParams = null fakeParams = null
fakeStreamer = null fakeStreamer = null
fakeStore =
SearchResource:
get: sinon.spy()
sandbox = null sandbox = null
beforeEach module('h') beforeEach module('h')
...@@ -20,19 +18,6 @@ describe 'h', -> ...@@ -20,19 +18,6 @@ describe 'h', ->
beforeEach module ($provide) -> beforeEach module ($provide) ->
sandbox = sinon.sandbox.create() sandbox = sinon.sandbox.create()
fakeAnnotator = {
plugins: {
Auth: {withToken: sandbox.spy()}
}
options: {}
socialView: {name: 'none'}
addPlugin: sandbox.spy()
}
fakeAuth = {
user: null
}
fakeIdentity = { fakeIdentity = {
watch: sandbox.spy() watch: sandbox.spy()
request: sandbox.spy() request: sandbox.spy()
...@@ -41,7 +26,9 @@ describe 'h', -> ...@@ -41,7 +26,9 @@ describe 'h', ->
fakeLocation = { fakeLocation = {
search: sandbox.stub().returns({}) search: sandbox.stub().returns({})
} }
fakeParams = {id: 'test'} fakeParams = {id: 'test'}
fakeStreamer = { fakeStreamer = {
open: sandbox.spy() open: sandbox.spy()
close: sandbox.spy() close: sandbox.spy()
...@@ -83,6 +70,69 @@ describe 'h', -> ...@@ -83,6 +70,69 @@ describe 'h', ->
it 'sets the isEmbedded property to false', -> it 'sets the isEmbedded property to false', ->
assert.isFalse($scope.isEmbedded) assert.isFalse($scope.isEmbedded)
describe 'ViewerController', ->
$scope = null
fakeAnnotationMapper = null
fakeAuth = null
fakeCrossFrame = null
fakeStore = null
fakeStreamer = null
sandbox = null
viewer = null
beforeEach module('h')
beforeEach module ($provide) ->
sandbox = sinon.sandbox.create()
fakeAnnotationMapper = {loadAnnotations: sandbox.spy()}
fakeAuth = {user: null}
fakeCrossFrame = {providers: []}
fakeStore = {
SearchResource:
get: (query, callback) ->
offset = query.offset or 0
limit = query.limit or 20
result =
total: 100
rows: [offset..offset+limit-1]
callback result
}
fakeStreamer = {
open: sandbox.spy()
close: sandbox.spy()
send: sandbox.spy()
}
$provide.value 'annotationMapper', fakeAnnotationMapper
$provide.value 'auth', fakeAuth
$provide.value 'crossframe', fakeCrossFrame
$provide.value 'store', fakeStore
$provide.value 'streamer', fakeStreamer
return
beforeEach inject ($controller, $rootScope) ->
$scope = $rootScope.$new()
viewer = $controller 'ViewerController', {$scope}
afterEach ->
sandbox.restore()
describe 'loadAnnotations', ->
it 'loads all annotation for a provider', ->
fakeCrossFrame.providers.push {entities: ['http://example.com']}
$scope.$digest()
loadSpy = fakeAnnotationMapper.loadAnnotations
assert.callCount(loadSpy, 5)
assert.calledWith(loadSpy, [0..19])
assert.calledWith(loadSpy, [20..39])
assert.calledWith(loadSpy, [40..59])
assert.calledWith(loadSpy, [60..79])
assert.calledWith(loadSpy, [80..99])
describe 'AnnotationUIController', -> describe 'AnnotationUIController', ->
$scope = null $scope = null
$rootScope = null $rootScope = null
......
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