mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-06 15:15:58 +00:00
Fix query for getting tag categoy summary
This commit is contained in:
parent
b781461b4a
commit
994e3df597
@ -4382,7 +4382,6 @@ components:
|
|||||||
description: |
|
description: |
|
||||||
Generic structure for counting something.
|
Generic structure for counting something.
|
||||||
required:
|
required:
|
||||||
- name
|
|
||||||
- count
|
- count
|
||||||
properties:
|
properties:
|
||||||
name:
|
name:
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
package docspell.store.queries
|
package docspell.store.queries
|
||||||
|
|
||||||
final case class CategoryCount(category: String, count: Int)
|
final case class CategoryCount(category: Option[String], count: Int)
|
||||||
|
@ -203,7 +203,7 @@ object QItem {
|
|||||||
.innerJoin(tag, tag.tid === ti.tagId)
|
.innerJoin(tag, tag.tid === ti.tagId)
|
||||||
.innerJoin(i, i.id === ti.itemId)
|
.innerJoin(i, i.id === ti.itemId)
|
||||||
|
|
||||||
val tagCloud =
|
val catCloud =
|
||||||
findItemsBase(q.fix, today, 0).unwrap
|
findItemsBase(q.fix, today, 0).unwrap
|
||||||
.withSelect(select(tag.category).append(countDistinct(i.id).as("num")))
|
.withSelect(select(tag.category).append(countDistinct(i.id).as("num")))
|
||||||
.changeFrom(_.prepend(tagFrom))
|
.changeFrom(_.prepend(tagFrom))
|
||||||
@ -213,14 +213,11 @@ object QItem {
|
|||||||
.query[CategoryCount]
|
.query[CategoryCount]
|
||||||
.to[List]
|
.to[List]
|
||||||
|
|
||||||
// the previous query starts from tags, so items with tag-count=0
|
|
||||||
// are not included they are fetched separately
|
|
||||||
for {
|
for {
|
||||||
existing <- tagCloud
|
existing <- catCloud
|
||||||
allCats <- RTag.listCategories(q.fix.account.collective)
|
allCats <- RTag.listCategories(q.fix.account.collective)
|
||||||
other = allCats.diff(existing.map(_.category))
|
other = allCats.diff(existing.flatMap(_.category))
|
||||||
} yield existing ++ other.map(CategoryCount(_, 0))
|
} yield existing ++ other.map(n => CategoryCount(n.some, 0))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def searchTagSummary(today: LocalDate)(q: Query): ConnectionIO[List[TagCount]] = {
|
def searchTagSummary(today: LocalDate)(q: Query): ConnectionIO[List[TagCount]] = {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module Comp.TagSelect exposing
|
module Comp.TagSelect exposing
|
||||||
( Model
|
( CategoryCount
|
||||||
|
, Model
|
||||||
, Msg
|
, Msg
|
||||||
, Selection
|
, Selection
|
||||||
, WorkModel
|
, WorkModel
|
||||||
@ -38,9 +39,9 @@ import Util.Maybe
|
|||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ availableTags : Dict String TagCount
|
{ availableTags : Dict String TagCount
|
||||||
, availableCats : Dict String NameCount
|
, availableCats : Dict String CategoryCount
|
||||||
, tagCounts : List TagCount
|
, tagCounts : List TagCount
|
||||||
, categoryCounts : List NameCount
|
, categoryCounts : List CategoryCount
|
||||||
, filterTerm : Maybe String
|
, filterTerm : Maybe String
|
||||||
, expandedTags : Bool
|
, expandedTags : Bool
|
||||||
, expandedCats : Bool
|
, expandedCats : Bool
|
||||||
@ -48,16 +49,22 @@ type alias Model =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type alias CategoryCount =
|
||||||
|
{ name : String
|
||||||
|
, count : Int
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
init : List TagCount -> List NameCount -> List TagCount -> List NameCount -> Model
|
init : List TagCount -> List NameCount -> List TagCount -> List NameCount -> Model
|
||||||
init allTags allCats tags cats =
|
init allTags allCats tags cats =
|
||||||
{ availableTags =
|
{ availableTags =
|
||||||
List.map (\e -> ( e.tag.id, e )) allTags
|
List.map (\e -> ( e.tag.id, e )) allTags
|
||||||
|> Dict.fromList
|
|> Dict.fromList
|
||||||
, availableCats =
|
, availableCats =
|
||||||
List.map (\e -> ( e.name, e )) allCats
|
List.filterMap (\e -> Maybe.map (\k -> ( k, CategoryCount k e.count )) e.name) allCats
|
||||||
|> Dict.fromList
|
|> Dict.fromList
|
||||||
, tagCounts = tags
|
, tagCounts = tags
|
||||||
, categoryCounts = cats
|
, categoryCounts = List.filterMap (\e -> Maybe.map (\k -> CategoryCount k e.count) e.name) cats
|
||||||
, filterTerm = Nothing
|
, filterTerm = Nothing
|
||||||
, expandedTags = False
|
, expandedTags = False
|
||||||
, expandedCats = False
|
, expandedCats = False
|
||||||
@ -72,7 +79,7 @@ modifyAll allTags allCats model =
|
|||||||
List.map (\e -> ( e.tag.id, e )) allTags
|
List.map (\e -> ( e.tag.id, e )) allTags
|
||||||
|> Dict.fromList
|
|> Dict.fromList
|
||||||
, availableCats =
|
, availableCats =
|
||||||
List.map (\e -> ( e.name, e )) allCats
|
List.filterMap (\e -> Maybe.map (\k -> ( k, CategoryCount k e.count )) e.name) allCats
|
||||||
|> Dict.fromList
|
|> Dict.fromList
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +88,7 @@ modifyCount : Model -> List TagCount -> List NameCount -> Model
|
|||||||
modifyCount model tags cats =
|
modifyCount model tags cats =
|
||||||
{ model
|
{ model
|
||||||
| tagCounts = tags
|
| tagCounts = tags
|
||||||
, categoryCounts = cats
|
, categoryCounts = List.filterMap (\e -> Maybe.map (\k -> CategoryCount k e.count) e.name) cats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -103,8 +110,8 @@ toggleTag id =
|
|||||||
type alias Selection =
|
type alias Selection =
|
||||||
{ includeTags : List TagCount
|
{ includeTags : List TagCount
|
||||||
, excludeTags : List TagCount
|
, excludeTags : List TagCount
|
||||||
, includeCats : List NameCount
|
, includeCats : List CategoryCount
|
||||||
, excludeCats : List NameCount
|
, excludeCats : List CategoryCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,7 +121,7 @@ emptySelection =
|
|||||||
|
|
||||||
|
|
||||||
type alias WorkModel =
|
type alias WorkModel =
|
||||||
{ filteredCats : List NameCount
|
{ filteredCats : List CategoryCount
|
||||||
, filteredTags : List TagCount
|
, filteredTags : List TagCount
|
||||||
, selectedTags : Dict String Bool
|
, selectedTags : Dict String Bool
|
||||||
, selectedCats : Dict String Bool
|
, selectedCats : Dict String Bool
|
||||||
@ -135,7 +142,7 @@ orderTagCountStable model tagCounts =
|
|||||||
List.sortBy order tagCounts
|
List.sortBy order tagCounts
|
||||||
|
|
||||||
|
|
||||||
orderCatCountStable : Model -> List NameCount -> List NameCount
|
orderCatCountStable : Model -> List CategoryCount -> List CategoryCount
|
||||||
orderCatCountStable model catCounts =
|
orderCatCountStable model catCounts =
|
||||||
let
|
let
|
||||||
order cat =
|
order cat =
|
||||||
@ -162,7 +169,7 @@ removeEmptyTagCounts sel tagCounts =
|
|||||||
List.filter (\tc -> isSelected tc || tc.count > 0) tagCounts
|
List.filter (\tc -> isSelected tc || tc.count > 0) tagCounts
|
||||||
|
|
||||||
|
|
||||||
removeEmptyCatCounts : Selection -> List NameCount -> List NameCount
|
removeEmptyCatCounts : Selection -> List CategoryCount -> List CategoryCount
|
||||||
removeEmptyCatCounts sel catCounts =
|
removeEmptyCatCounts sel catCounts =
|
||||||
let
|
let
|
||||||
selected =
|
selected =
|
||||||
@ -517,7 +524,7 @@ viewTagItem2 ddm settings model tag =
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
viewCategoryItem2 : UiSettings -> WorkModel -> NameCount -> Html Msg
|
viewCategoryItem2 : UiSettings -> WorkModel -> CategoryCount -> Html Msg
|
||||||
viewCategoryItem2 settings model cat =
|
viewCategoryItem2 settings model cat =
|
||||||
let
|
let
|
||||||
state =
|
state =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user