Commit c1a754ec authored by Mathieu's avatar Mathieu

Fix new user edition

parent b89dcff3
......@@ -31,7 +31,7 @@ object AdminPanel {
@JSExportTopLevel("admin")
def admin() = {
implicit def userDataSeqToRows(userData: Seq[UserData]): Seq[ExpandableRow] = userData.map { u =>
implicit def userDataSeqToRows(userData: Seq[UserData]): Seq[EmailRow] = userData.map { u =>
buildExpandable(u.name, u.email, u.password, u.role, u.omVersion, u.lastAccess, podInfos.now.filter {
_.userEmail == Some(u.email)
......@@ -44,18 +44,19 @@ object AdminPanel {
lazy val rowFlex = Seq(styles.display.flex, flexDirection.row, justifyContent.spaceAround, alignItems.center)
lazy val columnFlex = Seq(styles.display.flex, flexDirection.column, styles.justifyContent.center)
case class EmailRow(email: String, expandableRow: ExpandableRow)
lazy val rows: Var[Seq[ExpandableRow]] = Var(Seq())
lazy val rows: Var[Seq[EmailRow]] = Var(Seq())
lazy val open: Var[Option[String]] = Var(None)
lazy val podInfos: Var[Seq[PodInfo]] = Var(Seq())
def save(expandableRow: ExpandableRow, userData: UserData): Unit = {
if (userData.name.isEmpty)
rows.update(rows.now.filterNot(_ == expandableRow))
else {
upsert(userData)
}
// if (userData.name.isEmpty)
// rows.update(rows.now.filterNot(_.expandableRow == expandableRow))
// else {
upsert(userData)
// }
}
def upsert(userData: UserData) =
......@@ -68,10 +69,11 @@ object AdminPanel {
rows() = _
}
def updateRows =
def updateRows = {
Post[AdminApi].users().call().foreach { us =>
rows() = us
}
}
def updatePodInfos =
Post[AdminApi].podInfos().call().foreach { pi =>
......@@ -80,18 +82,26 @@ object AdminPanel {
updateRows
}
// def updatePodInfoTimer: Unit = {
// setTimeout(10000) {
// updatePodInfos
// updatePodInfoTimer
// }
// }
def isEditing(email: String): Boolean = rows.now.filter { er =>
er.expandableRow.editableRow.cells.exists {
_.editMode.now
}
}.map {
_.email
}.headOption == Some(email)
// def updatePodInfoTimer: Unit = {
// setTimeout(10000) {
// updatePodInfos
// updatePodInfoTimer
// }
// }
def closeAll(except: ExpandableRow) = rows.now.filterNot {
_ == except
_.expandableRow == except
}.foreach {
_.subRow.trigger() = false
_.expandableRow.subRow.trigger() = false
}
......@@ -102,11 +112,13 @@ object AdminPanel {
userOMVersion: String = "",
userLastAccess: Long = 0L,
podInfo: Option[PodInfo] = None,
expanded: Boolean = false): ExpandableRow = {
expanded: Boolean = false,
edited: Option[Boolean] = None): EmailRow = {
val aVar = Var(expanded)
val editing = edited.getOrElse(isEditing(userEmail))
lazy val aSubRow: StaticSubRow = StaticSubRow({
div(height := 300, rowFlex)(
div(height := 350, rowFlex)(
groupCell.build(margin := 25),
div(userLastAccess.toStringDate, fontSize := "12px", minWidth := 150),
label(label_primary, userOMVersion),
......@@ -139,9 +151,9 @@ object AdminPanel {
)), aSubRow)
lazy val groupCell: GroupCell = UserPanel.editableData(userName, userEmail, userPassword, userRole, podInfo, userOMVersion, userLastAccess, expanded, (uData: UserData) => save(expandableRow, uData))
lazy val groupCell: GroupCell = UserPanel.editableData(userName, userEmail, userPassword, userRole, podInfo, userOMVersion, userLastAccess, expanded, editing, (uData: UserData) => save(expandableRow, uData))
expandableRow
EmailRow(userEmail, expandableRow)
}
......@@ -150,7 +162,7 @@ object AdminPanel {
//updatePodInfoTimer
val addUserButton = button(btn_primary, "Add", onclick := { () =>
val row = buildExpandable(userRole = user, userOMVersion = "LATEST", expanded = true)
val row = buildExpandable(userRole = user, userOMVersion = "LATEST", expanded = true, edited = Some(true))
rows.update(rows.now :+ row)
})
......@@ -171,7 +183,9 @@ object AdminPanel {
),
Rx {
div(styles.display.flex, flexDirection.row, styles.justifyContent.center)(
EdiTable(Seq("Name", "Status"), rows()).render(width := "90%")
EdiTable(Seq("Name", "Status"), rows().map {
_.expandableRow
}).render(width := "90%")
)
}
)
......
......@@ -15,8 +15,8 @@ object UserPanel {
lazy val rowFlex = Seq(styles.display.flex, flexDirection.row, justifyContent.spaceAround)
lazy val columnFlex = Seq(styles.display.flex, flexDirection.column, styles.justifyContent.center, alignItems.flexStart)
lazy val roles = Seq(user, shared.Data.admin)
lazy val roleFilter = (r: Role) => r == shared.Data.admin
lazy val roles = Seq(user, admin)
lazy val roleFilter = (r: Role) => r == admin
def editableData(userName: String = "",
userEmail: String = "",
......@@ -26,19 +26,18 @@ object UserPanel {
userOMVersion: String,
userLastAccess: Long,
expanded: Boolean = false,
editing: Boolean = false,
upserting: (UserData) => Unit
): GroupCell = {
def roleStyle(s: Role) =
if (s == shared.Data.admin) label_success
if (s == admin) label_success
else label_default
val name = TextCell(userName, Some("Name"))
val email = TextCell(userEmail, Some("Email"))
val password = PasswordCell(userPassword, Some("Password"))
val role = LabelCell(userRole, roles, optionStyle = roleStyle, title = Some("Role"))
val rowEdit = Var(false)
val name = TextCell(userName, Some("Name"), editing)
val email = TextCell(userEmail, Some("Email"), editing)
val password = PasswordCell(userPassword, Some("Password"), editing)
val role = LabelCell(userRole, roles, optionStyle = roleStyle, title = Some("Role"), editing = editing)
lazy val groupCell: GroupCell = GroupCell(
div(columnFlex, width := "100%")(
......@@ -48,15 +47,13 @@ object UserPanel {
role.build(padding := 10),
span(rowFlex, marginTop := 50)(
Rx {
if (rowEdit()) button(btn_primary, "Save", onclick := { () =>
if (name.editMode()) button(btn_primary, "Save", onclick := { () =>
groupCell.switch
val userRole: Role = role.get
val modifiedUser = UserData(name.get, email.get, password.get, userRole, userOMVersion, userLastAccess)
upserting(modifiedUser)
rowEdit.update(!rowEdit.now)
})
else button(btn_default, "Edit", onclick := { () =>
//button("Edit", btn_default, onclick := { () =>
rowEdit.update(!rowEdit.now)
groupCell.switch
})
}
......
......@@ -3,7 +3,7 @@ package org.openmoleconnect.server
import shared.Data.{PodInfo, UserData}
import DB._
object AdminApiImpl extends shared.AdminApi {
class AdminApiImpl(kubeOff: Boolean) extends shared.AdminApi {
def users() = {
DB.users
......@@ -12,7 +12,8 @@ object AdminApiImpl extends shared.AdminApi {
def upserted(userData: UserData): Seq[UserData] = {
val id = DB.uuid(Email(userData.email)).getOrElse(UUID(java.util.UUID.randomUUID.toString))
upsert(toUser(id, userData))
K8sService.deployIfNotDeployedYet(id)
if (!kubeOff)
K8sService.deployIfNotDeployedYet(id)
users
}
......
......@@ -31,6 +31,7 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
implicit val secret: JWT.Secret = arguments.secret
val adminApiImpl = new AdminApiImpl(arguments.kubeOff)
val httpClient = HttpClients.createDefault()
......@@ -135,7 +136,7 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
val bytes: Array[Byte] = Iterator.continually(is.read()).takeWhile(_ != -1).map(_.asInstanceOf[Byte]).toArray[Byte]
val bb = ByteBuffer.wrap(bytes)
AutowireServer.route[shared.AdminApi](AdminApiImpl)(
AutowireServer.route[shared.AdminApi](adminApiImpl)(
autowire.Core.Request(
Data.adminRoutePrefix.split("/").toSeq ++ multiParams("splat").head.split("/"),
Unpickle[Map[String, ByteBuffer]].fromBytes(bb)
......
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