Allow editing metadata in item-detail

This commit is contained in:
Eike Kettner 2020-08-07 01:22:18 +02:00
parent f3ba224124
commit af7cfa0ae1
5 changed files with 263 additions and 6 deletions

View File

@ -31,6 +31,7 @@ module Api exposing
, getCollective , getCollective
, getCollectiveSettings , getCollectiveSettings
, getContacts , getContacts
, getEquipment
, getEquipments , getEquipments
, getFolderDetail , getFolderDetail
, getFolders , getFolders
@ -41,8 +42,10 @@ module Api exposing
, getJobQueueStateIn , getJobQueueStateIn
, getMailSettings , getMailSettings
, getNotifyDueItems , getNotifyDueItems
, getOrgFull
, getOrgLight , getOrgLight
, getOrganizations , getOrganizations
, getPersonFull
, getPersons , getPersons
, getPersonsLight , getPersonsLight
, getScanMailbox , getScanMailbox
@ -903,6 +906,15 @@ getEquipments flags query receive =
} }
getEquipment : Flags -> String -> (Result Http.Error Equipment -> msg) -> Cmd msg
getEquipment flags id receive =
Http2.authGet
{ url = flags.config.baseUrl ++ "/api/v1/sec/equipment/" ++ id
, account = getAccount flags
, expect = Http.expectJson receive Api.Model.Equipment.decoder
}
postEquipment : Flags -> Equipment -> (Result Http.Error BasicResult -> msg) -> Cmd msg postEquipment : Flags -> Equipment -> (Result Http.Error BasicResult -> msg) -> Cmd msg
postEquipment flags equip receive = postEquipment flags equip receive =
let let
@ -942,6 +954,15 @@ getOrgLight flags receive =
} }
getOrgFull : String -> Flags -> (Result Http.Error Organization -> msg) -> Cmd msg
getOrgFull id flags receive =
Http2.authGet
{ url = flags.config.baseUrl ++ "/api/v1/sec/organization/" ++ id
, account = getAccount flags
, expect = Http.expectJson receive Api.Model.Organization.decoder
}
getOrganizations : Flags -> String -> (Result Http.Error OrganizationList -> msg) -> Cmd msg getOrganizations : Flags -> String -> (Result Http.Error OrganizationList -> msg) -> Cmd msg
getOrganizations flags query receive = getOrganizations flags query receive =
Http2.authGet Http2.authGet
@ -990,6 +1011,15 @@ getPersonsLight flags receive =
} }
getPersonFull : String -> Flags -> (Result Http.Error Person -> msg) -> Cmd msg
getPersonFull id flags receive =
Http2.authGet
{ url = flags.config.baseUrl ++ "/api/v1/sec/person/" ++ id
, account = getAccount flags
, expect = Http.expectJson receive Api.Model.Person.decoder
}
getPersons : Flags -> String -> (Result Http.Error PersonList -> msg) -> Cmd msg getPersons : Flags -> String -> (Result Http.Error PersonList -> msg) -> Cmd msg
getPersons flags query receive = getPersons flags query receive =
Http2.authGet Http2.authGet

View File

