1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import * as commonmark from 'commonmark' ;
4
- import Assessment from './Assessment.js' ;
5
4
6
5
import ADASEditor from './editors/ADASEditor.jsx' ;
7
6
import CobbDouglasEditor from './editors/CobbDouglasEditor.jsx' ;
@@ -25,12 +24,9 @@ import PositiveExternalityIndustryEditor from
25
24
26
25
import ExportGraphButton from './buttons/ExportGraphButton.jsx' ;
27
26
import ResetGraphButton from './buttons/ResetGraphButton.jsx' ;
28
- import SubmitButton from './buttons/SubmitButton.jsx' ;
29
27
import JXGBoard from './JXGBoard.jsx' ;
30
28
import Feedback from './Feedback.jsx' ;
31
- import {
32
- forceFloat , getOrCreateSubmission , BOARD_WIDTH , BOARD_HEIGHT
33
- } from './utils' ;
29
+ import { BOARD_WIDTH , BOARD_HEIGHT } from './utils' ;
34
30
import RevenueElasticityEditor from './editors/RevenueElasticityEditor.jsx' ;
35
31
import TaxRevenueEditor from './editors/TaxRevenueEditor.jsx' ;
36
32
@@ -214,7 +210,7 @@ export default class GraphViewer extends React.Component {
214
210
< div className = "GraphViewer" >
215
211
{ titleEl }
216
212
{ instructionsEl }
217
- < form onSubmit = { this . handleSubmit . bind ( this ) } action = { action } method = "post" >
213
+ < form action = { action } method = "post" >
218
214
< input type = "hidden" name = "csrfmiddlewaretoken" value = { token } />
219
215
< input type = "hidden" name = "score" value = { this . state . score } />
220
216
< input type = "hidden" name = "next" value = { successUrl } />
@@ -228,17 +224,13 @@ export default class GraphViewer extends React.Component {
228
224
229
225
{ rightSide }
230
226
227
+ < hr />
228
+
231
229
< ResetGraphButton
232
230
initialState = { initialState }
233
231
updateGraph = { this . updateGraph } />
234
232
235
233
< ExportGraphButton />
236
-
237
- < SubmitButton
238
- assessment = { this . props . assessment }
239
- gNeedsSubmit = { this . props . gNeedsSubmit }
240
- submission = { this . props . submission }
241
- isInstructor = { isInstructor } />
242
234
</ form >
243
235
</ div >
244
236
) ;
@@ -301,7 +293,7 @@ export default class GraphViewer extends React.Component {
301
293
< div className = "GraphViewer" >
302
294
{ titleEl }
303
295
{ instructionsEl }
304
- < form onSubmit = { this . handleSubmit . bind ( this ) } action = { action } method = "post" >
296
+ < form action = { action } method = "post" >
305
297
< input type = "hidden" name = "csrfmiddlewaretoken" value = { token } />
306
298
< input type = "hidden" name = "score" value = { this . state . score } />
307
299
< input type = "hidden" name = "next" value = { successUrl } />
@@ -315,17 +307,13 @@ export default class GraphViewer extends React.Component {
315
307
316
308
{ rightSide }
317
309
310
+ < hr />
311
+
318
312
< ResetGraphButton
319
313
initialState = { initialState }
320
314
updateGraph = { this . updateGraph } />
321
315
322
316
< ExportGraphButton />
323
-
324
- < SubmitButton
325
- assessment = { this . props . assessment }
326
- gNeedsSubmit = { this . props . gNeedsSubmit }
327
- submission = { this . props . submission }
328
- isInstructor = { isInstructor } />
329
317
</ form >
330
318
</ div >
331
319
) ;
@@ -363,7 +351,7 @@ export default class GraphViewer extends React.Component {
363
351
< div className = "GraphViewer" >
364
352
{ titleEl }
365
353
{ instructionsEl }
366
- < form onSubmit = { this . handleSubmit . bind ( this ) } action = { action } method = "post" >
354
+ < form action = { action } method = "post" >
367
355
< input type = "hidden" name = "csrfmiddlewaretoken" value = { token } />
368
356
< input type = "hidden" name = "score" value = { this . state . score } />
369
357
< input type = "hidden" name = "next" value = { successUrl } />
@@ -381,98 +369,19 @@ export default class GraphViewer extends React.Component {
381
369
< div className = "col-lg-6" >
382
370
{ rightSide }
383
371
372
+ < hr />
373
+
384
374
< ResetGraphButton
385
375
initialState = { initialState }
386
376
updateGraph = { this . updateGraph } />
387
377
388
378
< ExportGraphButton />
389
-
390
- < SubmitButton
391
- assessment = { this . props . assessment }
392
- gNeedsSubmit = { this . props . gNeedsSubmit }
393
- submission = { this . props . submission }
394
- isInstructor = { isInstructor } />
395
379
</ div >
396
380
</ div >
397
381
</ form >
398
382
</ div >
399
383
) ;
400
384
}
401
- // When the submission is loaded by the Viewer, see if
402
- // this.state.currentFeedback should be updated.
403
- componentDidUpdate ( prevProps ) {
404
- if ( prevProps . submission !== this . props . submission ) {
405
- this . loadFeedback (
406
- this . props . submission . feedback_unfulfilled ,
407
- this . props . submission . feedback_fulfilled ) ;
408
- }
409
- }
410
- loadFeedback ( unfulfilledFeedback , fulfilledFeedback ) {
411
- const currentFeedback = [ ] ;
412
-
413
- unfulfilledFeedback = unfulfilledFeedback . split ( ';;' ) ;
414
- fulfilledFeedback = fulfilledFeedback . split ( ';;' ) ;
415
-
416
- unfulfilledFeedback . forEach ( e => {
417
- if ( e ) {
418
- currentFeedback . push ( {
419
- feedback : e ,
420
- fulfilled : false
421
- } ) ;
422
- }
423
- } ) ;
424
- fulfilledFeedback . forEach ( e => {
425
- if ( e ) {
426
- currentFeedback . push ( {
427
- feedback : e ,
428
- fulfilled : true
429
- } ) ;
430
- }
431
- } ) ;
432
-
433
- this . setState ( { currentFeedback : currentFeedback } ) ;
434
- }
435
- handleSubmit ( event ) {
436
- event . preventDefault ( ) ;
437
- const assessment = new Assessment ( this . props . assessment ) ;
438
- const responses = assessment . evalState ( this . props ) ;
439
-
440
- if ( this . props . gNeedsSubmit ) {
441
- // LTI Assessment graph submitted. Create a Submission
442
- // object and submit to Canvas with LTI.
443
- const form = event . target ;
444
-
445
- // Sum up the scores for all fulfilled rules.
446
- const scores = responses . map ( x => forceFloat ( x . score ) ) ;
447
- const score = scores . reduce ( ( a , b ) => a + b , 0 ) ;
448
-
449
- this . setState ( { score : score } ) ;
450
-
451
- // Save the user's feedback on their Submission object to
452
- // make it persistent.
453
- const fulfilledFeedback = responses
454
- . filter ( x => x . fulfilled )
455
- . map ( x => x . feedback )
456
- . join ( ';;' ) ;
457
- const unfulfilledFeedback = responses
458
- . filter ( x => ! x . fulfilled )
459
- . map ( x => x . feedback )
460
- . join ( ';;' ) ;
461
-
462
- getOrCreateSubmission ( {
463
- graph : this . props . gId ,
464
- feedback_fulfilled : fulfilledFeedback ,
465
- feedback_unfulfilled : unfulfilledFeedback ,
466
- score : score
467
- } ) . then ( function ( ) {
468
- form . submit ( ) ;
469
- } ) ;
470
- } else {
471
- // Practice Assessment submitted. Show feedback
472
- // immediately.
473
- this . setState ( { currentFeedback : responses } ) ;
474
- }
475
- }
476
385
updateGraph ( state ) {
477
386
this . setState ( { currentFeedback : state . currentFeedback } ) ;
478
387
return this . props . updateGraph ( state ) ;
@@ -484,7 +393,6 @@ GraphViewer.propTypes = {
484
393
gType : PropTypes . number ,
485
394
gTitle : PropTypes . string ,
486
395
gInstructions : PropTypes . string ,
487
- gNeedsSubmit : PropTypes . bool ,
488
396
gAssignmentType : PropTypes . number . isRequired ,
489
397
490
398
gShowIntersection : PropTypes . bool . isRequired ,
@@ -603,7 +511,5 @@ GraphViewer.propTypes = {
603
511
gExpression2 : PropTypes . string ,
604
512
gExpression3 : PropTypes . string ,
605
513
606
- assessment : PropTypes . array ,
607
- submission : PropTypes . object ,
608
514
updateGraph : PropTypes . func . isRequired
609
515
} ;
0 commit comments