@@ -2,7 +2,7 @@ const Boom = require('@hapi/boom')
22const etag = require ( 'etag' )
33
44class PagedCollection {
5- constructor ( getPage , total , pageSize ) {
5+ constructor ( getPage , notebookInfo , total , pageSize ) {
66 if ( Array . isArray ( getPage ) ) {
77 const items = getPage
88 this . _getPage = ( ) => items
@@ -13,6 +13,7 @@ class PagedCollection {
1313 this . total = total
1414 this . pageSize = pageSize
1515 }
16+ this . notebookInfo = notebookInfo
1617 }
1718
1819 getPage ( pageNumber ) {
@@ -31,19 +32,19 @@ function createPage(h, collection, pageNumber, iris) {
3132 return Boom . notFound ( )
3233 }
3334
35+ const items = collection . getPage ( pageNumber )
36+ const containerUrl = collection . notebookInfo . getContainerUrl ( )
3437 const page = {
3538 '@context' : 'http://www.w3.org/ns/anno.jsonld' ,
36- id : `http://example.org/annotations/?iris=${
37- iris ? 1 : 0
38- } &page=${ pageNumber } `,
39+ id : `${ containerUrl } /?page=${ pageNumber } &iris=${ iris ? 1 : 0 } ` ,
3940 type : 'AnnotationPage' ,
4041 partOf : {
41- id : `http://example.org/annotations /?iris=${ iris ? 1 : 0 } ` ,
42+ id : `${ containerUrl } /?iris=${ iris ? 1 : 0 } ` ,
4243 total : collection . total ,
4344 modified : '2016-07-20T12:00:00Z' ,
4445 } ,
4546 startIndex : pageNumber === 0 ? 0 : collection . pageSize * pageNumber ,
46- items : collection . getPage ( pageNumber ) ,
47+ items : iris ? items . map ( item => item . id ) : items ,
4748 }
4849
4950 const response = h . response ( page )
@@ -56,21 +57,20 @@ function createPage(h, collection, pageNumber, iris) {
5657}
5758
5859function createContainer ( h , collection , iris ) {
60+ const containerUrl = collection . notebookInfo . getContainerUrl ( )
5961 const container = {
6062 '@context' : [
6163 'http://www.w3.org/ns/anno.jsonld' ,
6264 'http://www.w3.org/ns/ldp.jsonld' ,
6365 ] ,
64- id : 'http://example.org/annotations/ ?iris=1' ,
66+ id : ` ${ containerUrl } / ?iris=${ iris ? 1 : 0 } ` ,
6567 type : [ 'BasicContainer' , 'AnnotationCollection' ] ,
6668 total : collection . total ,
6769 modified : '2016-07-20T12:00:00Z' ,
6870 label : 'tbd' ,
69- first : `http://example.org/annotations /?iris=${ iris ? 1 : 0 } &page=0` ,
71+ first : `${ containerUrl } /?iris=${ iris ? 1 : 0 } &page=0` ,
7072 ...( collection . lastPage > 0 && {
71- last : `http://example.org/annotations/?iris=${ iris ? 1 : 0 } &page=${
72- collection . lastPage
73- } `,
73+ last : `${ containerUrl } /?iris=${ iris ? 1 : 0 } &page=${ collection . lastPage } ` ,
7474 } ) ,
7575 }
7676
0 commit comments