Allow to change use enum for org/equipment

This commit is contained in:
Eike Kettner 2021-03-10 23:54:04 +01:00
parent 0229a867af
commit 274e433d9d
10 changed files with 252 additions and 7 deletions

View File

@ -213,6 +213,12 @@ val openapiScalaSettings = Seq(
case "personuse" =>
field =>
field.copy(typeDef = TypeDef("PersonUse", Imports("docspell.common.PersonUse")))
case "orguse" =>
field =>
field.copy(typeDef = TypeDef("OrgUse", Imports("docspell.common.OrgUse")))
case "equipmentuse" =>
field =>
field.copy(typeDef = TypeDef("EquipmentUse", Imports("docspell.common.EquipmentUse")))
}))
)

View File

@ -5064,6 +5064,7 @@ components:
- id
- name
- created
- use
properties:
id:
type: string
@ -5076,6 +5077,12 @@ components:
format: date-time
notes:
type: string
use:
type: string
format: equipmentuse
enum:
- concerning
- disabled
ReferenceList:
description:
Listing of entities with their id and a name.
@ -5119,6 +5126,7 @@ components:
- concerning
- correspondent
- both
- disabled
description: |
Whether this person should be used to create suggestions
for the "concerning person", "correspondent" or both.
@ -5145,6 +5153,7 @@ components:
- address
- contacts
- created
- use
properties:
id:
type: string
@ -5165,6 +5174,12 @@ components:
format: date-time
shortName:
type: string
use:
type: string
format: orguse
enum:
- correspondent
- disabled
OrganizationList:
description: |
A list of full organization values.

View File

@ -392,7 +392,8 @@ trait Conversions {
v.contacts.map(mkContact).toList,
ro.notes,
ro.created,
ro.shortName
ro.shortName,
ro.use
)
}
@ -415,7 +416,7 @@ trait Conversions {
now,
now,
v.shortName.map(_.trim),
OrgUse.Correspondent
v.use
)
} yield OOrganization.OrgAndContacts(org, cont)
}
@ -441,7 +442,7 @@ trait Conversions {
v.created,
now,
v.shortName.map(_.trim),
OrgUse.Correspondent
v.use
)
} yield OOrganization.OrgAndContacts(org, cont)
}
@ -630,17 +631,17 @@ trait Conversions {
// equipment
def mkEquipment(re: REquipment): Equipment =
Equipment(re.eid, re.name, re.created, re.notes)
Equipment(re.eid, re.name, re.created, re.notes, re.use)
def newEquipment[F[_]: Sync](e: Equipment, cid: Ident): F[REquipment] =
timeId.map({ case (id, now) =>
REquipment(id, cid, e.name.trim, now, now, e.notes, EquipmentUse.Concerning)
REquipment(id, cid, e.name.trim, now, now, e.notes, e.use)
})
def changeEquipment[F[_]: Sync](e: Equipment, cid: Ident): F[REquipment] =
Timestamp
.current[F]
.map(now => REquipment(e.id, cid, e.name.trim, e.created, now, e.notes, EquipmentUse.Concerning))
.map(now => REquipment(e.id, cid, e.name.trim, e.created, now, e.notes, e.use))
// idref

View File

@ -10,6 +10,8 @@ module Comp.EquipmentForm exposing
import Api.Model.Equipment exposing (Equipment)
import Comp.Basic as B
import Comp.FixedDropdown
import Data.EquipmentUse exposing (EquipmentUse)
import Data.Flags exposing (Flags)
import Html exposing (..)
import Html.Attributes exposing (..)
@ -22,6 +24,8 @@ type alias Model =
{ equipment : Equipment
, name : String
, notes : Maybe String
, use : EquipmentUse
, useModel : Comp.FixedDropdown.Model EquipmentUse
}
@ -30,6 +34,11 @@ emptyModel =
{ equipment = Api.Model.Equipment.empty
, name = ""
, notes = Nothing
, use = Data.EquipmentUse.Concerning
, useModel =
Comp.FixedDropdown.initMap
Data.EquipmentUse.label
Data.EquipmentUse.all
}
@ -44,6 +53,7 @@ getEquipment model =
, name = model.name
, created = model.equipment.created
, notes = model.notes
, use = Data.EquipmentUse.asString model.use
}
@ -51,6 +61,7 @@ type Msg
= SetName String
| SetEquipment Equipment
| SetNotes String
| UseDropdownMsg (Comp.FixedDropdown.Msg EquipmentUse)
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
@ -61,6 +72,9 @@ update _ msg model =
| equipment = t
, name = t.name
, notes = t.notes
, use =
Data.EquipmentUse.fromString t.use
|> Maybe.withDefault Data.EquipmentUse.Concerning
}
, Cmd.none
)
@ -71,6 +85,16 @@ update _ msg model =
SetNotes str ->
( { model | notes = Util.Maybe.fromString str }, Cmd.none )
UseDropdownMsg lm ->
let
( nm, mu ) =
Comp.FixedDropdown.update lm model.useModel
newUse =
Maybe.withDefault model.use mu
in
( { model | useModel = nm, use = newUse }, Cmd.none )
--- View2
@ -102,6 +126,22 @@ view2 model =
]
[]
]
, div [ class "mb-4" ]
[ label
[ class S.inputLabel
]
[ text "Use" ]
, Html.map UseDropdownMsg
(Comp.FixedDropdown.view2 (makeUseItem model) model.useModel)
, span [ class "opacity-50 text-sm" ]
[ case model.use of
Data.EquipmentUse.Concerning ->
text "Use as concerning equipment"
Data.EquipmentUse.Disabled ->
text "Do not use for suggestions."
]
]
, div [ class "mb-4" ]
[ h3 [ class S.header3 ]
[ text "Notes"
@ -116,3 +156,9 @@ view2 model =
]
]
]
makeUseItem : Model -> Maybe (Comp.FixedDropdown.Item EquipmentUse)
makeUseItem model =
Just <|
Comp.FixedDropdown.Item model.use (Data.EquipmentUse.label model.use)

