SPARK-1421: Accounts and Connections are now selected with checkboxes

This commit is contained in:
Michael Harding committed 2018-06-28 13:56:03 -04:00
1 parent b53825baa9
commit 55fc880b2e
6 files changed
+140 -101

No files matched your search

+3
View File
@@ -123,4 +123,7 @@ body {
height:2.5rem;
vertical-align: middle;
}
.is-checkbox-cell {
width: 3rem;
}
}
+20 -15
View File
@@ -491,29 +491,34 @@ let positionLimitsView model dispatch =
let ConnectionsView (model:Accounts.Types.Model) dispatch =
let conNames = model.scratch.connections.exchangeConnectionNames
let rws:TableControl.row list =
[for name in conNames do yield {
cells = [
(TableControl.Cell (Button.removeButton Button.Enabled (fun _ -> name |> ( RemoveConnection >> dispatch))))
(TableControl.Cell (str name))
]
className=""
header = None
}
]
let cons = match model.adminData with
| None -> Array.empty<ExchangeConnection>
| Some data -> data.connections
let conMap =
cons
|> Array.filter (fun a -> not <| (Array.contains a.name conNames))
|> Array.map (fun a -> a.id.ToString(), a.name)
|> Map.ofArray
let rows =
rws @ [{cells = [ {content = Fields.mapSelect "" conMap (Some "Add Connection") None (fun v -> v |> (AddConnection >> dispatch)); className = ""; isHeader = true; colSpan = 2 } ]; className = ""; header = None }]
let rows:TableControl.row list =
[for c in conMap do yield {
cells = [
{ 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)))
);
className = "is-checkbox-cell";
isHeader = false;
colSpan = 0
}
(TableControl.Cell (str c.Value))
]
className=""
header = None
}
]
div []
[
TableControl.createSelectorTable None rows
@@ -597,7 +602,7 @@ let accountSelectionGrid (accountList:BTSAccount list) (currentAccount:BTSAccoun
{
cells =
[
TableControl.Cell (str "Username")
TableControl.Cell (str "Account Name")
TableControl.Cell (str "Active")
TableControl.Cell (str "Description")
]
+62 -62
View File
@@ -9,13 +9,13 @@ open Global
open Fable
open JSMap
let text (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
let text (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
div [ ClassName "field" ]
[
[
label [ ClassName "label" ]
[ str lbl ]
div [ ClassName "control" ]
[ input ([
[ input ([
ClassName "input"
Type "text"
Value dv
@@ -24,13 +24,13 @@ let text (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
]
]
let textPair (v:string*string) (keyAttrs:IHTMLProp list) (valueAttrs:IHTMLProp list) (thirdCol:ReactElement list) (onchange: (string*string) -> string -> string -> unit) =
let textPair (v:string*string) (keyAttrs:IHTMLProp list) (valueAttrs:IHTMLProp list) (thirdCol:ReactElement list) (onchange: (string*string) -> string -> string -> unit) =
div [ ClassName "columns" ]
[
[
div [ ClassName "column is-3" ]
[
input (
[
[
ClassName "input"
Type "text"
Value (fst v)
@@ -43,9 +43,9 @@ let textPair (v:string*string) (keyAttrs:IHTMLProp list) (valueAttrs:IHTMLProp l
str ":"
]
div [ ClassName "column is-3" ]
[
[
input (
[
[
ClassName "input"
Type "text"
Value (snd v)
@@ -56,19 +56,19 @@ let textPair (v:string*string) (keyAttrs:IHTMLProp list) (valueAttrs:IHTMLProp l
div [ ClassName "column" ] thirdCol
]
let map (lbl:string) (dv:JSMap<string>) (attrs:IHTMLProp list) (onchange: JSMap<string> -> unit) =
let remove (item: string*string) =
let map (lbl:string) (dv:JSMap<string>) (attrs:IHTMLProp list) (onchange: JSMap<string> -> unit) =
let remove (item: string*string) =
let mp = JSMap.remove (fst item) dv
onchange (mp)
let newEntry (value:string) =
let newEntry (value:string) =
let origin = "", value
let newValue = value, ""
let rmp = JSMap.remove (fst origin) dv
let mp = JSMap.add (fst newValue) (snd newValue) rmp
onchange (mp)
let change (origin: string*string) (name:string) (value:string) =
let change (origin: string*string) (name:string) (value:string) =
let newValue = match name with
| "key" -> value, snd origin
| "value" -> fst origin, value
@@ -76,46 +76,46 @@ let map (lbl:string) (dv:JSMap<string>) (attrs:IHTMLProp list) (onchange: JSMap<
let rmp = JSMap.remove (fst origin) dv
let mp = JSMap.add (fst newValue) (snd newValue) rmp
onchange (mp)
let sortedSeq = Seq.sortBy (fst) (Seq.ofArray (JSMap.toArray dv))
let elementList:ReactElement list =
[for i in sortedSeq do yield
let elementList:ReactElement list =
[for i in sortedSeq do yield
(
match (fst i) with
| "" ->
textPair
("", (snd i) )
[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
]
| "" ->
textPair
("", (snd i) )
[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
]
change
| _ ->
textPair
i
[HTMLAttr.Disabled true]
[]
[Button.fabutton "Delete" "times" Button.Enabled (fun _ -> (remove i))]
| _ ->
textPair
i
[HTMLAttr.Disabled true]
[]
[Button.fabutton "Delete" "times" Button.Enabled (fun _ -> (remove i))]
change
)]
div [ ClassName "field" ]
[
label [ ClassName "label" ] [ str lbl ]
[
label [ ClassName "label" ] [ str lbl ]
div [] elementList
Button.fabutton "Add" "plus" Button.Enabled ((fun _ -> change ("","") "" ""))
Button.fabutton "Add" "plus" Button.Enabled ((fun _ -> change ("","") "" ""))
]
let password (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
let password (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
div [ ClassName "field" ]
[
[
label [ ClassName "label" ]
[ str lbl ]
div [ ClassName "control" ]
[ input ([
[ input ([
ClassName "input"
Type "password"
Value dv
@@ -144,13 +144,13 @@ let enumSelect<'a> (lbl:string) (dv:'a) (values:'a[]) (attrs:IHTMLProp list) (on
]
]
let checkbox (lbl:string) (description:string) (dv:bool) (attrs:IHTMLProp list) (onchange:bool->unit) =
let checkbox (lbl:string) (description:string) (dv:bool) (attrs:IHTMLProp list) (onchange:bool->unit) =
div [ ClassName "field" ]
[
[
div [ ClassName "control" ]
[
[
label [ ] [
input ([
input ([
ClassName "checkbox"
Type "checkbox"
Checked dv
@@ -162,49 +162,49 @@ let checkbox (lbl:string) (description:string) (dv:bool) (attrs:IHTMLProp list)
span [ClassName "is-size-7 has-text-grey-mid"][ str description]
]
]
let mapSelect (lbl:string) (options:Map<string,string>) (defaultText:string option) (defaultValue:string option) (onchange:'a->unit) =
let optList:ReactElement list =
let mapSelect (lbl:string) (options:Map<string,string>) (defaultText:string option) (defaultValue:string option) (onchange:'a->unit) =
let optList:ReactElement list =
match defaultText with
| None -> ([ for opt in options do yield option [ Value opt.Key ] [ str (opt.Value) ] ])
| Some dt -> (option [] [str dt]) :: ([ for opt in options do yield option [ Value opt.Key ] [ str (opt.Value) ] ])
let dv = match defaultValue with
| Some d ->
let dv = match defaultValue with
| Some d ->
d
| None -> ""
div [ ClassName "field" ]
[
label [ ClassName "label" ] [ str lbl ]
[
label [ ClassName "label" ] [ str lbl ]
div [ ClassName "control" ]
[
[
div [ ClassName "select" ]
[
[
select [
Value dv
OnChange (fun ev -> !!ev.target?value |> onchange)
]
optList
]
]
]
]
]
let simpleSelect (lbl:string) (options:string list) (defaultValue:string) (onchange:'a->unit) =
let simpleSelect (lbl:string) (options:string list) (defaultValue:string) (onchange:'a->unit) =
div [ ClassName "field" ]
[
label [ ClassName "label" ] [ str lbl ]
[
label [ ClassName "label" ] [ str lbl ]
div [ ClassName "control" ]
[
[
div [ ClassName "select" ]
[
select [
[
select [
Value defaultValue
OnChange (fun ev -> !!ev.target?value |> onchange)
]
[ for opt in options do yield option [ Value opt ] [ str (opt) ] ]
]
]
[ for opt in options do yield option [ Value opt ] [ str (opt) ] ]
]
]
]
+17 -1
View File
@@ -45,4 +45,20 @@ let createTable (headers:row option) (rl:row list) = createTableWithStyle header
let createDataTable (headers:row option) (rl:row list) = createTableWithStyle headers rl "bts-data-table" []
let createSelectorTable (headers:row option) (rl:row list) = createTableWithStyle headers rl "bts-selector-table" []
let createSelectorTableWithStyle (headers:row option) (rl:row list) className styles =
let rws = List.map<row,ReactElement> (createRow false) rl
let tbl = match headers with
| Some h ->
[
thead [] [ createRow true h]
tbody [] rws
]
| None ->
[ tbody [] rws ]
table [ ClassName (sprintf "table is-narrow bts-selector-table %s" className); Style styles ] tbl
(*
If a callback is provided add a checkbox as the first column and set a background color if it is checked... in addition to the callback
*)
let createSelectorTable (headers:row option) (rl:row list) = createSelectorTableWithStyle headers rl "" []
+1 -1
View File
@@ -12,7 +12,7 @@ open Fable.PowerPack.PromiseImpl
open bts.api.admin
open Global
let isNewAccount (user:BTSUser) =
let isNewUser (user:BTSUser) =
user.id = 0u && user.isPresent
let getAdminData (admin:IAdminService) =
+37 -22
View File
@@ -26,7 +26,7 @@ let isActiveUser id (currentUser:BTSUser) =
| false -> ""
let saveButton (model:Users.Types.Model) dispatch =
let buttonText = if State.isNewAccount model.scratchUser then "Create" else "Save"
let buttonText = if State.isNewUser model.scratchUser then "Create" else "Save"
let dirty = State.userIsdirty State.defaultScratchUser model.scratchUser (State.getCurrentUser model)
let enabled = if dirty then Button.Enabled else Button.Disabled
let flavor = if dirty then "is-success" else "is-light"
@@ -48,7 +48,7 @@ let generalTabContent (model:Model) (dispatch:Msg->Unit) =
Fields.text "Name" model.scratchUser.name [ ] (Name >> UpdateField >> dispatch)
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.isNewAccount model.scratchUser then modal else span[][])
(if State.isNewUser model.scratchUser then modal else span[][])
Button.button "Remove" "" "times" Button.Enabled (fun _ -> dispatch <| Delete model.scratchUser)
]
@@ -60,14 +60,23 @@ let accountNameLookup (accountsList:BTSAccount list) (id:string) =
let accountsTabContent (model:Model) (dispatch:Msg->Unit) =
let accountPermissions = model.scratchUser.userData.accountPermissions.accountPermissions
let keys =
Global.Reflection.keys accountPermissions
|> Array.map (fun i -> i, accountNameLookup model.accountsList i)
let keymap =
keys |> Array.map snd |> Set.ofArray
let accMap =
model.accountsList
|> List.filter (fun a -> a.isPresent)
|> List.map (fun a -> a.id.ToString(), a.name)
|> Map.ofList
let headerRow:TableControl.row =
{
cells =
[
TableControl.Cell(str "")
TableControl.Cell(str "Account")
TableControl.Cell(str "Trading Permission")
TableControl.Cell(str "Admin Permission")
@@ -75,30 +84,34 @@ let accountsTabContent (model:Model) (dispatch:Msg->Unit) =
className = ""
header = None
}
let rws:TableControl.row list =
[for (key,name) in keys do yield {
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 name)
TableControl.Cell( str "Full")
TableControl.Cell(str "Full")
//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))
);
className = "";
isHeader = false;
colSpan = 0
}
{ content = (Fields.checkbox "" "" (
model.scratchUser.name.Contains "bts" || model.scratchUser.name.Contains "admin")
[Disabled true]
ignore
);
className = "";
isHeader = false;
colSpan = 0
}
]
className=""
header = None
}
]
let keymap =
keys |> Array.map snd |> Set.ofArray
let accMap =
model.accountsList
|> List.filter (fun a -> a.isPresent && not <| keymap.Contains a.name)
|> List.map (fun a -> a.id.ToString(), a.name)
|> Map.ofList
let rows =
rws @ [{cells = [
{ content = Fields.mapSelect "" accMap (Some "Add Account") None (AddAccount >> UpdateField >> dispatch); className = ""; isHeader = false; colSpan = 4 }
]; className = ""; header = None }]
div []
[
@@ -216,6 +229,7 @@ let userSelectionGrid (usersList:BTSUser list) (currentUser:BTSUser) (dispatch:M
{
cells =
[
TableControl.Cell (str "")
TableControl.Cell (str "Username")
TableControl.Cell (str "Active")
]
@@ -226,6 +240,7 @@ let userSelectionGrid (usersList:BTSUser list) (currentUser:BTSUser) (dispatch:M
[ for u in activeUsers do yield {
cells =
[
{ content = (Fields.checkbox "" "" false [] ignore); className = "is-checkbox-cell"; isHeader = false; colSpan = 0 }
TableControl.Cell (a [ OnClick (fun _ -> (u |> SwitchUser |> dispatch))][
str u.name
])
@@ -278,7 +293,7 @@ let selectionPageContent (model:Model) (dispatch:Msg->Unit) =
(fun _ -> CancelAddUser |> dispatch)
div [] [
userSelectionGrid model.userList model.scratchUser dispatch
(if State.isNewAccount model.scratchUser then modal else span[][])
(if State.isNewUser model.scratchUser then modal else span[][])
]
let root (model:Model) (dispatch:Msg->Unit) =