Skip to content

Commit

Permalink
Issue #206 pulling
Browse files Browse the repository at this point in the history
  • Loading branch information
serag committed Apr 23, 2014
2 parents c2ff0a2 + 3e7bcbf commit f1e91e5
Show file tree
Hide file tree
Showing 38 changed files with 1,010 additions and 171 deletions.
2 changes: 1 addition & 1 deletion tutor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ models.svg

# Ignoring .java and .class files
/students_solutions/Java/*.java
/students_solutions/Class/*.class
/students_solutions/Class/*.class
3 changes: 3 additions & 0 deletions tutor/app/assets/javascripts/posts.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/
171 changes: 143 additions & 28 deletions tutor/app/assets/javascripts/solutions.js.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The list of variables
variables = null
# The number of the current index of the line to be executed
indexNumber = 0
index_number = 0

# [Debugger: Debug - Story 3.6]
# Sends the code to the server and changes the Variables to the data recieved
Expand All @@ -11,89 +11,142 @@ indexNumber = 0
# Author: Mussab ElDash
@start_debug = (problem_id) ->
input = $('#solution_code').val()
test = $('#testcases').val()
if input.length is 0
alert "You didn't write any code"
return
test = $('#solution_input').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']
if !data["success"]
compilation_error data["data"]["errors"]
return
variables = data["data"]
toggleDebug()
debug_console()
jump_state 0
error: ->
stop_spin()
return
return

# [Debugger: Debug - Story 3.6]
# Fills the console with the compilation errors
# Parameters: none
# Returns: none
# Author: Mussab ElDash
compilation_error = (data) ->
$('.compilation_failed').html("Compilation Failed!")
$('.compilation_feedback').html(data)
return

# [Debugger: Debug - Story 3.6]
# Clears the console
# Parameters: none
# Returns: none
# Author: Mussab ElDash
clear_console = ->
$('.compilation_failed').html("")
$('.compilation_feedback').html("")
return

# [Debugger: Debug - Story 3.6]
# Write successful debug in the console
# Parameters: none
# Returns: none
# Author: Mussab ElDash
debug_console = ->
$('.compilation_succeeded').html("Debugging Succeeded!")
return

# [Debugger: Debug - Story 3.6]
# Starts the Spinner
# Parameters: none
# Returns: none
# Author: Mussab ElDash
@start_spin = ->
$('#spinner').attr "class" , "spinner"
$('#spinner').addClass "spinner"
return

# [Debugger: Debug - Story 3.6]
# Stops the Spinner
# Parameters: none
# Returns: none
# Author: Mussab ElDash
@stop_spin = ->
$('#spinner').attr "class" , ""
$('#spinner').removeClass "spinner"
return

# [Debugger: Debug - Story 3.6]
# Toggles the Spinner
# Parameters: none
# Returns: none
# Author: Mussab ElDash
@toggle_spin = ->
$('#spinner').toggleClass "spinner"

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

$('#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
# 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
# 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
# Parameters: none
# Returns: none
# Author: Rami Khalil
@next = () ->
if indexNumber + 1 < variables.length
jump_state ++indexNumber
else if(indexNumber == 99)
if index_number + 1 < variables.length
jump_state ++index_number
else if(index_number == 99)
alert "The online debugger can only step forward 100 times."
jump_state index_number
else
alert "The program has terminated."
jump_state index_number

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

# [Execute Line By Line - Story 3.8]
# Highlights the target line number in the editor
Expand All @@ -102,7 +155,30 @@ indexNumber = 0
# Returns: none
# Author: Rami Khalil
@highlight_line = (line) ->
alert "At line: " + line
text_area = document.getElementById "solution_code"
code_lines = text_area.value.split '\n'
start_offset = 0
for i in[0..code_lines.length] by 1
if i == line
break
start_offset += code_lines[i].length+1
end_offset = start_offset + code_lines[line].length

# Chrome / Firefox
if typeof(text_area.selectionStart) != "undefined"
text_area.focus()
text_area.selectionStart = start_offset
text_area.selectionEnd = end_offset

# IE
if document.selection && document.selection.createRange
text_area.focus()
text_area.select()
document.selection.createRange()
text_area.collapse(true)
text_area.moveEnd("character", end_offset)
text_area.moveStart("character", start_offset)
text_area.select()

# [Execute Line By Line - Story 3.8]
# Jumps to the target state by highlighting the line and showing variables
Expand All @@ -111,15 +187,54 @@ indexNumber = 0
# Returns: none
# Author: Rami Khalil
@jump_state = (stateNumber) ->
highlight_line variables[stateNumber]['line']
highlight_line variables[stateNumber]['line'] - 2

# [Debug - Story 3.6]
# Stops the debugging session.
# Parameters:
# none
# Parameters: none
# Returns: none
# Author: Rami Khalil (Temporary)
@stop = () ->
toggleDebug()
indexNumber = 0;
index_number = 0;
variables = null;

# To be Used when changing to ajax in order not to refresh page
# [Compiler: Validate - Story 3.5]
# submits a solution in the form without refreshing
# using ajax showing an alert box for success and failure scenarios
# Parameters:
# problem_id: the id of the problem being solved
# Returns: a json object containing two arrays one for the errors
# of the current code and the other containing success messages
# Author: MOHAMEDSAEED
@validate_code = (problem_id) ->
code = $('#solution_code').val()
mins = parseInt($('#mins').text())
secs = parseInt($('#secs').text())
time = mins*60 + secs
start_spin()
$.ajax
type: "POST"
url: '/solutions'
data: {problem_id: problem_id, code: code, time: time}
datatype: 'json'
success: (data) ->
stop_spin()
success = $('#validate_success')
errors = $('#validate_error')
success.html("")
for i in data["success"]
success.append("#{i}<br>")
errors.html("")
for i in data["failure"]
errors.append("#{i}<br>")
if code.length isnt 0
alert 'Solution has been submitted successfully'
else
alert 'Blank submissions are not allowed'
return
error: (data) ->
stop_spin()
return
return
3 changes: 3 additions & 0 deletions tutor/app/assets/stylesheets/posts.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the posts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
1 change: 1 addition & 0 deletions tutor/app/assets/stylesheets/problems.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
.test {
width: 100%;
min-height: 200px;
float: left;
}

23 changes: 21 additions & 2 deletions tutor/app/assets/stylesheets/solutions.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ textarea {

.accepted {
display: none;
color: green;
color: green;
}

.wrong_answer {
Expand All @@ -31,6 +31,25 @@ textarea {
color: blue;
}

.fixed-content {
max-height: 200px;
overflow-y:scroll;
overflow-x:hidden;
}

.editor {
background-color: black;
color: white;
width: 100%;
min-height: 500px;
}

.test {
width: 100%;
min-height: 200px;
float: left;
}

.console {
color: orange;
font-family: monospace;
Expand Down Expand Up @@ -72,7 +91,7 @@ textarea {
background-color: black;
color: white;
width: 100%;
margin-top: -6px;
margin-top: -6px;
}

.editor_border {
Expand Down
Loading

0 comments on commit f1e91e5

Please sign in to comment.