Commit 49ab9b61 authored by Mathieu's avatar Mathieu

Fix last access display

parent de424a3a
......@@ -21,6 +21,7 @@ import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer}
import scaladget.bootstrapnative.bsn._
import scaladget.tools.{ModifierSeq, _}
import scalatags.JsDom.all._
import Utils._
import scala.scalajs.js.Date
......@@ -72,7 +73,7 @@ object AdminPanel {
userPassword: String = "",
userRole: Role = "",
userOMVersion: String = "",
userLastAccess: String = "",
userLastAccess: Long = 0L,
userStatus: Status = user,
expanded: Boolean = false): ExpandableRow = {
val aVar = Var(expanded)
......@@ -80,13 +81,13 @@ object AdminPanel {
lazy val aSubRow: StaticSubRow = StaticSubRow({
div(height := 300, rowFlex)(
groupCell.build(margin := 25),
div(userLastAccess.toStringDate, fontSize := "12px", minWidth := 150),
label(label_primary, userOMVersion),
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)
delete(userData)
}, margin := 10)
button(btn_danger, "Delete", onclick := { () =>
val userData = UserData(userName, userEmail, userPassword, userRole, userOMVersion, userLastAccess)
delete(userData)
}, margin := 10)
)
)
}, aVar)
......
......@@ -24,7 +24,7 @@ object UserPanel {
userRole: Role = "",
userStatus: Status = user,
userOMVersion: String,
userLastAccess: String,
userLastAccess: Long,
expanded: Boolean = false,
upserting: (UserData) => Unit
): GroupCell = {
......
......@@ -6,6 +6,8 @@ import scaladget.bootstrapnative.bsn._
import scaladget.tools._
import scalatags.JsDom.all._
import scala.scalajs.js.Date
object Utils {
val logoutLogo = toClass("glyphicon glyphicon-off")
......@@ -19,4 +21,47 @@ object Utils {
val logoutItem =
div(logoutLogo, itemStyle, onclick := { () org.scalajs.dom.window.location.href = s"${org.scalajs.dom.window.location.href}logout" })
implicit class FromInt(i: Int) {
def toDayString = i match {
case 0 => "Mon"
case 1 => "Tue"
case 2 => "Wed"
case 3 => "Thu"
case 4 => "Fri"
case 5 => "Sat"
case 6 => "Sun"
case _ => "ERROR"
}
def toMonthString = i match {
case 0 => "Jan"
case 1 => "Feb"
case 2 => "Mar"
case 3 => "Apr"
case 4 => "May"
case 5 => "Jun"
case 6 => "Jul"
case 7 => "Aug"
case 8 => "Sept"
case 9 => "Oct"
case 10 => "Nov"
case 11 => "Dec"
}
def toMinOrSecString = {
if (i < 10 ) s"0$i"
else i
}
}
implicit class FromLong(date: Long) {
def toStringDate = {
if (date == 0L) "NEVER CONNECTED"
else {
val d = new Date(date)
s"${d.getDay.toDayString}, ${d.getDate} ${d.getMonth.toMonthString} ${d.getFullYear} ${d.getHours}:${d.getMinutes.toMinOrSecString}:${d.getSeconds.toMinOrSecString}"
}
}
}
}
......@@ -281,9 +281,9 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
flexDirection.column,
justifyContent.center,
alignItems.center,
height := 300)(
width := 500)(
tags.div(
tags.img(src := "img/logo.svg",
tags.img(src := "img/logo.png",
paddingTop := 300,
width := 600),
div(paddingLeft := 180)("Wrong way buddy. Are you lost ?")
......
......@@ -28,8 +28,8 @@ object DB {
case class Version(value: String) extends MappedTo[String]
val admin = Role("admin")
val simpleUser = Role("simpleUser")
val admin = Role("Admin")
val simpleUser = Role("User")
case class User(name: String, email: Email, password: Password, omVersion: Version, lastAccess: Long, role: Role = simpleUser, uuid: UUID = UUID(""))
......@@ -40,7 +40,7 @@ object DB {
u.password.value,
u.role.value,
u.omVersion.value,
Utils.toStringDate(u.lastAccess.value))
u.lastAccess.value)
}
def toUser(uuid: UUID, userData: UserData): User = User(
......@@ -48,7 +48,7 @@ object DB {
Email(userData.email),
Password(userData.password),
Version(userData.omVersion),
Utils.toLongDate(userData.lastAccess),
userData.lastAccess,
Role(userData.role),
uuid
)
......
......@@ -12,15 +12,4 @@ 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: String)
case class UserData(name: String, email: String, password: String, role: Role, omVersion: String, lastAccess: Long)
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