diff --git a/tutor/app/assets/javascripts/solutions.js.coffee b/tutor/app/assets/javascripts/solutions.js.coffee index 09ab84de..cd3c7a95 100644 --- a/tutor/app/assets/javascripts/solutions.js.coffee +++ b/tutor/app/assets/javascripts/solutions.js.coffee @@ -1,7 +1,7 @@ # The list of variables -Variables = null +variables = null # The number of the current index of the line to be executed -IndexNumber = 0 +indexNumber = 0 # [Debugger: Debug - Story 3.6] # Sends the code to the server and changes the Variables to the data recieved @@ -12,8 +12,6 @@ IndexNumber = 0 @start_debug = (problem_id) -> input = $('#solution_code').val() test = $('#testcases').val() - alert input - alert test start_spin() $.ajax type: "POST" @@ -21,14 +19,10 @@ IndexNumber = 0 data: {code : input , case : test} datatype: 'json' success: (data) -> - $('#nextButton').attr "disabled", false - $('#previousButton').attr "disabled", true toggleDebug() - Variables = data + variables = data stop_spin() - for datum in data - alert "#{datum['line']}=>#{datum['locals']}locals is Empty for now" - return + highlight_line data[0]['line'] error: -> stop_spin() return @@ -82,7 +76,12 @@ IndexNumber = 0 # Returns: none # Author: Rami Khalil @next = () -> - alert "Next Step" + 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. @@ -91,7 +90,28 @@ IndexNumber = 0 # Returns: none # Author: Rami Khalil @previous = () -> - alert "Previous Step" + 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. @@ -101,3 +121,5 @@ IndexNumber = 0 # Author: Rami Khalil (Temporary) @stop = () -> toggleDebug() + indexNumber = 0; + variables = null; diff --git a/tutor/app/models/debugger.rb b/tutor/app/models/debugger.rb index 062e21bf..bf48d059 100644 --- a/tutor/app/models/debugger.rb +++ b/tutor/app/models/debugger.rb @@ -15,7 +15,7 @@ class Debugger < ActiveRecord::Base # regex : The input regex to be encountered to return # Returns: A String of the buffer # Author: Rami Khalil - def buffer_until regex + def buffer_until(regex) buffer = "" until !$wait_thread.alive? or regex.any? { |expression| buffer =~ expression } do begin @@ -53,7 +53,7 @@ def buffer_until_complete # input : The input to be written in the sub stream # Returns: none # Author: Rami Khalil - def input input + def input(input) $input.puts input end @@ -64,7 +64,7 @@ def input input # file_path : The path of the file to debugged # input : The arguments to be passed to the main method # Returns: A List of all 100 steps ahead - # Author: Mussab ElDash + # Authors: Mussab ElDash + Rami Khalil def start(file_path, input) to_be_compiled = file_path if file_path =~ /.*\.java/ diff --git a/tutor/app/models/solution.rb b/tutor/app/models/solution.rb index 6529ea4a..6715c011 100644 --- a/tutor/app/models/solution.rb +++ b/tutor/app/models/solution.rb @@ -10,9 +10,61 @@ class Solution < ActiveRecord::Base #Scoops #Methods + # [ + # Compiler: Compile - Story 3.4 + # Compiler: Validate - Story 3.5 + # Debugger: Debug - Story 3.6 + # Compiler: Test - Story 3.15 + # ] + # Returns the file name associated with this solution code. + # Parameters: + # append_extension: A boolean value deciding whether the file extension should be appended. + # Returns: The solution's java file name + # Author: Rami Khalil + def file_name + return 'st' + student_id.to_s + 'pr' + problem_id.to_s + 'so' + id.to_s + end + + # [ + # Compiler: Compile - Story 3.4 + # Compiler: Validate - Story 3.5 + # Debugger: Debug - Story 3.6 + # Compiler: Test - Story 3.15 + # ] + # Returns the java file name associated with this solution code. + # Parameters: + # append_extension: A boolean value deciding whether the file extension should be appended. + # Returns: The solution's java file name + # Author: Rami Khalil + def java_file_name(prepend_path = false, append_extension = false) + jfile_name = file_name + jfile_name += ".java" if append_extension + jfile_name = JAVA_PATH + jfile_name if prepend_path + return jfile_name + end + + # [ + # Compiler: Compile - Story 3.4 + # Compiler: Validate - Story 3.5 + # Debugger: Debug - Story 3.6 + # Compiler: Test - Story 3.15 + # ] + # Returns the class file name associated with this solution code. + # Parameters: + # append_extension: A boolean value deciding whether the file extension should be appended. + # Returns: The solution's class file name + # Author: Rami Khalil + def class_file_name(prepend_path = false, append_extension = false) + jfile_name = file_name + jfile_name += ".class" if append_extension + jfile_name = CLASS_PATH + jfile_name if prepend_path + return jfile_name + end #Constants STATUS_SUBMITTED = 0 STATUS_ACCEPTED = 1 + JAVA_PATH = 'students_solutions/Java/' + CLASS_PATH = 'students_solutions/Class/' end diff --git a/tutor/app/views/layouts/application.html.erb b/tutor/app/views/layouts/application.html.erb index 27cd9a3b..feee850c 100644 --- a/tutor/app/views/layouts/application.html.erb +++ b/tutor/app/views/layouts/application.html.erb @@ -50,7 +50,7 @@