Refactor Dropdown

This commit is contained in:
Eike Kettner
2021-04-02 15:54:02 +02:00
parent b9c98c6578
commit 8d15d97857
26 changed files with 493 additions and 504 deletions

View File

@ -14,8 +14,10 @@ import Comp.ItemDetail.Model
)
import Comp.KeyInput
import Comp.Tabs as TB
import Data.Direction
import Data.DropdownStyle
import Data.Fields
import Data.Flags exposing (Flags)
import Data.Icons as Icons
import Data.UiSettings exposing (UiSettings)
import Dict
@ -27,11 +29,13 @@ import Page exposing (Page(..))
import Set exposing (Set)
import Styles as S
import Util.Folder
import Util.Person
import Util.Tag
import Util.Time
view2 : UiSettings -> Model -> Html Msg
view2 settings model =
view2 : Flags -> UiSettings -> Model -> Html Msg
view2 flags settings model =
let
keyAttr =
if settings.itemDetailShortcuts then
@ -44,7 +48,7 @@ view2 settings model =
TB.searchMenuStyle
tabs =
formTabs settings model
formTabs flags settings model
allTabNames =
List.map .title tabs
@ -57,8 +61,8 @@ view2 settings model =
]
formTabs : UiSettings -> Model -> List (TB.Tab Msg)
formTabs settings model =
formTabs : Flags -> UiSettings -> Model -> List (TB.Tab Msg)
formTabs flags settings model =
let
dds =
Data.DropdownStyle.sidebarStyle
@ -106,6 +110,38 @@ formTabs settings model =
else
span [ class "invisible hidden" ] []
directionCfg =
{ makeOption =
\entry ->
{ text = Data.Direction.toString entry
, additional = ""
}
, placeholder = "Choose a direction"
, labelColor = \_ -> \_ -> ""
, style = dds
}
folderCfg =
{ makeOption = Util.Folder.mkFolderOption flags model.allFolders
, placeholder = ""
, labelColor = \_ -> \_ -> ""
, style = dds
}
idNameCfg =
{ makeOption = \e -> { text = e.name, additional = "" }
, labelColor = \_ -> \_ -> ""
, placeholder = "Select"
, style = dds
}
personCfg =
{ makeOption = \p -> Util.Person.mkPersonOption p model.allPersons
, labelColor = \_ -> \_ -> ""
, placeholder = "Select"
, style = dds
}
in
[ { title = "Name"
, titleRight = []
@ -163,7 +199,11 @@ formTabs settings model =
, info = Nothing
, body =
[ div [ class "mb-4 flex flex-col" ]
[ Html.map TagDropdownMsg (Comp.Dropdown.view2 dds settings model.tagModel)
[ Html.map TagDropdownMsg
(Comp.Dropdown.view2 (Util.Tag.tagSettings dds)
settings
model.tagModel
)
, div [ class "flex flex-row items-center justify-end" ]
[ a
[ class S.secondaryButton
@ -184,7 +224,7 @@ formTabs settings model =
[ div [ class "mb-4" ]
[ Html.map FolderDropdownMsg
(Comp.Dropdown.view2
dds
folderCfg
settings
model.folderModel
)
@ -254,7 +294,12 @@ item visible. This message will disappear then.
, addIconLink "Add new organization" StartCorrOrgModal
, editIconLink "Edit organization" model.corrOrgModel StartEditCorrOrgModal
]
, Html.map OrgDropdownMsg (Comp.Dropdown.view2 dds settings model.corrOrgModel)
, Html.map OrgDropdownMsg
(Comp.Dropdown.view2
(Comp.Dropdown.orgFormViewSettings dds)
settings
model.corrOrgModel
)
, renderOrgSuggestions model
]
, optional [ Data.Fields.CorrPerson ] <|
@ -267,7 +312,11 @@ item visible. This message will disappear then.
model.corrPersonModel
(StartEditPersonModal model.corrPersonModel)
]
, Html.map CorrPersonMsg (Comp.Dropdown.view2 dds settings model.corrPersonModel)
, Html.map CorrPersonMsg
(Comp.Dropdown.view2 personCfg
settings
model.corrPersonModel
)
, renderCorrPersonSuggestions model
, div
[ classList
@ -298,7 +347,7 @@ item visible. This message will disappear then.
]
, Html.map ConcPersonMsg
(Comp.Dropdown.view2
dds
personCfg
settings
model.concPersonModel
)
@ -316,7 +365,7 @@ item visible. This message will disappear then.
]
, Html.map ConcEquipMsg
(Comp.Dropdown.view2
dds
idNameCfg
settings
model.concEquipModel
)
@ -331,7 +380,7 @@ item visible. This message will disappear then.
[ div [ class "mb-4" ]
[ Html.map DirDropdownMsg
(Comp.Dropdown.view2
dds
directionCfg
settings
model.directionModel
)

View File

@ -39,7 +39,6 @@ import Comp.KeyInput
import Comp.LinkTarget exposing (LinkTarget)
import Comp.MarkdownInput
import Comp.SentMails
import Comp.YesNoDimmer
import Data.Direction exposing (Direction)
import Data.Fields exposing (Field)
import DatePicker exposing (DatePicker)
@ -136,45 +135,17 @@ emptyModel =
, visibleAttach = 0
, attachMenuOpen = False
, menuOpen = False
, tagModel =
Util.Tag.makeDropdownModel2
, tagModel = Util.Tag.makeDropdownModel
, directionModel =
Comp.Dropdown.makeSingleList
{ makeOption =
\entry ->
{ value = Data.Direction.toString entry
, text = Data.Direction.toString entry
, additional = ""
}
, options = Data.Direction.all
, placeholder = "Choose a direction"
{ options = Data.Direction.all
, selected = Nothing
}
, corrOrgModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, corrPersonModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, concPersonModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, concEquipModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, folderModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, corrOrgModel = Comp.Dropdown.makeSingle
, corrPersonModel = Comp.Dropdown.makeSingle
, concPersonModel = Comp.Dropdown.makeSingle
, concEquipModel = Comp.Dropdown.makeSingle
, folderModel = Comp.Dropdown.makeSingle
, allFolders = []
, nameModel = ""
, nameState = SaveSuccess

View File

@ -48,6 +48,7 @@ import Time
import Util.Folder exposing (mkFolderOption)
import Util.List
import Util.Maybe
import Util.Person
import Util.Tag
@ -117,45 +118,17 @@ type Msg
init : Model
init =
{ tagModel =
Util.Tag.makeDropdownModel2
{ tagModel = Util.Tag.makeDropdownModel
, directionModel =
Comp.Dropdown.makeSingleList
{ makeOption =
\entry ->
{ value = Data.Direction.toString entry
, text = Data.Direction.toString entry
, additional = ""
}
, options = Data.Direction.all
, placeholder = "Choose a direction"
{ options = Data.Direction.all
, selected = Nothing
}
, corrOrgModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, corrPersonModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, concPersonModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, concEquipModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, folderModel =
Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = ""
}
, corrOrgModel = Comp.Dropdown.makeSingle
, corrPersonModel = Comp.Dropdown.makeSingle
, concPersonModel = Comp.Dropdown.makeSingle
, concEquipModel = Comp.Dropdown.makeSingle
, folderModel = Comp.Dropdown.makeSingle
, allFolders = []
, nameModel = ""
, nameSaveThrottle = Throttle.create 1
@ -310,13 +283,7 @@ update flags msg model =
GetFolderResp (Ok fs) ->
let
model_ =
{ model
| allFolders = fs.items
, folderModel =
Comp.Dropdown.setMkOption
(mkFolderOption flags fs.items)
model.folderModel
}
{ model | allFolders = fs.items }
mkIdName fitem =
IdName fitem.id fitem.name
@ -635,13 +602,13 @@ defaultViewConfig =
--- View2
view2 : ViewConfig -> UiSettings -> Model -> Html Msg
view2 : Flags -> ViewConfig -> UiSettings -> Model -> Html Msg
view2 =
renderEditForm2
renderEditForm2 : ViewConfig -> UiSettings -> Model -> Html Msg
renderEditForm2 cfg settings model =
renderEditForm2 : Flags -> ViewConfig -> UiSettings -> Model -> Html Msg
renderEditForm2 flags cfg settings model =
let
fieldVisible field =
Data.UiSettings.fieldVisible settings field
@ -700,6 +667,31 @@ renderEditForm2 cfg settings model =
tabStyle =
TB.searchMenuStyle
folderCfg =
{ makeOption = Util.Folder.mkFolderOption flags model.allFolders
, placeholder = ""
, labelColor = \_ -> \_ -> ""
, style = dds
}
idNameCfg =
{ makeOption = \e -> { text = e.name, additional = "" }
, labelColor = \_ -> \_ -> ""
, placeholder = "Select"
, style = dds
}
directionCfg =
{ makeOption =
\entry ->
{ text = Data.Direction.toString entry
, additional = ""
}
, placeholder = "Choose a direction"
, labelColor = \_ -> \_ -> ""
, style = dds
}
in
div [ class cfg.menuClass, class "mt-2" ]
[ TB.akkordion
@ -747,7 +739,11 @@ renderEditForm2 cfg settings model =
[ tagModeIcon
]
]
, Html.map TagDropdownMsg (Comp.Dropdown.view2 dds settings model.tagModel)
, Html.map TagDropdownMsg
(Comp.Dropdown.view2 (Util.Tag.tagSettings dds)
settings
model.tagModel
)
, Markdown.toHtml [ class "opacity-50 text-sm" ] tagModeMsg
]
]
@ -756,7 +752,7 @@ renderEditForm2 cfg settings model =
, titleRight = []
, info = Nothing
, body =
[ Html.map FolderDropdownMsg (Comp.Dropdown.view2 dds settings model.folderModel)
[ Html.map FolderDropdownMsg (Comp.Dropdown.view2 folderCfg settings model.folderModel)
, div
[ classList
[ ( S.message, True )
@ -835,7 +831,7 @@ item visible. This message will disappear then.
[ text "Organization"
]
]
, Html.map OrgDropdownMsg (Comp.Dropdown.view2 dds settings model.corrOrgModel)
, Html.map OrgDropdownMsg (Comp.Dropdown.view2 idNameCfg settings model.corrOrgModel)
]
, optional [ Data.Fields.CorrPerson ] <|
div [ class "mb-4" ]
@ -845,7 +841,7 @@ item visible. This message will disappear then.
[ text "Person"
]
]
, Html.map CorrPersonMsg (Comp.Dropdown.view2 dds settings model.corrPersonModel)
, Html.map CorrPersonMsg (Comp.Dropdown.view2 idNameCfg settings model.corrPersonModel)
]
]
}
@ -860,7 +856,7 @@ item visible. This message will disappear then.
, span [ class "ml-2" ]
[ text "Person" ]
]
, Html.map ConcPersonMsg (Comp.Dropdown.view2 dds settings model.concPersonModel)
, Html.map ConcPersonMsg (Comp.Dropdown.view2 idNameCfg settings model.concPersonModel)
]
, optional [ Data.Fields.ConcEquip ] <|
div [ class "mb-4" ]
@ -869,7 +865,11 @@ item visible. This message will disappear then.
, span [ class "ml-2" ]
[ text "Equipment" ]
]
, Html.map ConcEquipMsg (Comp.Dropdown.view2 dds settings model.concEquipModel)
, Html.map ConcEquipMsg
(Comp.Dropdown.view2 idNameCfg
settings
model.concEquipModel
)
]
]
}
@ -877,7 +877,7 @@ item visible. This message will disappear then.
, titleRight = []
, info = Nothing
, body =
[ Html.map DirDropdownMsg (Comp.Dropdown.view2 dds settings model.directionModel)
[ Html.map DirDropdownMsg (Comp.Dropdown.view2 directionCfg settings model.directionModel)
]
}
, { title = "Name"

View File

@ -62,7 +62,6 @@ import Set exposing (Set)
import Throttle
import Time
import Util.File exposing (makeFileId)
import Util.Folder exposing (mkFolderOption)
import Util.Http
import Util.List
import Util.Maybe
@ -576,13 +575,7 @@ update key flags inav settings msg model =
GetFolderResp (Ok fs) ->
let
model_ =
{ model
| allFolders = fs.items
, folderModel =
Comp.Dropdown.setMkOption
(mkFolderOption flags fs.items)
model.folderModel
}
{ model | allFolders = fs.items }
mkIdName fitem =
IdName fitem.id fitem.name
@ -645,23 +638,8 @@ update key flags inav settings msg model =
List.filter personFilter correspondent
|> List.map (\e -> IdName e.id e.name)
mkPersonOption idref =
let
org =
Dict.get idref.id personDict
|> Maybe.andThen .organization
|> Maybe.map .name
|> Maybe.map (Util.String.ellipsis 15)
|> Maybe.withDefault ""
in
Comp.Dropdown.Option idref.id idref.name org
model_ =
{ model
| corrPersonModel = Comp.Dropdown.setMkOption mkPersonOption model.corrPersonModel
, concPersonModel = Comp.Dropdown.setMkOption mkPersonOption model.concPersonModel
, allPersons = personDict
}
{ model | allPersons = personDict }
res1 =
update key
@ -1505,7 +1483,7 @@ update key flags inav settings msg model =
ToggleOpenAllAkkordionTabs ->
let
allNames =
Comp.ItemDetail.EditForm.formTabs settings model
Comp.ItemDetail.EditForm.formTabs flags settings model
|> List.map .title
|> Set.fromList