mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Allow to remove tags from multiple items
This commit is contained in:
@ -46,6 +46,12 @@ trait OItem[F[_]] {
|
||||
collective: Ident
|
||||
): F[UpdateResult]
|
||||
|
||||
def removeTagsMultipleItems(
|
||||
items: NonEmptyList[Ident],
|
||||
tags: List[String],
|
||||
collective: Ident
|
||||
): F[UpdateResult]
|
||||
|
||||
/** Toggles tags of the given item. Tags must exist, but can be IDs or names. */
|
||||
def toggleTags(item: Ident, tags: List[String], collective: Ident): F[UpdateResult]
|
||||
|
||||
@ -225,6 +231,29 @@ object OItem {
|
||||
}
|
||||
}
|
||||
|
||||
def removeTagsMultipleItems(
|
||||
items: NonEmptyList[Ident],
|
||||
tags: List[String],
|
||||
collective: Ident
|
||||
): F[UpdateResult] =
|
||||
tags.distinct match {
|
||||
case Nil => UpdateResult.success.pure[F]
|
||||
case ws =>
|
||||
store.transact {
|
||||
(for {
|
||||
itemIds <- OptionT
|
||||
.liftF(RItem.filterItems(items, collective))
|
||||
.filter(_.nonEmpty)
|
||||
given <- OptionT.liftF(RTag.findAllByNameOrId(ws, collective))
|
||||
_ <- OptionT.liftF(
|
||||
itemIds.traverse(item =>
|
||||
RTagItem.removeAllTags(item, given.map(_.tagId).toList)
|
||||
)
|
||||
)
|
||||
} yield UpdateResult.success).getOrElse(UpdateResult.notFound)
|
||||
}
|
||||
}
|
||||
|
||||
def toggleTags(
|
||||
item: Ident,
|
||||
tags: List[String],
|
||||
|
Reference in New Issue
Block a user