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
, deselect
, init
, modify
, setSelected
, update
, updateDrop
@ -10,7 +11,8 @@ module Comp.FolderSelect exposing
, viewDrop
)
import Api.Model.FolderItem exposing (FolderItem)
import Api.Model.FolderStats exposing (FolderStats)
import Dict
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
@ -20,13 +22,13 @@ import Util.List
type alias Model =
{ all : List FolderItem
{ all : List FolderStats
, selected : Maybe String
, expanded : Bool
}
init : Maybe FolderItem -> List FolderItem -> Model
init : Maybe FolderStats -> List FolderStats -> Model
init selected all =
{ all = List.sortBy .name all
, 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 id model =
List.filter (\fi -> fi.id == id) model.all
@ -43,12 +65,7 @@ setSelected id model =
deselect : Model -> Maybe Msg
deselect model =
case model.selected of
Just id ->
setSelected id model
Nothing ->
Nothing
Maybe.andThen (\id -> setSelected id model) model.selected
@ -56,12 +73,12 @@ deselect model =
type Msg
= Toggle FolderItem
= Toggle FolderStats
| ToggleExpand
| FolderDDMsg DD.Msg
update : Msg -> Model -> ( Model, Maybe FolderItem )
update : Msg -> Model -> ( Model, Maybe FolderStats )
update msg model =
let
( m, f, _ ) =
@ -74,7 +91,7 @@ updateDrop :
DD.Model
-> Msg
-> Model
-> ( Model, Maybe FolderItem, DD.DragDropData )
-> ( Model, Maybe FolderStats, DD.DragDropData )
updateDrop dropModel msg model =
case msg of
Toggle item ->
@ -105,7 +122,7 @@ updateDrop dropModel msg model =
( model, selectedFolder model, ddd )
selectedFolder : Model -> Maybe FolderItem
selectedFolder : Model -> Maybe FolderStats
selectedFolder model =
let
isSelected f =
@ -177,7 +194,7 @@ collapseToggle max model =
ToggleExpand
viewItem : DD.Model -> Model -> FolderItem -> Html Msg
viewItem : DD.Model -> Model -> FolderStats -> Html Msg
viewItem dropModel model item =
let
selected =
@ -206,8 +223,11 @@ viewItem dropModel model item =
)
[ i [ class icon ] []
, div [ class "content" ]
[ div [ class "header" ]
[ div [ class "description" ]
[ 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.FolderItem exposing (FolderItem)
import Api.Model.FolderList exposing (FolderList)
import Api.Model.FolderStats exposing (FolderStats)
import Api.Model.IdName exposing (IdName)
import Api.Model.ItemSearch exposing (ItemSearch)
import Api.Model.PersonList exposing (PersonList)
@ -60,7 +61,7 @@ type alias Model =
, concPersonModel : Comp.Dropdown.Model IdName
, concEquipmentModel : Comp.Dropdown.Model Equipment
, folderList : Comp.FolderSelect.Model
, selectedFolder : Maybe FolderItem
, selectedFolder : Maybe FolderStats
, inboxCheckbox : Bool
, fromDateModel : DatePicker
, fromDate : Maybe Int
@ -350,7 +351,6 @@ type Msg
| ResetForm
| KeyUpMsg (Maybe KeyCode)
| FolderSelectMsg Comp.FolderSelect.Msg
| GetFolderResp (Result Http.Error FolderList)
| SetCorrOrg IdName
| SetCorrPerson IdName
| SetConcPerson IdName
@ -430,7 +430,6 @@ updateDrop ddm flags settings msg model =
, Api.getOrgLight flags GetOrgResp
, Api.getEquipments flags "" GetEquipResp
, Api.getPersons flags "" GetPersonResp
, Api.getFolders flags "" False GetFolderResp
, Cmd.map CustomFieldMsg (Comp.CustomFieldMultiInput.initCmd flags)
, cdp
]
@ -484,7 +483,13 @@ updateDrop ddm flags settings msg model =
|> Comp.TagSelect.modify model.tagSelection model.tagSelectModel
model_ =
{ model | tagSelectModel = selectModel }
{ model
| tagSelectModel = selectModel
, folderList =
Comp.FolderSelect.modify model.selectedFolder
model.folderList
stats.folderStats
}
in
{ model = model_
, cmd = Cmd.none
@ -797,28 +802,6 @@ updateDrop ddm flags settings msg model =
, 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 ->
let
( fsm, sel, ddd ) =