diff --git a/app/org/maproulette/framework/controller/TaskReviewController.scala b/app/org/maproulette/framework/controller/TaskReviewController.scala index eac57530..e5548fea 100644 --- a/app/org/maproulette/framework/controller/TaskReviewController.scala +++ b/app/org/maproulette/framework/controller/TaskReviewController.scala @@ -115,6 +115,7 @@ class TaskReviewController @Inject() ( onlySaved: Boolean = false, sort: String, order: String, + lastChallengeId: Long = -1, lastTaskId: Long = -1, excludeOtherReviewers: Boolean = false, asMetaReview: Boolean = false @@ -139,10 +140,12 @@ class TaskReviewController @Inject() ( onlySaved, sort, order, + (if (lastChallengeId == -1) None else Some(lastChallengeId)), (if (lastTaskId == -1) None else Some(lastTaskId)), excludeOtherReviewers, asMetaReview ) + val nextTask = result match { case Some(task) => Ok(Json.toJson(this.service.startTaskReview(user, task))) diff --git a/app/org/maproulette/framework/service/TaskReviewService.scala b/app/org/maproulette/framework/service/TaskReviewService.scala index 8d86b3ec..41979194 100644 --- a/app/org/maproulette/framework/service/TaskReviewService.scala +++ b/app/org/maproulette/framework/service/TaskReviewService.scala @@ -8,7 +8,7 @@ package org.maproulette.framework.service import javax.inject.{Inject, Singleton} import scala.concurrent.duration.FiniteDuration import org.joda.time.DateTime - +import scala.util.Random import org.maproulette.framework.model._ import org.maproulette.framework.psql.{Query, _} import org.maproulette.framework.psql.filter.{BaseParameter, _} @@ -140,6 +140,7 @@ class TaskReviewService @Inject() ( onlySaved: Boolean = false, sort: String, order: String, + lastChallengeId: Option[Long] = None, lastTaskId: Option[Long] = None, excludeOtherReviewers: Boolean = false, asMetaReview: Boolean = false @@ -151,10 +152,20 @@ class TaskReviewService @Inject() ( val params = copyParamsForMetaReview(asMetaReview, searchParameters) - val position = lastTaskId match { - case Some(taskId) => { - // Queries for a map of (taskId -> row position) - val rowMap = this.repository.queryTasksWithRowNumber( + // Define a function to prioritize tasks with the same challenge ID + def prioritizeByChallengeId(tasks: List[Task]): List[Task] = + lastChallengeId match { + case Some(challengeId) => + val filteredTasks = + tasks.filter(task => task.parent == challengeId && task.id != lastTaskId.getOrElse(-1)) + if (filteredTasks.nonEmpty) filteredTasks + else tasks.filter(_.id != lastTaskId.getOrElse(-1)) + case None => tasks + } + + val tasks = + prioritizeByChallengeId( + this.repository.queryTasks( getReviewRequestedQueries( user, params, @@ -166,35 +177,11 @@ class TaskReviewService @Inject() ( excludeOtherReviewers, asMetaReview ), - taskId + params ) - rowMap.get(taskId) - - // If our task id is in the row map, we have a position for it - rowMap.get(taskId) match { - case Some(row) => row - case _ => 0 - } - } - case _ => 0 - } - - this.repository - .queryTasks( - getReviewRequestedQueries( - user, - params, - onlySaved, - Paging(1, position), - sort, - order, - false, - excludeOtherReviewers, - asMetaReview - ), - params ) - .headOption + + Random.shuffle(tasks).headOption } /** diff --git a/conf/v2_route/review.api b/conf/v2_route/review.api index 03e931eb..ff31e4ab 100644 --- a/conf/v2_route/review.api +++ b/conf/v2_route/review.api @@ -173,7 +173,7 @@ GET /tasks/reviewed @org.maproulette.framework.cont # in: query # description: The search string used to match the Reviewer names. (reviewed_by) ### -GET /tasks/review/next @org.maproulette.framework.controller.TaskReviewController.nextTaskReview(onlySaved:Boolean ?= false, sort:String ?= "", order:String ?= "ASC", lastTaskId:Long ?= -1, excludeOtherReviewers:Boolean ?= false, asMetaReview: Boolean ?= false) +GET /tasks/review/next @org.maproulette.framework.controller.TaskReviewController.nextTaskReview(onlySaved:Boolean ?= false, sort:String ?= "", order:String ?= "ASC", lastChallengeId:Long ?= -1, lastTaskId:Long ?= -1, excludeOtherReviewers:Boolean ?= false, asMetaReview: Boolean ?= false) ### # tags: [ Review ] # summary: Retrieves nearby Tasks