diff --git a/nginx/public/index.html b/nginx/public/index.html
index 5443216..eade5e4 100644
--- a/nginx/public/index.html
+++ b/nginx/public/index.html
@@ -5,13 +5,13 @@
Office Hours
-
+
Welcome!
-Name
+Name:
diff --git a/nginx/public/officeHours.js b/nginx/public/officeHours.js
index 3514c14..50e0f5c 100644
--- a/nginx/public/officeHours.js
+++ b/nginx/public/officeHours.js
@@ -11,7 +11,7 @@ function displayQueue(queueJSON) {
const queue = JSON.parse(queueJSON);
let formattedQueue = "";
for (const student of queue) {
- formattedQueue += student['username'] + " has been waiting since " + student['timestamp'] + "
"
+ formattedQueue += student['username'] + " has been waiting since " + student['timestamp'] + " and is in position " + student['position'] + "
"
}
document.getElementById("queue").innerHTML = formattedQueue;
}
diff --git a/src/main/scala/model/OfficeHoursServer.scala b/src/main/scala/model/OfficeHoursServer.scala
index 09ef61b..15ef318 100644
--- a/src/main/scala/model/OfficeHoursServer.scala
+++ b/src/main/scala/model/OfficeHoursServer.scala
@@ -22,6 +22,8 @@ class OfficeHoursServer() {
setPort(8080)
}
+ var nextPosition: Int = 0
+
val server: SocketIOServer = new SocketIOServer(config)
server.addDisconnectListener(new DisconnectionListener(this))
@@ -60,7 +62,8 @@ class DisconnectionListener(server: OfficeHoursServer) extends DisconnectListene
class EnterQueueListener(server: OfficeHoursServer) extends DataListener[String] {
override def onData(socket: SocketIOClient, username: String, ackRequest: AckRequest): Unit = {
- server.database.addStudentToQueue(StudentInQueue(username, System.nanoTime()))
+ val position: Int = server.database.getQueue.sortBy(_.timestamp).length + 1
+ server.database.addStudentToQueue(StudentInQueue(username, System.nanoTime(), position))
server.socketToUsername += (socket -> username)
server.usernameToSocket += (username -> socket)
server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
diff --git a/src/main/scala/model/StudentInQueue.scala b/src/main/scala/model/StudentInQueue.scala
index 464108f..73315df 100644
--- a/src/main/scala/model/StudentInQueue.scala
+++ b/src/main/scala/model/StudentInQueue.scala
@@ -16,19 +16,20 @@ object StudentInQueue {
output
}
- def apply(username: String, timestamp: Long): StudentInQueue = {
- new StudentInQueue(cleanString(username), timestamp)
+ def apply(username: String, timestamp: Long, position: Int): StudentInQueue = {
+ new StudentInQueue(cleanString(username), timestamp, position)
}
}
-class StudentInQueue(val username: String, val timestamp: Long) {
+class StudentInQueue(val username: String, val timestamp: Long, position: Int) {
def asJsValue(): JsValue ={
val messageMap: Map[String, JsValue] = Map(
"username" -> Json.toJson(username),
- "timestamp" -> Json.toJson(timestamp)
+ "timestamp" -> Json.toJson(timestamp),
+ "position" -> Json.toJson(position)
)
Json.toJson(messageMap)
}
diff --git a/src/main/scala/model/database/Database.scala b/src/main/scala/model/database/Database.scala
index bbc9f7a..641e306 100644
--- a/src/main/scala/model/database/Database.scala
+++ b/src/main/scala/model/database/Database.scala
@@ -49,7 +49,8 @@ class Database extends DatabaseAPI{
while (result.next()) {
val username = result.getString("username")
val timestamp = result.getLong("timestamp")
- queue = new StudentInQueue(username, timestamp) :: queue
+ val position = result.getInt("position")
+ queue = new StudentInQueue(username, timestamp, position) :: queue
}
queue.reverse