Add folder count to search menu

This commit is contained in:
Eike Kettner 2020-12-16 19:20:30 +01:00
parent 8fba637ebe
commit b66738b4c3
2 changed files with 44 additions and 41 deletions

View File

@ -3,6 +3,7 @@ module Comp.FolderSelect exposing
, Msg , Msg
, deselect , deselect
, init , init
, modify
, setSelected , setSelected
, update , update
, updateDrop , updateDrop
@ -10,7 +11,8 @@ module Comp.FolderSelect exposing
, viewDrop , viewDrop
) )
import Api.Model.FolderItem exposing (FolderItem) import Api.Model.FolderStats exposing (FolderStats)
import Dict
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onClick) import Html.Events exposing (onClick)
@ -20,13 +22,13 @@ import Util.List
type alias Model = type alias Model =
{ all : List FolderItem { all : List FolderStats
, selected : Maybe String , selected : Maybe String
, expanded : Bool , expanded : Bool
} }
init : Maybe FolderItem -> List FolderItem -> Model init : Maybe FolderStats -> List FolderStats -> Model
init selected all = init selected all =
{ all = List.sortBy .name all { all = List.sortBy .name all
, selected = Maybe.map .id selected , selected = Maybe.map .id selected
@ -34,6 +36,26 @@ init selected all =
} }
modify : Maybe FolderStats -> Model -> List FolderStats -> Model
modify selected model all =
if List.isEmpty model.all then
init selected all
else
let
folderDict =
List.map (\f -> ( f.id, f )) all
|> Dict.fromList
replaced el =
Dict.get el.id folderDict |> Maybe.withDefault { el | count = 0 }
in
{ model
| all = List.map replaced model.all
, selected = Maybe.map .id selected
}
setSelected : String -> Model -> Maybe Msg setSelected : String -> Model -> Maybe Msg
setSelected id model = setSelected id model =
List.filter (\fi -> fi.id == id) model.all List.filter (\fi -> fi.id == id) model.all
@ -43,12 +65,7 @@ setSelected id model =
deselect : Model -> Maybe Msg deselect : Model -> Maybe Msg
deselect model = deselect model =
case model.selected of Maybe.andThen (\id -> setSelected id model) model.selected
Just id ->
setSelected id model
Nothing ->
Nothing
@ -56,12 +73,12 @@ deselect model =
type Msg type Msg
= Toggle FolderItem = Toggle FolderStats
| ToggleExpand | ToggleExpand
| FolderDDMsg DD.Msg | FolderDDMsg DD.Msg
update : Msg -> Model -> ( Model, Maybe FolderItem ) update : Msg -> Model -> ( Model, Maybe FolderStats )
update msg model = update msg model =
let let
( m, f, _ ) = ( m, f, _ ) =
@ -74,7 +91,7 @@ updateDrop :
DD.Model DD.Model
-> Msg -> Msg
-> Model -> Model
-> ( Model, Maybe FolderItem, DD.DragDropData ) -> ( Model, Maybe FolderStats, DD.DragDropData )
updateDrop dropModel msg model = updateDrop dropModel msg model =
case msg of case msg of
Toggle item -> Toggle item ->
@ -105,7 +122,7 @@ updateDrop dropModel msg model =
( model, selectedFolder model, ddd ) ( model, selectedFolder model, ddd )
selectedFolder : Model -> Maybe FolderItem selectedFolder : Model -> Maybe FolderStats
selectedFolder model = selectedFolder model =
let let
isSelected f = isSelected f =
@ -177,7 +194,7 @@ collapseToggle max model =
ToggleExpand ToggleExpand
viewItem : DD.Model -> Model -> FolderItem -> Html Msg viewItem : DD.Model -> Model -> FolderStats -> Html Msg
viewItem dropModel model item = viewItem dropModel model item =
let let
selected = selected =
@ -206,8 +223,11 @@ viewItem dropModel model item =
) )
[ i [ class icon ] [] [ i [ class icon ] []
, div [ class "content" ] , div [ class "content" ]
[ div [ class "header" ] [ div [ class "description" ]
[ text item.name [ text item.name
, div [ class "ui right floated circular label" ]
[ text (String.fromInt item.count)
]
] ]
] ]
] ]

