Commit 70db3d12 authored by Mathieu's avatar Mathieu

Add user function

parent 4c7fab34
......@@ -46,15 +46,22 @@ object AdminPanel {
def save(expandableRow: ExpandableRow, name: TextCell, email: TextCell, password: PasswordCell, role: LabelCell, status: Status): Unit = {
//SET USER
val userRole: Role = role.get
if (name.get.isEmpty)
rows.update(rows.now.filterNot(_ == expandableRow))
else {
val userRole: Role = role.get
val modifiedUser = UserData(name.get, email.get, password.get, userRole)
Post[AdminApi].updated(modifiedUser).call().foreach {
rows() = _
val modifiedUser = UserData(name.get, email.get, password.get, userRole)
upsert(modifiedUser)
}
}
def upsert(userData: UserData) =
Post[AdminApi].upserted(userData).call().foreach {
rows() = _
}
def closeAll(except: ExpandableRow) = rows.now.filterNot {
_ == except
}.foreach {
......@@ -62,7 +69,7 @@ object AdminPanel {
}
def buildExpandable(userName: String, userEmail: String, userPassword: String, userRole: Role, userStatus: Status, expanded: Boolean = false): ExpandableRow = {
def buildExpandable(userName: String = "", userEmail: String = "", userPassword: String = "", userRole: Role = "", userStatus: Status = user, expanded: Boolean = false): ExpandableRow = {
val aVar = Var(expanded)
def roleStyle(s: Role) =
......@@ -127,15 +134,20 @@ object AdminPanel {
Post[AdminApi].users().call().foreach { us =>
println("US " + us)
rows() = us
}
val addUserButton = button(btn_success, "Add", onclick := { () =>
val row = buildExpandable(userRole = user, expanded = true)
rows.update(rows.now :+ row)
})
val headerStyle: ModifierSeq = Seq(
height := 40.85
)
val editablePanel = div(
addUserButton(styles.display.flex, flexDirection.row, styles.justifyContent.flexEnd),
Rx {
div(styles.display.flex, flexDirection.row, styles.justifyContent.center)(
EdiTable(Seq("Name", "Status"), rows()).render(width := "90%")
......
......@@ -9,10 +9,9 @@ object AdminApiImpl extends shared.AdminApi {
DB.users
}
def updated(userData: UserData): Seq[UserData] = {
DB.uuid(Email(userData.email)).foreach { id =>
update(toUser(id, userData))
}
def upserted(userData: UserData): Seq[UserData] = {
val id = DB.uuid(Email(userData.email)).getOrElse(UUID(java.util.UUID.randomUUID.toString))
upsert(toUser(id, userData))
users
}
......
......@@ -79,10 +79,9 @@ object DB {
}
}
def update(user: User) = {
println("user updated " + user.name)
def upsert(user: User) = {
runTransaction(
getQuery(user.email).update(user.uuid, user.name, user.email, user.password, user.role)
userTable.insertOrUpdate(user.uuid, user.name, user.email, user.password, user.role)
)
}
......
......@@ -6,5 +6,5 @@ trait AdminApi {
def users(): Seq[UserData]
def updated(userData: UserData): Seq[UserData]
def upserted(userData: UserData): Seq[UserData]
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment