Return more tag details with item insights

This commit is contained in:
Eike Kettner 2020-08-08 00:41:20 +02:00
parent c8ad9bf11f
commit a4796f3f7f
5 changed files with 36 additions and 13 deletions

View File

@ -43,6 +43,9 @@ trait OCollective[F[_]] {
object OCollective { object OCollective {
type TagCount = QCollective.TagCount
val TagCount = QCollective.TagCount
type InsightData = QCollective.InsightData type InsightData = QCollective.InsightData
val insightData = QCollective.InsightData val insightData = QCollective.InsightData

View File

@ -3050,19 +3050,33 @@ components:
items: items:
type: array type: array
items: items:
$ref: "#/components/schemas/NameCount" $ref: "#/components/schemas/TagCount"
NameCount: TagCount:
description: | description: |
Generic structure for counting something. Generic structure for counting something.
required: required:
- name - tag
- count - count
properties: properties:
name: tag:
type: string $ref: "#/components/schemas/TagLight"
count: count:
type: integer type: integer
format: int32 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: AttachmentMeta:
description: | description: |
Extracted meta data of an attachment. Extracted meta data of an attachment.

View File

@ -31,9 +31,12 @@ trait Conversions {
d.incoming, d.incoming,
d.outgoing, d.outgoing,
d.bytes, 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 // attachment meta
def mkAttachmentMeta(rm: RAttachmentMeta): AttachmentMeta = def mkAttachmentMeta(rm: RAttachmentMeta): AttachmentMeta =
AttachmentMeta( AttachmentMeta(

View File

@ -11,12 +11,13 @@ import doobie._
import doobie.implicits._ import doobie.implicits._
object QCollective { object QCollective {
case class TagCount(id: Ident, name: String, category: Option[String], count: Int)
case class InsightData( case class InsightData(
incoming: Int, incoming: Int,
outgoing: Int, outgoing: Int,
bytes: Long, bytes: Long,
tags: Map[String, Int] tags: List[TagCount]
) )
def getInsights(coll: Ident): ConnectionIO[InsightData] = { def getInsights(coll: Ident): ConnectionIO[InsightData] = {
@ -52,7 +53,9 @@ object QCollective {
) as t""".query[Option[Long]].unique ) as t""".query[Option[Long]].unique
val q3 = fr"SELECT" ++ commas( val q3 = fr"SELECT" ++ commas(
TC.tid.prefix("t").f,
TC.name.prefix("t").f, TC.name.prefix("t").f,
TC.category.prefix("t").f,
fr"count(" ++ RC.itemId.prefix("r").f ++ fr")" fr"count(" ++ RC.itemId.prefix("r").f ++ fr")"
) ++ ) ++
fr"FROM" ++ RTagItem.table ++ fr"r" ++ fr"FROM" ++ RTagItem.table ++ fr"r" ++
@ -60,14 +63,14 @@ object QCollective {
.prefix("r") .prefix("r")
.is(TC.tid.prefix("t")) ++ .is(TC.tid.prefix("t")) ++
fr"WHERE" ++ TC.cid.prefix("t").is(coll) ++ 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 { for {
n0 <- q0 n0 <- q0
n1 <- q1 n1 <- q1
n2 <- fileSize n2 <- fileSize
n3 <- q3.query[(String, Int)].to[Vector] n3 <- q3.query[TagCount].to[List]
} yield InsightData(n0, n1, n2.getOrElse(0L), Map.from(n3)) } yield InsightData(n0, n1, n2.getOrElse(0L), n3)
} }
def getContacts( def getContacts(

View File

@ -1,6 +1,6 @@
module Page.CollectiveSettings.View exposing (view) module Page.CollectiveSettings.View exposing (view)
import Api.Model.NameCount exposing (NameCount) import Api.Model.TagCount exposing (TagCount)
import Comp.CollectiveSettingsForm import Comp.CollectiveSettingsForm
import Comp.SourceManage import Comp.SourceManage
import Comp.UserManage import Comp.UserManage
@ -145,14 +145,14 @@ viewInsights model =
] ]
makeTagStats : NameCount -> Html Msg makeTagStats : TagCount -> Html Msg
makeTagStats nc = makeTagStats nc =
div [ class "ui statistic" ] div [ class "ui statistic" ]
[ div [ class "value" ] [ div [ class "value" ]
[ String.fromInt nc.count |> text [ String.fromInt nc.count |> text
] ]
, div [ class "label" ] , div [ class "label" ]
[ text nc.name [ text nc.tag.name
] ]
] ]