SP-54: Save sorting
This commit is contained in:
1 parent
109858572f
commit
552d79f964
1 file changed
+15
-4
@@ -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<Msg> =
|
||||
| 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<Msg> =
|
||||
| None -> model.PnLFilterValues
|
||||
| Some record -> (decodeUint8<Map<string, ColFilter>> 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<string * bool> 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<Msg> =
|
||||
(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
|
||||
Reference in new issue
Block a user