mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 18:39:33 +00:00
Return custom field values with item details
This commit is contained in:
parent
1ee36cef8f
commit
1aefff37aa
@ -65,6 +65,9 @@ object OItemSearch {
|
||||
type ListItemWithTags = QItem.ListItemWithTags
|
||||
val ListItemWithTags = QItem.ListItemWithTags
|
||||
|
||||
type ItemFieldValue = QItem.ItemFieldValue
|
||||
val ItemFieldValue = QItem.ItemFieldValue
|
||||
|
||||
type ItemData = QItem.ItemData
|
||||
val ItemData = QItem.ItemData
|
||||
|
||||
|
@ -3492,6 +3492,35 @@ components:
|
||||
items:
|
||||
$ref: "#/components/schemas/CustomField"
|
||||
|
||||
ItemFieldValue:
|
||||
description: |
|
||||
Information about a custom field on an item.
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- ftype
|
||||
- value
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: ident
|
||||
name:
|
||||
type: string
|
||||
format: ident
|
||||
label:
|
||||
type: string
|
||||
ftype:
|
||||
type: string
|
||||
format: customfieldtype
|
||||
enum:
|
||||
- text
|
||||
- numeric
|
||||
- date
|
||||
- bool
|
||||
- money
|
||||
value:
|
||||
type: string
|
||||
|
||||
CustomFieldValue:
|
||||
description: |
|
||||
Data structure to update the value of a custom field.
|
||||
@ -4253,6 +4282,7 @@ components:
|
||||
- sources
|
||||
- archives
|
||||
- tags
|
||||
- customfields
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
@ -4312,6 +4342,10 @@ components:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Tag"
|
||||
customfields:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/ItemFieldValue"
|
||||
Attachment:
|
||||
description: |
|
||||
Information about an attachment to an item.
|
||||
|
@ -96,9 +96,13 @@ trait Conversions {
|
||||
data.attachments.map((mkAttachment(data) _).tupled).toList,
|
||||
data.sources.map((mkAttachmentSource _).tupled).toList,
|
||||
data.archives.map((mkAttachmentArchive _).tupled).toList,
|
||||
data.tags.map(mkTag).toList
|
||||
data.tags.map(mkTag).toList,
|
||||
data.customFields.map(mkItemFieldValue).toList
|
||||
)
|
||||
|
||||
def mkItemFieldValue(v: OItemSearch.ItemFieldValue): ItemFieldValue =
|
||||
ItemFieldValue(v.fieldId, v.fieldName, v.fieldLabel, v.fieldType, v.value)
|
||||
|
||||
def mkAttachment(
|
||||
item: OItemSearch.ItemData
|
||||
)(ra: RAttachment, m: FileMeta): Attachment = {
|
||||
|
@ -60,6 +60,13 @@ object QItem {
|
||||
|
||||
}
|
||||
|
||||
case class ItemFieldValue(
|
||||
fieldId: Ident,
|
||||
fieldName: Ident,
|
||||
fieldLabel: Option[String],
|
||||
fieldType: CustomFieldType,
|
||||
value: String
|
||||
)
|
||||
case class ItemData(
|
||||
item: RItem,
|
||||
corrOrg: Option[ROrganization],
|
||||
@ -71,7 +78,8 @@ object QItem {
|
||||
tags: Vector[RTag],
|
||||
attachments: Vector[(RAttachment, FileMeta)],
|
||||
sources: Vector[(RAttachmentSource, FileMeta)],
|
||||
archives: Vector[(RAttachmentArchive, FileMeta)]
|
||||
archives: Vector[(RAttachmentArchive, FileMeta)],
|
||||
customFields: Vector[ItemFieldValue]
|
||||
) {
|
||||
|
||||
def filterCollective(coll: Ident): Option[ItemData] =
|
||||
@ -126,11 +134,12 @@ object QItem {
|
||||
)
|
||||
]
|
||||
.option
|
||||
val attachs = RAttachment.findByItemWithMeta(id)
|
||||
val sources = RAttachmentSource.findByItemWithMeta(id)
|
||||
val archives = RAttachmentArchive.findByItemWithMeta(id)
|
||||
|
||||
val tags = RTag.findByItem(id)
|
||||
logger.trace(s"Find item query: $cq")
|
||||
val attachs = RAttachment.findByItemWithMeta(id)
|
||||
val sources = RAttachmentSource.findByItemWithMeta(id)
|
||||
val archives = RAttachmentArchive.findByItemWithMeta(id)
|
||||
val tags = RTag.findByItem(id)
|
||||
val customfields = findCustomFieldValues(id)
|
||||
|
||||
for {
|
||||
data <- q
|
||||
@ -138,11 +147,32 @@ object QItem {
|
||||
srcs <- sources
|
||||
arch <- archives
|
||||
ts <- tags
|
||||
cfs <- customfields
|
||||
} yield data.map(d =>
|
||||
ItemData(d._1, d._2, d._3, d._4, d._5, d._6, d._7, ts, att, srcs, arch)
|
||||
ItemData(d._1, d._2, d._3, d._4, d._5, d._6, d._7, ts, att, srcs, arch, cfs)
|
||||
)
|
||||
}
|
||||
|
||||
def findCustomFieldValues(itemId: Ident): ConnectionIO[Vector[ItemFieldValue]] = {
|
||||
val cfId = RCustomField.Columns.id.prefix("cf")
|
||||
val cfName = RCustomField.Columns.name.prefix("cf")
|
||||
val cfLabel = RCustomField.Columns.label.prefix("cf")
|
||||
val cfType = RCustomField.Columns.ftype.prefix("cf")
|
||||
val cvItem = RCustomFieldValue.Columns.itemId.prefix("cvf")
|
||||
val cvValue = RCustomFieldValue.Columns.value.prefix("cvf")
|
||||
val cvField = RCustomFieldValue.Columns.field.prefix("cvf")
|
||||
|
||||
val cfFrom =
|
||||
RCustomFieldValue.table ++ fr"cvf INNER JOIN" ++ RCustomField.table ++ fr"cf ON" ++ cvField
|
||||
.is(cfId)
|
||||
|
||||
selectSimple(
|
||||
Seq(cfId, cfName, cfLabel, cfType, cvValue),
|
||||
cfFrom,
|
||||
cvItem.is(itemId)
|
||||
).query[ItemFieldValue].to[Vector]
|
||||
}
|
||||
|
||||
case class ListItem(
|
||||
id: Ident,
|
||||
name: String,
|
||||
|
Loading…
x
Reference in New Issue
Block a user