@@ -76,6 +76,7 @@ export default class HParsons extends RunestoneBase {
7676
7777 // initializing functionalities for different feedback
7878 this . feedbackController . init ( ) ;
79+ this . checkServer ( 'hparsons' , true ) ;
7980 }
8081
8182 // copied from activecode, already modified to add parsons
@@ -115,7 +116,6 @@ export default class HParsons extends RunestoneBase {
115116 this . feedbackController . createOutput ( ) ;
116117 }
117118
118- // copied from activecode
119119 createControls ( ) {
120120 var ctrlDiv = document . createElement ( "div" ) ;
121121 $ ( ctrlDiv ) . addClass ( "hp_actions" ) ;
@@ -127,8 +127,10 @@ export default class HParsons extends RunestoneBase {
127127 ctrlDiv . appendChild ( this . runButton ) ;
128128 $ ( this . runButton ) . attr ( "type" , "button" ) ;
129129 $ ( this . runButton ) . text ( "Run" ) ;
130+ var that = this ;
130131 this . runButton . onclick = ( ) => {
131- this . feedbackController . runButtonHandler ( ) ;
132+ that . feedbackController . runButtonHandler ( ) ;
133+ that . setLocalStorage ( ) ;
132134 } ;
133135
134136 // Reset button
@@ -139,8 +141,9 @@ export default class HParsons extends RunestoneBase {
139141 ctrlDiv . appendChild ( resetBtn ) ;
140142 this . resetButton = resetBtn ;
141143 this . resetButton . onclick = ( ) => {
142- this . hparsonsInput . resetInput ( ) ;
143- this . feedbackController . reset ( ) ;
144+ that . hparsonsInput . resetInput ( ) ;
145+ that . setLocalStorage ( ) ;
146+ that . feedbackController . reset ( ) ;
144147 } ;
145148 $ ( resetBtn ) . attr ( "type" , "button" ) ;
146149
@@ -149,6 +152,7 @@ export default class HParsons extends RunestoneBase {
149152 }
150153
151154 // Return previous answers in local storage
155+ //
152156 localData ( ) {
153157 var data = localStorage . getItem ( this . storageId ) ;
154158 if ( data !== null ) {
@@ -164,28 +168,39 @@ export default class HParsons extends RunestoneBase {
164168 }
165169 // RunestoneBase: Sent when the server has data
166170 restoreAnswers ( serverData ) {
167- this . loadData ( serverData ) ;
171+ if ( serverData . answer ) {
172+ this . hparsonsInput . restoreAnswer ( serverData . answer ) ;
173+ }
168174 }
169175 // RunestoneBase: Load what is in local storage
170176 checkLocalStorage ( ) {
171177 if ( this . graderactive ) {
178+ // Zihan: I think this means the component is still loading?
172179 return ;
173180 }
174- this . loadData ( this . localData ( ) ) ;
181+ let localData = this . localData ( ) ;
182+ if ( localData . answer ) {
183+ this . hparsonsInput . restoreAnswer ( localData . answer ) ;
184+ }
185+ if ( localData . count ) {
186+ this . feedbackController . checkCount = localData . count ;
187+ }
175188 }
176189 // RunestoneBase: Set the state of the problem in local storage
177190 setLocalStorage ( data ) {
178- var toStore ;
191+ let currentState = { } ;
179192 if ( data == undefined ) {
180- toStore = {
181- source : this . sourceHash ( ) ,
182- answer : this . answerHash ( ) ,
183- timestamp : new Date ( ) ,
184- } ;
193+ currentState = {
194+ answer : this . hparsonsInput . getParsonsTextArray ( )
195+ }
196+ if ( this . isBlockGrading ) {
197+ // if this is block grading, add number of previous attempts too
198+ currentState . count = this . feedbackController . checkCount ;
199+ }
185200 } else {
186- toStore = data ;
201+ currentState = data ;
187202 }
188- localStorage . setItem ( this . storageId , JSON . stringify ( toStore ) ) ;
203+ localStorage . setItem ( this . storageId , JSON . stringify ( currentState ) ) ;
189204 }
190205
191206 logHorizontalParsonsEvent ( hparsonsEvent ) {
0 commit comments