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

Adding TA/Student sides #53

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b967235
~Creating a style.css to modify the html
Nildham21 Apr 24, 2020
e25cdc0
~Adding Student side function that will load the html that the studen…
Nildham21 Apr 25, 2020
44c29d2
~Adding the first select drop down that the student will select from
Nildham21 Apr 25, 2020
23a26d7
~Creating functions that will add html to the index.html
Nildham21 Apr 25, 2020
12fba21
~sending username,topic and subtopic to the server
Nildham21 Apr 25, 2020
2791017
~Working on the html of the TA side, adding a button
Nildham21 Apr 26, 2020
dc82636
~Debugging the queue, so that it does not show up in the first html l…
Nildham21 Apr 26, 2020
6990e30
~ Setting up database to work with mySQL
Nildham21 Apr 28, 2020
0ba76c1
~ Broadcasting Queue after each DisconnectionListener
Nildham21 Apr 28, 2020
e46a526
~ Loading the Queue for the TA side
Nildham21 Apr 28, 2020
e8cc3a8
~ Adding new columns into my table to store data for topic and subtopic
Nildham21 Apr 28, 2020
c1ec139
~ Fixing upper and lower case issues for topic namings
Nildham21 Apr 28, 2020
53d7fea
~ Centering the Queue
Nildham21 Apr 29, 2020
de46d1a
~ Adding bottom margin to space the viewing queue
Nildham21 Apr 29, 2020
25fc633
~ Adding alerts when a student is up
Nildham21 Apr 30, 2020
7b61fea
~ Fixing the bug where null would be passed if no one is in queue
Nildham21 May 1, 2020
bdb9007
~ A issue that was present in my code was that i manually add div que…
Nildham21 May 1, 2020
e89f95e
~ Fixing same name issues, every time a user enters a name a random i…
Nildham21 May 1, 2020
f5a489c
~ Adding Background Color
Nildham21 May 1, 2020
3fdf6bf
~ adding username label for student side
Nildham21 May 2, 2020
5a57eff
~ Adding a login page for the the TA before helping students
Nildham21 May 2, 2020
55973c6
~ Adding a data structure that keeps track of which TA is online, so …
Nildham21 May 2, 2020
e00c2a8
~ Created A TA database that keeps track of how many students that TA…
Nildham21 May 3, 2020
f5d33e1
~ Adding a google pie chart that will display the number of students …
Nildham21 May 3, 2020
aee3983
~ changing google charts background color
Nildham21 May 3, 2020
33508c4
~ made the stats button collapse once the the user was done looking a…
Nildham21 May 3, 2020
c14a95f
~ Cleaned up the Database for the TAstats, i was adding 2 entries by …
Nildham21 May 4, 2020
3dda81f
~ lower cased the word Time
Nildham21 May 6, 2020
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
Prev Previous commit
Next Next commit
~ A issue that was present in my code was that i manually add div que…
…ue to the html, so when a new user log on to the main page, it receives queue from the server broadcast message there is an error that occurs. Thus I created my own broadcast method for broadcasting queue
  • Loading branch information
Nildham21 committed May 1, 2020
commit bdb900771ca9bf85da91518043d263fc044d9b10
22 changes: 4 additions & 18 deletions nginx/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
<head>
<meta charset="UTF-8">
<title>Office Hours</title>

<!--stylesheets Css-->
<link rel="stylesheet" type="text/css" href="style.css">

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
</head>
<body>
<body onload="firstcounter()">

<br/>

Expand All @@ -24,25 +22,13 @@ <h2 id="subtitle">Pick which one you are</h2>

<div id="currentStudent"></div>

<div id="queueSection">

<!--<div id="queue"></div>-->
</div>

<div id="HelpInfo" >
</div>

<!--<button onclick="enterQueue();">Enter Queue</button>-->
<!--<br/><br/>-->
<!--<p>What do you need help in?</p><select id="topic"></select>-->
<!--<button onclick="readyToHelp();">TA Ready to Help</button>-->
<!--<br/>-->

<div id="queueSection"></div>

<div id="HelpInfo" ></div>

<div id="Counter" class="bar"></div>

<script src="officeHours.js"></script>


