Show custom field values in detail view

This commit is contained in:
Eike Kettner 2020-11-22 02:12:26 +01:00
parent 1aefff37aa
commit 76647d132f
3 changed files with 116 additions and 5 deletions

View File

@ -4,11 +4,13 @@ module Comp.CustomFieldInput exposing
, Msg , Msg
, UpdateResult , UpdateResult
, init , init
, initWith
, update , update
, view , view
) )
import Api.Model.CustomField exposing (CustomField) import Api.Model.CustomField exposing (CustomField)
import Api.Model.ItemFieldValue exposing (ItemFieldValue)
import Comp.DatePicker import Comp.DatePicker
import Data.CustomFieldType exposing (CustomFieldType) import Data.CustomFieldType exposing (CustomFieldType)
import Date exposing (Date) import Date exposing (Date)
@ -110,6 +112,54 @@ init field =
) )
initWith : ItemFieldValue -> ( Model, Cmd Msg )
initWith value =
let
field =
CustomField value.id value.name value.label value.ftype 0 0
( dm, dc ) =
Comp.DatePicker.init
in
( { field = field
, fieldModel =
case fieldType field of
Data.CustomFieldType.Text ->
TextField (Just value.value)
Data.CustomFieldType.Numeric ->
let
( fm, _ ) =
updateFloatModel value.value identity
in
NumberField fm
Data.CustomFieldType.Money ->
let
( fm, _ ) =
updateFloatModel value.value identity
in
MoneyField fm
Data.CustomFieldType.Boolean ->
BoolField (value.value == "true")
Data.CustomFieldType.Date ->
case Date.fromIsoString value.value of
Ok d ->
DateField (Just d) dm
Err _ ->
DateField Nothing dm
}
, if fieldType field == Data.CustomFieldType.Date then
Cmd.map DateMsg dc
else
Cmd.none
)
type FieldResult type FieldResult
= NoResult = NoResult
| RemoveField | RemoveField

View File

@ -6,6 +6,7 @@ module Comp.CustomFieldMultiInput exposing
, init , init
, initCmd , initCmd
, initWith , initWith
, setValues
, update , update
, view , view
) )
@ -13,6 +14,7 @@ module Comp.CustomFieldMultiInput exposing
import Api import Api
import Api.Model.CustomField exposing (CustomField) import Api.Model.CustomField exposing (CustomField)
import Api.Model.CustomFieldList exposing (CustomFieldList) import Api.Model.CustomFieldList exposing (CustomFieldList)
import Api.Model.ItemFieldValue exposing (ItemFieldValue)
import Comp.CustomFieldInput import Comp.CustomFieldInput
import Comp.FixedDropdown import Comp.FixedDropdown
import Data.Flags exposing (Flags) import Data.Flags exposing (Flags)
@ -21,6 +23,7 @@ import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onClick) import Html.Events exposing (onClick)
import Http import Http
import Util.List
import Util.Maybe import Util.Maybe
@ -39,6 +42,7 @@ type Msg
| CreateNewField | CreateNewField
| CustomFieldResp (Result Http.Error CustomFieldList) | CustomFieldResp (Result Http.Error CustomFieldList)
| FieldSelectMsg (Comp.FixedDropdown.Msg CustomField) | FieldSelectMsg (Comp.FixedDropdown.Msg CustomField)
| SetValues (List ItemFieldValue)
type FieldResult type FieldResult
@ -75,6 +79,11 @@ initCmd flags =
Api.getCustomFields flags "" CustomFieldResp Api.getCustomFields flags "" CustomFieldResp
setValues : List ItemFieldValue -> Msg
setValues values =
SetValues values
mkFieldSelect : List CustomField -> FieldSelect mkFieldSelect : List CustomField -> FieldSelect
mkFieldSelect fields = mkFieldSelect fields =
{ selected = Nothing { selected = Nothing
@ -107,10 +116,15 @@ update msg model =
CustomFieldResp (Ok list) -> CustomFieldResp (Ok list) ->
let let
avail =
List.filter
(\e -> not <| Dict.member e.name model.fieldModels)
list.items
model_ = model_ =
{ model { model
| availableFields = list.items | availableFields = avail
, fieldSelect = mkFieldSelect list.items , fieldSelect = mkFieldSelect avail
} }
in in
UpdateResult model_ Cmd.none Sub.none NoResult UpdateResult model_ Cmd.none Sub.none NoResult
@ -144,7 +158,7 @@ update msg model =
ApplyField f -> ApplyField f ->
let let
notSelected e = notSelected e =
e /= f e /= f && (not <| Dict.member e.name model.fieldModels)
( fm, fc ) = ( fm, fc ) =
Comp.CustomFieldInput.init f Comp.CustomFieldInput.init f
@ -153,7 +167,9 @@ update msg model =
List.filter notSelected model.availableFields List.filter notSelected model.availableFields
visible = visible =
f :: model.visibleFields f
:: model.visibleFields
|> List.sortBy .name
fSelect = fSelect =
mkFieldSelect avail mkFieldSelect avail
@ -233,6 +249,43 @@ update msg model =
Nothing -> Nothing ->
UpdateResult model Cmd.none Sub.none NoResult UpdateResult model Cmd.none Sub.none NoResult
SetValues values ->
let
field value =
CustomField value.id value.name value.label value.ftype 0 0
merge fv ( dict, cmds ) =
let
( fim, fic ) =
Comp.CustomFieldInput.initWith fv
in
( Dict.insert fv.name fim dict
, Cmd.map (CustomFieldInputMsg (field fv)) fic :: cmds
)
( modelDict, cmdList ) =
List.foldl merge ( Dict.empty, [] ) values
avail =
List.filter
(\e -> not <| Dict.member e.name modelDict)
(model.availableFields ++ model.visibleFields)
model_ =
{ model
| fieldModels = modelDict
, availableFields = avail
, fieldSelect = mkFieldSelect avail
, visibleFields =
model.visibleFields
++ model.availableFields
|> List.filter (\e -> Dict.member e.name modelDict)
|> Util.List.distinct
|> List.sortBy .name
}
in
UpdateResult model_ (Cmd.batch cmdList) Sub.none NoResult
view : String -> Model -> Html Msg view : String -> Model -> Html Msg
view classes model = view classes model =

View File

@ -199,6 +199,14 @@ update key flags inav settings msg model =
) )
res7.model res7.model
res9 =
update key
flags
inav
settings
(CustomFieldMsg (Comp.CustomFieldMultiInput.setValues item.customfields))
res8.model
proposalCmd = proposalCmd =
if item.state == "created" then if item.state == "created" then
Api.getItemProposals flags item.id GetProposalResp Api.getItemProposals flags item.id GetProposalResp
@ -207,7 +215,7 @@ update key flags inav settings msg model =
Cmd.none Cmd.none
lastModel = lastModel =
res8.model res9.model
in in
{ model = { model =
{ lastModel { lastModel