diff --git a/src/web/ui/src/Controls/Fields.fs b/src/web/ui/src/Controls/Fields.fs index e8ddf4845..55d925916 100644 --- a/src/web/ui/src/Controls/Fields.fs +++ b/src/web/ui/src/Controls/Fields.fs @@ -36,6 +36,21 @@ let text (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange = ] ] +let dvText (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange = + // floating point numbers require using DefaultValue instead of Value + div [ ClassName "field" ] + [ + Label lbl + div [ ClassName "control" ] + [ input ([ + ClassName "input" + Type "text" + DefaultValue dv + OnChange (fun ev -> !!ev.target?value |> string |> onchange) + ] @ attrs) + ] + ] + let inlineText (lbl:string) (dv:string) (attrs:IHTMLProp list) (disabled:bool) onchange = let disabledLabel = if disabled then "disabled-label" else "" span [ ClassName "field" ] @@ -180,7 +195,6 @@ let positiveIntNumber (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange = let validate value = let itp = System.Int32.TryParse value fst itp && snd itp >= 0 - number lbl dv attrs validate onchange @@ -191,15 +205,15 @@ let uncheckedInt (lbl:string) (dv:int) (attrs:IHTMLProp list) onchange = let uncheckedUint32 (lbl:string) (dv:uint32) (attrs:IHTMLProp list) onchange = text lbl (string dv) attrs (uint32>>onchange) - let uncheckedInt64 (lbl:string) (dv:int64) (attrs:IHTMLProp list) onchange = text lbl (string dv) attrs (int64>>onchange) -let uncheckedFloat (lbl:string) (dv:float) (attrs:IHTMLProp list) onchange = - text lbl (string dv) attrs (float>>onchange) - -let double (lbl:string) (dv:double) (attrs:IHTMLProp list) onchange = - text lbl (string dv) attrs (double>>onchange) +let uncheckedDouble (lbl:string) (dv:double) (attrs:IHTMLProp list) onchange = + match dv with + | System.Double.MinValue | System.Double.MaxValue -> + dvText lbl "" attrs (double>>onchange) + | _ -> + dvText lbl (string dv) attrs (double>>onchange) let enumSelect<'a> (lbl:string) (dv:'a) (values:'a[]) (attrs:IHTMLProp list) (onchange:'a->unit) = let vals = match (Array.tryFindIndex (fun elm -> unbox elm = unbox dv) values) with diff --git a/src/web/ui/src/Reports/State.fs b/src/web/ui/src/Reports/State.fs index f7362d78b..0535cb353 100644 --- a/src/web/ui/src/Reports/State.fs +++ b/src/web/ui/src/Reports/State.fs @@ -50,7 +50,7 @@ let getAdminData (admin:IAdminService) (token:string) = let getPersistenceData model = let nameSpace = sprintf "%i%s" (model |> getLoggedInID) model.persisenceBaseNamespace Cmd.ofPromise - model.persistenceService.retrieve {ns = nameSpace ; key = [|"pnlSettings"|]} + model.persistenceService.retrieve {ns = nameSpace ; key = [|"pnlColumns"; "pnlFilterValues"|]} UpdatePersistenceData (fun _ -> RpcResponse "Error getting Persistence data") @@ -106,12 +106,12 @@ let saveSettings (persServ:IPersistenceService) (model:Model) = promise { let! result = persServ.store { ns = sprintf "%i%s" (getLoggedInID model) model.persisenceBaseNamespace record = [| - { key = "pnlSettings" - value = (model.PnLColumns |> encodeUint8) - } + { key = "pnlColumns" + value = (model.PnLColumns |> encodeUint8) } + { key = "pnlFilterValues" + value = (model.PnLFilterValues |> encodeUint8) } |] } - match result.result with | StoreResponse.Result.OK -> return PersistenceUpdateSuccess result @@ -324,17 +324,28 @@ let update msg (model:Reports.Types.Model) : Model * Cmd = ] | SaveSettings -> model, Cmd.ofExistingPromise (saveSettings model.persistenceService model) id (box>>ErrorOccured) + | PersistenceUpdateSuccess sr -> - Browser.console.log "Settings saved successfully" model, Cmd.Empty | UpdatePersistenceData pd -> match pd.result with | RetrieveResponse.Result.OK -> - match Array.tryFind (fun (v:bts.api.persistence.Record) -> v.key = "pnlSettings") pd.record with - | None -> model, Cmd.Empty - | Some record -> - { model with PnLColumns = (decodeUint8> record.value) }, Cmd.Empty + let pnlCols = Array.tryFind (fun (v:bts.api.persistence.Record) -> v.key = "pnlColumns") pd.record + let pnlFilterValues = Array.tryFind (fun (v:bts.api.persistence.Record) -> v.key = "pnlFilterValues") pd.record + + let newCols = + match pnlCols with + | None -> model.PnLColumns + | Some record -> (decodeUint8> record.value) + + let newFilterValues = + match pnlFilterValues with + | None -> model.PnLFilterValues + | Some record -> (decodeUint8> record.value) + + { model with PnLColumns = newCols; PnLFilterValues = newFilterValues }, + Cmd.batch [ for f in newFilterValues do yield Cmd.ofMsg (SetPnLFilter (f.Key, f.Value))] | _ -> model, Cmd.Empty | RpcResponse str -> @@ -375,7 +386,6 @@ let update msg (model:Reports.Types.Model) : Model * Cmd = | UpdateProducts data -> { model with mdRelayProductData = data}, Cmd.ofExistingPromise (requestExpNames model.mdRelay) id (box>>ErrorOccured) | ChangePnLColumnVisibility (header, visibility) -> - Browser.console.log <| (header, visibility) let newData = [ for colHead, colVis in model.PnLColumns do yield ( match colHead = header with @@ -384,7 +394,6 @@ let update msg (model:Reports.Types.Model) : Model * Cmd = )] model, Cmd.ofMsg (SetPnLColumns <| newData) | SetPnLColumns data -> - Browser.console.log <| data { model with PnLColumns = data}, Cmd.ofMsg SaveSettings | ShowGridSettings data -> {model with GridSettingsOpen = data}, Cmd.Empty @@ -417,7 +426,10 @@ let update msg (model:Reports.Types.Model) : Model * Cmd = | true -> Map.remove header model.PnLFilter | false -> model.PnLFilter - { model with PnLFilter = newMap; PnLFilterValues = newFilterValues }, ("", false, Wherever) |> ShowFilterBox |> Cmd.ofMsg + { model with PnLFilter = newMap; PnLFilterValues = newFilterValues }, Cmd.batch [ + ("", false, Wherever) |> ShowFilterBox |> Cmd.ofMsg + Cmd.ofMsg SaveSettings + ] | false -> let newFilterValues = match Map.containsKey header model.PnLFilterValues with @@ -438,7 +450,10 @@ let update msg (model:Reports.Types.Model) : Model * Cmd = let newMap = model.PnLFilter.Add (header, newFilter) - { model with PnLFilter = newMap; PnLFilterValues = newFilterValues }, ("", false, Wherever) |> ShowFilterBox |> Cmd.ofMsg + { model with PnLFilter = newMap; PnLFilterValues = newFilterValues }, Cmd.batch [ + ("", false, Wherever) |> ShowFilterBox |> Cmd.ofMsg + Cmd.ofMsg SaveSettings + ] | ClearPnLFilter header -> match Map.containsKey header model.PnLFilterValues with diff --git a/src/web/ui/src/Reports/View.fs b/src/web/ui/src/Reports/View.fs index 6df8e1736..951bd3565 100644 --- a/src/web/ui/src/Reports/View.fs +++ b/src/web/ui/src/Reports/View.fs @@ -68,11 +68,11 @@ let PnLTabView (model:Model) (dispatch:Msg->Unit) = | NumberRange (min, max), true -> TableControl.showFilter (div[Id "filterbox"][ - Fields.number_novalidate "Min" min [] (fun v -> (filterHeader, NumberRange (v, max)) |> SetPnLTempFilter |> dispatch) - Fields.number_novalidate "Max" max [] (fun v -> (filterHeader, NumberRange (min, v)) |> SetPnLTempFilter |> dispatch) + Fields.uncheckedDouble "Min" min [] (fun dv -> (filterHeader, NumberRange (dv, max)) |> SetPnLTempFilter |> dispatch) + Fields.uncheckedDouble "Max" max [] (fun dv -> (filterHeader, NumberRange (min, dv)) |> SetPnLTempFilter |> dispatch) ]) (fun _ -> (filterHeader, filterType) |> SetPnLFilter |> dispatch) - (fun _ -> ("", false, Wherever) |> ShowFilterBox |> dispatch) + (fun _ -> filterHeader |> ClearPnLFilter |> dispatch) (fun _ -> ("", false, Wherever) |> ShowFilterBox |> dispatch) (sprintf "%fpx" (where |> snd)) (sprintf "%fpx" (where |> fst))