Extend dropdown to display additional option info

Use this to display folder information when setting the folder on an
item.
This commit is contained in:
Eike Kettner 2020-07-11 17:45:45 +02:00
parent 0df541f30a
commit e66c501056
13 changed files with 171 additions and 46 deletions

View File

@ -49,7 +49,7 @@ emptyModel =
, city = "" , city = ""
, country = , country =
Comp.Dropdown.makeSingleList Comp.Dropdown.makeSingleList
{ makeOption = \c -> { value = c.code, text = c.label } { makeOption = \c -> { value = c.code, text = c.label, additional = "" }
, placeholder = "Select Country" , placeholder = "Select Country"
, options = countries , options = countries
, selected = Nothing , selected = Nothing

View File

@ -43,6 +43,7 @@ init settings =
\l -> \l ->
{ value = Data.Language.toIso3 l { value = Data.Language.toIso3 l
, text = Data.Language.toName l , text = Data.Language.toName l
, additional = ""
} }
, placeholder = "" , placeholder = ""
, options = Data.Language.all , options = Data.Language.all

View File

@ -32,6 +32,7 @@ emptyModel =
\ct -> \ct ->
{ value = Data.ContactType.toString ct { value = Data.ContactType.toString ct
, text = Data.ContactType.toString ct , text = Data.ContactType.toString ct
, additional = ""
} }
, placeholder = "" , placeholder = ""
, options = Data.ContactType.all , options = Data.ContactType.all

View File

@ -8,6 +8,8 @@ module Comp.Dropdown exposing
, makeMultiple , makeMultiple
, makeSingle , makeSingle
, makeSingleList , makeSingleList
, mkOption
, setMkOption
, update , update
, view , view
) )
@ -27,9 +29,15 @@ import Util.List
type alias Option = type alias Option =
{ value : String { value : String
, text : String , text : String
, additional : String
} }
mkOption : String -> String -> Option
mkOption value text =
Option value text ""
type alias Item a = type alias Item a =
{ value : a { value : a
, option : Option , option : Option
@ -63,6 +71,11 @@ type alias Model a =
} }
setMkOption : (a -> Option) -> Model a -> Model a
setMkOption mkopt model =
{ model | makeOption = mkopt }
makeModel : makeModel :
{ multiple : Bool { multiple : Bool
, searchable : Int -> Bool , searchable : Int -> Bool
@ -508,4 +521,7 @@ renderOption item =
, onClick (AddItem item) , onClick (AddItem item)
] ]
[ text item.option.text [ text item.option.text
, span [ class "small-info right-float" ]
[ text item.option.additional
]
] ]

View File