View File

@ -19,6 +19,7 @@ import Api.Model.Equipment exposing (Equipment)
import Api.Model.EquipmentList exposing (EquipmentList) import Api.Model.EquipmentList exposing (EquipmentList)
import Api.Model.FolderItem exposing (FolderItem) import Api.Model.FolderItem exposing (FolderItem)
import Api.Model.FolderList exposing (FolderList) import Api.Model.FolderList exposing (FolderList)
import Api.Model.FolderStats exposing (FolderStats)
import Api.Model.IdName exposing (IdName) import Api.Model.IdName exposing (IdName)
import Api.Model.ItemSearch exposing (ItemSearch) import Api.Model.ItemSearch exposing (ItemSearch)
import Api.Model.PersonList exposing (PersonList) import Api.Model.PersonList exposing (PersonList)
@ -60,7 +61,7 @@ type alias Model =
, concPersonModel : Comp.Dropdown.Model IdName , concPersonModel : Comp.Dropdown.Model IdName
, concEquipmentModel : Comp.Dropdown.Model Equipment , concEquipmentModel : Comp.Dropdown.Model Equipment
, folderList : Comp.FolderSelect.Model , folderList : Comp.FolderSelect.Model
, selectedFolder : Maybe FolderItem , selectedFolder : Maybe FolderStats
, inboxCheckbox : Bool , inboxCheckbox : Bool
, fromDateModel : DatePicker , fromDateModel : DatePicker
, fromDate : Maybe Int , fromDate : Maybe Int
@ -350,7 +351,6 @@ type Msg
| ResetForm | ResetForm
| KeyUpMsg (Maybe KeyCode) | KeyUpMsg (Maybe KeyCode)
| FolderSelectMsg Comp.FolderSelect.Msg | FolderSelectMsg Comp.FolderSelect.Msg
| GetFolderResp (Result Http.Error FolderList)
| SetCorrOrg IdName | SetCorrOrg IdName
| SetCorrPerson IdName | SetCorrPerson IdName
| SetConcPerson IdName | SetConcPerson IdName
@ -430,7 +430,6 @@ updateDrop ddm flags settings msg model =
, Api.getOrgLight flags GetOrgResp , Api.getOrgLight flags GetOrgResp
, Api.getEquipments flags "" GetEquipResp , Api.getEquipments flags "" GetEquipResp
, Api.getPersons flags "" GetPersonResp , Api.getPersons flags "" GetPersonResp
, Api.getFolders flags "" False GetFolderResp
, Cmd.map CustomFieldMsg (Comp.CustomFieldMultiInput.initCmd flags) , Cmd.map CustomFieldMsg (Comp.CustomFieldMultiInput.initCmd flags)
, cdp , cdp
] ]
@ -484,7 +483,13 @@ updateDrop ddm flags settings msg model =
|> Comp.TagSelect.modify model.tagSelection model.tagSelectModel |> Comp.TagSelect.modify model.tagSelection model.tagSelectModel
model_ = model_ =
{ model | tagSelectModel = selectModel } { model
| tagSelectModel = selectModel
, folderList =
Comp.FolderSelect.modify model.selectedFolder
model.folderList
stats.folderStats
}
in in
{ model = model_ { model = model_
, cmd = Cmd.none , cmd = Cmd.none
@ -797,28 +802,6 @@ updateDrop ddm flags settings msg model =
, dragDrop = DD.DragDropData ddm Nothing , dragDrop = DD.DragDropData ddm Nothing
} }
GetFolderResp (Ok fs) ->
let
model_ =
{ model
| folderList =
Util.Folder.onlyVisible flags fs.items
|> Comp.FolderSelect.init model.selectedFolder
}
in
{ model = model_
, cmd = Cmd.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
}
GetFolderResp (Err _) ->
{ model = model
, cmd = Cmd.none
, stateChange = False
, dragDrop = DD.DragDropData ddm Nothing
}
FolderSelectMsg lm -> FolderSelectMsg lm ->
let let
( fsm, sel, ddd ) = ( fsm, sel, ddd ) =