mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 02:48:26 +00:00
Update tag counts in search menu
This commit is contained in:
@ -23,6 +23,7 @@ import Api.Model.IdName exposing (IdName)
|
||||
import Api.Model.ItemSearch exposing (ItemSearch)
|
||||
import Api.Model.PersonList exposing (PersonList)
|
||||
import Api.Model.ReferenceList exposing (ReferenceList)
|
||||
import Api.Model.SearchStats exposing (SearchStats)
|
||||
import Api.Model.TagCloud exposing (TagCloud)
|
||||
import Comp.CustomFieldMultiInput
|
||||
import Comp.DatePicker
|
||||
@ -338,7 +339,6 @@ type Msg
|
||||
| FromDueDateMsg Comp.DatePicker.Msg
|
||||
| UntilDueDateMsg Comp.DatePicker.Msg
|
||||
| ToggleInbox
|
||||
| GetTagsResp (Result Http.Error TagCloud)
|
||||
| GetOrgResp (Result Http.Error ReferenceList)
|
||||
| GetEquipResp (Result Http.Error EquipmentList)
|
||||
| GetPersonResp (Result Http.Error PersonList)
|
||||
@ -359,6 +359,7 @@ type Msg
|
||||
| SetTag String
|
||||
| CustomFieldMsg Comp.CustomFieldMultiInput.Msg
|
||||
| SetSource String
|
||||
| GetStatsResp (Result Http.Error SearchStats)
|
||||
|
||||
|
||||
type alias NextState =
|
||||
@ -425,7 +426,7 @@ updateDrop ddm flags settings msg model =
|
||||
{ model = mdp
|
||||
, cmd =
|
||||
Cmd.batch
|
||||
[ Api.getTagCloud flags GetTagsResp
|
||||
[ Api.itemSearchStats flags (getItemSearch model) GetStatsResp
|
||||
, Api.getOrgLight flags GetOrgResp
|
||||
, Api.getEquipments flags "" GetEquipResp
|
||||
, Api.getPersons flags "" GetPersonResp
|
||||
@ -475,12 +476,12 @@ updateDrop ddm flags settings msg model =
|
||||
SetTag id ->
|
||||
resetAndSet (TagSelectMsg (Comp.TagSelect.toggleTag id))
|
||||
|
||||
GetTagsResp (Ok tags) ->
|
||||
GetStatsResp (Ok stats) ->
|
||||
let
|
||||
selectModel =
|
||||
List.sortBy .count tags.items
|
||||
List.sortBy .count stats.tagCloud.items
|
||||
|> List.reverse
|
||||
|> Comp.TagSelect.init model.tagSelection
|
||||
|> Comp.TagSelect.modify model.tagSelection model.tagSelectModel
|
||||
|
||||
model_ =
|
||||
{ model | tagSelectModel = selectModel }
|
||||
@ -491,7 +492,7 @@ updateDrop ddm flags settings msg model =
|
||||
, dragDrop = DD.DragDropData ddm Nothing
|
||||
}
|
||||
|
||||
GetTagsResp (Err _) ->
|
||||
GetStatsResp (Err _) ->
|
||||
{ model = model
|
||||
, cmd = Cmd.none
|
||||
, stateChange = False
|
||||
|
@ -5,6 +5,7 @@ module Comp.TagSelect exposing
|
||||
, Selection
|
||||
, emptySelection
|
||||
, init
|
||||
, modify
|
||||
, reset
|
||||
, toggleTag
|
||||
, update
|
||||
@ -77,6 +78,45 @@ init sel tags =
|
||||
}
|
||||
|
||||
|
||||
modify : Selection -> Model -> List TagCount -> Model
|
||||
modify sel model tags =
|
||||
let
|
||||
newModel =
|
||||
init sel tags
|
||||
in
|
||||
if List.isEmpty model.all then
|
||||
newModel
|
||||
|
||||
else
|
||||
let
|
||||
tagId t =
|
||||
t.tag.id
|
||||
|
||||
catId c =
|
||||
c.name
|
||||
|
||||
tagDict =
|
||||
List.map (\e -> ( tagId e, e )) tags
|
||||
|> Dict.fromList
|
||||
|
||||
catDict =
|
||||
List.map (\e -> ( catId e, e )) newModel.categories
|
||||
|> Dict.fromList
|
||||
|
||||
replaceTag e =
|
||||
Dict.get e.tag.id tagDict |> Maybe.withDefault { e | count = 0 }
|
||||
|
||||
replaceCat c =
|
||||
Dict.get c.name catDict |> Maybe.withDefault { c | count = 0 }
|
||||
in
|
||||
{ model
|
||||
| all = List.map replaceTag model.all
|
||||
, filteredTags = List.map replaceTag model.filteredTags
|
||||
, categories = List.map replaceCat model.categories
|
||||
, filteredCats = List.map replaceCat model.filteredCats
|
||||
}
|
||||
|
||||
|
||||
reset : Model -> Model
|
||||
reset model =
|
||||
{ model
|
||||
|
Reference in New Issue
Block a user