Sort tags by category and then name

Issue: #1396
This commit is contained in:
eikek
2022-02-26 15:39:01 +01:00
parent dcd8267d6e
commit 79d58fe320
3 changed files with 20 additions and 2 deletions

View File

@ -442,7 +442,7 @@ object QItem {
cfields <- Stream.eval(findCustomFieldValuesForItem(item.id))
} yield ListItemWithTags(
item,
ftags.toList.sortBy(_.name),
RTag.sort(ftags.toList),
attachs.sortBy(_.position),
cfields.toList
)

View File

@ -164,4 +164,23 @@ object RTag {
def delete(tagId: Ident, coll: Ident): ConnectionIO[Int] =
DML.delete(T, T.tid === tagId && T.cid === coll)
def sort(tags: List[RTag]): List[RTag] =
tags match {
case Nil => tags
case _ =>
val byCat = tags
.groupBy(_.category)
.view
.mapValues(_.sortBy(_.name))
.toList
.sortBy(_._1)
byCat match {
case (None, tags) :: rest =>
rest.flatMap(_._2) ++ tags
case _ =>
byCat.flatMap(_._2)
}
}
}