</body>
</html>
14 changes: 13 additions & 1 deletion nginx/public/officeHours.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ socket.on('message', displayMessageTA);
socket.on('message2', displayMessageStu);
socket.on('alert', alertWindow);
socket.on('done', studentDone);
socket.on('count', counter);



Expand Down Expand Up @@ -148,7 +149,7 @@ function displayTA() {
function readyToHelp() {


if(document.getElementById("queue").innerHTML.length>23){
if(document.getElementById("currentStudent").innerHTML.length==0){
socket.emit("ready_for_student");
}
}
Expand All @@ -169,3 +170,14 @@ function alertWindow() {
function studentDone() {
document.getElementById('currentStudent').innerHTML="<h2 style=\"color:green\">Thanks for attending Office Hours! See you next TIME </h2>\n";
}
function counter(count) {
let values=JSON.parse(count)
let student=values["student"]
let ta=values["ta"]

document.getElementById("Counter").innerHTML="TA Count: "+ta+" Student Count: "+student
}
function firstcounter(){
socket.emit("first_count")

}
62 changes: 14 additions & 48 deletions nginx/public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,54 +41,6 @@ button {
border: 2px solid #005bbb;
}

/*.optionButton2 {*/
/* font-family:'Open Sans Condensed', sans-serif;*/
/* font-size: medium;*/
/* text-align: center;*/
/* border: 2px solid #b3b3b3;*/
/* margin-left: 5%;*/
/* text-transform: uppercase;*/
/* font-weight: bold;*/
/* background-color: #005bbb ;*/
/* width: 15%;*/
/* font-size: 17px;*/
/* line-height: 1.33333em;*/
/* padding: 7px 18px;*/
/* margin-top: 0.8em;*/
/* border-radius: 18px;*/
/* !*margin-bottom: 50px;*!*/

/*}*/

/*.optionButton2:hover {*/
/* background-color: #b3b3b3;*/
/* border: 2px solid #005bbb;*/
/*}*/

/*.optionButton3 {*/
/* font-family:'Open Sans Condensed', sans-serif;*/
/* font-size: medium;*/
/* text-align: center;*/
/* border: 2px solid #b3b3b3;*/
/* margin-right: 20%;*/
/* text-transform: uppercase;*/
/* font-weight: bold;*/
/* background-color: #005bbb ;*/
/* width: 15%;*/
/* font-size: 17px;*/
/* line-height: 1.33333em;*/
/* padding: 7px 18px;*/
/* margin-top: 0.8em;*/
/* border-radius: 18px;*/
/* !*margin-bottom: 50px;*!*/

/*}*/

/*.optionButton3:hover {*/
/* background-color: #b3b3b3;*/
/* border: 2px solid #005bbb;*/
/*}*/

.queue {
background-color: #b3b3b3 ;
width: 500px;
Expand All @@ -101,3 +53,17 @@ button {
margin: 0 auto;
text-align: center;
}
.bar {
text-align: center;
height: 25px;
margin-left: 25%;
margin-right: auto;
overflow: hidden;
background-color: #005bbb;
border: 2px solid #b3b3b3;
position: fixed;
bottom: 2px;
width: 50%;
border-radius: 5px;

}
71 changes: 59 additions & 12 deletions src/main/scala/model/OfficeHoursServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class OfficeHoursServer() {
var TAtoSocket: Map[String,SocketIOClient]= Map()
var SocketToTA: Map[SocketIOClient,String]=Map()

var loggedInClients:List[SocketIOClient]=List()
var studentCount:Int=0
var taCount:Int=0

val config: Configuration = new Configuration {
setHostname("0.0.0.0")
setPort(8080)
Expand All @@ -32,8 +36,7 @@ class OfficeHoursServer() {
server.addEventListener("display_TA", classOf[Nothing], new displayTAListener(this))
server.addEventListener("alert_page", classOf[String], new alertListener(this))
server.addEventListener("done_helping", classOf[String], new doneHelpingListener(this))


server.addEventListener("first_count", classOf[Nothing], new countListener(this))


server.start()
Expand All @@ -44,6 +47,21 @@ class OfficeHoursServer() {
Json.stringify(Json.toJson(queueJSON))
}

def countJSON():String={
var counter:Map[String,JsValue]=Map(
"student"->Json.toJson(studentCount),
"ta"->Json.toJson(taCount)
)
Json.stringify(Json.toJson(counter))
}

def removeSocket(socket: SocketIOClient,server:OfficeHoursServer): Unit ={
server.loggedInClients=server.loggedInClients.filter(_!=socket)
}
def broadcastQueue(server: OfficeHoursServer,messageType:String,value:String): Unit ={
server.loggedInClients.foreach(_.sendEvent(messageType,value))
}

}

object OfficeHoursServer {
Expand All @@ -54,7 +72,12 @@ object OfficeHoursServer {

class DisconnectionListener(server: OfficeHoursServer) extends DisconnectListener {
override def onDisconnect(socket: SocketIOClient): Unit = {

server.removeSocket(socket,server)

if (server.socketToUsername.contains(socket)) {

server.studentCount-=1
val username = server.socketToUsername(socket)

server.database.removeStudentFromQueue(username)
Expand All @@ -64,34 +87,42 @@ class DisconnectionListener(server: OfficeHoursServer) extends DisconnectListene
server.usernameToSocket -= username
}
}
server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
else{
server.taCount-=1
}
server.server.getBroadcastOperations.sendEvent("count", server.countJSON())
// server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
server.broadcastQueue(server,"queue",server.queueJSON())
}
}


class EnterQueueListener(server: OfficeHoursServer) extends DataListener[String] {
override def onData(socket: SocketIOClient, data: String, ackRequest: AckRequest): Unit = {

server.loggedInClients = server.loggedInClients :+ socket

server.studentCount+=1

val parsed:JsValue=Json.parse(data)
val username:String= (parsed\"username").as[String]
val topic:String= (parsed\"topic").as[String]
val subtopic:String= (parsed\"subtopic").as[String]

println(topic)
println(subtopic)

server.database.addStudentToQueue(StudentInQueue(username, System.nanoTime(),topic,subtopic))
server.socketToUsername += (socket -> username)
server.usernameToSocket += (username -> socket)
server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
// server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
server.broadcastQueue(server,"queue",server.queueJSON())

server.server.getBroadcastOperations.sendEvent("count", server.countJSON())
}
}


class ReadyForStudentListener(server: OfficeHoursServer) extends DataListener[Nothing] {
override def onData(socket: SocketIOClient, dirtyMessage: Nothing, ackRequest: AckRequest): Unit = {


val queue = server.database.getQueue.sortBy(_.timestamp)
if(queue.nonEmpty){

Expand All @@ -105,14 +136,24 @@ class ReadyForStudentListener(server: OfficeHoursServer) extends DataListener[No
server.usernameToSocket(studentToHelp.username).sendEvent("message2", "A TA is ready to help you!")
}

server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
// server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
server.broadcastQueue(server,"queue",server.queueJSON())

}
}
}

class displayTAListener(server:OfficeHoursServer) extends DataListener[Nothing]{
override def onData(socketIOClient: SocketIOClient, t: Nothing, ackRequest: AckRequest): Unit = {
server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
override def onData(socket: SocketIOClient, t: Nothing, ackRequest: AckRequest): Unit = {

server.loggedInClients = server.loggedInClients :+ socket

server.taCount+=1
// server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
server.broadcastQueue(server,"queue",server.queueJSON())

server.server.getBroadcastOperations.sendEvent("count", server.countJSON())

}
}

Expand All @@ -122,12 +163,18 @@ class alertListener(server: OfficeHoursServer) extends DataListener[String] {
socketToSend.sendEvent("alert")
}
}

class doneHelpingListener(server: OfficeHoursServer) extends DataListener[String] {
override def onData(socket: SocketIOClient, username: String, ackRequest: AckRequest): Unit = {
println("Done Helping Called")
val socketToSend=server.usernameToSocket(username)
socketToSend.sendEvent("done")
}
}

class countListener(server:OfficeHoursServer) extends DataListener[Nothing]{
override def onData(socketIOClient: SocketIOClient, t: Nothing, ackRequest: AckRequest): Unit = {
server.server.getBroadcastOperations.sendEvent("count", server.countJSON())
}
}