View File

@ -8,6 +8,7 @@ module Comp.EquipmentTable exposing
import Api.Model.Equipment exposing (Equipment)
import Comp.Basic as B
import Data.EquipmentUse
import Data.Flags exposing (Flags)
import Html exposing (..)
import Html.Attributes exposing (..)
@ -57,6 +58,9 @@ view2 model =
[ thead []
[ tr []
[ th [ class "" ] []
, th [ class "text-left pr-1 md:px-2 w-20" ]
[ text "Use"
]
, th [ class "text-left" ] [ text "Name" ]
]
]
@ -72,6 +76,14 @@ renderEquipmentLine2 model equip =
, class S.tableRow
]
[ B.editLinkTableCell (Select equip)
, td [ class "text-left pr-1 md:px-2" ]
[ div [ class "label inline-flex text-sm" ]
[ Data.EquipmentUse.fromString equip.use
|> Maybe.withDefault Data.EquipmentUse.Concerning
|> Data.EquipmentUse.label
|> text
]
]
, td [ class "text-left" ]
[ text equip.name
]

View File

@ -12,7 +12,9 @@ import Api.Model.Organization exposing (Organization)
import Comp.AddressForm
import Comp.Basic as B
import Comp.ContactField
import Comp.FixedDropdown
import Data.Flags exposing (Flags)
import Data.OrgUse exposing (OrgUse)
import Data.UiSettings exposing (UiSettings)
import Html exposing (..)
import Html.Attributes exposing (..)
@ -28,6 +30,8 @@ type alias Model =
, contactModel : Comp.ContactField.Model
, notes : Maybe String
, shortName : Maybe String
, use : OrgUse
, useModel : Comp.FixedDropdown.Model OrgUse
}
@ -39,6 +43,11 @@ emptyModel =
, contactModel = Comp.ContactField.emptyModel
, notes = Nothing
, shortName = Nothing
, use = Data.OrgUse.Correspondent
, useModel =
Comp.FixedDropdown.initMap
Data.OrgUse.label
Data.OrgUse.all
}
@ -59,6 +68,7 @@ getOrg model =
, contacts = Comp.ContactField.getContacts model.contactModel
, notes = model.notes
, shortName = model.shortName
, use = Data.OrgUse.asString model.use
}
@ -69,6 +79,7 @@ type Msg
| ContactMsg Comp.ContactField.Msg
| SetNotes String
| SetShortName String
| UseDropdownMsg (Comp.FixedDropdown.Msg OrgUse)
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
@ -87,6 +98,9 @@ update flags msg model =
, name = t.name
, notes = t.notes
, shortName = t.shortName
, use =
Data.OrgUse.fromString t.use
|> Maybe.withDefault Data.OrgUse.Correspondent
}
, Cmd.batch [ c1, c2 ]
)
@ -118,11 +132,27 @@ update flags msg model =
, Cmd.none
)
UseDropdownMsg lm ->
let
( nm, mu ) =
Comp.FixedDropdown.update lm model.useModel
newUse =
Maybe.withDefault model.use mu
in
( { model | useModel = nm, use = newUse }, Cmd.none )
--- View2
makeUseItem : Model -> Maybe (Comp.FixedDropdown.Item OrgUse)
makeUseItem model =
Just <|
Comp.FixedDropdown.Item model.use (Data.OrgUse.label model.use)
view2 : Bool -> UiSettings -> Model -> Html Msg
view2 mobile settings model =
div [ class "flex flex-col" ]
@ -167,6 +197,22 @@ view2 mobile settings model =
]
[]
]
, div [ class "mb-4" ]
[ label
[ class S.inputLabel
]
[ text "Use" ]
, Html.map UseDropdownMsg
(Comp.FixedDropdown.view2 (makeUseItem model) model.useModel)
, span [ class "opacity-50 text-sm" ]
[ case model.use of
Data.OrgUse.Correspondent ->
text "Use as correspondent"
Data.OrgUse.Disabled ->
text "Do not use for suggestions."
]
]
, div [ class "mb-4" ]
[ h3 [ class S.header3 ]
[ text "Address"

View File

@ -9,6 +9,7 @@ module Comp.OrgTable exposing
import Api.Model.Organization exposing (Organization)
import Comp.Basic as B
import Data.Flags exposing (Flags)
import Data.OrgUse
import Html exposing (..)
import Html.Attributes exposing (..)
import Styles as S
@ -58,6 +59,9 @@ view2 model =
[ thead []
[ tr []
[ th [ class "" ] []
, th [ class "text-left pr-1 md:px-2" ]
[ text "Use"
]
, th [ class "text-left" ] [ text "Name" ]
, th [ class "text-left hidden md:table-cell" ] [ text "Address" ]
, th [ class "text-left hidden sm:table-cell" ] [ text "Contact" ]
@ -75,6 +79,14 @@ renderOrgLine2 model org =
, class S.tableRow
]
[ B.editLinkTableCell (Select org)
, td [ class "text-left pr-1 md:px-2" ]
[ div [ class "label inline-flex text-sm" ]
[ Data.OrgUse.fromString org.use
|> Maybe.withDefault Data.OrgUse.Correspondent
|> Data.OrgUse.label
|> text
]
]
, td [ class "py-4 sm:py-2 pr-2 md:pr-4" ]
[ text org.name
]

View File

@ -33,6 +33,7 @@ import Comp.TagSelect
import Data.CustomFieldChange exposing (CustomFieldValueCollect)
import Data.Direction exposing (Direction)
import Data.DropdownStyle as DS
import Data.EquipmentUse
import Data.Fields
import Data.Flags exposing (Flags)
import Data.ItemQuery as Q exposing (ItemQuery)
@ -490,7 +491,11 @@ updateDrop ddm flags settings msg model =
SetConcEquip id ->
let
equip =
Equipment id.id id.name 0 Nothing
Equipment id.id
id.name
0
Nothing
(Data.EquipmentUse.asString Data.EquipmentUse.Concerning)
in
resetAndSet (ConcEquipmentMsg (Comp.Dropdown.SetSelection [ equip ]))

View File

@ -0,0 +1,52 @@
module Data.EquipmentUse exposing
( EquipmentUse(..)
, all
, asString
, fromString
, label
)
import Api.Model.Equipment exposing (Equipment)
type EquipmentUse
= Concerning
| Disabled
fromString : String -> Maybe EquipmentUse
fromString str =
case String.toLower str of
"concerning" ->
Just Concerning
"disabled" ->
Just Disabled
_ ->
Nothing
asString : EquipmentUse -> String
asString pu =
case pu of
Concerning ->
"concerning"
Disabled ->
"disabled"
label : EquipmentUse -> String
label pu =
case pu of
Concerning ->
"Concerning"
Disabled ->
"Disabled"
all : List EquipmentUse
all =
[ Concerning, Disabled ]

View File

@ -0,0 +1,50 @@
module Data.OrgUse exposing
( OrgUse(..)
, all
, asString
, fromString
, label
)
type OrgUse
= Correspondent
| Disabled
fromString : String -> Maybe OrgUse
fromString str =
case String.toLower str of
"correspondent" ->
Just Correspondent
"disabled" ->
Just Disabled
_ ->
Nothing
asString : OrgUse -> String
asString pu =
case pu of
Correspondent ->
"correspondent"
Disabled ->
"disabled"
label : OrgUse -> String
label pu =
case pu of
Correspondent ->
"Correspondent"
Disabled ->
"Disabled"
all : List OrgUse
all =
[ Correspondent, Disabled ]