Commit 7e6e6631 authored by Mathieu's avatar Mathieu

Fix date format

parent 69a7f0dd
......@@ -72,18 +72,16 @@ object AdminPanel {
userPassword: String = "",
userRole: Role = "",
userOMVersion: String = "",
userLastAccess: Long = 0L,
userLastAccess: String = "",
userStatus: Status = user,
expanded: Boolean = false): ExpandableRow = {
val aVar = Var(expanded)
val lastAccess = new Date(userLastAccess.toDouble)
lazy val aSubRow: StaticSubRow = StaticSubRow({
div(height := 300, rowFlex)(
groupCell.build(margin := 25),
label(label_primary, userOMVersion),
div(lastAccess.toUTCString), //.formatted("EEE, d MMM yyyy HH:mm:ss"),
div(userLastAccess, fontSize := "12px", minWidth := "150"),
span(columnFlex, alignItems.flexEnd, justifyContent.flexEnd)(
button(btn_danger, "Delete", onclick := { () =>
val userData = UserData(userName, userEmail, userPassword, userRole, userOMVersion, userLastAccess)
......@@ -117,8 +115,8 @@ object AdminPanel {
rows() = us
}
val addUserButton = button(btn_success, "Add", onclick := { () =>
val row = buildExpandable(userRole = user, expanded = true)
val addUserButton = button(btn_primary, "Add", onclick := { () =>
val row = buildExpandable(userRole = user, userOMVersion = "LATEST", expanded = true)
rows.update(rows.now :+ row)
})
......@@ -127,7 +125,10 @@ object AdminPanel {
)
val editablePanel = div(maxWidth := 1000, margin := "40px auto")(
addUserButton(styles.display.flex, flexDirection.row, styles.justifyContent.flexEnd),
Utils.logoutItem(styles.display.flex, flexDirection.row, justifyContent.flexEnd),
div(styles.display.flex, flexDirection.row, justifyContent.flexStart, marginLeft := 50, marginBottom := 20, marginTop := 80)(
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%")
......
......@@ -24,7 +24,7 @@ object UserPanel {
userRole: Role = "",
userStatus: Status = user,
userOMVersion: String,
userLastAccess: Long,
userLastAccess: String,
expanded: Boolean = false,
upserting: (UserData) => Unit
): GroupCell = {
......
package org.openmoleconnect.client
import scalatags.JsDom.styles
import scaladget.bootstrapnative.bsn._
import scaladget.tools._
import scalatags.JsDom.all._
object Utils {
val logoutLogo = toClass("glyphicon glyphicon-off")
val itemStyle: ModifierSeq = Seq(
fontSize := 30,
pointer,
color := "#337ab7"
)
val logoutItem =
div(logoutLogo, itemStyle, onclick := { () org.scalajs.dom.window.location.href = s"${org.scalajs.dom.window.location.href}logout" })
}
......@@ -44,7 +44,9 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
def withAccesToken(action: TokenData => ActionResult): Serializable = {
Authentication.tokenData(request, TokenType.accessToken) match {
case Some(tokenData: TokenData) => action(tokenData)
case Some(tokenData: TokenData) =>
DB.setLastAccess(tokenData.email, JWT.now)
action(tokenData)
case None =>
Authentication.isValid(request, TokenType.refreshToken) match {
case true =>
......@@ -166,9 +168,6 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
val host = Host(uuid, None)
buildAndAddCookieToHeader(TokenData.accessToken(host, DB.Email(email)))
buildAndAddCookieToHeader(TokenData.refreshToken(host, DB.Email(email)))
println("SET Last access")
DB.setLastAccess(DB.Email(email), JWT.now)
println("ACSS ? " + DB.get(DB.Email(email)).map{_.lastAccess})
redirect("/")
case _ => Ok(connectionHtml)
}
......
package org.openmoleconnect.server
import java.text.SimpleDateFormat
import java.util
import shared.Data.UserData
......@@ -39,16 +40,17 @@ object DB {
u.password.value,
u.role.value,
u.omVersion.value,
u.lastAccess.value) }
Utils.toStringDate(u.lastAccess.value))
}
def toUser(uuid: UUID, userData: UserData): User = User(
userData.name,
Email(userData.email),
Password(userData.password),
Version(userData.omVersion),
userData.lastAccess,
Utils.toLongDate(userData.lastAccess),
Role(userData.role),
uuid
uuid
)
class Users(tag: Tag) extends Table[(UUID, String, Email, Password, Role, Version, Long)](tag, "USERS") {
......
package org.openmoleconnect.server
import java.text.SimpleDateFormat
import java.util.Locale
import org.apache.http.impl.EnglishReasonPhraseCatalog
object Utils {
object openmoleversion {
......@@ -7,4 +12,15 @@ object Utils {
def developpement = DB.Version("FIXME DEV")
}
val DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss"
def toStringDate(date: Long) = date match {
case 0L => "NEVER CONNECTED"
case l => new SimpleDateFormat(DATE_FORMAT, new Locale("en")).format(l)
}
def toLongDate(date: String) = {
new SimpleDateFormat(DATE_FORMAT).parse(date).getTime
}
}
......@@ -14,7 +14,7 @@ object Data {
val off: Status = "Off"
val error: Status = "Error"
case class UserData(name: String, email: String, password: String, role: Role, omVersion: String, lastAccess: Long)
case class UserData(name: String, email: String, password: String, role: Role, omVersion: String, lastAccess: String)
case class PersonalUserData(name: String, email: String, password: String, role: Role)
......
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