@ -51,7 +51,12 @@ emptyModel =
, replyTo = Nothing , replyTo = Nothing
, sslType = , sslType =
Comp.Dropdown.makeSingleList Comp.Dropdown.makeSingleList
{ makeOption = \s -> { value = Data.SSLType.toString s, text = Data.SSLType.label s } { makeOption =
\s ->
{ value = Data.SSLType.toString s
, text = Data.SSLType.label s
, additional = ""
}
, placeholder = "" , placeholder = ""
, options = Data.SSLType.all , options = Data.SSLType.all
, selected = Just Data.SSLType.None , selected = Just Data.SSLType.None
@ -74,7 +79,12 @@ init ems =
, replyTo = ems.replyTo , replyTo = ems.replyTo
, sslType = , sslType =
Comp.Dropdown.makeSingleList Comp.Dropdown.makeSingleList
{ makeOption = \s -> { value = Data.SSLType.toString s, text = Data.SSLType.label s } { makeOption =
\s ->
{ value = Data.SSLType.toString s
, text = Data.SSLType.label s
, additional = ""
}
, placeholder = "" , placeholder = ""
, options = Data.SSLType.all , options = Data.SSLType.all
, selected = , selected =

View File

@ -47,7 +47,12 @@ emptyModel =
, password = Nothing , password = Nothing
, sslType = , sslType =
Comp.Dropdown.makeSingleList Comp.Dropdown.makeSingleList
{ makeOption = \s -> { value = Data.SSLType.toString s, text = Data.SSLType.label s } { makeOption =
\s ->
{ value = Data.SSLType.toString s
, text = Data.SSLType.label s
, additional = ""
}
, placeholder = "" , placeholder = ""
, options = Data.SSLType.all , options = Data.SSLType.all
, selected = Just Data.SSLType.None , selected = Just Data.SSLType.None
@ -68,7 +73,12 @@ init ems =
, password = ems.imapPassword , password = ems.imapPassword
, sslType = , sslType =
Comp.Dropdown.makeSingleList Comp.Dropdown.makeSingleList
{ makeOption = \s -> { value = Data.SSLType.toString s, text = Data.SSLType.label s } { makeOption =
\s ->
{ value = Data.SSLType.toString s
, text = Data.SSLType.label s
, additional = ""
}
, placeholder = "" , placeholder = ""
, options = Data.SSLType.all , options = Data.SSLType.all
, selected = , selected =

View File

@ -74,6 +74,7 @@ type alias Model =
, concPersonModel : Comp.Dropdown.Model IdName , concPersonModel : Comp.Dropdown.Model IdName
, concEquipModel : Comp.Dropdown.Model IdName , concEquipModel : Comp.Dropdown.Model IdName
, folderModel : Comp.Dropdown.Model IdName , folderModel : Comp.Dropdown.Model IdName
, allFolders : List FolderItem
, nameModel : String , nameModel : String
, notesModel : Maybe String , notesModel : Maybe String
, notesField : NotesField , notesField : NotesField
@ -130,6 +131,36 @@ isEditNotes field =
False False
mkFolderOption : Flags -> List FolderItem -> IdName -> Comp.Dropdown.Option
mkFolderOption flags allFolders idref =
let
folder =
List.filter (\e -> e.id == idref.id) allFolders
|> List.head
isMember =
folder
|> Maybe.map .isMember
|> Maybe.withDefault False
isOwner =
Maybe.map .owner folder
|> Maybe.map .name
|> (==) (Maybe.map .user flags.account)
adds =
if isOwner then
"owner"
else if isMember then
"member"
else
""
in
{ value = idref.id, text = idref.name, additional = adds }
emptyModel : Model emptyModel : Model
emptyModel = emptyModel =
{ item = Api.Model.ItemDetail.empty { item = Api.Model.ItemDetail.empty
@ -143,6 +174,7 @@ emptyModel =
\entry -> \entry ->
{ value = Data.Direction.toString entry { value = Data.Direction.toString entry
, text = Data.Direction.toString entry , text = Data.Direction.toString entry
, additional = ""
} }
, options = Data.Direction.all , options = Data.Direction.all
, placeholder = "Choose a direction" , placeholder = "Choose a direction"
@ -150,29 +182,30 @@ emptyModel =
} }
, corrOrgModel = , corrOrgModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name } { makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = "" , placeholder = ""
} }
, corrPersonModel = , corrPersonModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name } { makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = "" , placeholder = ""
} }
, concPersonModel = , concPersonModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name } { makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = "" , placeholder = ""
} }
, concEquipModel = , concEquipModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name } { makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = "" , placeholder = ""
} }
, folderModel = , folderModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name } { makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = "" , placeholder = ""
} }
, allFolders = []
, nameModel = "" , nameModel = ""
, notesModel = Nothing , notesModel = Nothing
, notesField = ViewNotes , notesField = ViewNotes
@ -885,12 +918,24 @@ update key flags next msg model =
GetFolderResp (Ok fs) -> GetFolderResp (Ok fs) ->
let let
model_ =
{ model
| allFolders = fs.items
, folderModel =
Comp.Dropdown.setMkOption
(mkFolderOption flags fs.items)
model.folderModel
}
mkIdName fitem =
IdName fitem.id fitem.name
opts = opts =
fs.items fs.items
|> List.map (\e -> IdName e.id e.name) |> List.map mkIdName
|> Comp.Dropdown.SetOptions |> Comp.Dropdown.SetOptions
in in
update key flags next (FolderDropdownMsg opts) model update key flags next (FolderDropdownMsg opts) model_
GetFolderResp (Err _) -> GetFolderResp (Err _) ->
noSub ( model, Cmd.none ) noSub ( model, Cmd.none )
@ -1450,29 +1495,33 @@ update key flags next msg model =
noSub ( { model | attachRename = Nothing }, Cmd.none ) noSub ( { model | attachRename = Nothing }, Cmd.none )
EditAttachNameResp (Ok res) -> EditAttachNameResp (Ok res) ->
case model.attachRename of if res.success then
Just m -> case model.attachRename of
let Just m ->
changeName a = let
if a.id == m.id then changeName a =
{ a | name = Util.Maybe.fromString m.newName } if a.id == m.id then
{ a | name = Util.Maybe.fromString m.newName }
else else
a a
changeItem i = changeItem i =
{ i | attachments = List.map changeName i.attachments } { i | attachments = List.map changeName i.attachments }
in in
noSub noSub
( { model ( { model
| attachRename = Nothing | attachRename = Nothing
, item = changeItem model.item , item = changeItem model.item
} }
, Cmd.none , Cmd.none
) )
Nothing -> Nothing ->
noSub ( model, Cmd.none ) noSub ( model, Cmd.none )
else
noSub ( model, Cmd.none )
EditAttachNameResp (Err _) -> EditAttachNameResp (Err _) ->
noSub ( model, Cmd.none ) noSub ( model, Cmd.none )
@ -2129,7 +2178,7 @@ renderEditForm settings model =
] ]
in in
div [ class "ui attached segment" ] div [ class "ui attached segment" ]
[ div [ class "ui form" ] [ div [ class "ui form warning" ]
[ div [ class "field" ] [ div [ class "field" ]
[ label [] [ label []
[ Icons.tagsIcon "grey" [ Icons.tagsIcon "grey"
@ -2156,6 +2205,18 @@ renderEditForm settings model =
, text "Folder" , text "Folder"
] ]
, Html.map FolderDropdownMsg (Comp.Dropdown.view settings model.folderModel) , Html.map FolderDropdownMsg (Comp.Dropdown.view settings model.folderModel)
, div
[ classList
[ ( "ui warning message", True )
, ( "hidden", isFolderMember model )
]
]
[ Markdown.toHtml [] """
You are **not a member** of this folder. This item will be **hidden**
from any search now. Use a folder where you are a member of to make this
item visible. This message will disappear then.
"""
]
] ]
, div [ class "field" ] , div [ class "field" ]
[ label [] [ label []
@ -2482,3 +2543,22 @@ renderEditAttachmentName model attach =
Nothing -> Nothing ->
span [ class "invisible hidden" ] [] span [ class "invisible hidden" ] []
isFolderMember : Model -> Bool
isFolderMember model =
let
selected =
Comp.Dropdown.getSelected model.folderModel
|> List.head
|> Maybe.map .id
findFolder id =
List.filter (\e -> e.id == id) model.allFolders
|> List.head
folder =
Maybe.andThen findFolder selected
in
Maybe.map .isMember folder
|> Maybe.withDefault True

View File

@ -61,7 +61,7 @@ emptyModel : Model
emptyModel = emptyModel =
{ connectionModel = { connectionModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \a -> { value = a, text = a } { makeOption = \a -> { value = a, text = a, additional = "" }
, placeholder = "Select connection..." , placeholder = "Select connection..."
} }
, subject = "" , subject = ""
@ -124,7 +124,7 @@ update flags msg model =
cm = cm =
Comp.Dropdown.makeSingleList Comp.Dropdown.makeSingleList
{ makeOption = \a -> { value = a, text = a } { makeOption = \a -> { value = a, text = a, additional = "" }
, placeholder = "Select Connection..." , placeholder = "Select Connection..."
, options = names , options = names
, selected = List.head names , selected = List.head names

View File

@ -139,7 +139,7 @@ init flags =
( { settings = Api.Model.NotificationSettings.empty ( { settings = Api.Model.NotificationSettings.empty
, connectionModel = , connectionModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \a -> { value = a, text = a } { makeOption = \a -> { value = a, text = a, additional = "" }
, placeholder = "Select connection..." , placeholder = "Select connection..."
} }
, tagInclModel = Util.Tag.makeDropdownModel , tagInclModel = Util.Tag.makeDropdownModel
@ -290,7 +290,7 @@ update flags msg model =
cm = cm =
Comp.Dropdown.makeSingleList Comp.Dropdown.makeSingleList
{ makeOption = \a -> { value = a, text = a } { makeOption = \a -> { value = a, text = a, additional = "" }
, placeholder = "Select Connection..." , placeholder = "Select Connection..."
, options = names , options = names
, selected = List.head names , selected = List.head names

View File

@ -129,7 +129,7 @@ init flags =
( { settings = Api.Model.ScanMailboxSettings.empty ( { settings = Api.Model.ScanMailboxSettings.empty
, connectionModel = , connectionModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \a -> { value = a, text = a } { makeOption = \a -> { value = a, text = a, additional = "" }
, placeholder = "Select connection..." , placeholder = "Select connection..."
} }
, enabled = False , enabled = False
@ -260,7 +260,7 @@ update flags msg model =
cm = cm =
Comp.Dropdown.makeSingleList Comp.Dropdown.makeSingleList
{ makeOption = \a -> { value = a, text = a } { makeOption = \a -> { value = a, text = a, additional = "" }
, placeholder = "Select Connection..." , placeholder = "Select Connection..."
, options = names , options = names
, selected = List.head names , selected = List.head names

View File

@ -74,6 +74,7 @@ init =
\entry -> \entry ->
{ value = Data.Direction.toString entry { value = Data.Direction.toString entry
, text = Data.Direction.toString entry , text = Data.Direction.toString entry
, additional = ""
} }
, options = Data.Direction.all , options = Data.Direction.all
, placeholder = "Choose a direction" , placeholder = "Choose a direction"
@ -83,25 +84,25 @@ init =
Comp.Dropdown.makeModel Comp.Dropdown.makeModel
{ multiple = False { multiple = False
, searchable = \n -> n > 5 , searchable = \n -> n > 5
, makeOption = \e -> { value = e.id, text = e.name } , makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, labelColor = \_ -> \_ -> "" , labelColor = \_ -> \_ -> ""
, placeholder = "Choose an organization" , placeholder = "Choose an organization"
} }
, corrPersonModel = , corrPersonModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name } { makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = "Choose a person" , placeholder = "Choose a person"
} }
, concPersonModel = , concPersonModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
{ makeOption = \e -> { value = e.id, text = e.name } { makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, placeholder = "Choose a person" , placeholder = "Choose a person"
} }
, concEquipmentModel = , concEquipmentModel =
Comp.Dropdown.makeModel Comp.Dropdown.makeModel
{ multiple = False { multiple = False
, searchable = \n -> n > 5 , searchable = \n -> n > 5
, makeOption = \e -> { value = e.id, text = e.name } , makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, labelColor = \_ -> \_ -> "" , labelColor = \_ -> \_ -> ""
, placeholder = "Choose an equipment" , placeholder = "Choose an equipment"
} }
@ -109,7 +110,7 @@ init =
Comp.Dropdown.makeModel Comp.Dropdown.makeModel
{ multiple = False { multiple = False
, searchable = \n -> n > 5 , searchable = \n -> n > 5
, makeOption = \e -> { value = e.id, text = e.name } , makeOption = \e -> { value = e.id, text = e.name, additional = "" }
, labelColor = \_ -> \_ -> "" , labelColor = \_ -> \_ -> ""
, placeholder = "Only items in folder" , placeholder = "Only items in folder"
} }

View File

@ -41,6 +41,7 @@ emptyModel =
\s -> \s ->
{ value = Data.UserState.toString s { value = Data.UserState.toString s
, text = Data.UserState.toString s , text = Data.UserState.toString s
, additional = ""
} }
, placeholder = "" , placeholder = ""
, options = Data.UserState.all , options = Data.UserState.all
@ -98,7 +99,12 @@ update _ msg model =
let let
state = state =
Comp.Dropdown.makeSingleList Comp.Dropdown.makeSingleList
{ makeOption = \s -> { value = Data.UserState.toString s, text = Data.UserState.toString s } { makeOption =
\s ->
{ value = Data.UserState.toString s
, text = Data.UserState.toString s
, additional = ""
}
, placeholder = "" , placeholder = ""
, options = Data.UserState.all , options = Data.UserState.all
, selected = , selected =

View File

@ -10,7 +10,7 @@ makeDropdownModel =
Comp.Dropdown.makeModel Comp.Dropdown.makeModel
{ multiple = True { multiple = True
, searchable = \n -> n > 5 , searchable = \n -> n > 5
, makeOption = \tag -> { value = tag.id, text = tag.name } , makeOption = \tag -> { value = tag.id, text = tag.name, additional = "" }
, labelColor = , labelColor =
\tag -> \tag ->
\settings -> \settings ->