@@ -237,15 +237,15 @@ class Collections @Inject() (datasets: DatasetService,
237237 }
238238 }
239239
240- def list (title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
241- Ok (toJson(listCollections(title, date, limit, Set [Permission ](Permission .ViewCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
240+ def list (when : Option [ String ], title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
241+ Ok (toJson(listCollections(when, title, date, limit, Set [Permission ](Permission .ViewCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
242242 }
243243
244- def listCanEdit (title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
245- Ok (toJson(listCollections(title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
244+ def listCanEdit (when : Option [ String ], title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
245+ Ok (toJson(listCollections(when, title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
246246 }
247247
248- def addDatasetToCollectionOptions (datasetId : UUID , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
248+ def addDatasetToCollectionOptions (when : Option [ String ], datasetId : UUID , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
249249 implicit val user = request.user
250250 var listAll = false
251251 var collectionList : List [Collection ] = List .empty
@@ -265,7 +265,7 @@ class Collections @Inject() (datasets: DatasetService,
265265 }
266266 }
267267 if (listAll) {
268- collectionList = listCollections(title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)
268+ collectionList = listCollections(when, title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)
269269 }
270270 Ok (toJson(collectionList))
271271 }
@@ -274,10 +274,10 @@ class Collections @Inject() (datasets: DatasetService,
274274 collections.get(current_collections.map(_.child_collection_ids).flatten).found
275275 }
276276
277- def listPossibleParents (currentCollectionId : String , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
277+ def listPossibleParents (when : Option [ String ], currentCollectionId : String , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
278278 val selfAndAncestors = collections.getSelfAndAncestors(UUID (currentCollectionId))
279279 val descendants = collections.getAllDescendants(UUID (currentCollectionId)).toList
280- val allCollections = listCollections(title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false ,
280+ val allCollections = listCollections(when, title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false ,
281281 request.user, request.user.fold(false )(_.superAdminMode), exact)
282282 val possibleNewParents = allCollections.filter(c =>
283283 if (play.api.Play .current.plugin[services.SpaceSharingPlugin ].isDefined) {
@@ -303,29 +303,55 @@ class Collections @Inject() (datasets: DatasetService,
303303 * Returns list of collections based on parameters and permissions.
304304 * TODO this needs to be cleaned up when do permissions for adding to a resource
305305 */
306- 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 ] = {
306+ 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 ] = {
307307 if (mine && user.isEmpty) return List .empty[Collection ]
308308
309- (title, date) match {
310- case (Some (t), Some (d)) => {
309+ (when, title, date) match {
310+ case (Some (w), Some (t), Some (d)) => {
311+ if (mine)
312+ collections.listUser(d, nextPage= (w== " a" ), limit, t, user, superAdmin, user.get, exact)
313+ else
314+ collections.listAccess(d, nextPage= (w== " a" ), limit, t, permission, user, superAdmin, true ,false , exact)
315+ }
316+ case (Some (w), Some (t), None ) => {
317+ if (mine)
318+ collections.listUser(limit, t, user, superAdmin, user.get, exact)
319+ else
320+ collections.listAccess(limit, t, permission, user, superAdmin, true ,false , exact)
321+ }
322+ case (Some (w), None , Some (d)) => {
323+ if (mine)
324+ collections.listUser(d, nextPage= (w== " a" ), limit, user, superAdmin, user.get)
325+ else
326+ collections.listAccess(d, nextPage= (w== " a" ), limit, permission, user, superAdmin, true ,false )
327+ }
328+ case (Some (w), None , None ) => {
329+ if (mine)
330+ collections.listUser(limit, user, superAdmin, user.get)
331+ else
332+ collections.listAccess(limit, permission, user, superAdmin, true ,false )
333+ }
334+
335+ // default when to be "after" if not present in parameters. i.e. nextPage=true
336+ case (None , Some (t), Some (d)) => {
311337 if (mine)
312338 collections.listUser(d, true , limit, t, user, superAdmin, user.get, exact)
313339 else
314340 collections.listAccess(d, true , limit, t, permission, user, superAdmin, true ,false , exact)
315341 }
316- case (Some (t), None ) => {
342+ case (None , Some (t), None ) => {
317343 if (mine)
318344 collections.listUser(limit, t, user, superAdmin, user.get, exact)
319345 else
320346 collections.listAccess(limit, t, permission, user, superAdmin, true ,false , exact)
321347 }
322- case (None , Some (d)) => {
348+ case (None , None , Some (d)) => {
323349 if (mine)
324350 collections.listUser(d, true , limit, user, superAdmin, user.get)
325351 else
326352 collections.listAccess(d, true , limit, permission, user, superAdmin, true ,false )
327353 }
328- case (None , None ) => {
354+ case (None , None , None ) => {
329355 if (mine)
330356 collections.listUser(limit, user, superAdmin, user.get)
331357 else
0 commit comments