Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nginx/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ <h3 id="message">Welcome!</h3>

<p>Name</p>
<input type="text" id="name"/>
<p>why u here</p>
<input type="text" id="description"/>
<button onclick="enterQueue();">Enter Queue</button>
<br/><br/>

Expand Down
6 changes: 4 additions & 2 deletions nginx/public/officeHours.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ function displayQueue(queueJSON) {
const queue = JSON.parse(queueJSON);
let formattedQueue = "";
for (const student of queue) {
formattedQueue += student['username'] + " has been waiting since " + student['timestamp'] + "<br/>"
formattedQueue += student['username'] + " has been waiting since " + student['timestamp'] + " for reason: " + student['description'] + "<br/>"
}
document.getElementById("queue").innerHTML = formattedQueue;
}


function enterQueue() {
let name = document.getElementById("name").value;
socket.emit("enter_queue", name);
let description = document.getElementById("description").value;
socket.emit("enter_queue", name + "::" + description);
document.getElementById("name").value = "";
document.getElementById("description").value = "";
}

function readyToHelp() {
Expand Down
8 changes: 6 additions & 2 deletions src/main/scala/model/OfficeHoursServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class OfficeHoursServer() {

var usernameToSocket: Map[String, SocketIOClient] = Map()
var socketToUsername: Map[SocketIOClient, String] = Map()
var userDescription: Map[SocketIOClient, String] = Map()

val config: Configuration = new Configuration {
setHostname("0.0.0.0")
Expand Down Expand Up @@ -59,10 +60,13 @@ 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()))
override def onData(socket: SocketIOClient, userdesc: String, ackRequest: AckRequest): Unit = {
val username = userdesc.split("::")(0)
val description = userdesc.split("::")(1)
server.database.addStudentToQueue(StudentInQueue(username, System.nanoTime(), description))
server.socketToUsername += (socket -> username)
server.usernameToSocket += (username -> socket)
server.userDescription += (socket -> description)
server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/scala/model/StudentInQueue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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, description: String): StudentInQueue = {
new StudentInQueue(cleanString(username), timestamp, description)
}


}

class StudentInQueue(val username: String, val timestamp: Long) {
class StudentInQueue(val username: String, val timestamp: Long, val description: String) {

def asJsValue(): JsValue ={
val messageMap: Map[String, JsValue] = Map(
"username" -> Json.toJson(username),
"timestamp" -> Json.toJson(timestamp)
"timestamp" -> Json.toJson(timestamp),
"description" -> Json.toJson(description)
)
Json.toJson(messageMap)
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/model/database/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ class Database extends DatabaseAPI{
var queue: List[StudentInQueue] = List()

while (result.next()) {
val username = result.getString("username")
val username = result.getString("username").split("::")(0)
val description = result.getString("username").split("::")(1)
val timestamp = result.getLong("timestamp")
queue = new StudentInQueue(username, timestamp) :: queue
queue = new StudentInQueue(username, timestamp, description) :: queue
}

queue.reverse
Expand Down