Skip to content

Commit 274e433

Browse files
committed
Allow to change use enum for org/equipment
1 parent 0229a86 commit 274e433

10 files changed

Lines changed: 252 additions & 7 deletions

File tree

build.sbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ val openapiScalaSettings = Seq(
213213
case "personuse" =>
214214
field =>
215215
field.copy(typeDef = TypeDef("PersonUse", Imports("docspell.common.PersonUse")))
216+
case "orguse" =>
217+
field =>
218+
field.copy(typeDef = TypeDef("OrgUse", Imports("docspell.common.OrgUse")))
219+
case "equipmentuse" =>
220+
field =>
221+
field.copy(typeDef = TypeDef("EquipmentUse", Imports("docspell.common.EquipmentUse")))
216222
}))
217223
)
218224

modules/restapi/src/main/resources/docspell-openapi.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5064,6 +5064,7 @@ components:
50645064
- id
50655065
- name
50665066
- created
5067+
- use
50675068
properties:
50685069
id:
50695070
type: string
@@ -5076,6 +5077,12 @@ components:
50765077
format: date-time
50775078
notes:
50785079
type: string
5080+
use:
5081+
type: string
5082+
format: equipmentuse
5083+
enum:
5084+
- concerning
5085+
- disabled
50795086
ReferenceList:
50805087
description:
50815088
Listing of entities with their id and a name.
@@ -5119,6 +5126,7 @@ components:
51195126
- concerning
51205127
- correspondent
51215128
- both
5129+
- disabled
51225130
description: |
51235131
Whether this person should be used to create suggestions
51245132
for the "concerning person", "correspondent" or both.
@@ -5145,6 +5153,7 @@ components:
51455153
- address
51465154
- contacts
51475155
- created
5156+
- use
51485157
properties:
51495158
id:
51505159
type: string
@@ -5165,6 +5174,12 @@ components:
51655174
format: date-time
51665175
shortName:
51675176
type: string
5177+
use:
5178+
type: string
5179+
format: orguse
5180+
enum:
5181+
- correspondent
5182+
- disabled
51685183
OrganizationList:
51695184
description: |
51705185
A list of full organization values.

modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ trait Conversions {
392392
v.contacts.map(mkContact).toList,
393393
ro.notes,
394394
ro.created,
395-
ro.shortName
395+
ro.shortName,
396+
ro.use
396397
)
397398
}
398399

@@ -415,7 +416,7 @@ trait Conversions {
415416
now,
416417
now,
417418
v.shortName.map(_.trim),
418-
OrgUse.Correspondent
419+
v.use
419420
)
420421
} yield OOrganization.OrgAndContacts(org, cont)
421422
}
@@ -441,7 +442,7 @@ trait Conversions {
441442
v.created,
442443
now,
443444
v.shortName.map(_.trim),
444-
OrgUse.Correspondent
445+
v.use
445446
)
446447
} yield OOrganization.OrgAndContacts(org, cont)
447448
}
@@ -630,17 +631,17 @@ trait Conversions {
630631

631632
// equipment
632633
def mkEquipment(re: REquipment): Equipment =
633-
Equipment(re.eid, re.name, re.created, re.notes)
634+
Equipment(re.eid, re.name, re.created, re.notes, re.use)
634635

635636
def newEquipment[F[_]: Sync](e: Equipment, cid: Ident): F[REquipment] =
636637
timeId.map({ case (id, now) =>
637-
REquipment(id, cid, e.name.trim, now, now, e.notes, EquipmentUse.Concerning)
638+
REquipment(id, cid, e.name.trim, now, now, e.notes, e.use)
638639
})
639640

640641
def changeEquipment[F[_]: Sync](e: Equipment, cid: Ident): F[REquipment] =
641642
Timestamp
642643
.current[F]
643-
.map(now => REquipment(e.id, cid, e.name.trim, e.created, now, e.notes, EquipmentUse.Concerning))
644+
.map(now => REquipment(e.id, cid, e.name.trim, e.created, now, e.notes, e.use))
644645

645646
// idref
646647

modules/webapp/src/main/elm/Comp/EquipmentForm.elm

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module Comp.EquipmentForm exposing
1010

1111
import Api.Model.Equipment exposing (Equipment)
1212
import Comp.Basic as B
13+
import Comp.FixedDropdown
14+
import Data.EquipmentUse exposing (EquipmentUse)
1315
import Data.Flags exposing (Flags)
1416
import Html exposing (..)
1517
import Html.Attributes exposing (..)
@@ -22,6 +24,8 @@ type alias Model =
2224
{ equipment : Equipment
2325
, name : String
2426
, notes : Maybe String
27+
, use : EquipmentUse
28+
, useModel : Comp.FixedDropdown.Model EquipmentUse
2529
}
2630

2731

@@ -30,6 +34,11 @@ emptyModel =
3034
{ equipment = Api.Model.Equipment.empty
3135
, name = ""
3236
, notes = Nothing
37+
, use = Data.EquipmentUse.Concerning
38+
, useModel =
39+
Comp.FixedDropdown.initMap
40+
Data.EquipmentUse.label
41+
Data.EquipmentUse.all
3342
}
3443

3544

@@ -44,13 +53,15 @@ getEquipment model =
4453
, name = model.name
4554
, created = model.equipment.created
4655
, notes = model.notes
56+
, use = Data.EquipmentUse.asString model.use
4757
}
4858

