Restrict person dropdown options to the associated organization

This commit is contained in:
Eike Kettner 2020-12-01 00:28:58 +01:00
parent a6dd71af9f
commit d4470ab5fd
3 changed files with 80 additions and 6 deletions

View File

@ -7,6 +7,7 @@ module Comp.ItemDetail.Model exposing
, UpdateResult , UpdateResult
, emptyModel , emptyModel
, isEditNotes , isEditNotes
, personMatchesOrg
, resultModel , resultModel
, resultModelCmd , resultModelCmd
, resultModelCmdSub , resultModelCmdSub
@ -20,6 +21,7 @@ import Api.Model.FolderList exposing (FolderList)
import Api.Model.IdName exposing (IdName) import Api.Model.IdName exposing (IdName)
import Api.Model.ItemDetail exposing (ItemDetail) import Api.Model.ItemDetail exposing (ItemDetail)
import Api.Model.ItemProposals exposing (ItemProposals) import Api.Model.ItemProposals exposing (ItemProposals)
import Api.Model.Person exposing (Person)
import Api.Model.PersonList exposing (PersonList) import Api.Model.PersonList exposing (PersonList)
import Api.Model.ReferenceList exposing (ReferenceList) import Api.Model.ReferenceList exposing (ReferenceList)
import Api.Model.SentMails exposing (SentMails) import Api.Model.SentMails exposing (SentMails)
@ -100,6 +102,7 @@ type alias Model =
, customFieldSavingIcon : Dict String String , customFieldSavingIcon : Dict String String
, customFieldThrottle : Throttle Msg , customFieldThrottle : Throttle Msg
, allTags : List Tag , allTags : List Tag
, allPersons : Dict String Person
} }
@ -205,6 +208,7 @@ emptyModel =
, customFieldSavingIcon = Dict.empty , customFieldSavingIcon = Dict.empty
, customFieldThrottle = Throttle.create 1 , customFieldThrottle = Throttle.create 1
, allTags = [] , allTags = []
, allPersons = Dict.empty
} }
@ -322,3 +326,19 @@ resultModelCmd ( model, cmd ) =
resultModelCmdSub : ( Model, Cmd Msg, Sub Msg ) -> UpdateResult resultModelCmdSub : ( Model, Cmd Msg, Sub Msg ) -> UpdateResult
resultModelCmdSub ( model, cmd, sub ) = resultModelCmdSub ( model, cmd, sub ) =
UpdateResult model cmd sub Comp.LinkTarget.LinkNone UpdateResult model cmd sub Comp.LinkTarget.LinkNone
personMatchesOrg : Model -> Bool
personMatchesOrg model =
let
org =
Comp.Dropdown.getSelected model.corrOrgModel
|> List.head
persOrg =
Comp.Dropdown.getSelected model.corrPersonModel
|> List.head
|> Maybe.andThen (\idref -> Dict.get idref.id model.allPersons)
|> Maybe.andThen .organization
in
org == Nothing || org == persOrg

View File

@ -252,6 +252,7 @@ update key flags inav settings msg model =
, getOptions flags , getOptions flags
, proposalCmd , proposalCmd
, Api.getSentMails flags item.id SentMailsResp , Api.getSentMails flags item.id SentMailsResp
, Api.getPersons flags "" GetPersonResp
, Cmd.map CustomFieldMsg (Comp.CustomFieldMultiInput.initCmd flags) , Cmd.map CustomFieldMsg (Comp.CustomFieldMultiInput.initCmd flags)
] ]
, sub = , sub =
@ -347,12 +348,14 @@ update key flags inav settings msg model =
( m2, c2 ) = ( m2, c2 ) =
Comp.Dropdown.update m model.corrOrgModel Comp.Dropdown.update m model.corrOrgModel
newModel =
{ model | corrOrgModel = m2 }
idref = idref =
Comp.Dropdown.getSelected m2 |> List.head Comp.Dropdown.getSelected m2 |> List.head
newModel =
{ model
| corrOrgModel = m2
}
save = save =
if isDropdownChangeMsg m then if isDropdownChangeMsg m then
setCorrOrg flags newModel idref setCorrOrg flags newModel idref
@ -609,11 +612,46 @@ update key flags inav settings msg model =
( conc, corr ) = ( conc, corr ) =
List.partition .concerning ps.items List.partition .concerning ps.items
personDict =
List.map (\p -> ( p.id, p )) ps.items
|> Dict.fromList
corrOrg =
Comp.Dropdown.getSelected model.corrOrgModel
|> List.head
personFilter =
case corrOrg of
Just n ->
\p -> p.organization == Just n
Nothing ->
\_ -> True
concRefs = concRefs =
List.map (\e -> IdName e.id e.name) conc List.map (\e -> IdName e.id e.name) conc
corrRefs = corrRefs =
List.map (\e -> IdName e.id e.name) corr List.filter personFilter corr
|> 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
}
res1 = res1 =
update key update key
@ -621,7 +659,7 @@ update key flags inav settings msg model =
inav inav
settings settings
(CorrPersonMsg (Comp.Dropdown.SetOptions corrRefs)) (CorrPersonMsg (Comp.Dropdown.SetOptions corrRefs))
model model_
res2 = res2 =
update key update key

View File

@ -10,7 +10,14 @@ import Comp.DetailEdit
import Comp.Dropdown import Comp.Dropdown
import Comp.Dropzone import Comp.Dropzone
import Comp.ItemDetail.AttachmentTabMenu import Comp.ItemDetail.AttachmentTabMenu
import Comp.ItemDetail.Model exposing (Model, Msg(..), NotesField(..), SaveNameState(..)) import Comp.ItemDetail.Model
exposing
( Model
, Msg(..)
, NotesField(..)
, SaveNameState(..)
, personMatchesOrg
)
import Comp.ItemMail import Comp.ItemMail
import Comp.KeyInput import Comp.KeyInput
import Comp.LinkTarget import Comp.LinkTarget
@ -882,6 +889,15 @@ item visible. This message will disappear then.
] ]
, Html.map CorrPersonMsg (Comp.Dropdown.view settings model.corrPersonModel) , Html.map CorrPersonMsg (Comp.Dropdown.view settings model.corrPersonModel)
, renderCorrPersonSuggestions model , renderCorrPersonSuggestions model
, div
[ classList
[ ( "ui warning message", True )
, ( "invisible hidden", personMatchesOrg model )
]
]
[ i [ class "info icon" ] []
, text "The selected person doesn't belong to the selected organization."
]
] ]
, optional [ Data.Fields.ConcPerson, Data.Fields.ConcEquip ] <| , optional [ Data.Fields.ConcPerson, Data.Fields.ConcEquip ] <|
h4 [ class "ui dividing header" ] h4 [ class "ui dividing header" ]