SPARK-1106 - Fix up web ui grids a bit
This commit is contained in:
1 parent
84115df405
commit
71993d4a2d
11 files changed
+1616
-1635
No files matched your search
Generated
+1409
-1409
File diff suppressed because it is too large.
Load diff
@@ -12,6 +12,12 @@ let getAdminData (admin:IAdminService) (fsuc) (ffail) =
|
||||
fsuc
|
||||
(fun e -> ffail e.Message)
|
||||
|
||||
module Lens =
|
||||
// type Setter<'a,'b> = {
|
||||
type Setter<'a,'b> = 'b -> 'a -> 'a
|
||||
|
||||
|
||||
|
||||
module SecurityScope =
|
||||
let exchangeString ex =
|
||||
match ex with
|
||||
|
||||
@@ -1,48 +1,46 @@
|
||||
module ClipLimits
|
||||
open ReactGrid
|
||||
open DataGrid
|
||||
open bts.api.admin
|
||||
open Accounts.Types
|
||||
open Fable.Core
|
||||
open bts.api
|
||||
|
||||
let columns = [|
|
||||
// ReactGrid.buttonColumn "dispatch" "Delete" "trash"
|
||||
selectColumn "exchange" "Exchange" bts.api.Venue.values
|
||||
selectColumn "securityType" "Type" bts.api.SecurityType.values
|
||||
[ Key "symbol"; Name "Symbol"; Editable true]
|
||||
[ Key "symbol"; Name "Symbol"; Editable true ]
|
||||
[ Key "security"; Name "Security"; Editable false ]
|
||||
[ Key "clipSize"; Name "Clip Size"; Editable true ]
|
||||
|]
|
||||
|
||||
let toRow index (limit:AccountSecurityClipLimitUnit) =
|
||||
{ index = index
|
||||
exchange = limit.security.exchange
|
||||
securityType = limit.security.securityType
|
||||
symbol = limit.security.securitySymbol
|
||||
security = "*"
|
||||
clipSize = limit.clipSize
|
||||
}
|
||||
[<Pojo>]
|
||||
type ClipLimit = {
|
||||
exchange: Venue
|
||||
securityType : SecurityType
|
||||
symbol : string
|
||||
security : string
|
||||
clipSize : uint32
|
||||
}
|
||||
|
||||
let toRow (limit:AccountSecurityClipLimitUnit) = {
|
||||
exchange = limit.security.exchange
|
||||
securityType = limit.security.securityType
|
||||
symbol = limit.security.securitySymbol
|
||||
security = "*"
|
||||
clipSize = limit.clipSize
|
||||
}
|
||||
|
||||
let fromRow (limit:ClipLimit) : AccountSecurityClipLimitUnit =
|
||||
{ clipSize = limit.clipSize; security = SecurityScope.create limit.exchange limit.securityType limit.symbol 0 }
|
||||
|
||||
|
||||
let applyNewLimits (model:AccountSecurityClipLimitUnit[]) (limits:ClipLimit[]) =
|
||||
let newLimits = Array.copy model
|
||||
for l in limits do
|
||||
newLimits.[l.index] <- fromRow l
|
||||
newLimits
|
||||
|
||||
let emptyLimit = {
|
||||
security = Access.SecurityScope.empty
|
||||
clipSize = 0u
|
||||
}
|
||||
|
||||
let addLimit (account:BTSAccount) =
|
||||
{ account with securityClipLimits = { limit = Array.append account.securityClipLimits.limit [| emptyLimit |] }}
|
||||
|
||||
let removeLimit (limit:ClipLimit[]) (account:BTSAccount) =
|
||||
let toRemove = Array.map (fun (i:ClipLimit) -> i.index) limit |> Set.ofSeq
|
||||
let rows =
|
||||
account.securityClipLimits.limit
|
||||
|> Array.mapi (fun i v -> if toRemove.Contains i then None else Some v)
|
||||
|> Array.choose id
|
||||
{ account with securityClipLimits = { limit = rows } }
|
||||
let descriptor = {
|
||||
columns = columns
|
||||
toGridRow = toRow
|
||||
fromGridRow = fromRow
|
||||
emptyRow = emptyLimit
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
module ProductLimits
|
||||
open ReactGrid
|
||||
open DataGrid
|
||||
open bts.api.admin
|
||||
open Accounts.Types
|
||||
open bts.api
|
||||
open Fable.Core
|
||||
|
||||
module ProductScope =
|
||||
let empty : ProductScope = {
|
||||
@@ -17,24 +18,34 @@ let positionColumn name =
|
||||
[ Key (sprintf "max%sPosition" name)
|
||||
Name (sprintf "Max %s Position" name)
|
||||
Editable true ]
|
||||
|
||||
|
||||
let columns = [|
|
||||
// ReactGrid.buttonColumn dispatch "Delete" "trash"
|
||||
selectColumn "exchange" "Exchange" bts.api.Venue.values
|
||||
selectColumn "securityType" "Type" bts.api.SecurityType.values
|
||||
[ Key "symbol"; Name "Symbol"; Editable true]
|
||||
[ Key "symbol"; Name "Symbol"; Editable true ]
|
||||
positionColumn "Long"
|
||||
positionColumn "Short"
|
||||
positionColumn "Net"
|
||||
|]
|
||||
|
||||
let toRow index (limit:AccountProductPositionLimitUnit) : ProductLimit =
|
||||
{ index = index
|
||||
exchange = limit.product.exchange
|
||||
[<Pojo>]
|
||||
type ProductLimit = {
|
||||
exchange: Venue
|
||||
securityType : SecurityType
|
||||
symbol : string
|
||||
maxLongPosition : uint32
|
||||
maxShortPosition : uint32
|
||||
maxNetPosition : uint32
|
||||
}
|
||||
let toRow (limit:AccountProductPositionLimitUnit) : ProductLimit =
|
||||
{ exchange = limit.product.exchange
|
||||
securityType = limit.product.securityType
|
||||
symbol = limit.product.securitySymbol
|
||||
maxLongPosition = limit.longPositionLimit
|
||||
maxShortPosition = limit.shortPositionLimit
|
||||
maxNetPosition = limit.netPositionLimit
|
||||
}
|
||||
maxNetPosition = limit.netPositionLimit }
|
||||
|
||||
let fromRow (limit:ProductLimit) : AccountProductPositionLimitUnit =
|
||||
{ product = ProductScope.create limit.exchange limit.securityType limit.symbol
|
||||
@@ -43,13 +54,6 @@ let fromRow (limit:ProductLimit) : AccountProductPositionLimitUnit =
|
||||
netPositionLimit = limit.maxNetPosition
|
||||
}
|
||||
|
||||
let applyNewLimits (model:AccountProductPositionLimitUnit[]) (limits:ProductLimit[]) =
|
||||
let newLimits = Array.copy model
|
||||
for l in limits do
|
||||
newLimits.[l.index] <- fromRow l
|
||||
newLimits
|
||||
|
||||
|
||||
let emptyLimit = {
|
||||
product = ProductScope.empty
|
||||
longPositionLimit = 0u
|
||||
@@ -57,13 +61,9 @@ let emptyLimit = {
|
||||
netPositionLimit = 0u
|
||||
}
|
||||
|
||||
let addLimit (account:BTSAccount) =
|
||||
{ account with productPositionLimits = Array.append account.productPositionLimits [| emptyLimit |] }
|
||||
|
||||
let removeLimit limit (account:BTSAccount) =
|
||||
let toRemove = Array.map (fun (i:ProductLimit) -> i.index) limit |> Set.ofSeq
|
||||
let rows =
|
||||
account.productPositionLimits
|
||||
|> Array.mapi (fun i v -> if toRemove.Contains i then None else Some v)
|
||||
|> Array.choose id
|
||||
{ account with productPositionLimits = rows }
|
||||
let descriptor = {
|
||||
columns = columns
|
||||
toGridRow = toRow
|
||||
fromGridRow = fromRow
|
||||
emptyRow = emptyLimit
|
||||
}
|
||||
@@ -1,42 +1,47 @@
|
||||
module SecurityLimits
|
||||
open ReactGrid
|
||||
open DataGrid
|
||||
open bts.api.admin
|
||||
open Accounts.Types
|
||||
open bts.api
|
||||
open Fable.Core
|
||||
|
||||
let positionColumn = ProductLimits.positionColumn in
|
||||
let coumns = [|
|
||||
let columns = [|
|
||||
selectColumn "exchange" "Exchange" bts.api.Venue.values
|
||||
selectColumn "securityType" "Type" bts.api.SecurityType.values
|
||||
[ Key "symbol"; Name "Symbol"; Editable true]
|
||||
[ Key "symbol"; Name "Symbol"; Editable true]
|
||||
positionColumn "Long"
|
||||
positionColumn "Short"
|
||||
positionColumn "Net"
|
||||
|]
|
||||
|
||||
let toRow index (limit:AccountSecurityPositionLimitUnit) : SecurityLimit =
|
||||
{ index = index
|
||||
exchange = limit.security.exchange
|
||||
securityType = limit.security.securityType
|
||||
symbol = limit.security.securitySymbol
|
||||
security = "*"
|
||||
maxLongPosition = limit.longPositionLimit
|
||||
maxShortPosition = limit.shortPositionLimit
|
||||
maxNetPosition = limit.netPositionLimit
|
||||
}
|
||||
[<Pojo>]
|
||||
type SecurityLimit = {
|
||||
security : string
|
||||
exchange: Venue
|
||||
securityType : SecurityType
|
||||
symbol : string
|
||||
maxLongPosition : uint32
|
||||
maxShortPosition : uint32
|
||||
maxNetPosition : uint32
|
||||
}
|
||||
|
||||
let fromRow (limit:SecurityLimit) : AccountSecurityPositionLimitUnit =
|
||||
{ security = SecurityScope.create limit.exchange limit.securityType limit.symbol 0
|
||||
longPositionLimit = limit.maxLongPosition
|
||||
shortPositionLimit = limit.maxShortPosition
|
||||
netPositionLimit = limit.maxNetPosition
|
||||
}
|
||||
let toRow (limit:AccountSecurityPositionLimitUnit) : SecurityLimit = {
|
||||
exchange = limit.security.exchange
|
||||
securityType = limit.security.securityType
|
||||
symbol = limit.security.securitySymbol
|
||||
security = "*"
|
||||
maxLongPosition = limit.longPositionLimit
|
||||
maxShortPosition = limit.shortPositionLimit
|
||||
maxNetPosition = limit.netPositionLimit
|
||||
}
|
||||
|
||||
let applyNewLimits (model:AccountSecurityPositionLimitUnit[]) (limits:SecurityLimit[]) =
|
||||
let newLimits = Array.copy model
|
||||
for l in limits do
|
||||
newLimits.[l.index] <- fromRow l
|
||||
newLimits
|
||||
let fromRow (limit:SecurityLimit) : AccountSecurityPositionLimitUnit = {
|
||||
security = SecurityScope.create limit.exchange limit.securityType limit.symbol 0
|
||||
longPositionLimit = limit.maxLongPosition
|
||||
shortPositionLimit = limit.maxShortPosition
|
||||
netPositionLimit = limit.maxNetPosition
|
||||
}
|
||||
|
||||
let emptyLimit = {
|
||||
security = SecurityScope.empty
|
||||
@@ -45,16 +50,9 @@ let emptyLimit = {
|
||||
netPositionLimit = 0u
|
||||
}
|
||||
|
||||
let addLimit (account:BTSAccount) =
|
||||
{ account with securityPositionLimits = Array.append account.securityPositionLimits [| emptyLimit |] }
|
||||
|
||||
let removeLimit limit (account:BTSAccount) =
|
||||
let toRemove = Array.map (fun (i:SecurityLimit) -> i.index) limit |> Set.ofSeq
|
||||
let rows =
|
||||
account.securityPositionLimits
|
||||
|> Array.mapi (fun i v -> if toRemove.Contains i then None else Some v)
|
||||
|> Array.choose id
|
||||
{ account with securityPositionLimits = rows }
|
||||
|
||||
|
||||
|
||||
let descriptor = {
|
||||
columns = columns
|
||||
toGridRow = toRow
|
||||
fromGridRow = fromRow
|
||||
emptyRow = emptyLimit
|
||||
}
|
||||
@@ -16,7 +16,6 @@ let init (context:ServiceContext.ServiceContext) =
|
||||
adminData = None
|
||||
selectedAccount = None
|
||||
scratch = emptyAccount
|
||||
gridSelection = emptySelection
|
||||
}, Access.getAdminData admin UpdateAdminData NoAdminData
|
||||
|
||||
let selectAccount account model =
|
||||
@@ -64,42 +63,10 @@ let createAccount (admin:IAdminService) (account:BTSAccount) = promise {
|
||||
return ErrorOccured (sprintf "Error creating account: %s" result.errorText)
|
||||
}
|
||||
|
||||
let updateClipLimits (msg:UpdateGrid<ClipLimit>) model =
|
||||
match msg with
|
||||
| AddRow ->
|
||||
{ model with scratch = ClipLimits.addLimit model.scratch }
|
||||
| RemoveRows ->
|
||||
{ model with scratch = ClipLimits.removeLimit model.gridSelection.clip model.scratch }
|
||||
| SelectRows rows ->
|
||||
{ model with gridSelection = { emptySelection with clip = rows } }
|
||||
| UpdateRows newLimits ->
|
||||
let limits = ClipLimits.applyNewLimits model.scratch.securityClipLimits.limit newLimits
|
||||
{ model with scratch = { model.scratch with securityClipLimits = { limit = limits } } }
|
||||
|
||||
let updateProductLimits (msg:UpdateGrid<ProductLimit>) model =
|
||||
match msg with
|
||||
| AddRow ->
|
||||
{ model with scratch = ProductLimits.addLimit model.scratch }
|
||||
| RemoveRows ->
|
||||
{ model with scratch = ProductLimits.removeLimit model.gridSelection.product model.scratch }
|
||||
| SelectRows rows ->
|
||||
{ model with gridSelection = { model.gridSelection with product = rows } }
|
||||
| UpdateRows newLimits ->
|
||||
let limits = ProductLimits.applyNewLimits model.scratch.productPositionLimits newLimits
|
||||
{ model with scratch = { model.scratch with productPositionLimits = limits } }
|
||||
|
||||
let updateSecurityLimits (msg:UpdateGrid<SecurityLimit>) model =
|
||||
match msg with
|
||||
| AddRow ->
|
||||
{ model with scratch = SecurityLimits.addLimit model.scratch }
|
||||
| RemoveRows ->
|
||||
{ model with scratch = SecurityLimits.removeLimit model.gridSelection.security model.scratch }
|
||||
| SelectRows rows ->
|
||||
{ model with gridSelection = { model.gridSelection with security = rows } }
|
||||
| UpdateRows newLimits ->
|
||||
let limits = SecurityLimits.applyNewLimits model.scratch.securityPositionLimits newLimits
|
||||
{ model with scratch = { model.scratch with securityPositionLimits = limits } }
|
||||
|
||||
let erase (arr:'a[]) i =
|
||||
let left = arr.[..i-1]
|
||||
let right = arr.[1+i..]
|
||||
Array.concat [left;right]
|
||||
|
||||
let update msg (model:Model) =
|
||||
match msg with
|
||||
@@ -111,13 +78,13 @@ let update msg (model:Model) =
|
||||
model, Cmd.Empty
|
||||
| SelectAccount account ->
|
||||
// When an account is selected 'scratch' account is discarded
|
||||
{ model with selectedAccount = Some account; scratch = account; gridSelection = emptySelection }, Cmd.Empty
|
||||
{ model with selectedAccount = Some account; scratch = account }, Cmd.Empty
|
||||
| DeleteAccount _ ->
|
||||
Global.alert Global.Error "Delete account function missing from server"
|
||||
model, Cmd.Empty
|
||||
| AddAccount ->
|
||||
// Create a new scratch account. Send to server after user has filled in details
|
||||
{ model with scratch = emptyAccount; selectedAccount = Some { emptyAccount with name = "" }; gridSelection = emptySelection }, Cmd.ofMsg <| SelectTab General
|
||||
{ model with scratch = emptyAccount; selectedAccount = Some { emptyAccount with name = "" } }, Cmd.ofMsg <| SelectTab General
|
||||
| SaveScratch ->
|
||||
match isNewAccount model.scratch with
|
||||
| true -> model, Cmd.ofExistingPromise (createAccount model.admin model.scratch) id (string>>ErrorOccured)
|
||||
@@ -126,12 +93,24 @@ let update msg (model:Model) =
|
||||
Global.alert Global.Error msg
|
||||
model,Cmd.Empty
|
||||
| SelectTab tab ->
|
||||
{ model with tab = tab; gridSelection = emptySelection }, Cmd.Empty
|
||||
{ model with tab = tab }, Cmd.Empty
|
||||
| Update field ->
|
||||
{ model with scratch = applyUpdate model.scratch field }, Cmd.Empty
|
||||
| ClipLimits m -> updateClipLimits m model, Cmd.Empty
|
||||
| ProductLimits m -> updateProductLimits m model, Cmd.Empty
|
||||
| SecurityLimits m -> updateSecurityLimits m model, Cmd.Empty
|
||||
| ClipLimits limits ->
|
||||
{ model with scratch = { model.scratch with securityClipLimits = { limit = limits } } }, Cmd.Empty
|
||||
| DeleteClipLimit i ->
|
||||
let limits = erase model.scratch.securityClipLimits.limit i
|
||||
{ model with scratch = { model.scratch with securityClipLimits = { limit = limits } } }, Cmd.Empty
|
||||
| ProductLimits limits ->
|
||||
{ model with scratch = { model.scratch with productPositionLimits = limits } }, Cmd.Empty
|
||||
| DeleteProductLimit i ->
|
||||
let limits = erase model.scratch.productPositionLimits i
|
||||
{ model with scratch = { model.scratch with productPositionLimits = limits } }, Cmd.Empty
|
||||
| SecurityLimits limits ->
|
||||
{ model with scratch = { model.scratch with securityPositionLimits = limits } }, Cmd.Empty
|
||||
| DeleteSecurityLimit i ->
|
||||
let limits = erase model.scratch.securityPositionLimits i
|
||||
{ model with scratch = { model.scratch with securityPositionLimits = limits } }, Cmd.Empty
|
||||
//
|
||||
// Exchange data
|
||||
| UpdateCME field ->
|
||||
|
||||
@@ -12,44 +12,7 @@ type Tab =
|
||||
| CreditLimitsTab
|
||||
| ExchangeSettingsTab
|
||||
|
||||
[<Pojo>]
|
||||
type ClipLimit = {
|
||||
index : int
|
||||
exchange: Venue
|
||||
securityType : SecurityType
|
||||
symbol : string
|
||||
security : string
|
||||
clipSize : uint32
|
||||
}
|
||||
|
||||
[<Pojo>]
|
||||
type ProductLimit = {
|
||||
index: int
|
||||
exchange: Venue
|
||||
securityType : SecurityType
|
||||
symbol : string
|
||||
maxLongPosition : uint32
|
||||
maxShortPosition : uint32
|
||||
maxNetPosition : uint32
|
||||
}
|
||||
[<Pojo>]
|
||||
type SecurityLimit = {
|
||||
index: int
|
||||
security : string
|
||||
exchange: Venue
|
||||
securityType : SecurityType
|
||||
symbol : string
|
||||
maxLongPosition : uint32
|
||||
maxShortPosition : uint32
|
||||
maxNetPosition : uint32
|
||||
}
|
||||
|
||||
type LimitGridSelection = {
|
||||
clip : ClipLimit[]
|
||||
product : ProductLimit[]
|
||||
security : SecurityLimit[]
|
||||
}
|
||||
let emptySelection = { clip = [||]; product = [||]; security = [||] }
|
||||
let emptyAccount = Access.Accounts.empty
|
||||
|
||||
type Model = {
|
||||
@@ -58,7 +21,6 @@ type Model = {
|
||||
adminData : AdminData option
|
||||
selectedAccount : BTSAccount option
|
||||
scratch : BTSAccount
|
||||
gridSelection : LimitGridSelection
|
||||
}
|
||||
|
||||
type AccountField =
|
||||
@@ -79,12 +41,6 @@ type CMEExchangeField =
|
||||
| CommodityDerivativeIndicator of string
|
||||
| MiscTagMapping of JSMap<string>
|
||||
|
||||
type UpdateGrid<'a> =
|
||||
| AddRow
|
||||
| RemoveRows
|
||||
| UpdateRows of 'a[]
|
||||
| SelectRows of 'a[]
|
||||
|
||||
type Msg =
|
||||
| UpdateAdminData of AdminData
|
||||
| NoAdminData of string
|
||||
@@ -97,10 +53,12 @@ type Msg =
|
||||
| SelectTab of Tab
|
||||
// General
|
||||
| Update of AccountField
|
||||
// Clip limits
|
||||
| ClipLimits of UpdateGrid<ClipLimit>
|
||||
| ProductLimits of UpdateGrid<ProductLimit>
|
||||
| SecurityLimits of UpdateGrid<SecurityLimit>
|
||||
| ClipLimits of AccountSecurityClipLimitUnit[]
|
||||
| DeleteClipLimit of int
|
||||
| ProductLimits of AccountProductPositionLimitUnit[]
|
||||
| DeleteProductLimit of int
|
||||
| SecurityLimits of AccountSecurityPositionLimitUnit[]
|
||||
| DeleteSecurityLimit of int
|
||||
// ExchangeData
|
||||
| UpdateCME of CMEExchangeField
|
||||
|
||||
@@ -24,6 +24,26 @@ let saveButton model dispatch =
|
||||
let flavor = if dirty then "is-success" else "is-light"
|
||||
Button.button buttonText flavor "" enabled (fun _ -> dispatch SaveScratch)
|
||||
|
||||
let mappedDataGridWithAddDelete<'a,'r> title (descriptor:MappedDataGridDescriptor<'a,'r>) props (rows:'a[]) erase (dispatch:'a[]->unit) =
|
||||
let addRow _ = Array.append rows [| descriptor.emptyRow |] |> dispatch
|
||||
// Why can't `erase` have the same signature as dispatch?
|
||||
// Because the react Column is the one invoking erase and it doesn't really understand equality
|
||||
// so when rows is updated this column probably *won't be* so it **cannot** close over rows
|
||||
// If it closes over rows the grid will reset to the first visible state (when the tab was made visible)
|
||||
let deleteColumn = ReactGrid.buttonColumn erase "Delete" "trash" (box rows)
|
||||
let descriptor' = { descriptor with columns = Array.append [| deleteColumn |] descriptor.columns }
|
||||
div [] [
|
||||
h3 [ClassName "title is-3"] [ str title ]
|
||||
mappedDataGrid descriptor' props rows dispatch
|
||||
div [ClassName "level"] [
|
||||
div [ClassName "level-right"] [
|
||||
div [ClassName "level-item"] [
|
||||
Button.fabutton "Add Row" "plus" Button.Enabled addRow
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
//
|
||||
// General
|
||||
//
|
||||
@@ -38,44 +58,32 @@ let generalView model dispatch =
|
||||
]
|
||||
|
||||
|
||||
let gridCommonProps = [
|
||||
EnableCellSelect true
|
||||
EnableRowSelect true
|
||||
RowKey "index"
|
||||
]
|
||||
let inline selectRows<'a> = unbox<'a[]> >> SelectRows
|
||||
let clipLimitsView model dispatch =
|
||||
let rows = Array.mapi ClipLimits.toRow model.scratch.securityClipLimits.limit
|
||||
let enableRemove = if Array.isEmpty model.gridSelection.clip then Disabled else Enabled
|
||||
div [] [
|
||||
div [ClassName "field is-grouped"] [
|
||||
Button.button "Add Limit" "is-primary" "" Enabled (fun _ -> ClipLimits AddRow |> dispatch )
|
||||
Button.button "Remove Limits" "is-danger" "" enableRemove (fun _ -> ClipLimits RemoveRows |> dispatch )
|
||||
]
|
||||
dataGrid ClipLimits.columns
|
||||
( OnRowSelect (selectRows>>ClipLimits>>dispatch) :: gridCommonProps )
|
||||
rows (UpdateRows>>ClipLimits>>dispatch)
|
||||
]
|
||||
mappedDataGridWithAddDelete
|
||||
"Clip Limits"
|
||||
ClipLimits.descriptor
|
||||
[ EnableCellSelect true ]
|
||||
model.scratch.securityClipLimits.limit
|
||||
(DeleteClipLimit>>dispatch)
|
||||
(ClipLimits>>dispatch)
|
||||
|
||||
let productLimits model dispatch =
|
||||
let rows = Array.mapi ProductLimits.toRow model.scratch.productPositionLimits
|
||||
let enableRemove = if Array.isEmpty model.gridSelection.product then Disabled else Enabled
|
||||
div [] [
|
||||
div [ClassName "field is-grouped"] [
|
||||
Button.button "Add Product Limit" "is-primary" "" Enabled (fun _ -> ProductLimits AddRow |> dispatch )
|
||||
Button.button "Remove Product Limits" "is-danger" "" enableRemove (fun _ -> ProductLimits RemoveRows |> dispatch )
|
||||
]
|
||||
dataGrid ProductLimits.columns ([MinHeight 200; OnRowSelect (selectRows>>ProductLimits>>dispatch) ] @ gridCommonProps) rows (UpdateRows>>ProductLimits>>dispatch)
|
||||
]
|
||||
mappedDataGridWithAddDelete
|
||||
"Product Limits"
|
||||
ProductLimits.descriptor
|
||||
[ EnableCellSelect true; MinHeight 200 ]
|
||||
model.scratch.productPositionLimits
|
||||
(DeleteProductLimit>>dispatch)
|
||||
(ProductLimits>>dispatch)
|
||||
|
||||
let securityLimits model dispatch =
|
||||
let rows = Array.mapi SecurityLimits.toRow model.scratch.securityPositionLimits
|
||||
let enableRemove = if Array.isEmpty model.gridSelection.security then Disabled else Enabled
|
||||
div [] [
|
||||
div [ClassName "field is-grouped"] [
|
||||
Button.button "Add Security Limit" "is-primary" "" Enabled (fun _ -> SecurityLimits AddRow |> dispatch)
|
||||
Button.button "Remove Security Limits" "is-danger" "" enableRemove (fun _ -> SecurityLimits RemoveRows |> dispatch )
|
||||
]
|
||||
dataGrid SecurityLimits.coumns ([MinHeight 200; OnRowSelect (selectRows>>SecurityLimits>>dispatch)] @ gridCommonProps) rows (UpdateRows>>SecurityLimits>>dispatch)
|
||||
]
|
||||
mappedDataGridWithAddDelete
|
||||
"Security Limits"
|
||||
SecurityLimits.descriptor
|
||||
[ EnableCellSelect true; MinHeight 200 ]
|
||||
model.scratch.securityPositionLimits
|
||||
(DeleteSecurityLimit>>dispatch)
|
||||
(SecurityLimits>>dispatch)
|
||||
|
||||
let positionLimitsView model dispatch =
|
||||
div [] [
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module DataGrid
|
||||
open Fable.Core.Exceptions
|
||||
open Fable.Core
|
||||
open Fable.Helpers.React
|
||||
|
||||
type GridProps = ReactGrid.GridProps
|
||||
|
||||
@@ -19,3 +20,32 @@ let dataGrid<'a> columns props (rows:'a[]) dispatch =
|
||||
ReactGrid.RowsCount (Array.length rows)
|
||||
]
|
||||
ReactGrid.reactGrid columns rgprops
|
||||
|
||||
|
||||
//
|
||||
// Highest level grid control which handles mapping to a row type and back
|
||||
|
||||
type MappedDataGridDescriptor<'a,'r> = {
|
||||
columns : ReactGrid.ColumnProps list []
|
||||
toGridRow : 'a->'r
|
||||
fromGridRow : 'r->'a
|
||||
emptyRow : 'a
|
||||
}
|
||||
|
||||
let private updateMapped<'a,'r> (descriptor:MappedDataGridDescriptor<'a,'r>) (rows:'a[]) (gridUpdate:ReactGrid.GridUpdate) =
|
||||
for x in [gridUpdate.fromRow..gridUpdate.toRow] do
|
||||
let original = descriptor.toGridRow rows.[x]
|
||||
let changed = Global.Reflection.spread original gridUpdate.updated
|
||||
rows.[x] <- descriptor.fromGridRow changed
|
||||
rows
|
||||
|
||||
let mappedDataGrid<'a,'r> (descriptor:MappedDataGridDescriptor<'a,'r>) props (rows:'a[]) (dispatch:'a[]->unit) =
|
||||
let getRow id = rows.[id] |> descriptor.toGridRow |> box
|
||||
let onUpdate u = updateMapped descriptor rows u |> dispatch
|
||||
let rgprops =
|
||||
props @ [
|
||||
ReactGrid.RowGetter getRow
|
||||
ReactGrid.RowsCount (Array.length rows)
|
||||
ReactGrid.OnGridRowsUpdated onUpdate
|
||||
]
|
||||
ReactGrid.reactGrid descriptor.columns rgprops
|
||||
@@ -61,28 +61,32 @@ let selectColumn<'a> key header (options:'a[]) =
|
||||
]
|
||||
|
||||
[<Pojo>]
|
||||
type ButtonProps = {
|
||||
type private ButtonProps = {
|
||||
icon : string
|
||||
title: string
|
||||
value : obj option
|
||||
action : int->unit
|
||||
// .value will be row.[ColumnProps.Key] -but- if we set it then it does't get overwritten
|
||||
// value : obj option
|
||||
rowIdx : int
|
||||
misc : obj
|
||||
}
|
||||
type ButtonFormatter(initProps : ButtonProps) as self =
|
||||
type private ButtonFormatter(initProps : ButtonProps) as self =
|
||||
inherit React.Component<ButtonProps, obj>(initProps) with
|
||||
do self.setInitState ()
|
||||
override __.render() =
|
||||
// Browser.console.log(self.props)
|
||||
p [ ClassName "control" ] [
|
||||
a [ ClassName "button is-warn"
|
||||
a [ ClassName "button"
|
||||
Title self.props.title
|
||||
OnClick ignore ] [
|
||||
OnClick (fun _ -> self.props.action self.props.rowIdx) ] [
|
||||
span [ ClassName "icon is-small" ] [
|
||||
i [ ClassName (sprintf "fa fa-%s" self.props.icon)] [ ] ]
|
||||
]
|
||||
]
|
||||
|
||||
let buttonColumn key header icon =
|
||||
[ Key key
|
||||
Name header
|
||||
Width 50
|
||||
Formatter (ofType<ButtonFormatter,_,_> { title = header; icon = icon; value = None } [])
|
||||
let buttonColumn action header icon misc =
|
||||
[ Name header
|
||||
Width 60
|
||||
Formatter (ofType<ButtonFormatter,_,_> { title = header; icon = icon; action = action; rowIdx = 0; misc = misc } [])
|
||||
]
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
<!-- Global to the app -->
|
||||
<Compile Include="Global.fs" />
|
||||
<Compile Include="Cmd.fs" />
|
||||
<Compile Include="Controls/Button.fs" />
|
||||
<Compile Include="Controls/ReactGrid.fs" />
|
||||
<Compile Include="Controls/DataGrid.fs" />
|
||||
<Compile Include="Controls/Button.fs" />
|
||||
<Compile Include="Controls/Fields.fs" />
|
||||
<Compile Include="Controls/Table.fs" />
|
||||
<Compile Include="Access.fs" />
|
||||
|
||||
Reference in new issue
Block a user