diff --git a/build.sbt b/build.sbt index 290f5109..4188df7a 100644 --- a/build.sbt +++ b/build.sbt @@ -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"))) })) ) diff --git a/modules/restapi/src/main/resources/docspell-openapi.yml b/modules/restapi/src/main/resources/docspell-openapi.yml index 951f2395..41494740 100644 --- a/modules/restapi/src/main/resources/docspell-openapi.yml +++ b/modules/restapi/src/main/resources/docspell-openapi.yml @@ -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. diff --git a/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala b/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala index 55531fff..b826488c 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala @@ -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 diff --git a/modules/webapp/src/main/elm/Comp/EquipmentForm.elm b/modules/webapp/src/main/elm/Comp/EquipmentForm.elm index 6783212c..2968db76 100644 --- a/modules/webapp/src/main/elm/Comp/EquipmentForm.elm +++ b/modules/webapp/src/main/elm/Comp/EquipmentForm.elm @@ -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) diff --git a/modules/webapp/src/main/elm/Comp/EquipmentTable.elm b/modules/webapp/src/main/elm/Comp/EquipmentTable.elm index 3524e3f9..aabaccaa 100644 --- a/modules/webapp/src/main/elm/Comp/EquipmentTable.elm +++ b/modules/webapp/src/main/elm/Comp/EquipmentTable.elm @@ -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 ] diff --git a/modules/webapp/src/main/elm/Comp/OrgForm.elm b/modules/webapp/src/main/elm/Comp/OrgForm.elm index b0d8d848..5f2584fe 100644 --- a/modules/webapp/src/main/elm/Comp/OrgForm.elm +++ b/modules/webapp/src/main/elm/Comp/OrgForm.elm @@ -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" diff --git a/modules/webapp/src/main/elm/Comp/OrgTable.elm b/modules/webapp/src/main/elm/Comp/OrgTable.elm index 46ff10ab..33d64e38 100644 --- a/modules/webapp/src/main/elm/Comp/OrgTable.elm +++ b/modules/webapp/src/main/elm/Comp/OrgTable.elm @@ -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 ] diff --git a/modules/webapp/src/main/elm/Comp/SearchMenu.elm b/modules/webapp/src/main/elm/Comp/SearchMenu.elm index 262a2011..0c7261a2 100644 --- a/modules/webapp/src/main/elm/Comp/SearchMenu.elm +++ b/modules/webapp/src/main/elm/Comp/SearchMenu.elm @@ -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 ])) diff --git a/modules/webapp/src/main/elm/Data/EquipmentUse.elm b/modules/webapp/src/main/elm/Data/EquipmentUse.elm new file mode 100644 index 00000000..7341a2fd --- /dev/null +++ b/modules/webapp/src/main/elm/Data/EquipmentUse.elm @@ -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 ] diff --git a/modules/webapp/src/main/elm/Data/OrgUse.elm b/modules/webapp/src/main/elm/Data/OrgUse.elm new file mode 100644 index 00000000..ca0f6fec --- /dev/null +++ b/modules/webapp/src/main/elm/Data/OrgUse.elm @@ -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 ]