Merged in SparkAdmin (pull request #47)

SparkAdmin

Approved-by: Eric Harding <eric.harding@bluetradesys.com>
This commit is contained in:
Michael Harding committed 2018-07-16 18:03:27 +00:00
commit 71ddcd135b
12 files changed
+708 -282

No files matched your search

+120 -16
View File
@@ -15,14 +15,94 @@ body {
height:100%;
}
.nbsp {
margin-left:1em;
}
.is-sidebar-menu {
padding: 2.5rem;
padding: 1.5rem;
background: $grey-lighter;
border-right: 0.6px solid $border;
min-width: 12rem;
min-width: 14rem;
li {
a {
color: $grey-dark
color: $grey-dark;
&:hover {
.menu-icon {
display: inline;
}
}
}
}
.menu-label {
color: $text;
text-transform: none;
}
.circle-icon {
margin: 0 0em 0 3.5em;
.button {
&:active {
box-shadow: none;
}
}
.fabutton {
background-color: transparent;
border-width: 0;
.icon {
i {
color: $menu-label-color;
font-size: 1.75em;
margin-top:-0.2em;
&:hover {
color:$text;
}
}
}
}
}
.is-active {
.menu-icon {
display:inline;
.button {
color: $white;
}
}
}
.menu-icon {
display:none;
margin: 0 -0.5em 0 0;
.dropdown {
.dropdown-trigger {
.button {
padding: 0 1ex;
margin: -0.1em 0 0 0;
height:auto;
border:0;
background-color:transparent;
&:active {
box-shadow: none;
}
}
.fabutton {
max-height: 1em;
background-color: transparent;
border-width: 0;
//padding:0 0.25em;
.icon {
i {
font-size: 1em;
&:hover {
color:$menu-label-color;
}
}
}
}
}
.dropdown-menu {
left: unset;
right:0;//-1.25em;
width:10rem;
}
}
}
}
@@ -87,34 +167,51 @@ body {
-moz-appearance: none;
-webkit-appearance: none;
background-color: transparent;
//color: $white;
border: none;
color: $menu-label-color;
border: 2px solid $menu-label-color;
border-radius: 50%;
cursor: pointer;
display: inline-block;
flex-grow: 0;
flex-shrink: 0;
font-size: 14px;
height: 21px;
max-height: 21px;
max-width: 21px;
min-height: 21px;
min-width: 21px;
width: 21px;
line-height:14px;
height: 20px;
max-height: 20px;
min-height: 20px;
width: 20px;
max-width: 20px;
min-width: 20px;
outline: none;
position: relative;
vertical-align: middle;
text-align: center;
padding: 0.275em 0 0 0.07em;
padding: 0px;
margin: 0ex 0 0 1.5em;
padding: auto;
&:hover {
background-color: $shell_gray;
color: $text;
border-color: $text;
}
.icon {
&.is-small{
height:14px;
width:14px;
min-width:14px;
line-height: 14px;
font-size: 14px;
margin:2px 3.3px;
vertical-align: middle;
text-align: center;
i {
height:14px;
width:14px;
min-width:14px;
line-height: 14px;
font-size: 14px;
vertical-align: middle;
text-align: center;
}
}
}
i {
@@ -221,9 +318,10 @@ body {
&:focus {
background-color: $white;
}
}
.is-checkbox-cell {
width: 3rem;
&[type="checkbox"] {
height:1em;
margin-top: 0.75em;
}
}
.delete {
margin:.6rem .4rem;
@@ -231,5 +329,11 @@ body {
.table-buttons {
width:auto;
}
tr.is-selected {
background: $grey_lighter;
}
tr.is-warning {
background: $yellow;
}
}
+114 -11
View File
@@ -6,6 +6,7 @@ open Elmish
open Fable.PowerPack.PromiseImpl
open Fable.Import
open bts.co2
open Fable
let isNewAccount (account:BTSAccount) =
account.id = 0u && account.isPresent
@@ -23,8 +24,12 @@ let init (context:ServiceContext.ServiceContext) =
mdRelayExpNameData = Array.empty<ExpirationNameList>
scratch = emptyAccount
previousScratch = emptyAccount
AllValue = "*"
AllValueDisplay = "All"
AllValue = ""
AllValueDisplay = "Select"
OptionsMenuOpen = ""
ConfirmModal = "", (Msg.SelectTab General)
SelectedClipLimits = []
SelectedPositionLimits = []
}, Access.getAdminData admin UpdateAdminData NoAdminData
let existingSelection (scratch:BTSAccount) (previousScratch:BTSAccount) (data:AdminData) =
@@ -99,6 +104,38 @@ let erase (arr:'a[]) i =
let right = arr.[1+i..]
Array.concat [left;right]
let clearSelection model =
{ model with
SelectedClipLimits = []
SelectedPositionLimits = []
}
let ClipLimitIsEqual (limit1:AccountSecurityClipLimitUnit) (limit2:AccountSecurityClipLimitUnit) =
(limit1.security.exchange = limit2.security.exchange)
&& (limit1.security.securityType = limit2.security.securityType)
&& (limit1.security.securitySymbol = limit2.security.securitySymbol)
let PositionLimitIsEqual (limit1:AccountProductPositionLimitUnit) (limit2:AccountProductPositionLimitUnit) =
(limit1.product.exchange = limit2.product.exchange)
&& (limit1.product.securityType = limit2.product.securityType)
&& (limit1.product.securitySymbol = limit2.product.securitySymbol)
let modifyClipLimitRow limits (oldRow:AccountSecurityClipLimitUnit) (newRow:AccountSecurityClipLimitUnit) =
match (Array.tryFindIndex (fun l -> oldRow = l) limits) with
| None -> limits
| Some ind ->
let left = Array.append (limits.[..ind-1]) [| newRow |]
let right = limits.[1+ind..]
Array.concat [left; right]
let modifyProductPositionRow limits (oldRow:AccountProductPositionLimitUnit) (newRow:AccountProductPositionLimitUnit) =
match (Array.tryFindIndex (fun l -> oldRow = l) limits) with
| None -> limits
| Some ind ->
let left = Array.append (limits.[..ind-1]) [| newRow |]
let right = limits.[1+ind..]
Array.concat [left; right]
let update msg (model:Model) : Model * Cmd<Msg> =
match msg with
| UpdateAdminData data ->
@@ -110,11 +147,12 @@ let update msg (model:Model) : Model * Cmd<Msg> =
Global.alert Global.Info msg
model, Cmd.Empty
| SelectAccount account ->
{ model with previousScratch = model.scratch; scratch = account }, Cmd.Empty
{ (clearSelection model) with previousScratch = model.scratch; scratch = account }, Cmd.Empty
| DeleteAccount account ->
let mdl = { model with OptionsMenuOpen = ""}
match Fable.Import.Browser.window.confirm (sprintf "Are you sure you want to delete '%s'" account.name) with
| true -> model, Cmd.ofExistingPromise (deleteAccount model.admin account) id (box>>ErrorOccured)
| false -> model, Cmd.Empty
| true -> mdl, Cmd.ofExistingPromise (deleteAccount model.admin account) id (box>>ErrorOccured)
| false -> mdl, Cmd.Empty
| AddAccount ->
// Create a new scratch account. Send to server after user has filled in details
{ model with previousScratch = model.scratch; scratch = { emptyAccount with name = "New Account" } }, Cmd.ofMsg <| SelectTab General
@@ -127,16 +165,77 @@ let update msg (model:Model) : Model * Cmd<Msg> =
Browser.console.log msg
model,Cmd.Empty
| SelectTab tab ->
{ model with tab = tab }, Cmd.Empty
{ (clearSelection model) with tab = tab }, Cmd.Empty
| Update field ->
{ model with scratch = applyUpdate model.scratch field }, Cmd.Empty
| ClipLimits limits ->
{ model with scratch = { model.scratch with securityClipLimits = { limit = limits } } }, Cmd.Empty
| ClipLimits (oldLimit, newLimit) ->
//if the new limit matches the empty limit then add it to the list, otherwise update the existing row
match (ClipLimitIsEqual newLimit { security = { SecurityScope.empty with securitySymbol = model.AllValue }; clipSize = 0u }), (Array.tryFindIndex (fun l -> ClipLimitIsEqual newLimit l) model.scratch.securityClipLimits.limit) with
| true, None ->
let limits = Array.concat [ model.scratch.securityClipLimits.limit; [| newLimit |]]
{ model with scratch = { model.scratch with securityClipLimits = { limit = limits } } }, Cmd.Empty
| true, Some i -> model, Cmd.Empty
| false, _ ->
let limits = modifyClipLimitRow model.scratch.securityClipLimits.limit oldLimit newLimit
let selectedlimits = List.ofArray (modifyClipLimitRow (Array.ofList model.SelectedClipLimits) oldLimit newLimit)
{ model with scratch = { model.scratch with securityClipLimits = { limit = limits } }; SelectedClipLimits = selectedlimits }, Cmd.Empty
| ChangeMultipleClipLimits (value, selectedLimits) ->
let newLimits = Array.ofList [for row in (List.ofArray model.scratch.securityClipLimits.limit) do yield (
match (Array.tryFindIndex (fun elm -> ClipLimitIsEqual elm row) selectedLimits) with
| None -> row
| Some _ -> {row with clipSize = value}
)]
let newSelected = [for row in (List.ofArray selectedLimits) do yield ( {row with clipSize = value})]
{ model with scratch = { model.scratch with securityClipLimits = { limit = newLimits } }; SelectedClipLimits = newSelected }, Cmd.Empty
| SelectClipLimit (chckd, limit) ->
let scl = match chckd with
| true -> (limit::model.SelectedClipLimits)
| false -> List.filter (fun elm -> (ClipLimitIsEqual elm limit) |> not) model.SelectedClipLimits
{model with SelectedClipLimits = scl}, 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
| ProductLimits (oldLimit, newLimit) ->
let emptyLimit = {
product = {
exchange = bts.api.Venue.GLBX
securityType = bts.api.SecurityType.FUTURE
securitySymbol = model.AllValue
}
longPositionLimit = 0u
shortPositionLimit = 0u
netPositionLimit = 0u
}
//if the new limit matches the empty limit then add it to the list, otherwise update the existing row
match (PositionLimitIsEqual newLimit emptyLimit), (Array.tryFindIndex (fun l -> PositionLimitIsEqual newLimit l) model.scratch.productPositionLimits) with
| true, None ->
let limits = Array.concat [ model.scratch.productPositionLimits; [| newLimit |]]
{ model with scratch = { model.scratch with productPositionLimits = limits } }, Cmd.Empty
| true, Some i -> model, Cmd.Empty
| false, _ ->
let limits = modifyProductPositionRow model.scratch.productPositionLimits oldLimit newLimit
let selectedlimits = List.ofArray (modifyProductPositionRow (Array.ofList model.SelectedPositionLimits) oldLimit newLimit)
{ model with scratch = { model.scratch with productPositionLimits = limits }; SelectedPositionLimits = selectedlimits }, Cmd.Empty
| ChangeMultipleProductLimits (valueName, value, selectedLimits) ->
let newLimits = Array.ofList [for row in (List.ofArray model.scratch.productPositionLimits) do yield (
match (Array.tryFindIndex (fun elm -> PositionLimitIsEqual elm row) selectedLimits), valueName with
| Some _, "long" -> {row with longPositionLimit = value}
| Some _, "short" -> {row with shortPositionLimit = value}
| Some _, _ -> row
| None, _ -> row
)]
let newSelected = [for row in (List.ofArray selectedLimits) do yield (
match valueName with
| "long" -> { row with longPositionLimit = value}
| "short" -> { row with shortPositionLimit = value}
| _ -> row
)]
{ model with scratch = { model.scratch with productPositionLimits = newLimits }; SelectedPositionLimits = newSelected }, Cmd.Empty
| SelectProductLimit (chckd, limit) ->
let scl = match chckd with
| true -> (limit::model.SelectedPositionLimits)
| false -> List.filter (fun elm -> (PositionLimitIsEqual elm limit) |> not) model.SelectedPositionLimits
{model with SelectedPositionLimits = scl}, Cmd.Empty
| DeleteProductLimit i ->
let limits = erase model.scratch.productPositionLimits i
{ model with scratch = { model.scratch with productPositionLimits = limits } }, Cmd.Empty
@@ -156,7 +255,7 @@ let update msg (model:Model) : Model * Cmd<Msg> =
{ model with scratch = { model.scratch with connections = { model.scratch.connections with exchangeConnectionNames = newCons }}}, Cmd.Empty
| RemoveConnection conName ->
let newCons = erase model.scratch.connections.exchangeConnectionNames (Array.findIndex (fun a -> a = conName) model.scratch.connections.exchangeConnectionNames)
{ model with scratch = { model.scratch with connections = { model.scratch.connections with exchangeConnectionNames = newCons }}}, Cmd.Empty
{ model with scratch = { model.scratch with connections = { model.scratch.connections with exchangeConnectionNames = newCons }}; ConfirmModal = ("", Msg.SelectTab model.tab)}, Cmd.Empty
//
// Exchange data
| UpdateCME field ->
@@ -171,3 +270,7 @@ let update msg (model:Model) : Model * Cmd<Msg> =
model, Cmd.ofExistingPromise (requestExpNames model.mdRelay) id (box>>ErrorOccured)
| UpdateExpirationNames (data:ExpirationNameList[]) ->
{ model with mdRelayExpNameData = data }, Cmd.Empty
| OpenOptionsMenu acc ->
{model with OptionsMenuOpen = acc}, Cmd.Empty
| OpenConfirmModal (title, okMessage) ->
{model with ConfirmModal = title, okMessage}, Cmd.Empty
+28 -16
View File
@@ -8,7 +8,6 @@ open bts.co2
type Tab =
| General
//| ClipLimitsTab
| LimitsTab
| CreditLimitsTab
| ExchangeSettingsTab
@@ -19,19 +18,6 @@ let securityTypes = SecurityType.values |> Array.skip 1
let emptyAccount = Access.Accounts.empty
type Model = {
tab : Tab
admin : IAdminService
adminData : AdminData option
mdRelay : IMarketDataRelay
mdRelayProductData: Product[]
mdRelayExpNameData: ExpirationNameList[]
scratch : BTSAccount
previousScratch : BTSAccount
AllValue: string
AllValueDisplay: string
}
type AccountField =
| AccountName of string
| Description of string
@@ -61,10 +47,17 @@ type Msg =
| SelectTab of Tab
// General
| Update of AccountField
| ClipLimits of AccountSecurityClipLimitUnit[]
// Clip Limits
| ClipLimits of AccountSecurityClipLimitUnit * AccountSecurityClipLimitUnit
| ChangeMultipleClipLimits of uint32 * AccountSecurityClipLimitUnit[]
| SelectClipLimit of bool * AccountSecurityClipLimitUnit
| DeleteClipLimit of int
| ProductLimits of AccountProductPositionLimitUnit[]
//Product (position) Limits
| ChangeMultipleProductLimits of string * uint32 * AccountProductPositionLimitUnit []
| SelectProductLimit of bool * AccountProductPositionLimitUnit
| ProductLimits of AccountProductPositionLimitUnit * AccountProductPositionLimitUnit
| DeleteProductLimit of int
| SecurityLimits of AccountSecurityPositionLimitUnit[]
| DeleteSecurityLimit of int
// ExchangeData
@@ -75,4 +68,23 @@ type Msg =
| UpdateExpirationNames of ExpirationNameList[]
| AddConnection of string
| RemoveConnection of string
| OpenOptionsMenu of string
| OpenConfirmModal of string * Msg
type Model = {
tab : Tab
admin : IAdminService
adminData : AdminData option
mdRelay : IMarketDataRelay
mdRelayProductData: Product[]
mdRelayExpNameData: ExpirationNameList[]
scratch : BTSAccount
previousScratch : BTSAccount
AllValue: string
AllValueDisplay: string
SelectedClipLimits: AccountSecurityClipLimitUnit list
SelectedPositionLimits: AccountProductPositionLimitUnit list
OptionsMenuOpen:string
ConfirmModal: string * Msg
}
+283 -170
View File
@@ -4,7 +4,6 @@ open Accounts.Types
open Accounts.State
open Fable.Helpers.React
open Fable.Helpers.React.Props
open Button
open bts.api.admin
open bts.api.orderman
open EnumUtils
@@ -30,41 +29,15 @@ let saveButton model dispatch =
let isNew = isNewAccount model.scratch
let buttonText = if isNew then "Create" else "Save"
let dirty = isDirty model || isNew
let enabled = if dirty then Enabled else Disabled
let enabled = if dirty then Button.Enabled else Button.Disabled
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 "" "times" (box rows)
let descriptor' = { descriptor with columns = Array.append [| deleteColumn |] descriptor.columns }
div [] [
h5 [ClassName "title is-5"] [ str title ]
mappedDataGrid descriptor' props rows dispatch
div [ClassName "level"] [
div [ClassName "level-left"] []
div [ClassName "level-right"] [
div [ClassName "level-item"] [
Button.addButton Button.Enabled addRow
]
]
]
]
*)
//
// General
//
let generalView model dispatch =
let account = model.scratch
let remButton =
match selectedAccount model with
| None -> Button.button "Remove Account" "is-danger-hover" "times" Disabled ignore
| Some acc -> Button.button "Remove Account" "is-danger-hover" "times" Enabled (fun _ -> dispatch <| DeleteAccount acc)
let revertFun =
match model.adminData with
@@ -76,7 +49,7 @@ let generalView model dispatch =
(div [] [
Fields.text "Name" account.name [] (AccountName >> Update >> dispatch)
Fields.text "Description" account.description [] (Description >> Update >> dispatch)
Fields.checkbox "Active" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch)
Fields.checkbox "Can Trade Into Account" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch)
])
(fun _ -> dispatch SaveScratch)
revertFun
@@ -86,37 +59,38 @@ let generalView model dispatch =
br []
Fields.text "Name" account.name [] (AccountName >> Update >> dispatch)
Fields.text "Description" account.description [] (Description >> Update >> dispatch)
Fields.checkbox "Active" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch)
remButton
Fields.checkbox "Can Trade Into Account" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch)
(if State.isNewAccount account then modal else span[][])
]
let clipLimitsView model dispatch =
let headerRow:TableControl.row =
{
cells =
[
TableControl.Cell (str "")
TableControl.Cell (str "Exchange")
TableControl.Cell (str "Security Type")
TableControl.Cell (str "Symbol")
TableControl.Cell (str "Security")
TableControl.Cell (str "Clip Size")
]
className = ""
header = None
}
let GetSymbolArray (model:Model) =
[|
[| model.AllValueDisplay |];
Array.map<bts.api.Product, string> (fun a -> a.symbol ) model.mdRelayProductData
|]
|> Array.concat
|> Array.distinct
let symbolArray = [|
[| model.AllValueDisplay |];
Array.map<bts.api.Product, string> (fun a -> a.symbol ) model.mdRelayProductData
|]
|> Array.concat
|> Array.distinct
let limitFilter (positionLimit:AccountSecurityPositionLimitUnit option) (clipLimit:AccountSecurityClipLimitUnit option) allValueDisplay (array:'a []) =
match positionLimit, clipLimit with
| Some limit, None ->
Array.filter (fun (x:bts.co2.ExpirationNameList) -> (
((x.product.exchange = limit.security.exchange) || (x.product.exchange = bts.api.Venue.UNSET))
&& ((x.product.``type`` = limit.security.securityType) || (x.product.``type`` = bts.api.SecurityType.UNSET))
&& ((x.product.symbol = limit.security.securitySymbol) || (x.product.symbol = allValueDisplay))
))
array
| None, Some limit ->
Array.filter (fun (x:bts.co2.ExpirationNameList) -> (
((x.product.exchange = limit.security.exchange) || (x.product.exchange = bts.api.Venue.UNSET))
&& ((x.product.``type`` = limit.security.securityType) || (x.product.``type`` = bts.api.SecurityType.UNSET))
&& ((x.product.symbol = limit.security.securitySymbol) || (x.product.symbol = allValueDisplay))
))
array
| _ , _ -> array
let getSecurityMap (limit:AccountSecurityClipLimitUnit) =
let allOption = {
product = {
let getSecurityMap (model:Model) (positionLimit:AccountSecurityPositionLimitUnit option) (clipLimit:AccountSecurityClipLimitUnit option) =
let allOption = { product = {
exchange = bts.api.Venue.UNSET
``type`` = bts.api.SecurityType.UNSET
symbol = model.AllValueDisplay
@@ -125,92 +99,148 @@ let clipLimitsView model dispatch =
}:ExpirationNameList
Array.concat [ [| allOption |]; model.mdRelayExpNameData]
|> Array.filter (fun (x:bts.co2.ExpirationNameList) -> (
((x.product.exchange = limit.security.exchange) || (x.product.exchange = bts.api.Venue.UNSET))
&& ((x.product.``type`` = limit.security.securityType) || (x.product.``type`` = bts.api.SecurityType.UNSET))
&& ((x.product.symbol = limit.security.securitySymbol) || (x.product.symbol = model.AllValueDisplay))
)
)
|> (limitFilter positionLimit clipLimit model.AllValueDisplay)
|> Seq.map (fun x -> x.names ) |> JSMap.concat
let modifyRow (oldRow:AccountSecurityClipLimitUnit) (newRow:AccountSecurityClipLimitUnit) =
let i = Array.findIndex (fun l -> oldRow = l) model.scratch.securityClipLimits.limit
let left = Array.append (model.scratch.securityClipLimits.limit.[..i-1]) [| newRow |]
let right = model.scratch.securityClipLimits.limit.[1+i..]
Array.concat [left; right]
let changeVenue (oldRow:AccountSecurityClipLimitUnit) (value:string) =
let clipLimitsView model dispatch =
let symbols = GetSymbolArray model
let headerRow:TableControl.row =
{
cells =
[
TableControl.Cell (str "")
TableControl.Cell (str "")
TableControl.Cell (str "Exchange")
TableControl.Cell (str "Security Type")
TableControl.Cell (str "Symbol")
//TableControl.Cell (str "Security")
TableControl.Cell (str "Clip Size")
]
className = ""
header = None
}
let footerRow:TableControl.row =
{
cells =
[
{ content = span [Class "nbsp"] [str "Apply to Selected Rows:"]
className = "has-text-right"
isHeader = false
colSpan = 5
}
TableControl.Cell (Fields.text
""
(sprintf "%i" (match (List.tryHead model.SelectedClipLimits) with
| Some r -> r.clipSize
| None -> 0u
))
[ ]
((fun value -> (value, (Array.ofList model.SelectedClipLimits))) >> ChangeMultipleClipLimits >> dispatch)
)
]
className = match (model.SelectedClipLimits.Length > 0) with
| true -> ""
| false -> "is-hidden-touch is-hidden-desktop"
header = None
}
let changeVenue (oldRow:AccountSecurityClipLimitUnit) (value:string) =
let venueValue = EnumUtils.fromHuman<bts.api.Venue> venues value
let newRow = { oldRow with security = { oldRow.security with exchange = venueValue } }
modifyRow oldRow newRow
{ oldRow with security = { oldRow.security with exchange = venueValue } }
let changeType (oldRow:AccountSecurityClipLimitUnit) (value:string) =
let typeValue = EnumUtils.fromHuman<bts.api.SecurityType> securityTypes value
let newRow = { oldRow with security = { oldRow.security with securityType = typeValue } }
modifyRow oldRow newRow
{ oldRow with security = { oldRow.security with securityType = typeValue } }
let changeSymbol (oldRow:AccountSecurityClipLimitUnit) (value:string) =
let v = match (value = model.AllValueDisplay) with
| false -> value
| true -> model.AllValue
modifyRow oldRow { oldRow with security = { oldRow.security with securitySymbol = v } }
{ oldRow with security = { oldRow.security with securitySymbol = v } }
let changeSecurityId (oldRow:AccountSecurityClipLimitUnit) (value:string) =
modifyRow oldRow { oldRow with security = { oldRow.security with securityId = (uint32 value) } }
let changeSecurityId (oldRow:AccountSecurityClipLimitUnit) (value:string) =
{ oldRow with security = { oldRow.security with securityId = (uint32 value) } }
let changeClipSize (oldRow:AccountSecurityClipLimitUnit) (value:string) =
{ oldRow with clipSize = (uint32 value) }
let limitIsDuplicate exchange secType symbol (limits:AccountSecurityClipLimitUnit []) =
Array.exists<AccountSecurityClipLimitUnit>
(fun elem -> (
elem.security.exchange = exchange &&
elem.security.securityType = secType &&
elem.security.securitySymbol = symbol
)
)
limits
let filterSymbols exchange secType symbol =
Array.filter (fun elem -> (limitIsDuplicate exchange secType symbol model.scratch.securityClipLimits.limit))
let isSelected limit =
List.exists (fun (elm:AccountSecurityClipLimitUnit) -> State.ClipLimitIsEqual elm limit) model.SelectedClipLimits
let changeClipSize (oldRow:AccountSecurityClipLimitUnit) (value:string) =
modifyRow oldRow { oldRow with clipSize = (uint32 value) }
let rws:TableControl.row list =
[ for limit in model.scratch.securityClipLimits.limit do yield {
cells =
[
TableControl.controlCell (Button.deleteButton Button.Enabled (fun _ -> (Array.findIndex (fun l -> limit = l) model.scratch.securityClipLimits.limit) |> DeleteClipLimit |> dispatch))
TableControl.controlCell (Fields.checkbox "" ""
(List.exists (fun (elm:AccountSecurityClipLimitUnit) -> State.ClipLimitIsEqual elm limit) model.SelectedClipLimits)
[]
(fun chckd -> ((chckd, limit) |> SelectClipLimit |> dispatch)))
TableControl.Cell (Fields.enumSelect<string>
""
(EnumUtils.toHuman<bts.api.Venue> false venues limit.security.exchange)
(EnumUtils.allToHuman<bts.api.Venue> false venues)
[Class ""]
((changeVenue limit) >> ClipLimits >> dispatch)
(fun value -> ((limit, (changeVenue limit value)) |> ClipLimits |> dispatch))
)
TableControl.Cell (Fields.enumSelect<string>
""
(EnumUtils.toHuman<bts.api.SecurityType> false securityTypes limit.security.securityType)
(EnumUtils.allToHuman<bts.api.SecurityType> false (Array.filter (fun a -> a <> bts.api.SecurityType.SYNTHETIC) securityTypes))
[]
((changeType limit) >> ClipLimits >> dispatch)
(fun value -> ((limit, (changeType limit value)) |> ClipLimits |> dispatch))
)
TableControl.Cell (Fields.enumSelect<string>
""
limit.security.securitySymbol
symbolArray
(GetSymbolArray model)
[]
((changeSymbol limit) >> ClipLimits >> dispatch)
(fun value -> ((limit, (changeSymbol limit value)) |> ClipLimits |> dispatch))
)
TableControl.Cell (Fields.mapSelect
(*TableControl.Cell (Fields.mapSelect
""
(JSMap.toMap (getSecurityMap limit))
(JSMap.toMap (getSecurityMap model None (Some limit)))
None
(Some (sprintf "%i" limit.security.securityId))
((changeSecurityId limit) >> ClipLimits >> dispatch)
)
)*)
TableControl.Cell (Fields.text
""
(sprintf "%i" limit.clipSize)
[ ]
((changeClipSize limit) >> ClipLimits >> dispatch)
(fun value -> ((limit, (changeClipSize limit value)) |> ClipLimits |> dispatch))
)
]
className = ""
className = match (isSelected limit), (limit.security.securitySymbol = "") with
| false, false -> ""
| true, false -> "is-selected"
| _, true -> "is-warning"
header = None
}
]
] @ [footerRow]
let emptyLimit = {
security = { SecurityScope.empty with securitySymbol = model.AllValue }
clipSize = 0u
}
let addRow _ = Array.append model.scratch.securityClipLimits.limit [| emptyLimit |] |> (ClipLimits >> dispatch)
let addRow _ = (emptyLimit, emptyLimit) |> ClipLimits |> dispatch
div []
[
div [ ClassName "columns" ][
@@ -226,6 +256,7 @@ let productLimits model dispatch =
{
cells =
[
TableControl.Cell (str "")
TableControl.Cell (str "")
TableControl.Cell (str "Exchange")
TableControl.Cell (str "Security Type")
@@ -237,84 +268,125 @@ let productLimits model dispatch =
header = None
}
let symbolArray = [|
[| model.AllValueDisplay |];
Array.map<bts.api.Product, string> (fun a -> a.symbol ) model.mdRelayProductData
|]
|> Array.concat
|> Array.distinct
let modifyRow (oldRow:AccountProductPositionLimitUnit) (newRow:AccountProductPositionLimitUnit) =
let i = Array.findIndex (fun l -> oldRow = l) model.scratch.productPositionLimits
let left = Array.append (model.scratch.productPositionLimits.[..i-1]) [| newRow |]
let right = model.scratch.productPositionLimits.[1+i..]
Array.concat [left; right]
let footerRow:TableControl.row =
{
cells =
[
{ content = span [Class "nbsp"] [str "Apply to Selected Rows:"]
className = "has-text-right"
isHeader = false
colSpan = 5
}
TableControl.Cell (Fields.text
""
(sprintf "%i" (match (List.tryHead model.SelectedPositionLimits) with
| Some r -> r.longPositionLimit
| None -> 0u
))
[ ]
((fun value -> ("long", value, (Array.ofList model.SelectedPositionLimits))) >> ChangeMultipleProductLimits >> dispatch)
)
TableControl.Cell (Fields.text
""
(sprintf "%i" (match (List.tryHead model.SelectedPositionLimits) with
| Some r -> r.shortPositionLimit
| None -> 0u
))
[ ]
((fun value -> ("short", value, (Array.ofList model.SelectedPositionLimits))) >> ChangeMultipleProductLimits >> dispatch)
)
]
className = match (model.SelectedPositionLimits.Length > 0) with
| true -> ""
| false -> "is-hidden-touch is-hidden-desktop"
header = None
}
let changeVenue (oldRow:AccountProductPositionLimitUnit) (value:string) =
let venueValue = EnumUtils.fromHuman<bts.api.Venue> venues value
let newRow = { oldRow with product = { oldRow.product with exchange = venueValue } }
modifyRow oldRow newRow
{ oldRow with product = { oldRow.product with exchange = venueValue } }
let changeType (oldRow:AccountProductPositionLimitUnit) (value:string) =
let typeValue = EnumUtils.fromHuman<bts.api.SecurityType> securityTypes value
let newRow = { oldRow with product = { oldRow.product with securityType = typeValue } }
modifyRow oldRow newRow
{ oldRow with product = { oldRow.product with securityType = typeValue } }
let changeSymbol (oldRow:AccountProductPositionLimitUnit) (value:string) =
let v = match (value = model.AllValueDisplay) with
| false -> value
| true -> model.AllValue
modifyRow oldRow { oldRow with product = { oldRow.product with securitySymbol = v } }
{ oldRow with product = { oldRow.product with securitySymbol = v } }
let changeLongPositionLimit (oldRow:AccountProductPositionLimitUnit) (value:string) =
modifyRow oldRow { oldRow with longPositionLimit = (uint32 value) }
{ oldRow with longPositionLimit = (uint32 value) }
let changeShortPositionLimit (oldRow:AccountProductPositionLimitUnit) (value:string) =
modifyRow oldRow { oldRow with shortPositionLimit = (uint32 value) }
{ oldRow with shortPositionLimit = (uint32 value) }
let limitIsDuplicate exchange secType symbol (limits:AccountProductPositionLimitUnit []) =
Array.exists<AccountProductPositionLimitUnit>
(fun elem -> (
elem.product.exchange = exchange &&
elem.product.securityType = secType &&
elem.product.securitySymbol = symbol
)
)
limits
let isSelected limit =
List.exists (fun (elm:AccountProductPositionLimitUnit) -> State.PositionLimitIsEqual elm limit) model.SelectedPositionLimits
let rws:TableControl.row list =
[ for limit in model.scratch.productPositionLimits do yield {
cells =
[
TableControl.Cell (Button.deleteButton Button.Enabled (fun _ -> (Array.findIndex (fun l -> limit = l) model.scratch.productPositionLimits) |> DeleteProductLimit |> dispatch))
TableControl.controlCell (Fields.checkbox "" ""
(List.exists (fun (elm:AccountProductPositionLimitUnit) -> State.PositionLimitIsEqual elm limit) model.SelectedPositionLimits)
[]
(fun chckd -> ((chckd, limit) |> SelectProductLimit |> dispatch)))
TableControl.Cell (Fields.enumSelect<string>
""
(EnumUtils.toHuman<bts.api.Venue> false venues limit.product.exchange)
(EnumUtils.allToHuman<bts.api.Venue> false venues)
[]
((changeVenue limit) >> ProductLimits >> dispatch)
(fun value -> ((limit, (changeVenue limit value)) |> ProductLimits |> dispatch))
)
TableControl.Cell (Fields.enumSelect<string>
""
(EnumUtils.toHuman<bts.api.SecurityType> false securityTypes limit.product.securityType)
(EnumUtils.allToHuman<bts.api.SecurityType> false (Array.filter (fun a -> a <> bts.api.SecurityType.SYNTHETIC) securityTypes))
[]
((changeType limit) >> ProductLimits >> dispatch)
(fun value -> ((limit, (changeType limit value)) |> ProductLimits |> dispatch))
)
TableControl.Cell (Fields.enumSelect<string>
""
limit.product.securitySymbol
symbolArray
(GetSymbolArray model)
[]
((changeSymbol limit) >> ProductLimits >> dispatch)
(fun value -> ((limit, (changeSymbol limit value)) |> ProductLimits |> dispatch))
)
TableControl.Cell (Fields.text
""
(sprintf "%i" limit.longPositionLimit)
[ ]
((changeLongPositionLimit limit) >> ProductLimits >> dispatch)
(fun value -> ((limit, (changeLongPositionLimit limit value)) |> ProductLimits |> dispatch))
)
TableControl.Cell (Fields.text
""
(sprintf "%i" limit.shortPositionLimit)
[ ]
((changeShortPositionLimit limit) >> ProductLimits >> dispatch)
(fun value -> ((limit, (changeShortPositionLimit limit value)) |> ProductLimits |> dispatch))
)
]
className = ""
className = match (isSelected limit), (limit.product.securitySymbol = "") with
| false, false -> ""
| true, false -> "is-selected"
| _, true -> "is-warning"
header = None
}
]
] @ [footerRow]
let emptyLimit = {
product = {
exchange = bts.api.Venue.GLBX
@@ -326,11 +398,11 @@ let productLimits model dispatch =
netPositionLimit = 0u
}
let addRow _ = Array.append model.scratch.productPositionLimits [| emptyLimit |] |> (ProductLimits >> dispatch)
let addRow _ = (emptyLimit, emptyLimit) |> ProductLimits |> dispatch
div []
[
div [ ClassName "columns" ][
h1 [ ClassName "is-size-3 column is-narrow" ][str "Product Limits" ]
h1 [ ClassName "is-size-3 column is-narrow" ][str "Position Limits" ]
div [ ClassName "column is-size-7 has-text-grey-mid is-help-text" ]
[str "This limits the net position for a product (i.e. accumulated position over all securities belonging to a product). This can be set for one product, or for all products within a security type by selecting \"All\" for symbol"]
]
@@ -339,7 +411,7 @@ let productLimits model dispatch =
]
let securityLimits model dispatch =
let securityLimitsView model dispatch =
let headerRow:TableControl.row =
{
cells =
@@ -356,32 +428,6 @@ let securityLimits model dispatch =
header = None
}
let symbolArray = [|
[| model.AllValueDisplay |];
Array.map<bts.api.Product, string> (fun a -> a.symbol ) model.mdRelayProductData
|]
|> Array.concat
|> Array.distinct
let getSecurityMap (limit:AccountSecurityPositionLimitUnit) =
let allOption = {
product = {
exchange = bts.api.Venue.UNSET
``type`` = bts.api.SecurityType.UNSET
symbol = model.AllValueDisplay
};
names = (JSMap.add<string> "0" model.AllValueDisplay JSMap.empty<string>)
}:ExpirationNameList
Array.concat [ [| allOption |]; model.mdRelayExpNameData]
|> Array.filter (fun (x:bts.co2.ExpirationNameList) -> (
((x.product.exchange = limit.security.exchange) || (x.product.exchange = bts.api.Venue.UNSET))
&& ((x.product.``type`` = limit.security.securityType) || (x.product.``type`` = bts.api.SecurityType.UNSET))
&& ((x.product.symbol = limit.security.securitySymbol) || (x.product.symbol = model.AllValueDisplay))
)
)
|> Seq.map (fun x -> x.names ) |> JSMap.concat
let modifyRow (oldRow:AccountSecurityPositionLimitUnit) (newRow:AccountSecurityPositionLimitUnit) =
let i = Array.findIndex (fun l -> oldRow = l) model.scratch.securityPositionLimits
let left = Array.append (model.scratch.securityPositionLimits.[..i-1]) [| newRow |]
@@ -435,13 +481,13 @@ let securityLimits model dispatch =
TableControl.Cell (Fields.enumSelect<string>
""
limit.security.securitySymbol
symbolArray
(GetSymbolArray model)
[]
((changeSymbol limit) >> SecurityLimits >> dispatch)
)
TableControl.Cell (Fields.mapSelect
""
(JSMap.toMap (getSecurityMap limit))
(JSMap.toMap (getSecurityMap model (Some limit) None))
None
(Some (sprintf "%i" limit.security.securityId))
((changeSecurityId limit) >> SecurityLimits >> dispatch)
@@ -485,8 +531,7 @@ let LimitsView model dispatch =
div [ Class "limits-container"] [
clipLimitsView model dispatch
productLimits model dispatch
securityLimits model dispatch
//securityLimitsView model dispatch
]
let ConnectionsView (model:Accounts.Types.Model) dispatch =
@@ -504,25 +549,47 @@ let ConnectionsView (model:Accounts.Types.Model) dispatch =
let rows:TableControl.row list =
[for c in conMap do yield {
cells = [
{ content = str c.Value
className = "is-narrow"
isHeader = false
colSpan = 1
}
{ content = (Fields.checkbox "" "" (
Array.contains c.Value conNames)
[]
(fun _ -> (match (Array.contains c.Value conNames) with | true -> c.Value |> (RemoveConnection >> dispatch) | false -> c.Key |> (AddConnection>> dispatch)))
(fun _ -> (
let message:Msg = c.Value |> (RemoveConnection)
match (Array.contains c.Value conNames) with
| true -> (OpenConfirmModal ((sprintf "Are you sure you want to remove the %s connection from this account?" c.Value), message))
| false -> (c.Key |> (AddConnection))
|> dispatch
)
)
);
className = "is-checkbox-cell";
className = "";
isHeader = false;
colSpan = 0
}
(TableControl.Cell (str c.Value))
}
]
className=""
header = None
}
]
div []
let headerRow:TableControl.row = {
cells =
[
TableControl.Cell(str "Connection")
TableControl.Cell(str "Enabled")
]
className = ""
header = None
}
div [ ]
[
TableControl.createSelectorTable None rows
TableControl.createSelectorTable (Some headerRow) rows
]
let creditLimitsView model dispatch = div [] [str "lorem ipsum"]
@@ -547,7 +614,6 @@ let tabContent model dispatch =
div [Key (string model.scratch.id); ClassName "is-tab-content"] [
(match model.tab with
| General -> generalView model dispatch
//| ClipLimitsTab -> clipLimitsView model dispatch
| LimitsTab -> LimitsView model dispatch
| ConnectionsTab -> ConnectionsView model dispatch
| CreditLimitsTab -> creditLimitsView model dispatch
@@ -563,13 +629,18 @@ let accountControls model (dispatch:Msg->unit) =
div [ClassName "is-main-control-bar"] [
saveButton model dispatch
Button.button "Revert" "is-light" "" (if isDirty model then Enabled else Disabled) revertFun
Button.button "Revert" "is-light" "" (if isDirty model then Button.Enabled else Button.Disabled) revertFun
]
let isActive account = function
| Some a when a = account-> "is-active"
| Some a when a = account -> "is-active"
| _ -> ""
let isOptionsMenuOpen accountName openName =
match accountName = openName with
| true -> "is-active"
| false -> ""
let isActiveItem a b = if a = b then "is-active" else ""
let accountsMenu (accounts:BTSAccount[]) selectedAccount dispatch =
@@ -638,7 +709,7 @@ let selectionPageContent (adminData:AdminData) (model:Model) (dispatch:Msg->Unit
(div [] [
Fields.text "Name" account.name [] (AccountName >> Update >> dispatch)
Fields.text "Description" account.description [] (Description >> Update >> dispatch)
Fields.checkbox "Active" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch)
Fields.checkbox "Can Trade Into Account" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch)
])
(fun _ -> dispatch SaveScratch)
revertFun
@@ -649,27 +720,60 @@ let selectionPageContent (adminData:AdminData) (model:Model) (dispatch:Msg->Unit
(if State.isNewAccount model.scratch then modal else span[][])
]
let menuItem account selectedAccount model dispatch =
a [ ClassName (isActive account selectedAccount)
OnClick (fun _ -> SelectAccount account |> dispatch)
] [
span [] [ str account.name ]
span [ Class "is-pulled-right menu-icon" ]
[
div [ Class (sprintf "dropdown %s" (isOptionsMenuOpen account.name model.OptionsMenuOpen)) ]
[ div [ Class "dropdown-trigger" ]
[ button [ Class "button"
AriaHasPopup true
OnClick (fun _ -> account.name |> OpenOptionsMenu |> dispatch)
HTMLAttr.Custom ("aria-controls", (sprintf "dropdown-menu-%s" account.name)) ]
[ span [ Class "icon is-small" ]
[ i [ Class "fa fa-ellipsis-v"
HTMLAttr.Custom ("aria-hidden", "true") ][ ]
]
]
]
div [ Class "dropdown-menu"
Id (sprintf "dropdown-menu-%s" account.name)
Role "menu"
let NavRoot (accounts:BTSAccount[]) selectedAccount dispatch =
]
[ div [ Class "dropdown-content" ]
[ //hr [ Class "dropdown-divider" ]
a [ Class "dropdown-item"
OnClick (fun _ -> dispatch <| DeleteAccount account)
]
[ str "Remove" ]
]
]
]
]
]
let NavRoot (accounts:BTSAccount[]) selectedAccount model dispatch =
div [ Class "column is-narrow is-sidebar-menu" ]
[ aside [ Class "menu" ]
[ div [ Class "has-text-right" ]
[ Button.faRoundButton "Add Account" "plus" Enabled (fun _ -> dispatch AddAccount) ]
[ p [ Class "menu-label" ] [
span [Class "is-size-4"] [str "Accounts"]
span [ Class "is-pulled-right circle-icon" ]
[ Button.fabutton "Add Account" "plus-circle" "" Button.Enabled (fun _ -> dispatch AddAccount) ]
]
ul [ Class "menu-list" ]
[
for account in accounts do
yield li [] [
a [
ClassName (isActive account selectedAccount)
OnClick (fun _ -> SelectAccount account |> dispatch) ] [
str account.name]
]
yield li [] [ menuItem account selectedAccount model dispatch ]
]
]
]
let tabName = function
//| ClipLimitsTab -> "Clip Limits"
| LimitsTab -> "Limits"
| CreditLimitsTab -> "Credit Limits"
| ConnectionsTab -> "Connections"
@@ -682,18 +786,26 @@ let tabHeader tab currentTab dispatch =
]
let root (model:Model) dispatch =
let modal = match (fst model.ConfirmModal) with
| "" -> span [] []
| _ -> Modal.showConfirm (fst model.ConfirmModal) (fun () -> (snd model.ConfirmModal) |> dispatch) (fun _ -> OpenConfirmModal ("", Msg.SelectTab model.tab ) |> dispatch)
match model.adminData with
| None -> div[][str "Loading account list..."]
| Some data ->
div
[ Class "columns is-fullheight" ]
[ NavRoot data.accounts (selectedAccount model) dispatch
[ Class "columns is-fullheight"
OnClick (fun _ ->
match model.OptionsMenuOpen.Length > 0 with
| true -> "" |> OpenOptionsMenu |> dispatch
| _ -> ()
)
]
[ NavRoot data.accounts (selectedAccount model) model dispatch
div [ Class "column is-main-content" ]
[
div [ ClassName "tabs is-boxed" ] [
ul [] [
tabHeader General model.tab dispatch
//tabHeader ClipLimitsTab model.tab dispatch
tabHeader LimitsTab model.tab dispatch
tabHeader ConnectionsTab model.tab dispatch
// tabHeader CreditLimits model.tab dispatch
@@ -702,5 +814,6 @@ let root (model:Model) dispatch =
]
tabContent model dispatch
accountControls model dispatch
modal
]
]
+2 -9
View File
@@ -22,16 +22,9 @@ open ServiceContext
let topLevel (sc:ServiceContext.ServiceContext) currentPage dispatch content =
div
[ Class "columns is-fullheight" ]
[ Nav.root currentPage sc dispatch
[ Nav.navRoot currentPage sc dispatch
div [ Class "column is-main-content" ]
[ content]
(*
div
[ ClassName "navbar-bg" ]
[ div
[ ClassName "container" ]
[(App.Nav.navRoot currentPage sc dispatch) ] ]
//[(App.Nav.nav' currentPage sc dispatch) ] ]*)
[ content ]
]
let root model dispatch =
+2 -2
View File
@@ -48,12 +48,12 @@ let faRoundButton title icon disabled click =
]
let fabutton title icon disabled click =
let fabutton title icon classname disabled click =
a [ ClassName "button fabutton"
HTMLAttr.Disabled (isDisabled disabled)
Title title
OnClick click ] [
span [ ClassName "icon is-small" ] [
span [ ClassName (sprintf "icon %s" classname) ] [
i [ ClassName (sprintf "fa fa-%s" icon)] [ ] ]
]
+21 -4
View File
@@ -96,8 +96,8 @@ let map (lbl:string) (dv:JSMap<string>) (attrs:IHTMLProp list) (onchange: JSMap<
[HTMLAttr.Disabled true; Placeholder "Enter New Item Name:"; ]
[ OnBlur ((fun ev -> !!ev.target?value |> newEntry )) ]
[
Button.fabutton "" "" Button.Enabled ignore
Button.fabutton "Add" "check" Button.Enabled ignore
Button.fabutton "" "" "is-small" Button.Enabled ignore
Button.fabutton "Add" "check" "is-small" Button.Enabled ignore
]
change
| _ ->
@@ -105,7 +105,7 @@ let map (lbl:string) (dv:JSMap<string>) (attrs:IHTMLProp list) (onchange: JSMap<
i
[HTMLAttr.Disabled true]
[]
[Button.fabutton "Delete" "times" Button.Enabled (fun _ -> (remove i))]
[Button.fabutton "Delete" "times" "is-small" Button.Enabled (fun _ -> (remove i))]
change
)]
@@ -113,7 +113,7 @@ let map (lbl:string) (dv:JSMap<string>) (attrs:IHTMLProp list) (onchange: JSMap<
[
Label lbl
div [] elementList
Button.fabutton "Add" "plus" Button.Enabled ((fun _ -> change ("","") "" ""))
Button.fabutton "Add" "plus" "is-small" Button.Enabled ((fun _ -> change ("","") "" ""))
]
let password (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
@@ -213,4 +213,21 @@ let simpleSelect (lbl:string) (options:string list) (defaultValue:string) (oncha
[ for opt in options do yield option [ Value opt ] [ str (opt) ] ]
]
]
]
let menuSelect (options:string list) (onchange:'a->unit) =
div [ ClassName "field" ]
[
div [ ClassName "control" ]
[
div [ ClassName "select menu-select" ]
[
select [
Value ""
OnChange (fun ev -> !!ev.target?value |> onchange)
]
[ for opt in options do yield option [ Value opt ] [ str (opt) ] ]
]
]
]
+17 -9
View File
@@ -9,31 +9,39 @@ open Global
open Fable
let show (title:string) (content:ReactElement) (footerContent:ReactElement) (onCloseClick: MouseEvent -> Unit) =
let show (title:string) (content:ReactElement) (footerContent:ReactElement) (onCloseClick: MouseEvent -> Unit) =
div [ Class "modal is-active" ]
[ div [ Class "modal-background" ][ ]
div [ Class "modal-card" ]
[ header [ Class "modal-card-head" ]
[ p [ Class "modal-card-title" ][ str title ]
button [ Class "delete"; OnClick onCloseClick ] [ ]
button [ Class "delete"; OnClick onCloseClick ] [ ]
]
section [ Class "modal-card-body" ] [ content ]
footer [ Class "modal-card-foot" ] [ footerContent ]
]
]
]
let showCreate title content (onCreateClick: MouseEvent -> Unit) (onCloseClick: MouseEvent -> Unit) =
show
title
content
show
title
content
(div [] [ button [ Class "button is-success"; OnClick onCreateClick ]
[ str "Create" ]
button [ Class "button"; OnClick onCloseClick ]
[ str "Cancel" ]
])
(onCloseClick: MouseEvent -> Unit)
let showConfirm description (onOK:unit->unit) onCancel =
show
"Confirm"
(str description)
(div [] [ button [ Class "button is-success"; OnClick (ignore>>onOK) ]
[ str "Confirm" ]
button [ Class "button"; OnClick onCancel ]
[ str "Cancel" ]
])
(onCancel: MouseEvent -> Unit)
+3 -1
View File
@@ -17,6 +17,8 @@ open Fable.Helpers.React.Props
open Elmish.React.Common
open ServiceContext
open Fable.Helpers
open Imports
open Fable.Import.React
let isCurrentPage page currentPage =
match page, currentPage with
@@ -57,4 +59,4 @@ let root (currentPage:Page) (sc:ServiceContext) dispatch =
]
]
//let navRoot = lazyView3With (fun a b -> isCurrentPage (fst a) (fst b)) root
let (navRoot: 'a -> ServiceContext -> Dispatch<Msg> -> ReactElement) = lazyView3With (fun b c -> isCurrentPage (fst b) (fst c)) root
+16 -4
View File
@@ -12,6 +12,12 @@ open Fable.PowerPack.PromiseImpl
open bts.api.admin
open Global
let SMPInstructionMap:Map<string, string> = Map.empty
.Add("O", "Cancel Resting")
.Add("N", "Cancel Agressing")
.Add("", "Undefined")
let isNewUser (user:BTSUser) =
user.id = 0u && user.isPresent
@@ -90,6 +96,8 @@ let init (context:ServiceContext.ServiceContext) : Model * Cmd<Msg> =
currentTab = Tab.General
admin = admin
adminData = None
OptionsMenuOpen = ""
ConfirmModal = "", (Msg.SwitchTab Tab.General)
}, getAdminData admin
let rec removeUser (user:BTSUser) (userList:BTSUser list) =
@@ -116,7 +124,6 @@ let getCurrentOrFirstUser (model:Model) (userList:BTSUser list) =
| Some cu, _ -> cu
| None, Some pu -> pu
| None, None -> getFirstUser userList
//| None, None -> defaultScratchUser
let getCurrentUser (model:Model) = getCurrentOrFirstUser model model.userList
@@ -212,7 +219,7 @@ let update msg (model:Users.Types.Model) : Model * Cmd<Msg> =
printf "%s" str
model, Cmd.Empty
| UpdateField field ->
{ model with scratchUser = applyUpdate field model.scratchUser } , Cmd.Empty
{ model with scratchUser = applyUpdate field model.scratchUser; ConfirmModal = ("", Msg.SwitchTab model.currentTab) } , Cmd.Empty
| Clone usr ->
{ model with scratchUser = { usr with id = 0u; name = usr.name + "_copy" }}, Cmd.Empty
| CopyFrom (usrSrc, usrDest) ->
@@ -225,9 +232,10 @@ let update msg (model:Users.Types.Model) : Model * Cmd<Msg> =
{ model with scratchUser = nusr }, Cmd.Empty
| Delete usr ->
let mdl = { model with OptionsMenuOpen = "" }
match Fable.Import.Browser.window.confirm (sprintf "Are you sure you want to delete '%s'" usr.name) with
| true -> model, Cmd.ofExistingPromise (deleteUser model.admin usr) id (box>>ErrorOccured)
| false -> model, Cmd.Empty
| true -> mdl, Cmd.ofExistingPromise (deleteUser model.admin usr) id (box>>ErrorOccured)
| false -> mdl, Cmd.Empty
| AddUser ->
{ model with PreviousScratchUser = model.scratchUser; scratchUser = { defaultScratchUser with name = "New User" }}, Cmd.ofMsg (SwitchTab General)
@@ -247,3 +255,7 @@ let update msg (model:Users.Types.Model) : Model * Cmd<Msg> =
//Browser.console.log msg
Global.alert Global.Error (string msg)
model,Cmd.Empty
| OpenOptionsMenu usrName ->
{ model with OptionsMenuOpen = usrName }, Cmd.Empty
| OpenConfirmModal (title, okMessage) ->
{model with ConfirmModal = title, okMessage}, Cmd.Empty
+13 -10
View File
@@ -9,16 +9,6 @@ type Tab =
| MDEntitlements
| OrderRouting
type Model = {
userList: BTSUser list
accountsList: BTSAccount list
scratchUser:BTSUser
PreviousScratchUser:BTSUser
currentTab:Tab
admin : IAdminService
adminData : AdminData option
}
type UserField =
| Name of string
| Password of string
@@ -53,4 +43,17 @@ type Msg =
| SwitchUser of BTSUser
| SaveUser
| ErrorOccured of obj
| OpenOptionsMenu of string
| OpenConfirmModal of string * Msg
type Model = {
userList: BTSUser list
accountsList: BTSAccount list
scratchUser:BTSUser
PreviousScratchUser:BTSUser
currentTab:Tab
admin : IAdminService
adminData : AdminData option
OptionsMenuOpen: string
ConfirmModal: string * Msg
}
+89 -30
View File
@@ -25,6 +25,11 @@ let isActiveUser id (currentUser:BTSUser) =
| true -> "is-active"
| false -> ""
let isOptionsMenuOpen userName openName =
match userName = openName with
| true -> "is-active"
| false -> ""
let saveButton (model:Users.Types.Model) dispatch =
let buttonText = if State.isNewUser model.scratchUser then "Create" else "Save"
let dirty = State.userIsdirty State.defaultScratchUser model.scratchUser (State.getCurrentUser model)
@@ -32,7 +37,7 @@ let saveButton (model:Users.Types.Model) dispatch =
let flavor = if dirty then "is-success" else "is-light"
Button.button buttonText flavor "" enabled (fun _ -> dispatch SaveUser)
let generalTabContent (model:Model) (dispatch:Msg->Unit) =
let generalTabView (model:Model) (dispatch:Msg->Unit) =
let modal = Modal.showCreate
"Create User"
(div [][
@@ -49,7 +54,6 @@ let generalTabContent (model:Model) (dispatch:Msg->Unit) =
Fields.password "Password" model.scratchUser.password [ ] (Password >> UpdateField >> dispatch)
Fields.checkbox "Active" "Unchecking this stops the user from entering orders" model.scratchUser.isActive [] (IsActive >> UpdateField >> dispatch)
(if State.isNewUser model.scratchUser then modal else span[][])
Button.button "Remove User" "is-danger-hover" "times" Button.Enabled (fun _ -> dispatch <| Delete model.scratchUser)
]
let accountNameLookup (accountsList:BTSAccount list) (id:string) =
@@ -58,7 +62,7 @@ let accountNameLookup (accountsList:BTSAccount list) (id:string) =
| None -> "Account Not Found"
let accountsTabContent (model:Model) (dispatch:Msg->Unit) =
let accountsTabView (model:Model) (dispatch:Msg->Unit) =
let accountPermissions = model.scratchUser.userData.accountPermissions.accountPermissions
let keys =
@@ -87,12 +91,18 @@ let accountsTabContent (model:Model) (dispatch:Msg->Unit) =
let rows:TableControl.row list =
[for acc in accMap do yield {
cells = [
//TableControl.Cell(Button.removeButton Button.Enabled (fun _ -> key |> (RemoveAccount >> UpdateField >> dispatch)))
TableControl.Cell(str acc.Value)
{ content = (Fields.checkbox "" "" (
keymap.Contains <| acc.Value)
[]
(fun _ -> acc.Key |> ((match (keymap.Contains <| acc.Value) with | true -> RemoveAccount | false -> AddAccount) >> UpdateField >> dispatch))
(fun _ -> (
let message:Msg = acc.Key |> (RemoveAccount >> UpdateField)
match (keymap.Contains <| acc.Value) with
| true -> (OpenConfirmModal ((sprintf "Are you sure you want to remove trading permission for %s?" acc.Value), message))
| false -> (acc.Key |> (AddAccount >> UpdateField))
|> dispatch
)
)
);
className = "";
isHeader = false;
@@ -118,7 +128,7 @@ let accountsTabContent (model:Model) (dispatch:Msg->Unit) =
TableControl.createSelectorTable (Some headerRow) rows
]
let mdEntitlementsTabContent (model:Model) (dispatch:Msg->Unit) =
let mdEntitlementsTabView (model:Model) (dispatch:Msg->Unit) =
let cmeData = model.scratchUser.userData.exchangeMdEntitlementData.cmeData
div []
[
@@ -134,7 +144,7 @@ let mdEntitlementsTabContent (model:Model) (dispatch:Msg->Unit) =
]
]
let orderRoutingTabContent (model:Model) (dispatch:Msg->Unit) =
let orderRoutingTabView (model:Model) (dispatch:Msg->Unit) =
let cmeData = model.scratchUser.userData.exchangeUserData.cmeData
div []
[
@@ -143,8 +153,8 @@ let orderRoutingTabContent (model:Model) (dispatch:Msg->Unit) =
[
Fields.text "Operator ID" cmeData.operatorId [] (OperatorID >> UpdateField >> dispatch)
//Fields.text "ATS Operator ID" cmeData.atsOperatorId [] (ATSOperatorID >> UpdateField >> dispatch)
//Fields.text "SMP ID" cmeData.smpId [] (SMPID >> UpdateField >> dispatch)
Fields.text "SMP Instruction" cmeData.smpInstruction [] (SMPInstruction >> UpdateField >> dispatch)
Fields.text "SMP ID" cmeData.smpId [] (SMPID >> UpdateField >> dispatch)
Fields.mapSelect "SMP Instruction" State.SMPInstructionMap None (Some cmeData.smpInstruction) (SMPInstruction >> UpdateField >> dispatch)
Fields.text "Location" cmeData.location [] (Location >> UpdateField >> dispatch)
//Fields.text "Max Order Rate Per Connection" cmeData.maxOrderRatePerConnection [] (MaxOrderRatePerConnection >> UpdateField >> dispatch)
//Fields.map "Misc Tag Mapping" cmeData.miscTags [] (MiscTags >> UpdateField >> dispatch)
@@ -155,10 +165,10 @@ let tabContent (model:Model) (dispatch:Msg->Unit) =
div [Key (string model.scratchUser.id); ClassName "is-tab-content"] [
(match model.currentTab, (State.userIsSelected model.scratchUser State.defaultScratchUser) with
| _, false -> p [Style [ Color "Red" ]] [ str "Select a User" ]
| Tab.General, true -> generalTabContent model dispatch
| Tab.Accounts, true -> accountsTabContent model dispatch
| Tab.MDEntitlements, true -> mdEntitlementsTabContent model dispatch
| Tab.OrderRouting, true -> orderRoutingTabContent model dispatch)
| Tab.General, true -> generalTabView model dispatch
| Tab.Accounts, true -> accountsTabView model dispatch
| Tab.MDEntitlements, true -> mdEntitlementsTabView model dispatch
| Tab.OrderRouting, true -> orderRoutingTabView model dispatch)
]
let userControls (model:Model) (dispatch:Msg->Unit) =
@@ -167,7 +177,6 @@ let userControls (model:Model) (dispatch:Msg->Unit) =
div [ ClassName "is-main-control-bar" ]
[
nbsp.element
saveButton model dispatch
Button.button "Revert" "is-light" "" (if dirty then Button.Enabled else Button.Disabled) (fun _ -> SwitchUser (currentUser) |> dispatch)
(*p [ ClassName "control" ]
@@ -254,28 +263,59 @@ let userSelectionGrid (usersList:BTSUser list) (currentUser:BTSUser) (dispatch:M
TableControl.createSelectorTable (Some headerRow) rws
]
let menuItem (user:BTSUser) (selectedUser:BTSUser) model dispatch =
a [ ClassName (isActiveUser user.id selectedUser)
OnClick (fun _ -> SwitchUser user |> dispatch)
] [
span [] [ str user.name ]
span [ Class "is-pulled-right menu-icon" ]
[
div [ Class (sprintf "dropdown %s" (isOptionsMenuOpen user.name model.OptionsMenuOpen)) ]
[ div [ Class "dropdown-trigger" ]
[ button [ Class "button"
AriaHasPopup true
OnClick (fun _ -> user.name |> OpenOptionsMenu |> dispatch)
HTMLAttr.Custom ("aria-controls", (sprintf "dropdown-menu-%s" user.name))
]
[ span [ Class "icon is-small" ]
[ i [ Class "fa fa-ellipsis-v"
HTMLAttr.Custom ("aria-hidden", "true") ][ ]
]
]
]
div [ Class "dropdown-menu"
Id (sprintf "dropdown-menu-%s" user.name)
Role "menu"
let NavRoot (usersList:BTSUser list) (currentUser:BTSUser) (dispatch:Msg->Unit) =
]
[ div [ Class "dropdown-content" ]
[ //hr [ Class "dropdown-divider" ]
a [ Class "dropdown-item"
OnClick (fun _ -> dispatch <| Delete user)
]
[ str "Remove" ]
]
]
]
]
]
let NavRoot (usersList:BTSUser list) (currentUser:BTSUser) model (dispatch:Msg->Unit) =
let activeUsers =
usersList |> List.sortBy (fun u -> u.name.ToLower())
div [ Class "column is-narrow is-sidebar-menu" ]
[ aside [ Class "menu" ]
[ div [ Class "has-text-right" ]
[
Button.faRoundButton "Add User" "plus" Button.Enabled (fun _ -> dispatch <| AddUser)
]
[ p [ Class "menu-label" ] [
span [Class "is-size-4"] [str "Users"]
span [ Class "is-pulled-right circle-icon" ]
[ Button.fabutton "Add User" "plus-circle" "" Button.Enabled (fun _ -> dispatch AddUser) ]
]
ul [ Class "menu-list" ]
[
for u in activeUsers do yield li []
[ a [
ClassName (isActiveUser u.id currentUser)
OnClick (fun _ -> (u |> SwitchUser |> dispatch))
]
[
str u.name
]
]
[ menuItem u currentUser model dispatch]
]
]
]
@@ -297,13 +337,31 @@ let selectionPageContent (model:Model) (dispatch:Msg->Unit) =
]
let root (model:Model) (dispatch:Msg->Unit) =
(*
Fable.Import.Browser.document.addEventListener_keydown (fun (e:Fable.Import.Browser.KeyboardEvent) ->
match e.ctrlKey, (e.keyCode = 83.0) with
| true, true ->
match (State.userIsdirty State.defaultScratchUser model.scratchUser (State.getCurrentUser model)) with
| true -> SaveUser |> dispatch |> e.preventDefault
| false -> () |> e.preventDefault
| _, _ -> ()
)
*)
let modal = match (fst model.ConfirmModal) with
| "" -> span [] []
| _ -> Modal.showConfirm (fst model.ConfirmModal) (fun () -> (snd model.ConfirmModal) |> dispatch) (fun _ -> OpenConfirmModal ("", Msg.SwitchTab model.currentTab ) |> dispatch)
(match model.adminData with
| None -> div[][str "Loading user list..."]
| Some data ->
div
[ Class "columns is-fullheight" ]
[ NavRoot model.userList model.scratchUser dispatch
[ Class "columns is-fullheight"
OnClick (fun _ ->
match model.OptionsMenuOpen.Length > 0 with
| true -> "" |> OpenOptionsMenu |> dispatch
| _ -> ()
)
]
[ NavRoot model.userList model.scratchUser model dispatch
div [ Class "column is-main-content" ]
[
div [ ClassName "tabs is-boxed" ]
@@ -325,6 +383,7 @@ let root (model:Model) (dispatch:Msg->Unit) =
]
tabContent model dispatch
userControls model dispatch
modal
]
]