From 552d79f9642a116d0df4d3fe031cd38bb7c128b6 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Wed, 22 Jan 2020 15:53:56 -0500 Subject: [PATCH] SP-54: Save sorting --- src/web/ui/src/Reports/State.fs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/web/ui/src/Reports/State.fs b/src/web/ui/src/Reports/State.fs index 0535cb353..30b2506ee 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 = [|"pnlColumns"; "pnlFilterValues"|]} + model.persistenceService.retrieve {ns = nameSpace ; key = [|"pnlColumns"; "pnlFilterValues"; "pnlSorting" |]} UpdatePersistenceData (fun _ -> RpcResponse "Error getting Persistence data") @@ -110,6 +110,8 @@ let saveSettings (persServ:IPersistenceService) (model:Model) = promise { value = (model.PnLColumns |> encodeUint8) } { key = "pnlFilterValues" value = (model.PnLFilterValues |> encodeUint8) } + { key = "pnlSorting" + value = (model.PnLSortDirection |> encodeUint8) } |] } match result.result with @@ -333,6 +335,7 @@ let update msg (model:Reports.Types.Model) : Model * Cmd = | RetrieveResponse.Result.OK -> 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 pnlSorting = Array.tryFind (fun (v:bts.api.persistence.Record) -> v.key = "pnlSorting") pd.record let newCols = match pnlCols with @@ -344,8 +347,16 @@ let update msg (model:Reports.Types.Model) : Model * Cmd = | 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))] + let newSorting = + match pnlSorting with + | None -> model.PnLSortDirection + | Some record -> + let srt = (decodeUint8 record.value) + (fst srt, not <| snd srt) + + { model with PnLColumns = newCols; PnLFilterValues = newFilterValues; PnLSortDirection = newSorting }, + Cmd.batch ( + (Cmd.ofMsg (SetPnLSort <| fst newSorting ))::[ for f in newFilterValues do yield Cmd.ofMsg (SetPnLFilter (f.Key, f.Value))]) | _ -> model, Cmd.Empty | RpcResponse str -> @@ -672,4 +683,4 @@ let update msg (model:Reports.Types.Model) : Model * Cmd = (fun (left:PNLUnit) (right:PNLUnit) -> (compNum left.cashValue right.cashValue) * 1000.0 |> int )// CPP/cash value | _ -> (fun (left:PNLUnit) (right:PNLUnit) -> 0) - { model with PnLSortFun = sortFn; PnLSortDirection = header, direction }, Cmd.Empty + { model with PnLSortFun = sortFn; PnLSortDirection = header, direction }, Cmd.ofMsg SaveSettings