From a4796f3f7f53b7ddc2982d7a84b05db08903743e Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sat, 8 Aug 2020 00:41:20 +0200 Subject: [PATCH] Return more tag details with item insights --- .../docspell/backend/ops/OCollective.scala | 3 +++ .../src/main/resources/docspell-openapi.yml | 24 +++++++++++++++---- .../restserver/conv/Conversions.scala | 5 +++- .../docspell/store/queries/QCollective.scala | 11 +++++---- .../main/elm/Page/CollectiveSettings/View.elm | 6 ++--- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala b/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala index 72e82f50..79f41d2b 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala @@ -43,6 +43,9 @@ trait OCollective[F[_]] { object OCollective { + type TagCount = QCollective.TagCount + val TagCount = QCollective.TagCount + type InsightData = QCollective.InsightData val insightData = QCollective.InsightData diff --git a/modules/restapi/src/main/resources/docspell-openapi.yml b/modules/restapi/src/main/resources/docspell-openapi.yml index 2b23aab9..10bd2488 100644 --- a/modules/restapi/src/main/resources/docspell-openapi.yml +++ b/modules/restapi/src/main/resources/docspell-openapi.yml @@ -3050,19 +3050,33 @@ components: items: type: array items: - $ref: "#/components/schemas/NameCount" - NameCount: + $ref: "#/components/schemas/TagCount" + TagCount: description: | Generic structure for counting something. required: - - name + - tag - count properties: - name: - type: string + tag: + $ref: "#/components/schemas/TagLight" count: type: integer format: int32 + TagLight: + description: | + A subset of tag properties. + required: + - id + - name + properties: + id: + type: string + format: ident + name: + type: string + category: + type: string AttachmentMeta: description: | Extracted meta data of an attachment. diff --git a/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala b/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala index ef732d30..fc05d14b 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala @@ -31,9 +31,12 @@ trait Conversions { d.incoming, d.outgoing, d.bytes, - TagCloud(d.tags.toList.map(p => NameCount(p._1, p._2))) + TagCloud(d.tags.map(tc => TagCount(mkTagLight(tc), tc.count))) ) + def mkTagLight(t: OCollective.TagCount): TagLight = + TagLight(t.id, t.name, t.category) + // attachment meta def mkAttachmentMeta(rm: RAttachmentMeta): AttachmentMeta = AttachmentMeta( diff --git a/modules/store/src/main/scala/docspell/store/queries/QCollective.scala b/modules/store/src/main/scala/docspell/store/queries/QCollective.scala index 4eb129d4..fbe814dc 100644 --- a/modules/store/src/main/scala/docspell/store/queries/QCollective.scala +++ b/modules/store/src/main/scala/docspell/store/queries/QCollective.scala @@ -11,12 +11,13 @@ import doobie._ import doobie.implicits._ object QCollective { + case class TagCount(id: Ident, name: String, category: Option[String], count: Int) case class InsightData( incoming: Int, outgoing: Int, bytes: Long, - tags: Map[String, Int] + tags: List[TagCount] ) def getInsights(coll: Ident): ConnectionIO[InsightData] = { @@ -52,7 +53,9 @@ object QCollective { ) as t""".query[Option[Long]].unique val q3 = fr"SELECT" ++ commas( + TC.tid.prefix("t").f, TC.name.prefix("t").f, + TC.category.prefix("t").f, fr"count(" ++ RC.itemId.prefix("r").f ++ fr")" ) ++ fr"FROM" ++ RTagItem.table ++ fr"r" ++ @@ -60,14 +63,14 @@ object QCollective { .prefix("r") .is(TC.tid.prefix("t")) ++ fr"WHERE" ++ TC.cid.prefix("t").is(coll) ++ - fr"GROUP BY" ++ TC.name.prefix("t").f + fr"GROUP BY" ++ commas(TC.name.prefix("t").f, TC.tid.prefix("t").f, TC.category.prefix("t").f) for { n0 <- q0 n1 <- q1 n2 <- fileSize - n3 <- q3.query[(String, Int)].to[Vector] - } yield InsightData(n0, n1, n2.getOrElse(0L), Map.from(n3)) + n3 <- q3.query[TagCount].to[List] + } yield InsightData(n0, n1, n2.getOrElse(0L), n3) } def getContacts( diff --git a/modules/webapp/src/main/elm/Page/CollectiveSettings/View.elm b/modules/webapp/src/main/elm/Page/CollectiveSettings/View.elm index 09afa7cd..513e2719 100644 --- a/modules/webapp/src/main/elm/Page/CollectiveSettings/View.elm +++ b/modules/webapp/src/main/elm/Page/CollectiveSettings/View.elm @@ -1,6 +1,6 @@ module Page.CollectiveSettings.View exposing (view) -import Api.Model.NameCount exposing (NameCount) +import Api.Model.TagCount exposing (TagCount) import Comp.CollectiveSettingsForm import Comp.SourceManage import Comp.UserManage @@ -145,14 +145,14 @@ viewInsights model = ] -makeTagStats : NameCount -> Html Msg +makeTagStats : TagCount -> Html Msg makeTagStats nc = div [ class "ui statistic" ] [ div [ class "value" ] [ String.fromInt nc.count |> text ] , div [ class "label" ] - [ text nc.name + [ text nc.tag.name ] ]