Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project contribution for Yujun Lu #147

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion nginx/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

<h3 id="message">Welcome!</h3>

<p>Name</p>
<p>put your name in the first box and write problem description for your problem in the second box</p>
<input type="text" id="name"/>
<input type="text" id="description"/>
<button onclick="enterQueue();">Enter Queue</button>
<br/><br/>

Expand Down
10 changes: 8 additions & 2 deletions nginx/public/officeHours.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ 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'] + " and has a description about his/her problem that '" +student['description']+ "'" + "<br/>"
}
document.getElementById("queue").innerHTML = formattedQueue;
}


function enterQueue() {
let name = document.getElementById("name").value;
socket.emit("enter_queue", name);
let problem = document.getElementById("description").value
let sendfile = new Map()
sendfile["name"] = name
sendfile["description"] = problem
var sendstuff = JSON.stringify(sendfile)
socket.emit("enter_queue", sendstuff);
document.getElementById("name").value = "";
document.getElementById("description").value = "";
}

function readyToHelp() {
Expand Down
13 changes: 10 additions & 3 deletions src/main/scala/model/OfficeHoursServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import model.database.{Database, DatabaseAPI, TestingDatabase}
import play.api.libs.json.{JsValue, Json}



class OfficeHoursServer() {
//come on

val database: DatabaseAPI = if(Configuration.DEV_MODE){
new TestingDatabase
Expand Down Expand Up @@ -60,9 +62,14 @@ 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()))
server.socketToUsername += (socket -> username)
server.usernameToSocket += (username -> socket)
val parsed: JsValue = Json.parse(username)
// unused values, but this is how we would extract message and timestamp
val username1: String = (parsed \ "name").as[String]
val timestamp1: String = (parsed \ "description").as[String]

server.database.addStudentToQueue(StudentInQueue(username1,System.nanoTime(),timestamp1))
server.socketToUsername += (socket -> username1)
server.usernameToSocket += (username1 -> socket)
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
3 changes: 2 additions & 1 deletion src/main/scala/model/database/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 description = result.getString("description")
queue = new StudentInQueue(username, timestamp,description) :: queue
}

queue.reverse
Expand Down