@ -2,6 +2,9 @@ module Comp.DetailEdit exposing
( Model ( Model
, Msg , Msg
, Value(..) , Value(..)
, editEquip
, editOrg
, editPerson
, initConcPerson , initConcPerson
, initCorrPerson , initCorrPerson
, initEquip , initEquip
@ -44,6 +47,7 @@ type alias Model =
{ form : FormModel { form : FormModel
, itemId : String , itemId : String
, submitting : Bool , submitting : Bool
, loading : Bool
, result : Maybe BasicResult , result : Maybe BasicResult
} }
@ -86,6 +90,7 @@ init itemId fm =
{ form = fm { form = fm
, itemId = itemId , itemId = itemId
, submitting = False , submitting = False
, loading = False
, result = Nothing , result = Nothing
} }
@ -100,6 +105,42 @@ initOrg itemId om =
init itemId (OM om) init itemId (OM om)
editOrg : Flags -> String -> Comp.OrgForm.Model -> ( Model, Cmd Msg )
editOrg flags orgId om =
( { form = OM om
, itemId = ""
, submitting = False
, loading = True
, result = Nothing
}
, Api.getOrgFull orgId flags GetOrgResp
)
editPerson : Flags -> String -> Comp.PersonForm.Model -> ( Model, Cmd Msg )
editPerson flags persId pm =
( { form = PMC pm
, itemId = ""
, submitting = False
, loading = True
, result = Nothing
}
, Api.getPersonFull persId flags GetPersonResp
)
editEquip : Flags -> String -> Comp.EquipmentForm.Model -> ( Model, Cmd Msg )
editEquip flags equipId em =
( { form = EM em
, itemId = ""
, submitting = False
, loading = True
, result = Nothing
}
, Api.getEquipment flags equipId GetEquipResp
)
initCorrPerson : String -> Comp.PersonForm.Model -> Model initCorrPerson : String -> Comp.PersonForm.Model -> Model
initCorrPerson itemId pm = initCorrPerson itemId pm =
init itemId (PMR pm) init itemId (PMR pm)
@ -135,6 +176,9 @@ type Msg
| Submit | Submit
| Cancel | Cancel
| SubmitResp (Result Http.Error BasicResult) | SubmitResp (Result Http.Error BasicResult)
| GetOrgResp (Result Http.Error Organization)
| GetPersonResp (Result Http.Error Person)
| GetEquipResp (Result Http.Error Equipment)
type Value type Value
@ -174,6 +218,87 @@ update flags msg model =
Cancel -> Cancel ->
( model, Cmd.none, Just CancelForm ) ( model, Cmd.none, Just CancelForm )
GetOrgResp (Ok org) ->
case model.form of
OM om ->
let
( om_, oc_ ) =
Comp.OrgForm.update flags (Comp.OrgForm.SetOrg org) om
in
( { model
| loading = False
, form = OM om_
}
, Cmd.map OrgMsg oc_
, Nothing
)
_ ->
( { model | loading = False }
, Cmd.none
, Nothing
)
GetOrgResp (Err err) ->
( { model | loading = False, result = Just (BasicResult False (Util.Http.errorToString err)) }
, Cmd.none
, Nothing
)
GetPersonResp (Ok pers) ->
case model.form of
PMC pm ->
let
( pm_, pc_ ) =
Comp.PersonForm.update flags (Comp.PersonForm.SetPerson pers) pm
in
( { model
| loading = False
, form = PMC pm_
}
, Cmd.map PersonMsg pc_
, Nothing
)
_ ->
( { model | loading = False }
, Cmd.none
, Nothing
)
GetPersonResp (Err err) ->
( { model | loading = False, result = Just (BasicResult False (Util.Http.errorToString err)) }
, Cmd.none
, Nothing
)
GetEquipResp (Ok equip) ->
case model.form of
EM em ->
let
( em_, ec_ ) =
Comp.EquipmentForm.update flags (Comp.EquipmentForm.SetEquipment equip) em
in
( { model
| loading = False
, form = EM em_
}
, Cmd.map EquipMsg ec_
, Nothing
)
_ ->
( { model | loading = False }
, Cmd.none
, Nothing
)
GetEquipResp (Err err) ->
( { model | loading = False, result = Just (BasicResult False (Util.Http.errorToString err)) }
, Cmd.none
, Nothing
)
SubmitResp (Ok res) -> SubmitResp (Ok res) ->
( { model ( { model
| result = Just res | result = Just res
@ -222,7 +347,11 @@ update flags msg model =
in in
if Comp.OrgForm.isValid om then if Comp.OrgForm.isValid om then
( { model | submitting = True } ( { model | submitting = True }
, Api.addCorrOrg flags model.itemId org SubmitResp , if model.itemId == "" then
Api.postOrg flags org SubmitResp
else
Api.addCorrOrg flags model.itemId org SubmitResp
, Nothing , Nothing
) )
@ -239,7 +368,11 @@ update flags msg model =
in in
if Comp.PersonForm.isValid pm then if Comp.PersonForm.isValid pm then
( { model | submitting = True } ( { model | submitting = True }
, Api.addConcPerson flags model.itemId pers SubmitResp , if model.itemId == "" then
Api.postPerson flags pers SubmitResp
else
Api.addConcPerson flags model.itemId pers SubmitResp
, Nothing , Nothing
) )
@ -256,7 +389,11 @@ update flags msg model =
in in
if Comp.PersonForm.isValid pm then if Comp.PersonForm.isValid pm then
( { model | submitting = True } ( { model | submitting = True }
, Api.addCorrPerson flags model.itemId pers SubmitResp , if model.itemId == "" then
Api.postPerson flags pers SubmitResp
else
Api.addCorrPerson flags model.itemId pers SubmitResp
, Nothing , Nothing
) )
@ -273,7 +410,11 @@ update flags msg model =
in in
if Comp.EquipmentForm.isValid em then if Comp.EquipmentForm.isValid em then
( { model | submitting = True } ( { model | submitting = True }
, Api.addConcEquip flags model.itemId equip SubmitResp , if model.itemId == "" then
Api.postEquipment flags equip SubmitResp
else
Api.addConcEquip flags model.itemId equip SubmitResp
, Nothing , Nothing
) )
@ -379,9 +520,9 @@ viewButtons model =
[ class "ui primary button" [ class "ui primary button"
, href "#" , href "#"
, onClick Submit , onClick Submit
, disabled model.submitting , disabled (model.submitting || model.loading)
] ]
[ if model.submitting then [ if model.submitting || model.loading then
i [ class "ui spinner loading icon" ] [] i [ class "ui spinner loading icon" ] []
else else

View File

@ -9,6 +9,7 @@ module Comp.Dropdown exposing
, makeSingle , makeSingle
, makeSingleList , makeSingleList
, mkOption , mkOption
, notSelected
, setMkOption , setMkOption
, update , update
, view , view
@ -155,6 +156,11 @@ getSelected model =
List.map .value model.selected List.map .value model.selected
notSelected : Model a -> Bool
notSelected model =
getSelected model |> List.isEmpty
type Msg a type Msg a
= SetOptions (List a) = SetOptions (List a)
| SetSelection (List a) | SetSelection (List a)

View File

@ -122,6 +122,9 @@ type Msg
| EditAttachNameResp (Result Http.Error BasicResult) | EditAttachNameResp (Result Http.Error BasicResult)
| GetFolderResp (Result Http.Error FolderList) | GetFolderResp (Result Http.Error FolderList)
| FolderDropdownMsg (Comp.Dropdown.Msg IdName) | FolderDropdownMsg (Comp.Dropdown.Msg IdName)
| StartEditCorrOrgModal
| StartEditPersonModal (Comp.Dropdown.Model IdName)
| StartEditEquipModal
update : Nav.Key -> Flags -> Maybe String -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg ) update : Nav.Key -> Flags -> Maybe String -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
@ -1046,6 +1049,42 @@ update key flags next msg model =
, Cmd.none , Cmd.none
) )
StartEditCorrOrgModal ->
let
orgId =
Comp.Dropdown.getSelected model.corrOrgModel
|> List.head
|> Maybe.map .id
in
case orgId of
Just oid ->
let
( m, c ) =
Comp.DetailEdit.editOrg flags oid Comp.OrgForm.emptyModel
in
noSub ( { model | modalEdit = Just m }, Cmd.map ModalEditMsg c )
Nothing ->
( model, Cmd.none, Sub.none )
StartEditEquipModal ->
let
equipId =
Comp.Dropdown.getSelected model.concEquipModel
|> List.head
|> Maybe.map .id
in
case equipId of
Just eid ->
let
( m, c ) =
Comp.DetailEdit.editEquip flags eid Comp.EquipmentForm.emptyModel
in
noSub ( { model | modalEdit = Just m }, Cmd.map ModalEditMsg c )
Nothing ->
( model, Cmd.none, Sub.none )
StartCorrPersonModal -> StartCorrPersonModal ->
noSub noSub
( { model ( { model
@ -1072,6 +1111,24 @@ update key flags next msg model =
, Cmd.none , Cmd.none
) )
StartEditPersonModal pm ->
let
persId =
Comp.Dropdown.getSelected pm
|> List.head
|> Maybe.map .id
in
case persId of
Just pid ->
let
( m, c ) =
Comp.DetailEdit.editPerson flags pid Comp.PersonForm.emptyModel
in
noSub ( { model | modalEdit = Just m }, Cmd.map ModalEditMsg c )
Nothing ->
( model, Cmd.none, Sub.none )
StartEquipModal -> StartEquipModal ->
noSub noSub
( { model ( { model

View File

@ -741,6 +741,19 @@ renderEditForm settings model =
] ]
[ i [ class "grey plus link icon" ] [] [ i [ class "grey plus link icon" ] []
] ]
editIconLink tip dm m =
a
[ classList
[ ( "right-float", True )
, ( "invisible hidden", Comp.Dropdown.notSelected dm )
]
, href "#"
, title tip
, onClick m
]
[ i [ class "grey pencil alternate link icon" ] []
]
in in
div [ class "ui attached segment" ] div [ class "ui attached segment" ]
[ div [ class "ui form warning" ] [ div [ class "ui form warning" ]
@ -834,6 +847,7 @@ item visible. This message will disappear then.
[ Icons.organizationIcon "grey" [ Icons.organizationIcon "grey"
, text "Organization" , text "Organization"
, addIconLink "Add new organization" StartCorrOrgModal , addIconLink "Add new organization" StartCorrOrgModal
, editIconLink "Edit organization" model.corrOrgModel StartEditCorrOrgModal
] ]
, Html.map OrgDropdownMsg (Comp.Dropdown.view settings model.corrOrgModel) , Html.map OrgDropdownMsg (Comp.Dropdown.view settings model.corrOrgModel)
, renderOrgSuggestions model , renderOrgSuggestions model
@ -843,6 +857,9 @@ item visible. This message will disappear then.
[ Icons.personIcon "grey" [ Icons.personIcon "grey"
, text "Person" , text "Person"
, addIconLink "Add new correspondent person" StartCorrPersonModal , addIconLink "Add new correspondent person" StartCorrPersonModal
, editIconLink "Edit person"
model.corrPersonModel
(StartEditPersonModal model.corrPersonModel)
] ]
, Html.map CorrPersonMsg (Comp.Dropdown.view settings model.corrPersonModel) , Html.map CorrPersonMsg (Comp.Dropdown.view settings model.corrPersonModel)
, renderCorrPersonSuggestions model , renderCorrPersonSuggestions model
@ -856,6 +873,9 @@ item visible. This message will disappear then.
[ Icons.personIcon "grey" [ Icons.personIcon "grey"
, text "Person" , text "Person"
, addIconLink "Add new concerning person" StartConcPersonModal , addIconLink "Add new concerning person" StartConcPersonModal
, editIconLink "Edit person"
model.concPersonModel
(StartEditPersonModal model.concPersonModel)
] ]
, Html.map ConcPersonMsg (Comp.Dropdown.view settings model.concPersonModel) , Html.map ConcPersonMsg (Comp.Dropdown.view settings model.concPersonModel)
, renderConcPersonSuggestions model , renderConcPersonSuggestions model
@ -865,6 +885,9 @@ item visible. This message will disappear then.
[ Icons.equipmentIcon "grey" [ Icons.equipmentIcon "grey"
, text "Equipment" , text "Equipment"
, addIconLink "Add new equipment" StartEquipModal , addIconLink "Add new equipment" StartEquipModal
, editIconLink "Edit equipment"
model.concEquipModel
StartEditEquipModal
] ]
, Html.map ConcEquipMsg (Comp.Dropdown.view settings model.concEquipModel) , Html.map ConcEquipMsg (Comp.Dropdown.view settings model.concEquipModel)
, renderConcEquipSuggestions model , renderConcEquipSuggestions model