Skip to content

Commit

Permalink
Issue #297 Using composite key and handling exception, more improveme…
Browse files Browse the repository at this point in the history
…nt in scenario
  • Loading branch information
AbdullRahman ElHusseini committed Apr 22, 2014
2 parents c827122 + ac1bd1b commit e626835
Show file tree
Hide file tree
Showing 44 changed files with 816 additions and 52 deletions.
4 changes: 4 additions & 0 deletions tutor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ Gemfile.lock, .ruby-version, .ruby-gemset

# Ignoring generated model diagram
models.svg

# Ignoring .java and .class files
/students_solutions/Java/*.java
/students_solutions/Class/*.class
3 changes: 3 additions & 0 deletions tutor/app/assets/javascripts/compilers.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions tutor/app/assets/javascripts/debuggers.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
15 changes: 15 additions & 0 deletions tutor/app/assets/javascripts/problems.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ min = 0
time = 0
timer_is_on = 0

# [Give Hints - Story 3.6, Problem Timer - Story 3.10, Consistent Timer - Story 3.13]
# Counts up the time spent so far on the problem since the page opened
# and displays hints accordingly
# Parameters: none
# Returns: none
# Author: Mohamed Fadel + Rami Khalil
timer = ->
digit++
if digit > 59
Expand All @@ -16,6 +22,15 @@ timer = ->
if digit <= 9
digit = "0" + digit
document.getElementById("secs").innerHTML = digit
i = 0
while true
hint = $('#hint' + i)
if typeof(hint.attr 'time') == 'undefined'
break
time = hint.attr 'time'
if time <= min*60 + parseInt(digit, 10)
hint.attr 'class', ''
i++

activate = ->
unless timer_is_on
Expand Down
125 changes: 125 additions & 0 deletions tutor/app/assets/javascripts/solutions.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# The list of variables
variables = null
# The number of the current index of the line to be executed
indexNumber = 0

# [Debugger: Debug - Story 3.6]
# Sends the code to the server and changes the Variables to the data recieved
# Parameters:
# problem_id: The id of the problem being solved
# Returns: none
# Author: Mussab ElDash
@start_debug = (problem_id) ->
input = $('#solution_code').val()
test = $('#testcases').val()
start_spin()
$.ajax
type: "POST"
url: '/debuggers/' + problem_id
data: {code : input , case : test}
datatype: 'json'
success: (data) ->
toggleDebug()
variables = data
stop_spin()
highlight_line data[0]['line']
error: ->
stop_spin()
return
return

@start_spin = ->
$('#spinner').attr "class" , "spinner"
return

@stop_spin = ->
$('#spinner').attr "class" , ""
return

# [Execute Line By Line - Story 3.8]
# Toggles debugging mode by changing the available buttons.
# Parameters:
# none
# Returns: none
# Author: Rami Khalil (Temporary)
@toggleDebug = () ->
$('#debugButton').prop 'hidden', !$('#debugButton').prop 'hidden'
$('#compileButton').prop 'hidden', !$('#compileButton').prop 'hidden'
$('#testButton').prop 'hidden', !$('#testButton').prop 'hidden'

$('#nextButton').prop 'hidden', !$('#nextButton').prop 'hidden'
$('#previousButton').prop 'hidden', !$('#previousButton').prop 'hidden'
$('#stopButton').prop 'hidden', !$('#stopButton').prop 'hidden'

# [Compile - Story 3.4]
# Sends the code to the server to be compiled.
# Parameters:
# none
# Returns: none
# Author: Rami Khalil (Temporary)
@compile = () ->
alert "Compiling"

# [Test - Story 3.15]
# Sends the code and the input to be processed on the server.
# Parameters:
# none
# Returns: none
# Author: Rami Khalil (Temporary)
@test = () ->
alert "Testing"

# [Execute Line By Line - Story 3.8]
# Moves to the next state of execution.
# Parameters:
# none
# Returns: none
# Author: Rami Khalil
@next = () ->
if indexNumber + 1 < variables.length
jump_state ++indexNumber
else if(indexNumber == 99)
alert "The online debugger can only step forward 100 times."
else
alert "The program has terminated."

# [Execute Line By Line - Story 3.8]
# Moves to the previous state of execution.
# Parameters:
# none
# Returns: none
# Author: Rami Khalil
@previous = () ->
if indexNumber > 0
jump_state --indexNumber
else
alert "This is the first step in the program."

# [Execute Line By Line - Story 3.8]
# Highlights the target line number in the editor
# Parameters:
# line: The line number to highlight.
# Returns: none
# Author: Rami Khalil
@highlight_line = (line) ->
alert "At line: " + line

# [Execute Line By Line - Story 3.8]
# Jumps to the target state by highlighting the line and showing variables
# Parameters:
# stateNumber: The target state number.
# Returns: none
# Author: Rami Khalil
@jump_state = (stateNumber) ->
highlight_line variables[stateNumber]['line']

# [Debug - Story 3.6]
# Stops the debugging session.
# Parameters:
# none
# Returns: none
# Author: Rami Khalil (Temporary)
@stop = () ->
toggleDebug()
indexNumber = 0;
variables = null;
3 changes: 3 additions & 0 deletions tutor/app/assets/stylesheets/compilers.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the compilers controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions tutor/app/assets/stylesheets/debuggers.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Debuggers controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions tutor/app/assets/stylesheets/hints.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.hidden {
display: none;
}
3 changes: 3 additions & 0 deletions tutor/app/assets/stylesheets/problems.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
color: white;
width: 100%;
min-height: 500px;
margin-top: -1px;
border: none;
font-family: monospace;
}

.test {
Expand Down
51 changes: 51 additions & 0 deletions tutor/app/assets/stylesheets/solutions.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,55 @@ textarea {
.presentation_error {
display: none;
color: blue;
}

.console {
color: orange;
font-family: monospace;
border: #999999;
border-style: solid;
border-width: thin;
max-height: 150px;
min-height: 150px;
background: #3d1451;
overflow: scroll;
overflow-y: scroll;
overflow-x: scroll;
max-width: 750px;
min-width: 750px;
}

.compilation_succeeded {
color: green;
margin: 5px;
}

.compilation_failed {
color: red;
margin: 5px;
}

.compilation_feedback {
white-space: pre;
margin: 5px;
}

.editor_top {
background-color: black;
color: white;
width: 100%;
}

.editor_bottom {
background-color: black;
color: white;
width: 100%;
margin-top: -6px;
}

.editor_border {
border: #999999;
border-style: solid;
border-width: 3px;
font-family: monospace;
}
54 changes: 54 additions & 0 deletions tutor/app/assets/stylesheets/spinner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.spinner {
display: inline-block;
width: 15px;
height: 15px;
position: relative;
border: 2px solid rgba(0,0,0,0.5);
border-top-color: transparent;
border-radius: 100%;

-webkit-animation: spin 1s infinite linear;
-moz-animation: spin 1s infinite linear;
-ms-animation: spin 1s infinite linear;
-o-animation: spin 1s infinite linear;
animation: spin 1s infinite linear;
}

.spinner:after {
content: '';
display: block;
width: 0;
height: 0;
position: absolute;
top: -5px;
left: 0px;

border: 4px solid transparent;
border-bottom-color: rgba(0,0,0,0.5);

-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}

@-webkit-keyframes spin {
to { -webkit-transform: rotate(360deg); }
}

@-moz-keyframes spin {
to { -moz-transform: rotate(360deg); }
}

@-ms-keyframes spin {
to { -ms-transform: rotate(360deg); }
}

@-o-keyframes spin {
to { -o-transform: rotate(360deg); }
}

@keyframes spin {
to { transform: rotate(360deg); }
}
2 changes: 2 additions & 0 deletions tutor/app/controllers/compilers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class CompilersController < ApplicationController
end
17 changes: 9 additions & 8 deletions tutor/app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CoursesController < ApplicationController
# Allows students to sign-up/register for new courses by choosing
# the desired course attributes in the following order:
# University > Semester > Course > Instructor > Sign-Up > Confirmation
# Parameter:
# Parameters:
# params[]: A hash of the request URL attributes
# Returns:
# @status: The next status (0:Failure:Not a student, 1:University, 2:Semester, 3:Course,
Expand All @@ -14,16 +14,18 @@ class CoursesController < ApplicationController
# @lecturer: The chosen lecturer
# Author: Ahmed Moataz
def sign_up
@status = params[:status]
@status = params[:status]
if student_signed_in?
case params[:status]
when nil
@courses = Course.select(:university).distinct
@status = "1"
when "2"
@courses = Course.where("university= " + "\"" + params[:university] + "\"").select(:semester).distinct
@courses = Course.where("university= " + "\"" + params[:university] +
"\"").select(:semester).distinct
when "3"
@courses = Course.where("semester= " + params[:semester] + " AND university = " + "\"" + params[:university] + "\"")
@courses = Course.where("semester= " + params[:semester] +
" AND university = " + "\"" + params[:university] + "\"")
when "4"
@course = Course.find(params[:id])
when "5"
Expand All @@ -32,17 +34,16 @@ def sign_up
when "6"
@course = Course.find(params[:id])
@lecturer = Lecturer.find(params[:lecturer])
#Insertion in the DB
student = Student.find(current_student.id)
if student.courses.find_by_id(@course.id) == nil
student.courses << @course
else
@status = "7"
end
end
end
else
@status = "0"
end
@status = "0"
end
end

# [View Courses - Stroy 1.11]
Expand Down
25 changes: 25 additions & 0 deletions tutor/app/controllers/debuggers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class DebuggersController < ApplicationController

# [Debugger: Debug - Story 3.6]
# Send the recieved code to be debugged
# and return the result to the user as a json object
# Parameters:
# id: The id of the problem being solved
# code: The code to be debugged
# case: Test case to be debugged against
# Returns: Json object with the result of the debugging
# Author: Mussab ElDash
def start
if lecturer_signed_in? || teaching_assistant_signed_in?
render json: {}
end
id = current_student.id
pid = params[:id]
input = params[:code]
cases = params[:case]
result = Debugger.debug(id, pid, input, cases)
p result
render json: result
end

end
Loading

0 comments on commit e626835

Please sign in to comment.