WebUI: add initial Users page
This commit is contained in:
1 parent
27940b65ee
commit
9bd6c53642
7 files changed
+283
-3
No files matched your search
@@ -20,7 +20,8 @@ open Elmish.React.Common
|
||||
let isCurrentPage page currentPage =
|
||||
match page, currentPage with
|
||||
| HomeModel _, HomeModel _ -> true
|
||||
| CounterModel _, CounterModel _ -> true
|
||||
| CounterModel _, CounterModel _ -> true
|
||||
| UsersModel _, UsersModel _ -> true
|
||||
| _ -> false
|
||||
|
||||
|
||||
@@ -42,6 +43,8 @@ let menu currentPage sc dispatch =
|
||||
[ ClassName "menu-list" ]
|
||||
[ menuItem "Home" (tmap (Home.State.init sc) (HomeModel,Cmd.map HomeMsg)) currentPage dispatch
|
||||
menuItem "Counter sample" (tmap (Counter.State.init()) (CounterModel,Cmd.map CounterMsg)) currentPage dispatch
|
||||
menuItem "Users" (tmap (Users.State.init()) (UsersModel, Cmd.map UsersMsg)) currentPage dispatch
|
||||
// menuItem "About" Page.About currentPage dispatch
|
||||
] ]
|
||||
|
||||
let menu' = lazyView3With (fun a b -> isCurrentPage (fst a) (fst b)) menu
|
||||
@@ -61,7 +64,7 @@ let topLevel sc currentPage dispatch content =
|
||||
[ div
|
||||
[ ClassName "columns" ]
|
||||
[ div
|
||||
[ ClassName "column is-3" ]
|
||||
[ ClassName "column is-2" ]
|
||||
[ menu' currentPage sc dispatch ]
|
||||
div
|
||||
[ ClassName "column" ]
|
||||
@@ -74,8 +77,9 @@ let root model dispatch =
|
||||
match model.page with
|
||||
| HomeModel m -> Home.View.root m (HomeMsg>>dispatch) |> topLevel model.context model.page dispatch
|
||||
| CounterModel c -> Counter.View.root c (CounterMsg>>dispatch) |> topLevel model.context model.page dispatch
|
||||
| UsersModel m -> Users.View.root m (UsersMsg>>dispatch) |> topLevel model.context model.page dispatch
|
||||
| None -> Info.View.root |> topLevel model.context None dispatch
|
||||
|
||||
|
||||
open Elmish.React
|
||||
open Elmish.Debug
|
||||
open Elmish.HMR
|
||||
|
||||
@@ -14,6 +14,9 @@ let init () =
|
||||
|
||||
let updateLoggedIn msg model =
|
||||
match msg, model.page with
|
||||
| UsersMsg msg, UsersModel m ->
|
||||
let (Users, UsersCmd) = Users.State.update msg m
|
||||
{ model with page = UsersModel Users }, Cmd.map UsersMsg UsersCmd
|
||||
| CounterMsg msg, CounterModel m ->
|
||||
let (counter, counterCmd) = Counter.State.update msg m
|
||||
{ model with page = CounterModel counter }, Cmd.map CounterMsg counterCmd
|
||||
|
||||
@@ -7,11 +7,13 @@ open Imports
|
||||
type Page =
|
||||
| CounterModel of Counter.Types.Model
|
||||
| HomeModel of Home.Types.Model
|
||||
| UsersModel of Users.Types.Model
|
||||
| None
|
||||
|
||||
type Msg =
|
||||
| CounterMsg of Counter.Types.Msg
|
||||
| HomeMsg of Home.Types.Msg
|
||||
| UsersMsg of Users.Types.Msg
|
||||
| LoginMsg of Login.Message
|
||||
| Navigate of Page*Elmish.Cmd<Msg>
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
module Users.State
|
||||
|
||||
open Elmish
|
||||
open Types
|
||||
open System
|
||||
open System.Runtime.InteropServices
|
||||
|
||||
let blankUser = {
|
||||
id = 0;
|
||||
isActive = false
|
||||
username= "NewUser"
|
||||
password = ""
|
||||
userType = UserType.NonAdmin
|
||||
accounts = None
|
||||
mdEntitlements = None
|
||||
operator = None
|
||||
}
|
||||
|
||||
let init () : Model * Cmd<Msg> =
|
||||
let tempList = [
|
||||
{ blankUser with
|
||||
id = 0;
|
||||
isActive = true
|
||||
username= "bts"
|
||||
password = ""
|
||||
userType = UserType.Admin
|
||||
}
|
||||
{ blankUser with
|
||||
id = 1;
|
||||
isActive = true
|
||||
username= "userTwo"
|
||||
password = ""
|
||||
}
|
||||
{ blankUser with
|
||||
id = 2;
|
||||
isActive = true
|
||||
username= "userThree"
|
||||
password = ""
|
||||
}
|
||||
]
|
||||
|
||||
{
|
||||
userList = tempList
|
||||
currentUser = tempList.Head
|
||||
currentTab= Tab.General
|
||||
}, Cmd.Empty
|
||||
|
||||
|
||||
let rec removeUser (user:User) (userList:User list) =
|
||||
match userList with
|
||||
| hd::tl when (fun usr -> usr.id = user.id) hd -> tl
|
||||
| hd::tl -> hd::removeUser user tl
|
||||
| _ -> []
|
||||
|
||||
|
||||
let update msg model : Model * Cmd<Msg> =
|
||||
match msg with
|
||||
| ChangeUserName str ->
|
||||
{ model with currentUser = {model.currentUser with username=str}}, Cmd.Empty
|
||||
| ChangePass str ->
|
||||
{ model with currentUser = {model.currentUser with password=str}}, Cmd.Empty
|
||||
| ChangeActive boo ->
|
||||
{ model with currentUser = {model.currentUser with isActive=boo}}, Cmd.Empty
|
||||
| Clone usr ->
|
||||
let rnd = System.Random()
|
||||
let rndId = rnd.Next()
|
||||
let nusr = {usr with id = usr.id + rndId }
|
||||
{ model with userList = nusr::model.userList; currentUser=nusr}, Cmd.Empty
|
||||
| CopyFrom (usrSrc, usrDest) ->
|
||||
let nusr = { usrSrc with
|
||||
id = usrDest.id
|
||||
username= usrDest.username
|
||||
password = usrDest.password
|
||||
isActive = usrDest.isActive
|
||||
userType = usrDest.userType
|
||||
}
|
||||
let nuList = removeUser usrDest model.userList
|
||||
{ model with userList = nusr::nuList }, Cmd.Empty
|
||||
| Delete usr ->
|
||||
{ model with userList = removeUser usr model.userList; currentUser=model.userList.Head }, Cmd.Empty
|
||||
| SwitchTab tb ->
|
||||
{model with currentTab = tb}, Cmd.Empty
|
||||
| SwitchUser usr ->
|
||||
{ model with currentUser = usr}, Cmd.Empty
|
||||
@@ -0,0 +1,53 @@
|
||||
module Users.Types
|
||||
open System
|
||||
|
||||
type UserType =
|
||||
| SuperAdmin
|
||||
| Admin
|
||||
| NonAdmin
|
||||
|
||||
type Operator = {
|
||||
operatorId:int
|
||||
canTrade:bool
|
||||
}
|
||||
|
||||
type Account = {
|
||||
id:int
|
||||
accountName:string
|
||||
}
|
||||
|
||||
type User = {
|
||||
id: int
|
||||
isActive:bool
|
||||
username:string
|
||||
password:string
|
||||
userType:UserType
|
||||
accounts:Account list option
|
||||
mdEntitlements:string list option
|
||||
operator:Operator list option
|
||||
|
||||
}
|
||||
|
||||
type Tab =
|
||||
| General
|
||||
| Accounts
|
||||
| MDEntitlements
|
||||
| OrderRouting
|
||||
|
||||
type Model = {
|
||||
userList: User list
|
||||
currentUser:User
|
||||
currentTab:Tab
|
||||
}
|
||||
|
||||
|
||||
type Msg =
|
||||
| ChangeUserName of string
|
||||
| ChangePass of string
|
||||
| ChangeActive of bool
|
||||
| Clone of User
|
||||
| CopyFrom of User * User
|
||||
| Delete of User
|
||||
| SwitchTab of Tab
|
||||
| SwitchUser of User
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
module Users.View
|
||||
|
||||
open Fable.Core
|
||||
open Fable.Core.JsInterop
|
||||
open Fable.Helpers.React
|
||||
open Fable.Helpers.React.Props
|
||||
open Types
|
||||
open Login
|
||||
|
||||
let isActiveTab tab currentTab =
|
||||
let ia = "is-active"
|
||||
match tab, currentTab with
|
||||
| Tab.General, Tab.General -> ia
|
||||
| Tab.Accounts, Tab.Accounts -> ia
|
||||
| Tab.MDEntitlements, Tab.MDEntitlements -> ia
|
||||
| Tab.OrderRouting, Tab.OrderRouting -> ia
|
||||
| _ -> ""
|
||||
|
||||
let isActiveUser (id:int) (currentId:int) =
|
||||
match id = currentId with
|
||||
| true -> "is-active"
|
||||
| false -> ""
|
||||
|
||||
let tabContent (currentTab:Tab) (currentUser:User) (dispatch:Msg->Unit) =
|
||||
match currentTab with
|
||||
| Tab.General ->
|
||||
div []
|
||||
[
|
||||
p
|
||||
[ ClassName "control" ]
|
||||
[ input
|
||||
[ ClassName "input"
|
||||
Type "text"
|
||||
Placeholder "Type your name"
|
||||
DefaultValue currentUser.username
|
||||
AutoFocus true
|
||||
OnChange (fun ev -> !!ev.target?value |> ChangeUserName |> dispatch ) ]
|
||||
]
|
||||
br [ ]
|
||||
span
|
||||
[ ]
|
||||
[ str (sprintf "Hello %s" currentUser.username) ]
|
||||
]
|
||||
| Tab.Accounts -> div [] [ str <| sprintf "Accounts for %s" currentUser.username ]
|
||||
| Tab.MDEntitlements -> div [] [ str <| sprintf "Market Data Things for %s" currentUser.username ]
|
||||
| Tab.OrderRouting -> div [] [ str <| sprintf "Order Routing for %s" currentUser.username ]
|
||||
|
||||
let usersMenu (usersList:User list) (currentUser:User) (dispatch:Msg->Unit) =
|
||||
div
|
||||
[ ClassName "column is-3" ]
|
||||
[
|
||||
aside [ ClassName "menu" ]
|
||||
[ p [ ClassName "menu-label" ]
|
||||
[ str "Users" ]
|
||||
ul [ ClassName "menu-list" ]
|
||||
[ li [ ]
|
||||
[ a [ ]
|
||||
[ str "" ]
|
||||
ul [ ]
|
||||
[ for u in usersList do yield li [] [
|
||||
a [
|
||||
ClassName (isActiveUser u.id currentUser.id)
|
||||
OnClick (fun _ -> (u |> SwitchUser |> dispatch))
|
||||
]
|
||||
[ str u.username ]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
div [ ClassName "field is-grouped has-addons" ]
|
||||
[ p [ ClassName "control" ]
|
||||
[ a [ ClassName "button is-light"
|
||||
Title "Clone"
|
||||
OnClick (fun _ -> dispatch <| Clone currentUser)
|
||||
]
|
||||
[ span [ ClassName "icon is-small" ]
|
||||
[ i [ ClassName "fa fa-clone" ]
|
||||
[ ] ]
|
||||
]
|
||||
]
|
||||
p [ ClassName "control" ]
|
||||
[ a [ ClassName "button is-light"
|
||||
Title "Delete"
|
||||
OnClick (fun _ -> dispatch <| Delete currentUser)
|
||||
]
|
||||
[ span [ ClassName "icon is-small" ]
|
||||
[ i [ ClassName "fa fa-minus" ] [ ]
|
||||
]
|
||||
]
|
||||
]
|
||||
p [ ClassName "control" ]
|
||||
[ a [ ClassName "button is-light" ]
|
||||
[ span [ ClassName "icon is-small"
|
||||
Title "Copy..."
|
||||
OnClick (fun _ -> dispatch <| CopyFrom (usersList.Head, currentUser))
|
||||
]
|
||||
[ i [ ClassName "fa fa-copy" ]
|
||||
[ ] ]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
let root (model:Users.Types.Model) (dispatch:Msg->Unit) =
|
||||
div
|
||||
[ ClassName "columns" ]
|
||||
[
|
||||
usersMenu model.userList model.currentUser dispatch
|
||||
div
|
||||
[ ClassName "column" ]
|
||||
[
|
||||
div [ ClassName "tabs is-small is-boxed" ]
|
||||
[ ul [ ]
|
||||
[ li [ ClassName (isActiveTab Tab.General model.currentTab) ]
|
||||
[ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.General)) ]
|
||||
[ str "General" ] ]
|
||||
li [ ClassName (isActiveTab Tab.Accounts model.currentTab) ]
|
||||
[ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.Accounts)) ]
|
||||
[ str "Accounts" ] ]
|
||||
li [ ClassName (isActiveTab Tab.MDEntitlements model.currentTab) ]
|
||||
[ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.MDEntitlements)) ]
|
||||
[ str "Market Data Entitlements" ] ]
|
||||
li [ ClassName (isActiveTab Tab.OrderRouting model.currentTab) ]
|
||||
[ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.OrderRouting)) ]
|
||||
[ str "Order Routing" ] ] ]
|
||||
]
|
||||
tabContent model.currentTab model.currentUser dispatch
|
||||
]
|
||||
]
|
||||
@@ -21,6 +21,10 @@
|
||||
<Compile Include="Home/Types.fs" />
|
||||
<Compile Include="Home/State.fs" />
|
||||
<Compile Include="Home/View.fs" />
|
||||
<!-- Users -->
|
||||
<Compile Include="Users/Types.fs" />
|
||||
<Compile Include="Users/State.fs" />
|
||||
<Compile Include="Users/View.fs" />
|
||||
<!-- Navbar -->
|
||||
<Compile Include="Navbar/View.fs" />
|
||||
<!-- App -->
|
||||
|
||||
Reference in new issue
Block a user