4959

5060
type Msg
5161
= SetName String
5262
| SetEquipment Equipment
5363
| SetNotes String
64+
| UseDropdownMsg (Comp.FixedDropdown.Msg EquipmentUse)
5465

5566

5667
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
@@ -61,6 +72,9 @@ update _ msg model =
6172
| equipment = t
6273
, name = t.name
6374
, notes = t.notes
75+
, use =
76+
Data.EquipmentUse.fromString t.use
77+
|> Maybe.withDefault Data.EquipmentUse.Concerning
6478
}
6579
, Cmd.none
6680
)
@@ -71,6 +85,16 @@ update _ msg model =
7185
SetNotes str ->
7286
( { model | notes = Util.Maybe.fromString str }, Cmd.none )
7387

88+
UseDropdownMsg lm ->
89+
let
90+
( nm, mu ) =
91+
Comp.FixedDropdown.update lm model.useModel
92+
93+
newUse =
94+
Maybe.withDefault model.use mu
95+
in
96+
( { model | useModel = nm, use = newUse }, Cmd.none )
97+
7498

7599

76100
--- View2
@@ -102,6 +126,22 @@ view2 model =
102126
]
103127
[]
104128
]
129+
, div [ class "mb-4" ]
130+
[ label
131+
[ class S.inputLabel
132+
]
133+
[ text "Use" ]
134+
, Html.map UseDropdownMsg
135+
(Comp.FixedDropdown.view2 (makeUseItem model) model.useModel)
136+
, span [ class "opacity-50 text-sm" ]
137+
[ case model.use of
138+
Data.EquipmentUse.Concerning ->
139+
text "Use as concerning equipment"
140+
141+
Data.EquipmentUse.Disabled ->
142+
text "Do not use for suggestions."
143+
]
144+
]
105145
, div [ class "mb-4" ]
106146
[ h3 [ class S.header3 ]
107147
[ text "Notes"
@@ -116,3 +156,9 @@ view2 model =
116156
]
117157
]
118158
]
159+
160+
161+
makeUseItem : Model -> Maybe (Comp.FixedDropdown.Item EquipmentUse)
162+
makeUseItem model =
163+
Just <|
164+
Comp.FixedDropdown.Item model.use (Data.EquipmentUse.label model.use)

modules/webapp/src/main/elm/Comp/EquipmentTable.elm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Comp.EquipmentTable exposing
88

99
import Api.Model.Equipment exposing (Equipment)
1010
import Comp.Basic as B
11+
import Data.EquipmentUse
1112
import Data.Flags exposing (Flags)
1213
import Html exposing (..)
1314
import Html.Attributes exposing (..)
@@ -57,6 +58,9 @@ view2 model =
5758
[ thead []
5859
[ tr []
5960
[ th [ class "" ] []
61+
, th [ class "text-left pr-1 md:px-2 w-20" ]
62+
[ text "Use"
63+
]
6064
, th [ class "text-left" ] [ text "Name" ]
6165
]
6266
]
@@ -72,6 +76,14 @@ renderEquipmentLine2 model equip =
7276
, class S.tableRow
7377
]
7478
[ B.editLinkTableCell (Select equip)
79+
, td [ class "text-left pr-1 md:px-2" ]
80+
[ div [ class "label inline-flex text-sm" ]
81+
[ Data.EquipmentUse.fromString equip.use
82+
|> Maybe.withDefault Data.EquipmentUse.Concerning
83+
|> Data.EquipmentUse.label
84+
|> text
85+
]
86+
]
7587
, td [ class "text-left" ]
7688
[ text equip.name
7789
]

modules/webapp/src/main/elm/Comp/OrgForm.elm

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import Api.Model.Organization exposing (Organization)
1212
import Comp.AddressForm
1313
import Comp.Basic as B
1414
import Comp.ContactField
15+
import Comp.FixedDropdown
1516
import Data.Flags exposing (Flags)
17+
import Data.OrgUse exposing (OrgUse)
1618
import Data.UiSettings exposing (UiSettings)
1719
import Html exposing (..)
1820
import Html.Attributes exposing (..)
@@ -28,6 +30,8 @@ type alias Model =
2830
, contactModel : Comp.ContactField.Model
2931
, notes : Maybe String
3032
, shortName : Maybe String
33+
, use : OrgUse
34+
, useModel : Comp.FixedDropdown.Model OrgUse
3135
}
3236

