mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Implement item merge
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
|
||||
package docspell.store.queries
|
||||
|
||||
import cats.data.{NonEmptyList => Nel}
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.common._
|
||||
@ -19,7 +20,7 @@ object QCustomField {
|
||||
private val f = RCustomField.as("f")
|
||||
private val v = RCustomFieldValue.as("v")
|
||||
|
||||
case class CustomFieldData(field: RCustomField, usageCount: Int)
|
||||
final case class CustomFieldData(field: RCustomField, usageCount: Int)
|
||||
|
||||
def findAllLike(
|
||||
coll: Ident,
|
||||
@ -47,4 +48,24 @@ object QCustomField {
|
||||
GroupBy(f.all)
|
||||
)
|
||||
}
|
||||
|
||||
final case class FieldValue(
|
||||
field: RCustomField,
|
||||
itemId: Ident,
|
||||
value: String
|
||||
)
|
||||
|
||||
def findAllValues(itemIds: Nel[Ident]): ConnectionIO[List[FieldValue]] = {
|
||||
val cf = RCustomField.as("cf")
|
||||
val cv = RCustomFieldValue.as("cv")
|
||||
|
||||
run(
|
||||
select(cf.all, Nel.of(cv.itemId, cv.value)),
|
||||
from(cv).innerJoin(cf, cv.field === cf.id),
|
||||
cv.itemId.in(itemIds)
|
||||
)
|
||||
.query[FieldValue]
|
||||
.to[List]
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -97,6 +97,9 @@ object RAttachment {
|
||||
DML.set(T.fileId.setTo(fId))
|
||||
)
|
||||
|
||||
def updateItemId(attachId: Ident, itemId: Ident): ConnectionIO[Int] =
|
||||
DML.update(T, T.id === attachId, DML.set(T.itemId.setTo(itemId)))
|
||||
|
||||
def updatePosition(attachId: Ident, pos: Int): ConnectionIO[Int] =
|
||||
DML.update(T, T.id === attachId, DML.set(T.position.setTo(pos)))
|
||||
|
||||
|
@ -130,6 +130,30 @@ object RItem {
|
||||
def getCollective(itemId: Ident): ConnectionIO[Option[Ident]] =
|
||||
Select(T.cid.s, from(T), T.id === itemId).build.query[Ident].option
|
||||
|
||||
def updateAll(item: RItem): ConnectionIO[Int] =
|
||||
for {
|
||||
t <- currentTime
|
||||
n <- DML.update(
|
||||
T,
|
||||
T.id === item.id,
|
||||
DML.set(
|
||||
T.name.setTo(item.name),
|
||||
T.itemDate.setTo(item.itemDate),
|
||||
T.source.setTo(item.source),
|
||||
T.incoming.setTo(item.direction),
|
||||
T.corrOrg.setTo(item.corrOrg),
|
||||
T.corrPerson.setTo(item.corrPerson),
|
||||
T.concPerson.setTo(item.concPerson),
|
||||
T.concEquipment.setTo(item.concEquipment),
|
||||
T.inReplyTo.setTo(item.inReplyTo),
|
||||
T.dueDate.setTo(item.dueDate),
|
||||
T.notes.setTo(item.notes),
|
||||
T.folder.setTo(item.folderId),
|
||||
T.updated.setTo(t)
|
||||
)
|
||||
)
|
||||
} yield n
|
||||
|
||||
def updateState(
|
||||
itemId: Ident,
|
||||
itemState: ItemState,
|
||||
|
@ -34,6 +34,9 @@ object RTagItem {
|
||||
def insert(v: RTagItem): ConnectionIO[Int] =
|
||||
DML.insert(T, T.all, fr"${v.tagItemId},${v.itemId},${v.tagId}")
|
||||
|
||||
def moveTags(from: Ident, to: Ident): ConnectionIO[Int] =
|
||||
DML.update(T, T.itemId === from, DML.set(T.itemId.setTo(to)))
|
||||
|
||||
def deleteItemTags(item: Ident): ConnectionIO[Int] =
|
||||
DML.delete(T, T.itemId === item)
|
||||
|
||||
|
Reference in New Issue
Block a user