mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 09:58:26 +00:00
Edit direction of multiple items
This commit is contained in:
@ -49,7 +49,11 @@ trait OItem[F[_]] {
|
|||||||
/** Toggles tags of the given item. Tags must exist, but can be IDs or names. */
|
/** 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]
|
def toggleTags(item: Ident, tags: List[String], collective: Ident): F[UpdateResult]
|
||||||
|
|
||||||
def setDirection(item: Ident, direction: Direction, collective: Ident): F[AddResult]
|
def setDirection(
|
||||||
|
item: NonEmptyList[Ident],
|
||||||
|
direction: Direction,
|
||||||
|
collective: Ident
|
||||||
|
): F[UpdateResult]
|
||||||
|
|
||||||
def setFolder(item: Ident, folder: Option[Ident], collective: Ident): F[UpdateResult]
|
def setFolder(item: Ident, folder: Option[Ident], collective: Ident): F[UpdateResult]
|
||||||
|
|
||||||
@ -252,14 +256,14 @@ object OItem {
|
|||||||
.getOrElse(AddResult.Failure(new Exception("Collective mismatch")))
|
.getOrElse(AddResult.Failure(new Exception("Collective mismatch")))
|
||||||
|
|
||||||
def setDirection(
|
def setDirection(
|
||||||
item: Ident,
|
items: NonEmptyList[Ident],
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
collective: Ident
|
collective: Ident
|
||||||
): F[AddResult] =
|
): F[UpdateResult] =
|
||||||
store
|
UpdateResult.fromUpdate(
|
||||||
.transact(RItem.updateDirection(item, collective, direction))
|
store
|
||||||
.attempt
|
.transact(RItem.updateDirection(items, collective, direction))
|
||||||
.map(AddResult.fromUpdate)
|
)
|
||||||
|
|
||||||
def setFolder(
|
def setFolder(
|
||||||
item: Ident,
|
item: Ident,
|
||||||
|
@ -94,12 +94,13 @@ object ItemMultiRoutes {
|
|||||||
resp <- Ok(Conversions.basicResult(res, "Folder updated"))
|
resp <- Ok(Conversions.basicResult(res, "Folder updated"))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
// case req @ PUT -> Root / "direction" =>
|
case req @ PUT -> Root / "direction" =>
|
||||||
// for {
|
for {
|
||||||
// dir <- req.as[DirectionValue]
|
json <- req.as[ItemsAndDirection]
|
||||||
// res <- backend.item.setDirection(id, dir.direction, user.account.collective)
|
items <- readIds[F](json.items)
|
||||||
// resp <- Ok(Conversions.basicResult(res, "Direction updated"))
|
res <- backend.item.setDirection(items, json.direction, user.account.collective)
|
||||||
// } yield resp
|
resp <- Ok(Conversions.basicResult(res, "Direction updated"))
|
||||||
|
} yield resp
|
||||||
|
|
||||||
// case req @ PUT -> Root / "corrOrg" =>
|
// case req @ PUT -> Root / "corrOrg" =>
|
||||||
// for {
|
// for {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package docspell.restserver.routes
|
package docspell.restserver.routes
|
||||||
|
|
||||||
|
import cats.data.NonEmptyList
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import cats.implicits._
|
import cats.implicits._
|
||||||
|
|
||||||
@ -165,8 +166,12 @@ object ItemRoutes {
|
|||||||
|
|
||||||
case req @ PUT -> Root / Ident(id) / "direction" =>
|
case req @ PUT -> Root / Ident(id) / "direction" =>
|
||||||
for {
|
for {
|
||||||
dir <- req.as[DirectionValue]
|
dir <- req.as[DirectionValue]
|
||||||
res <- backend.item.setDirection(id, dir.direction, user.account.collective)
|
res <- backend.item.setDirection(
|
||||||
|
NonEmptyList.of(id),
|
||||||
|
dir.direction,
|
||||||
|
user.account.collective
|
||||||
|
)
|
||||||
resp <- Ok(Conversions.basicResult(res, "Direction updated"))
|
resp <- Ok(Conversions.basicResult(res, "Direction updated"))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
|
@ -145,12 +145,16 @@ object RItem {
|
|||||||
).update.run
|
).update.run
|
||||||
} yield n
|
} yield n
|
||||||
|
|
||||||
def updateDirection(itemId: Ident, coll: Ident, dir: Direction): ConnectionIO[Int] =
|
def updateDirection(
|
||||||
|
itemIds: NonEmptyList[Ident],
|
||||||
|
coll: Ident,
|
||||||
|
dir: Direction
|
||||||
|
): ConnectionIO[Int] =
|
||||||
for {
|
for {
|
||||||
t <- currentTime
|
t <- currentTime
|
||||||
n <- updateRow(
|
n <- updateRow(
|
||||||
table,
|
table,
|
||||||
and(id.is(itemId), cid.is(coll)),
|
and(id.isIn(itemIds), cid.is(coll)),
|
||||||
commas(incoming.setTo(dir), updated.setTo(t))
|
commas(incoming.setTo(dir), updated.setTo(t))
|
||||||
).update.run
|
).update.run
|
||||||
} yield n
|
} yield n
|
||||||
|
@ -82,6 +82,7 @@ module Api exposing
|
|||||||
, setCorrOrg
|
, setCorrOrg
|
||||||
, setCorrPerson
|
, setCorrPerson
|
||||||
, setDirection
|
, setDirection
|
||||||
|
, setDirectionMultiple
|
||||||
, setFolder
|
, setFolder
|
||||||
, setFolderMultiple
|
, setFolderMultiple
|
||||||
, setItemDate
|
, setItemDate
|
||||||
@ -134,6 +135,7 @@ import Api.Model.ItemLightList exposing (ItemLightList)
|
|||||||
import Api.Model.ItemProposals exposing (ItemProposals)
|
import Api.Model.ItemProposals exposing (ItemProposals)
|
||||||
import Api.Model.ItemSearch exposing (ItemSearch)
|
import Api.Model.ItemSearch exposing (ItemSearch)
|
||||||
import Api.Model.ItemUploadMeta exposing (ItemUploadMeta)
|
import Api.Model.ItemUploadMeta exposing (ItemUploadMeta)
|
||||||
|
import Api.Model.ItemsAndDirection exposing (ItemsAndDirection)
|
||||||
import Api.Model.ItemsAndName exposing (ItemsAndName)
|
import Api.Model.ItemsAndName exposing (ItemsAndName)
|
||||||
import Api.Model.ItemsAndRef exposing (ItemsAndRef)
|
import Api.Model.ItemsAndRef exposing (ItemsAndRef)
|
||||||
import Api.Model.ItemsAndRefs exposing (ItemsAndRefs)
|
import Api.Model.ItemsAndRefs exposing (ItemsAndRefs)
|
||||||
@ -1328,6 +1330,20 @@ setFolderMultiple flags data receive =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setDirectionMultiple :
|
||||||
|
Flags
|
||||||
|
-> ItemsAndDirection
|
||||||
|
-> (Result Http.Error BasicResult -> msg)
|
||||||
|
-> Cmd msg
|
||||||
|
setDirectionMultiple flags data receive =
|
||||||
|
Http2.authPut
|
||||||
|
{ url = flags.config.baseUrl ++ "/api/v1/sec/items/direction"
|
||||||
|
, account = getAccount flags
|
||||||
|
, body = Http.jsonBody (Api.Model.ItemsAndDirection.encode data)
|
||||||
|
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Item
|
--- Item
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ module Comp.ItemDetail.FormChange exposing
|
|||||||
import Api
|
import Api
|
||||||
import Api.Model.BasicResult exposing (BasicResult)
|
import Api.Model.BasicResult exposing (BasicResult)
|
||||||
import Api.Model.IdName exposing (IdName)
|
import Api.Model.IdName exposing (IdName)
|
||||||
|
import Api.Model.ItemsAndDirection exposing (ItemsAndDirection)
|
||||||
import Api.Model.ItemsAndName exposing (ItemsAndName)
|
import Api.Model.ItemsAndName exposing (ItemsAndName)
|
||||||
import Api.Model.ItemsAndRef exposing (ItemsAndRef)
|
import Api.Model.ItemsAndRef exposing (ItemsAndRef)
|
||||||
import Api.Model.ItemsAndRefs exposing (ItemsAndRefs)
|
import Api.Model.ItemsAndRefs exposing (ItemsAndRefs)
|
||||||
@ -63,5 +64,12 @@ multiUpdate flags ids change receive =
|
|||||||
in
|
in
|
||||||
Api.setFolderMultiple flags data receive
|
Api.setFolderMultiple flags data receive
|
||||||
|
|
||||||
|
DirectionChange dir ->
|
||||||
|
let
|
||||||
|
data =
|
||||||
|
ItemsAndDirection items (Data.Direction.toString dir)
|
||||||
|
in
|
||||||
|
Api.setDirectionMultiple flags data receive
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Cmd.none
|
Cmd.none
|
||||||
|
Reference in New Issue
Block a user