3337

@@ -39,6 +43,11 @@ emptyModel =
3943
, contactModel = Comp.ContactField.emptyModel
4044
, notes = Nothing
4145
, shortName = Nothing
46+
, use = Data.OrgUse.Correspondent
47+
, useModel =
48+
Comp.FixedDropdown.initMap
49+
Data.OrgUse.label
50+
Data.OrgUse.all
4251
}
4352

4453

@@ -59,6 +68,7 @@ getOrg model =
5968
, contacts = Comp.ContactField.getContacts model.contactModel
6069
, notes = model.notes
6170
, shortName = model.shortName
71+
, use = Data.OrgUse.asString model.use
6272
}
6373

6474

@@ -69,6 +79,7 @@ type Msg
6979
| ContactMsg Comp.ContactField.Msg
7080
| SetNotes String
7181
| SetShortName String
82+
| UseDropdownMsg (Comp.FixedDropdown.Msg OrgUse)
7283

7384

7485
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
@@ -87,6 +98,9 @@ update flags msg model =
8798
, name = t.name
8899
, notes = t.notes
89100
, shortName = t.shortName
101+
, use =
102+
Data.OrgUse.fromString t.use
103+
|> Maybe.withDefault Data.OrgUse.Correspondent
90104
}
91105
, Cmd.batch [ c1, c2 ]
92106
)
@@ -118,11 +132,27 @@ update flags msg model =
118132
, Cmd.none
119133
)
120134

135+
UseDropdownMsg lm ->
136+
let
137+
( nm, mu ) =
138+
Comp.FixedDropdown.update lm model.useModel
139+
140+
newUse =
141+
Maybe.withDefault model.use mu
142+
in
143+
( { model | useModel = nm, use = newUse }, Cmd.none )
144+
121145

122146

123147
--- View2
124148

125149

150+
makeUseItem : Model -> Maybe (Comp.FixedDropdown.Item OrgUse)
151+
makeUseItem model =
152+
Just <|
153+
Comp.FixedDropdown.Item model.use (Data.OrgUse.label model.use)
154+
155+
126156
view2 : Bool -> UiSettings -> Model -> Html Msg
127157
view2 mobile settings model =
128158
div [ class "flex flex-col" ]
@@ -167,6 +197,22 @@ view2 mobile settings model =
167197
]
168198
[]
169199
]
200+
, div [ class "mb-4" ]
201+
[ label
202+
[ class S.inputLabel
203+
]
204+
[ text "Use" ]
205+
, Html.map UseDropdownMsg
206+
(Comp.FixedDropdown.view2 (makeUseItem model) model.useModel)
207+
, span [ class "opacity-50 text-sm" ]
208+
[ case model.use of
209+
Data.OrgUse.Correspondent ->
210+
text "Use as correspondent"
211+
212+
Data.OrgUse.Disabled ->
213+
text "Do not use for suggestions."
214+
]
215+
]
170216
, div [ class "mb-4" ]
171217
[ h3 [ class S.header3 ]
172218
[ text "Address"

modules/webapp/src/main/elm/Comp/OrgTable.elm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Comp.OrgTable exposing
99
import Api.Model.Organization exposing (Organization)
1010
import Comp.Basic as B
1111
import Data.Flags exposing (Flags)
12+
import Data.OrgUse
1213
import Html exposing (..)
1314
import Html.Attributes exposing (..)
1415
import Styles as S
@@ -58,6 +59,9 @@ view2 model =
5859
[ thead []
5960
[ tr []
6061
[ th [ class "" ] []
62+
, th [ class "text-left pr-1 md:px-2" ]
63+
[ text "Use"
64+
]
6165
, th [ class "text-left" ] [ text "Name" ]
6266
, th [ class "text-left hidden md:table-cell" ] [ text "Address" ]
6367
, th [ class "text-left hidden sm:table-cell" ] [ text "Contact" ]
@@ -75,6 +79,14 @@ renderOrgLine2 model org =
7579
, class S.tableRow
7680
]
7781
[ B.editLinkTableCell (Select org)
82+
, td [ class "text-left pr-1 md:px-2" ]
83+
[ div [ class "label inline-flex text-sm" ]
84+
[ Data.OrgUse.fromString org.use
85+
|> Maybe.withDefault Data.OrgUse.Correspondent
86+
|> Data.OrgUse.label
87+
|> text
88+
]
89+
]
7890
, td [ class "py-4 sm:py-2 pr-2 md:pr-4" ]
7991
[ text org.name
8092
]

0 commit comments

Comments
 (0)