mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-10-30 21:40:12 +00:00 
			
		
		
		
	Allow editing metadata in item-detail
This commit is contained in:
		| @@ -31,6 +31,7 @@ module Api exposing | ||||
|     , getCollective | ||||
|     , getCollectiveSettings | ||||
|     , getContacts | ||||
|     , getEquipment | ||||
|     , getEquipments | ||||
|     , getFolderDetail | ||||
|     , getFolders | ||||
| @@ -41,8 +42,10 @@ module Api exposing | ||||
|     , getJobQueueStateIn | ||||
|     , getMailSettings | ||||
|     , getNotifyDueItems | ||||
|     , getOrgFull | ||||
|     , getOrgLight | ||||
|     , getOrganizations | ||||
|     , getPersonFull | ||||
|     , getPersons | ||||
|     , getPersonsLight | ||||
|     , 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 equip receive = | ||||
|     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 query receive = | ||||
|     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 query receive = | ||||
|     Http2.authGet | ||||
|   | ||||
| @@ -2,6 +2,9 @@ module Comp.DetailEdit exposing | ||||
|     ( Model | ||||
|     , Msg | ||||
|     , Value(..) | ||||
|     , editEquip | ||||
|     , editOrg | ||||
|     , editPerson | ||||
|     , initConcPerson | ||||
|     , initCorrPerson | ||||
|     , initEquip | ||||
| @@ -44,6 +47,7 @@ type alias Model = | ||||
|     { form : FormModel | ||||
|     , itemId : String | ||||
|     , submitting : Bool | ||||
|     , loading : Bool | ||||
|     , result : Maybe BasicResult | ||||
|     } | ||||
|  | ||||
| @@ -86,6 +90,7 @@ init itemId fm = | ||||
|     { form = fm | ||||
|     , itemId = itemId | ||||
|     , submitting = False | ||||
|     , loading = False | ||||
|     , result = Nothing | ||||
|     } | ||||
|  | ||||
| @@ -100,6 +105,42 @@ initOrg itemId 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 itemId pm = | ||||
|     init itemId (PMR pm) | ||||
| @@ -135,6 +176,9 @@ type Msg | ||||
|     | Submit | ||||
|     | Cancel | ||||
|     | SubmitResp (Result Http.Error BasicResult) | ||||
|     | GetOrgResp (Result Http.Error Organization) | ||||
|     | GetPersonResp (Result Http.Error Person) | ||||
|     | GetEquipResp (Result Http.Error Equipment) | ||||
|  | ||||
|  | ||||
| type Value | ||||
| @@ -174,6 +218,87 @@ update flags msg model = | ||||
|         Cancel -> | ||||
|             ( 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) -> | ||||
|             ( { model | ||||
|                 | result = Just res | ||||
| @@ -222,7 +347,11 @@ update flags msg model = | ||||
|                     in | ||||
|                     if Comp.OrgForm.isValid om then | ||||
|                         ( { 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 | ||||
|                         ) | ||||
|  | ||||
| @@ -239,7 +368,11 @@ update flags msg model = | ||||
|                     in | ||||
|                     if Comp.PersonForm.isValid pm then | ||||
|                         ( { 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 | ||||
|                         ) | ||||
|  | ||||
| @@ -256,7 +389,11 @@ update flags msg model = | ||||
|                     in | ||||
|                     if Comp.PersonForm.isValid pm then | ||||
|                         ( { 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 | ||||
|                         ) | ||||
|  | ||||
| @@ -273,7 +410,11 @@ update flags msg model = | ||||
|                     in | ||||
|                     if Comp.EquipmentForm.isValid em then | ||||
|                         ( { 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 | ||||
|                         ) | ||||
|  | ||||
| @@ -379,9 +520,9 @@ viewButtons model = | ||||
|         [ class "ui primary button" | ||||
|         , href "#" | ||||
|         , 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" ] [] | ||||
|  | ||||
|           else | ||||
|   | ||||
| @@ -9,6 +9,7 @@ module Comp.Dropdown exposing | ||||
|     , makeSingle | ||||
|     , makeSingleList | ||||
|     , mkOption | ||||
|     , notSelected | ||||
|     , setMkOption | ||||
|     , update | ||||
|     , view | ||||
| @@ -155,6 +156,11 @@ getSelected model = | ||||
|     List.map .value model.selected | ||||
|  | ||||
|  | ||||
| notSelected : Model a -> Bool | ||||
| notSelected model = | ||||
|     getSelected model |> List.isEmpty | ||||
|  | ||||
|  | ||||
| type Msg a | ||||
|     = SetOptions (List a) | ||||
|     | SetSelection (List a) | ||||
|   | ||||
| @@ -122,6 +122,9 @@ type Msg | ||||
|     | EditAttachNameResp (Result Http.Error BasicResult) | ||||
|     | GetFolderResp (Result Http.Error FolderList) | ||||
|     | 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 ) | ||||
| @@ -1046,6 +1049,42 @@ update key flags next msg model = | ||||
|                 , 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 -> | ||||
|             noSub | ||||
|                 ( { model | ||||
| @@ -1072,6 +1111,24 @@ update key flags next msg model = | ||||
|                 , 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 -> | ||||
|             noSub | ||||
|                 ( { model | ||||
|   | ||||
| @@ -741,6 +741,19 @@ renderEditForm settings model = | ||||
|                 ] | ||||
|                 [ 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 | ||||
|     div [ class "ui attached segment" ] | ||||
|         [ div [ class "ui form warning" ] | ||||
| @@ -834,6 +847,7 @@ item visible. This message will disappear then. | ||||
|                     [ Icons.organizationIcon "grey" | ||||
|                     , text "Organization" | ||||
|                     , addIconLink "Add new organization" StartCorrOrgModal | ||||
|                     , editIconLink "Edit organization" model.corrOrgModel StartEditCorrOrgModal | ||||
|                     ] | ||||
|                 , Html.map OrgDropdownMsg (Comp.Dropdown.view settings model.corrOrgModel) | ||||
|                 , renderOrgSuggestions model | ||||
| @@ -843,6 +857,9 @@ item visible. This message will disappear then. | ||||
|                     [ Icons.personIcon "grey" | ||||
|                     , text "Person" | ||||
|                     , addIconLink "Add new correspondent person" StartCorrPersonModal | ||||
|                     , editIconLink "Edit person" | ||||
|                         model.corrPersonModel | ||||
|                         (StartEditPersonModal model.corrPersonModel) | ||||
|                     ] | ||||
|                 , Html.map CorrPersonMsg (Comp.Dropdown.view settings model.corrPersonModel) | ||||
|                 , renderCorrPersonSuggestions model | ||||
| @@ -856,6 +873,9 @@ item visible. This message will disappear then. | ||||
|                     [ Icons.personIcon "grey" | ||||
|                     , text "Person" | ||||
|                     , addIconLink "Add new concerning person" StartConcPersonModal | ||||
|                     , editIconLink "Edit person" | ||||
|                         model.concPersonModel | ||||
|                         (StartEditPersonModal model.concPersonModel) | ||||
|                     ] | ||||
|                 , Html.map ConcPersonMsg (Comp.Dropdown.view settings model.concPersonModel) | ||||
|                 , renderConcPersonSuggestions model | ||||
| @@ -865,6 +885,9 @@ item visible. This message will disappear then. | ||||
|                     [ Icons.equipmentIcon "grey" | ||||
|                     , text "Equipment" | ||||
|                     , addIconLink "Add new equipment" StartEquipModal | ||||
|                     , editIconLink "Edit equipment" | ||||
|                         model.concEquipModel | ||||
|                         StartEditEquipModal | ||||
|                     ] | ||||
|                 , Html.map ConcEquipMsg (Comp.Dropdown.view settings model.concEquipModel) | ||||
|                 , renderConcEquipSuggestions model | ||||
|   | ||||
		Reference in New Issue
	
	Block a user