SP-54: Save Column settings to PersistenceService
This commit is contained in:
1 parent
ce7f347256
commit
368e07ede4
4 files changed
+80
-12
No files matched your search
@@ -105,7 +105,7 @@ KeyModel = namedtuple("KeyModel", "type field")
|
||||
DefaultKeyModel = KeyModel("int", "id")
|
||||
def transform_service(service, keymap):
|
||||
return ServiceModel(
|
||||
service.name,
|
||||
service.name,
|
||||
option(service.options, apioptions_pb2.service_description, ""),
|
||||
[transform_method(m, keymap.get(m.output_type, DefaultKeyModel)) for m in service.method],
|
||||
service.name.lower())
|
||||
@@ -158,7 +158,7 @@ def to_type_model(field, msg):
|
||||
elif field.type == types.TYPE_DOUBLE: return TypeModel("double", islist, "double?", jstype='number')
|
||||
elif field.type == types.TYPE_FLOAT: return TypeModel("float", islist, "float?", jstype='number', fstype='float32')
|
||||
elif field.type == types.TYPE_STRING: return TypeModel("string", islist, cpptype="std::string")
|
||||
elif field.type == types.TYPE_BYTES: return TypeModel("ByteString", islist, cpptype="std::string", jstype='Uint8Array', fstype='Fable.Import.JS.Uint8Array')
|
||||
elif field.type == types.TYPE_BYTES: return TypeModel("ByteString", islist, cpptype="std::string", jstype='Uint8Array', fstype='uint8[]')
|
||||
elif field.type == types.TYPE_BOOL: return TypeModel("bool", islist, "bool?", jstype='boolean', natural_key=True)
|
||||
elif field.type == types.TYPE_ENUM:
|
||||
nested_enums = [x.name for x in msg.enum_type]
|
||||
@@ -185,8 +185,8 @@ def to_type_model(field, msg):
|
||||
map_value = to_type_model([f for f in t.field if f.name == 'value'][0], msg)
|
||||
itype = map_value.cstype+immutable_postfix
|
||||
return TypeModel(
|
||||
map_value.cstype,
|
||||
cpptype=map_value.cpptype,
|
||||
map_value.cstype,
|
||||
cpptype=map_value.cpptype,
|
||||
jstype=map_value.jstype,
|
||||
fstype=map_value.fstype,
|
||||
isMessage=True,
|
||||
@@ -234,7 +234,7 @@ def enum_short_name(enum_name, entry):
|
||||
return camel_case(entry[len(enum_name)+1:])
|
||||
return camel_case(entry)
|
||||
|
||||
def camel_case(item):
|
||||
def camel_case(item):
|
||||
if item.isupper() and not '_' in item: return item
|
||||
return item.title().replace('_', '')
|
||||
return d
|
||||
@@ -307,7 +307,7 @@ def generate_code(request, response):
|
||||
|
||||
#### MAIN #########
|
||||
if __name__ == "__main__":
|
||||
if DEBUG:
|
||||
if DEBUG:
|
||||
data = open("data", mode='rb').read()
|
||||
else:
|
||||
data = sys.stdin.read()
|
||||
@@ -317,7 +317,7 @@ if __name__ == "__main__":
|
||||
response = plugin.CodeGeneratorResponse()
|
||||
generate_code(request, response)
|
||||
|
||||
if DEBUG:
|
||||
if DEBUG:
|
||||
for f in response.file:
|
||||
print f.content
|
||||
else:
|
||||
|
||||
@@ -31,7 +31,7 @@ function gen_method(service:IService, method_id : number, request_type : string,
|
||||
assertValid(request_proto, r)
|
||||
const buffer = request_proto.encode(r).finish()
|
||||
const result = await service.context.call(service.name, service.qualifier, method_id, buffer)
|
||||
let temp = result_proto.decode(result)
|
||||
// let temp = result_proto.decode(result)
|
||||
// There is a built in library function do do this but it doesn't work recursively
|
||||
// https://github.com/dcodeIO/protobuf.js/issues/1041
|
||||
// result_proto.toObject(temp, { enums: String, default: true })
|
||||
|
||||
@@ -12,9 +12,14 @@ open System.Xml
|
||||
open Fable.PowerPack.PromiseImpl
|
||||
open bts.api.admin
|
||||
open bts.api.position
|
||||
open bts.api.persistence
|
||||
open bts.co2
|
||||
open Global
|
||||
|
||||
let getLoggedInID model =
|
||||
match model.adminData with
|
||||
| Some adata -> (Array.find (fun (usr:BTSUser) -> usr.name = model.this_username) adata.users).id
|
||||
| None -> 0u
|
||||
|
||||
let venueToString (venue:bts.api.Venue) =
|
||||
match venue with
|
||||
@@ -42,6 +47,13 @@ let getAdminData (admin:IAdminService) (token:string) =
|
||||
UpdateAdminData
|
||||
(fun _ -> RpcResponse "Error getting admin data")
|
||||
|
||||
let getPersistenceData model =
|
||||
let nameSpace = sprintf "%i%s" (model |> getLoggedInID) model.persisenceBaseNamespace
|
||||
Cmd.ofPromise
|
||||
model.persistenceService.retrieve {ns = nameSpace ; key = [|"pnlSettings"|]}
|
||||
UpdatePersistenceData
|
||||
(fun _ -> RpcResponse "Error getting Persistence data")
|
||||
|
||||
let PnLSub model dispatch =
|
||||
match model.unsub with
|
||||
| Some (unsub) -> unsub.Dispose()
|
||||
@@ -82,6 +94,34 @@ let requestExpNames (mdRelay:IMarketDataRelay) = promise {
|
||||
return UpdateExpirationNames result.securities
|
||||
}
|
||||
|
||||
let encodeUint8 (source:Object) =
|
||||
[| for ch in (toJson source) -> (uint8 ch) |]
|
||||
|
||||
let inline decodeUint8<'a> (source:uint8 []) =
|
||||
[| for ch in (source) -> (char ch) |]
|
||||
|> String
|
||||
|> ofJson<'a>
|
||||
|
||||
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)
|
||||
}
|
||||
|]
|
||||
}
|
||||
|
||||
match result.result with
|
||||
| StoreResponse.Result.OK ->
|
||||
return PersistenceUpdateSuccess result
|
||||
| _ ->
|
||||
return ErrorOccured (sprintf "Error saving settings" )
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
let defaultPnLColumns = [
|
||||
("Account", true)
|
||||
("Symbol", false)
|
||||
@@ -133,6 +173,7 @@ let init (context:ServiceContext.ServiceContext) : Model * Cmd<Msg> =
|
||||
let admin = AdminService.Create context ""
|
||||
let posServ = PositionService.Create context ""
|
||||
let basePosServ = BasePositionService.Create context ""
|
||||
let persServ = PersistenceService.Create context "settings"
|
||||
let mdr = MarketDataRelay.Create context ""
|
||||
{
|
||||
currentTab = Tab.PnL
|
||||
@@ -141,6 +182,8 @@ let init (context:ServiceContext.ServiceContext) : Model * Cmd<Msg> =
|
||||
positionData = [||]
|
||||
basePositionService = basePosServ
|
||||
positionService = posServ
|
||||
persistenceService = persServ
|
||||
persisenceBaseNamespace = "#admin_ui"
|
||||
unsub = None
|
||||
ConfirmModal = "", (Msg.SwitchTab Tab.PnL)
|
||||
token = context.token
|
||||
@@ -269,12 +312,31 @@ let filterIsDefault filter =
|
||||
let update msg (model:Reports.Types.Model) : Model * Cmd<Msg> =
|
||||
match msg with
|
||||
| UpdateAdminData adm ->
|
||||
{ model with
|
||||
adminData = Some adm
|
||||
}, Cmd.batch [
|
||||
let newModel =
|
||||
{ model with
|
||||
adminData = Some adm
|
||||
}
|
||||
|
||||
newModel, Cmd.batch [
|
||||
selectSub (Some PnL) model
|
||||
Cmd.ofExistingPromise (requestProducts model.mdRelay) id (box>>ErrorOccured)
|
||||
getPersistenceData newModel
|
||||
]
|
||||
| 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<List<string * bool>> record.value) }, Cmd.Empty
|
||||
| _ ->
|
||||
model, Cmd.Empty
|
||||
| RpcResponse str ->
|
||||
printf "%s" str
|
||||
model, Cmd.Empty
|
||||
@@ -323,7 +385,7 @@ let update msg (model:Reports.Types.Model) : Model * Cmd<Msg> =
|
||||
model, Cmd.ofMsg (SetPnLColumns <| newData)
|
||||
| SetPnLColumns data ->
|
||||
Browser.console.log <| data
|
||||
{ model with PnLColumns = data}, Cmd.Empty
|
||||
{ model with PnLColumns = data}, Cmd.ofMsg SaveSettings
|
||||
| ShowGridSettings data ->
|
||||
{model with GridSettingsOpen = data}, Cmd.Empty
|
||||
| SetPnLTempFilter (header, filter) ->
|
||||
|
||||
@@ -2,6 +2,7 @@ module Reports.Types
|
||||
open System
|
||||
open bts.api.admin
|
||||
open bts.api.position
|
||||
open bts.api.persistence
|
||||
open bts.api
|
||||
open bts.co2
|
||||
open JSMap
|
||||
@@ -29,6 +30,9 @@ type Location =
|
||||
type Msg =
|
||||
| RpcResponse of string
|
||||
| UpdateAdminData of AdminData
|
||||
| SaveSettings
|
||||
| UpdatePersistenceData of RetrieveResponse
|
||||
| PersistenceUpdateSuccess of StoreResponse
|
||||
| SwitchTab of Tab
|
||||
| ErrorOccured of obj
|
||||
| OpenConfirmModal of string * Msg
|
||||
@@ -53,6 +57,8 @@ type Model = {
|
||||
positionData : PNLUnit []
|
||||
basePositionService: IBasePositionService
|
||||
positionService: IPositionService
|
||||
persistenceService: IPersistenceService
|
||||
persisenceBaseNamespace: string
|
||||
mdRelay : IMarketDataRelay
|
||||
mdRelayProductData: Product[]
|
||||
mdRelayExpNameData: ExpirationNameList[]
|
||||
|
||||
Reference in new issue
Block a user