From 79d58fe3209a7f52609782de4650a736d3e05bd1 Mon Sep 17 00:00:00 2001 From: eikek Date: Sat, 26 Feb 2022 15:39:01 +0100 Subject: [PATCH] Sort tags by category and then name Issue: #1396 --- .../scala/docspell/store/queries/QItem.scala | 2 +- .../scala/docspell/store/records/RTag.scala | 19 +++++++++++++++++++ .../webapp/src/main/elm/Comp/ItemCardList.elm | 1 - 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/store/src/main/scala/docspell/store/queries/QItem.scala b/modules/store/src/main/scala/docspell/store/queries/QItem.scala index 66203292..b5f456c4 100644 --- a/modules/store/src/main/scala/docspell/store/queries/QItem.scala +++ b/modules/store/src/main/scala/docspell/store/queries/QItem.scala @@ -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 ) diff --git a/modules/store/src/main/scala/docspell/store/records/RTag.scala b/modules/store/src/main/scala/docspell/store/records/RTag.scala index 44b0e617..b9e9ab27 100644 --- a/modules/store/src/main/scala/docspell/store/records/RTag.scala +++ b/modules/store/src/main/scala/docspell/store/records/RTag.scala @@ -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) + } + } } diff --git a/modules/webapp/src/main/elm/Comp/ItemCardList.elm b/modules/webapp/src/main/elm/Comp/ItemCardList.elm index f9f2967b..7d37664a 100644 --- a/modules/webapp/src/main/elm/Comp/ItemCardList.elm +++ b/modules/webapp/src/main/elm/Comp/ItemCardList.elm @@ -33,7 +33,6 @@ import Html exposing (..) import Html.Attributes exposing (..) import Messages.Comp.ItemCardList exposing (Texts) import Page exposing (Page(..)) -import Set exposing (Set) import Styles as S import Util.ItemDragDrop as DD import Util.List