@@ -28,10 +28,11 @@ def autograde_done
2828
2929 extend_config_module ( @assessment , submissions [ 0 ] , @cud )
3030
31- if ( @assessment . use_unique_module_name )
31+ if @assessment . use_unique_module_name
3232 require_relative ( @assessment . unique_config_file_path )
3333 else
34- require_relative ( Rails . root . join ( "assessmentConfig" , "#{ @course . name } -#{ @assessment . name } .rb" ) )
34+ require_relative ( Rails . root . join ( "assessmentConfig" ,
35+ "#{ @course . name } -#{ @assessment . name } .rb" ) )
3536 end
3637
3738 if @assessment . overwrites_method? ( :autogradeDone )
@@ -86,7 +87,19 @@ def regrade
8687 #
8788 # action_auth_level :regradeBatch, :instructor
8889 def regradeBatch
89- submission_ids = params [ :submission_ids ]
90+ request_body = request . body . read
91+ submission_ids = begin if request_body . present?
92+ parsed_data = JSON . parse ( request_body )
93+ Array ( parsed_data [ 'submission_ids' ] )
94+ else
95+ params [ :submission_ids ]
96+ end
97+ rescue JSON ::ParserError => e
98+ params [ :submission_ids ] || [ ]
99+ end
100+
101+ # Ensure submission_ids is an array
102+ submission_ids = Array ( submission_ids )
90103
91104 # Now regrade only the most recent submissions. Keep track of
92105 # any handins that fail.
@@ -106,26 +119,32 @@ def regradeBatch
106119
107120 failure_jobs = failed_list . length
108121 if failure_jobs > 0
109- flash [ :error ] = "Warning: Could not regrade #{ ActionController ::Base . helpers . pluralize ( failure_jobs , "submission" ) } :<br>"
122+ flash [ :error ] =
123+ "Warning: Could not regrade #{ ActionController ::Base . helpers . pluralize ( failure_jobs ,
124+ "submission" ) } :<br>"
110125 failed_list . each do |failure |
111- if failure [ :error ] . error_code == :nil_submission
112- flash [ :error ] += "Unrecognized submission ID<br>"
113- else
114- flash [ :error ] += "#{ failure [ :submission ] . filename } : #{ failure [ :error ] . message } <br>"
115- end
126+ flash [ :error ] += if failure [ :error ] . error_code == :nil_submission
127+ "Unrecognized submission ID<br>"
128+ else
129+ "#{ failure [ :submission ] . filename } : #{ failure [ :error ] . message } <br>"
130+ end
116131 end
117132 end
118133
119134 success_jobs = submissions . size - failure_jobs
120135 if success_jobs > 0
121- link = "<a href=\" #{ url_for ( controller : 'jobs' ) } \" >#{ ActionController ::Base . helpers . pluralize ( success_jobs , "submission" ) } </a>"
122- flash [ :success ] = ( "Regrading #{ link } " )
136+ link = "<a href=\" #{ url_for ( controller : 'jobs' ) } \" >#{ ActionController ::Base . helpers . pluralize (
137+ success_jobs , "submission" ) } </a>"
138+ flash [ :success ] = "Regrading #{ link } "
123139 end
124140
125141 # For both :success and :error
126142 flash [ :html_safe ] = true
127143
128- redirect_to ( [ @course , @assessment , :submissions ] ) && return
144+ respond_to do |format |
145+ format . html { redirect_to [ @course , @assessment , :submissions ] }
146+ format . json { render json : { redirect : url_for ( [ @course , @assessment , :submissions ] ) } }
147+ end
129148 end
130149
131150 #
@@ -136,7 +155,7 @@ def regradeBatch
136155 # action_auth_level :regradeAll, :instructor
137156 def regradeAll
138157 # Grab all of the submissions for this assessment
139- @submissions = @assessment . submissions . where ( special_type : Submission ::NORMAL )
158+ @submissions = @assessment . submissions . where ( special_type : [ Submission ::NORMAL , nil ] )
140159 . order ( "version DESC" )
141160
142161 last_submissions = @submissions . latest
@@ -153,20 +172,22 @@ def regradeAll
153172
154173 failure_jobs = failed_list . length
155174 if failure_jobs > 0
156- flash [ :error ] = "Warning: Could not regrade #{ ActionController ::Base . helpers . pluralize ( failure_jobs , "submission" ) } :<br>"
175+ flash [ :error ] =
176+ "Warning: Could not regrade #{ ActionController ::Base . helpers . pluralize ( failure_jobs , "submission" ) } "
177+
178+ @failure_messages = [ ]
157179 failed_list . each do |failure |
158- if failure [ :error ] . error_code == :nil_submission
159- flash [ :error ] += "Unrecognized submission ID<br> "
160- else
161- flash [ :error ] += "#{ failure [ :submission ] . filename } : #{ failure [ :error ] . message } <br> "
162- end
180+ @failure_messages << if failure [ :error ] . error_code == :nil_submission
181+ "Unrecognized submission ID"
182+ else
183+ "#{ failure [ :submission ] . filename } : #{ failure [ :error ] . message } "
184+ end
163185 end
164186 end
165187
166188 success_jobs = last_submissions . size - failure_jobs
167189 if success_jobs > 0
168- link = "<a href=\" #{ url_for ( controller : 'jobs' ) } \" >#{ ActionController ::Base . helpers . pluralize ( success_jobs , "student" ) } </a>"
169- flash [ :success ] = ( "Regrading the most recent submissions from #{ link } " )
190+ flash [ :success ] = "Regrading #{ success_jobs } recent submissions"
170191 end
171192
172193 # For both :success and :error
@@ -189,7 +210,8 @@ def regradeAll
189210 #
190211 def sendJob_AddHTMLMessages ( course , assessment , submissions )
191212 # Check for nil first, since students should know about this
192- flash [ :error ] = "Submission could not be autograded due to an error in creation" && return if submissions . blank?
213+ flash [ :error ] =
214+ "Submission could not be autograded due to an error in creation" && return if submissions . blank?
193215
194216 begin
195217 job = sendJob ( course , assessment , submissions , @cud )
@@ -198,36 +220,42 @@ def sendJob_AddHTMLMessages(course, assessment, submissions)
198220 when :missing_autograding_props
199221 flash [ :error ] = "Autograding failed because there are no autograding properties."
200222 if @cud . instructor?
201- link = ( view_context . link_to "Autograder Settings" , [ :edit , course , assessment , :autograder ] )
223+ link = ( view_context . link_to "Autograder Settings" ,
224+ [ :edit , course , assessment , :autograder ] )
202225 flash [ :error ] += " Visit #{ link } to set the autograding properties."
203226 flash [ :html_safe ] = true
204227 else
205228 flash [ :error ] += " Please contact your instructor."
206229 end
207230 when :tango_open
208- flash [ :error ] = "There was an error submitting your autograding job. We are likely down for maintenance if issues persist, please contact #{ Rails . configuration . school [ 'support_email' ] } "
231+ flash [ :error ] =
232+ "There was an error submitting your autograding job. We are likely down for maintenance if issues persist, please contact #{ Rails . configuration . school [ 'support_email' ] } "
209233 when :tango_upload
210234 flash [ :error ] = "There was an error uploading the submission file."
211235 when :tango_add_job
212236 flash [ :error ] = "Submission was rejected by autograder."
213237 if @cud . instructor?
214- link = ( view_context . link_to "Autograder Settings" , [ :edit , course , assessment , :autograder ] )
238+ link = ( view_context . link_to "Autograder Settings" ,
239+ [ :edit , course , assessment , :autograder ] )
215240 flash [ :error ] += " Verify the autograding properties at #{ link } .<br>ErrorMsg: " + e . additional_data
216241 flash [ :html_safe ] = true
217242 end
218243 when :missing_autograder_file
219- flash [ :error ] = "One or more files are missing in the server. Please contact the instructor. The missing files are: " + e . additional_data
244+ flash [ :error ] =
245+ "One or more files are missing in the server. Please contact the instructor. The missing files are: " + e . additional_data
220246 else
221247 flash [ :error ] = "Autograding failed because of an unexpected exception in the system."
222248 end
223249
224250 raise e # pass it on
225251 end
226252
227- link = "<a href=\" #{ url_for ( controller : 'jobs' , action : 'getjob' , id : job ) } \" >Job ID = #{ job } </a>"
228- viewFeedbackLink = "<a href=\" #{ url_for ( controller : 'assessments' , action : 'viewFeedback' , submission_id : submissions [ 0 ] . id , feedback : assessment . problems [ 0 ] . id ) } \" >View autograding progress.</a>"
229- flash [ :success ] = ( "Submitted file #{ submissions [ 0 ] . filename } (#{ link } ) for autograding." \
230- " #{ viewFeedbackLink } " )
253+ link = "<a href=\" #{ url_for ( controller : 'jobs' , action : 'getjob' ,
254+ id : job ) } \" >Job ID = #{ job } </a>"
255+ viewFeedbackLink = "<a href=\" #{ url_for ( controller : 'assessments' , action : 'viewFeedback' ,
256+ submission_id : submissions [ 0 ] . id , feedback : assessment . problems [ 0 ] . id ) } \" >View autograding progress.</a>"
257+ flash [ :success ] = "Submitted file #{ submissions [ 0 ] . filename } (#{ link } ) for autograding." \
258+ " #{ viewFeedbackLink } "
231259 flash [ :html_safe ] = true
232260 job
233261 end
0 commit comments