@@ -240,15 +240,15 @@ class Collections @Inject() (datasets: DatasetService,
240240 }
241241 }
242242
243- def list (title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
244- Ok (toJson(listCollections(title, date, limit, Set [Permission ](Permission .ViewCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
243+ def list (when : Option [ String ], title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
244+ Ok (toJson(listCollections(when, title, date, limit, Set [Permission ](Permission .ViewCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
245245 }
246246
247- def listCanEdit (title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
248- Ok (toJson(listCollections(title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
247+ def listCanEdit (when : Option [ String ], title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
248+ Ok (toJson(listCollections(when, title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
249249 }
250250
251- def addDatasetToCollectionOptions (datasetId : UUID , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
251+ def addDatasetToCollectionOptions (when : Option [ String ], datasetId : UUID , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
252252 implicit val user = request.user
253253 var listAll = false
254254 var collectionList : List [Collection ] = List .empty
@@ -268,7 +268,7 @@ class Collections @Inject() (datasets: DatasetService,
268268 }
269269 }
270270 if (listAll) {
271- collectionList = listCollections(title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)
271+ collectionList = listCollections(when, title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)
272272 }
273273 Ok (toJson(collectionList))
274274 }
@@ -277,10 +277,10 @@ class Collections @Inject() (datasets: DatasetService,
277277 collections.get(current_collections.map(_.child_collection_ids).flatten).found
278278 }
279279
280- def listPossibleParents (currentCollectionId : String , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
280+ def listPossibleParents (when : Option [ String ], currentCollectionId : String , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
281281 val selfAndAncestors = collections.getSelfAndAncestors(UUID (currentCollectionId))
282282 val descendants = collections.getAllDescendants(UUID (currentCollectionId)).toList
283- val allCollections = listCollections(title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false ,
283+ val allCollections = listCollections(when, title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false ,
284284 request.user, request.user.fold(false )(_.superAdminMode), exact)
285285 val possibleNewParents = allCollections.filter(c =>
286286 if (play.api.Play .current.plugin[services.SpaceSharingPlugin ].isDefined) {
@@ -306,29 +306,55 @@ class Collections @Inject() (datasets: DatasetService,
306306 * Returns list of collections based on parameters and permissions.
307307 * TODO this needs to be cleaned up when do permissions for adding to a resource
308308 */
309- private def listCollections (title : Option [String ], date : Option [String ], limit : Int , permission : Set [Permission ], mine : Boolean , user : Option [User ], superAdmin : Boolean , exact : Boolean ) : List [Collection ] = {
309+ private def listCollections (when : Option [ String ], title : Option [String ], date : Option [String ], limit : Int , permission : Set [Permission ], mine : Boolean , user : Option [User ], superAdmin : Boolean , exact : Boolean ) : List [Collection ] = {
310310 if (mine && user.isEmpty) return List .empty[Collection ]
311311
312- (title, date) match {
313- case (Some (t), Some (d)) => {
312+ (when, title, date) match {
313+ case (Some (w), Some (t), Some (d)) => {
314+ if (mine)
315+ collections.listUser(d, nextPage= (w== " a" ), limit, t, user, superAdmin, user.get, exact)
316+ else
317+ collections.listAccess(d, nextPage= (w== " a" ), limit, t, permission, user, superAdmin, true ,false , exact)
318+ }
319+ case (Some (w), Some (t), None ) => {
320+ if (mine)
321+ collections.listUser(limit, t, user, superAdmin, user.get, exact)
322+ else
323+ collections.listAccess(limit, t, permission, user, superAdmin, true ,false , exact)
324+ }
325+ case (Some (w), None , Some (d)) => {
326+ if (mine)
327+ collections.listUser(d, nextPage= (w== " a" ), limit, user, superAdmin, user.get)
328+ else
329+ collections.listAccess(d, nextPage= (w== " a" ), limit, permission, user, superAdmin, true ,false )
330+ }
331+ case (Some (w), None , None ) => {
332+ if (mine)
333+ collections.listUser(limit, user, superAdmin, user.get)
334+ else
335+ collections.listAccess(limit, permission, user, superAdmin, true ,false )
336+ }
337+
338+ // default when to be "after" if not present in parameters. i.e. nextPage=true
339+ case (None , Some (t), Some (d)) => {
314340 if (mine)
315341 collections.listUser(d, true , limit, t, user, superAdmin, user.get, exact)
316342 else
317343 collections.listAccess(d, true , limit, t, permission, user, superAdmin, true ,false , exact)
318344 }
319- case (Some (t), None ) => {
345+ case (None , Some (t), None ) => {
320346 if (mine)
321347 collections.listUser(limit, t, user, superAdmin, user.get, exact)
322348 else
323349 collections.listAccess(limit, t, permission, user, superAdmin, true ,false , exact)
324350 }
325- case (None , Some (d)) => {
351+ case (None , None , Some (d)) => {
326352 if (mine)
327353 collections.listUser(d, true , limit, user, superAdmin, user.get)
328354 else
329355 collections.listAccess(d, true , limit, permission, user, superAdmin, true ,false )
330356 }
331- case (None , None ) => {
357+ case (None , None , None ) => {
332358 if (mine)
333359 collections.listUser(limit, user, superAdmin, user.get)
334360 else
0 commit comments