Sort due items by their earliest due date

This commit is contained in:
Eike Kettner 2020-04-22 21:53:35 +02:00
parent e1f9ae2629
commit ffc1cdee51
4 changed files with 24 additions and 8 deletions

View File

@ -26,7 +26,7 @@ this is Docspell informing you about due items coming up.
{{/more}} {{/more}}
Sincerly, Sincerely yours,
Docspell Docspell
""" """

View File

@ -73,7 +73,8 @@ object NotifyDueItemsTask {
states = ItemState.validStates, states = ItemState.validStates,
tagsInclude = ctx.args.tagsInclude, tagsInclude = ctx.args.tagsInclude,
tagsExclude = ctx.args.tagsExclude, tagsExclude = ctx.args.tagsExclude,
dueDateTo = Some(now + Duration.days(ctx.args.remindDays.toLong)) dueDateTo = Some(now + Duration.days(ctx.args.remindDays.toLong)),
orderAsc = Some(_.dueDate)
) )
res <- ctx.store.transact(QItem.findItems(q).take(maxItems)).compile.toVector res <- ctx.store.transact(QItem.findItems(q).take(maxItems)).compile.toVector
} yield res } yield res

View File

@ -120,7 +120,8 @@ trait Conversions {
m.dateFrom, m.dateFrom,
m.dateUntil, m.dateUntil,
m.dueDateFrom, m.dueDateFrom,
m.dueDateUntil m.dueDateUntil,
None
) )
def mkItemList(v: Vector[OItem.ListItem]): ItemLightList = { def mkItemList(v: Vector[OItem.ListItem]): ItemLightList = {

View File

@ -9,6 +9,7 @@ import doobie.implicits._
import docspell.common.{IdRef, _} import docspell.common.{IdRef, _}
import docspell.store.Store import docspell.store.Store
import docspell.store.records._ import docspell.store.records._
import docspell.store.impl._
import docspell.store.impl.Implicits._ import docspell.store.impl.Implicits._
import org.log4s._ import org.log4s._
@ -122,7 +123,8 @@ object QItem {
dateFrom: Option[Timestamp], dateFrom: Option[Timestamp],
dateTo: Option[Timestamp], dateTo: Option[Timestamp],
dueDateFrom: Option[Timestamp], dueDateFrom: Option[Timestamp],
dueDateTo: Option[Timestamp] dueDateTo: Option[Timestamp],
orderAsc: Option[RItem.Columns.type => Column]
) )
object Query { object Query {
@ -141,6 +143,7 @@ object QItem {
None, None,
None, None,
None, None,
None,
None None
) )
} }
@ -173,7 +176,13 @@ object QItem {
PC.pid.prefix("p1").f, PC.pid.prefix("p1").f,
PC.name.prefix("p1").f, PC.name.prefix("p1").f,
EC.eid.prefix("e1").f, EC.eid.prefix("e1").f,
EC.name.prefix("e1").f EC.name.prefix("e1").f,
q.orderAsc match {
case Some(co) =>
coalesce(co(IC).prefix("i").f, IC.created.prefix("i").f)
case None =>
IC.created.prefix("i").f
}
) )
val withItem = selectSimple(itemCols, RItem.table, IC.cid.is(q.collective)) val withItem = selectSimple(itemCols, RItem.table, IC.cid.is(q.collective))
@ -258,9 +267,14 @@ object QItem {
q.dueDateTo.map(d => IC.dueDate.prefix("i").isLt(d)).getOrElse(Fragment.empty) q.dueDateTo.map(d => IC.dueDate.prefix("i").isLt(d)).getOrElse(Fragment.empty)
) )
val order = orderBy( val order = q.orderAsc match {
coalesce(IC.itemDate.prefix("i").f, IC.created.prefix("i").f) ++ fr"DESC" case Some(co) =>
) orderBy(coalesce(co(IC).prefix("i").f, IC.created.prefix("i").f) ++ fr"ASC")
case None =>
orderBy(
coalesce(IC.itemDate.prefix("i").f, IC.created.prefix("i").f) ++ fr"DESC"
)
}
val frag = query ++ fr"WHERE" ++ cond ++ order val frag = query ++ fr"WHERE" ++ cond ++ order
logger.trace(s"List items: $frag") logger.trace(s"List items: $frag")
frag.query[ListItem].stream frag.query[ListItem].stream