@@ -4,26 +4,25 @@ import BlockBasedGrader from "./blockGrader.js";
44export default class BlockFeedback extends HParsonsFeedback {
55 createOutput ( ) {
66 // Block based grading output
7- this . hparsons . messageDiv = document . createElement ( "div" ) ;
8- this . hparsons . outerDiv . appendChild ( this . hparsons . messageDiv ) ;
7+ this . messageDiv = document . createElement ( "div" ) ;
8+ this . hparsons . outerDiv . appendChild ( this . messageDiv ) ;
99 }
1010 customizeUI ( ) {
1111 $ ( this . hparsons . runButton ) . text ( 'Check Me' ) ;
1212 }
1313
1414 init ( ) {
15- this . hparsons . blockIndex = 0 ;
16- this . hparsons . checkCount = 0 ;
17- this . hparsons . numDistinct = 0 ;
18- this . hparsons . hasSolved = false ;
15+ this . checkCount = 0 ;
16+ this . solved = false ;
1917 // TODO: not sure what is the best way to do this
20- this . hparsons . grader = new BlockBasedGrader ( ) ;
18+ this . grader = new BlockBasedGrader ( ) ;
2119 let solutionBlocks = [ ] ;
2220 for ( let i = 0 ; i < this . hparsons . blockAnswer . length ; ++ i ) {
2321 solutionBlocks . push ( this . hparsons . originalBlocks [ this . hparsons . blockAnswer [ i ] ] ) ;
2422 }
25- this . hparsons . solution = solutionBlocks ;
26- this . hparsons . grader . solution = solutionBlocks ;
23+ this . solution = solutionBlocks ;
24+ this . grader . solution = solutionBlocks ;
25+ this . answerArea = this . hparsons . hparsonsInput . shadowRoot . querySelector ( '.drop-area' ) ;
2726 }
2827
2928 // Called when check button clicked (block-based Feedback)
@@ -34,62 +33,62 @@ export default class BlockFeedback extends HParsonsFeedback {
3433
3534 // Used for block-based feedback
3635 checkCurrentAnswer ( ) {
37- if ( ! this . hparsons . hasSolved ) {
38- this . hparsons . checkCount ++ ;
36+ if ( ! this . solved ) {
37+ this . checkCount ++ ;
3938 this . clearFeedback ( ) ;
40- this . hparsons . grader . answer = this . hparsons . hparsonsInput . getParsonsTextArray ( ) ;
41- this . hparsons . grade = this . hparsons . grader . grade ( ) ;
42- if ( this . hparsons . grade == "correct" ) {
43- this . hparsons . hasSolved = true ;
44- this . hparsons . correct = true ;
39+ this . grader . answer = this . hparsons . hparsonsInput . getParsonsTextArray ( ) ;
40+ this . grade = this . grader . grade ( ) ;
41+ if ( this . grade == "correct" ) {
42+ this . solved = true ;
4543 $ ( this . hparsons . runButton ) . prop ( "disabled" , true ) ;
4644 }
4745 }
4846 }
4947
5048 renderFeedback ( ) {
51- this . hparsons . grade = this . hparsons . grader . graderState ;
49+ this . grade = this . grader . graderState ;
5250 var feedbackArea ;
53- var answerArea = $ ( this . hparsons . answerArea ) ;
54- feedbackArea = $ ( this . hparsons . messageDiv ) ;
51+ var answerArea = $ ( this . answerArea ) ;
52+ feedbackArea = $ ( this . messageDiv ) ;
5553
56- if ( this . hparsons . grade === "correct" ) {
54+ if ( this . grade === "correct" ) {
5755 answerArea . addClass ( "correct" ) ;
5856 feedbackArea . fadeIn ( 100 ) ;
5957 feedbackArea . attr ( "class" , "alert alert-info" ) ;
60- if ( this . hparsons . checkCount > 1 ) {
58+ if ( this . checkCount > 1 ) {
6159 feedbackArea . html (
62- $ . i18n ( "msg_parson_correct" , this . hparsons . checkCount )
60+ $ . i18n ( "msg_parson_correct" , this . checkCount )
6361 ) ;
6462 } else {
6563 feedbackArea . html ( $ . i18n ( "msg_parson_correct_first_try" ) ) ;
6664 }
65+ this . checkCount = 0 ;
6766 }
6867
69- if ( this . hparsons . grade === "incorrectTooShort" ) {
68+ if ( this . grade === "incorrectTooShort" ) {
7069 // too little code
7170 answerArea . addClass ( "incorrect" ) ;
7271 feedbackArea . fadeIn ( 500 ) ;
7372 feedbackArea . attr ( "class" , "alert alert-danger" ) ;
7473 feedbackArea . html ( $ . i18n ( "msg_parson_too_short" ) ) ;
7574 }
7675
77- if ( this . hparsons . grade === "incorrectMoveBlocks" ) {
78- var answerBlocks = this . hparsons . answerArea . children ;
76+ if ( this . grade === "incorrectMoveBlocks" ) {
77+ var answerBlocks = this . answerArea . children ;
7978 var inSolution = [ ] ;
8079 var inSolutionIndexes = [ ] ;
8180 var notInSolution = [ ] ;
8281 for ( let i = 0 ; i < answerBlocks . length ; i ++ ) {
8382 var block = answerBlocks [ i ] ;
84- var index = this . hparsons . solution . indexOf ( block . textContent ) ;
83+ var index = this . solution . indexOf ( block . textContent ) ;
8584 if ( index == - 1 ) {
8685 notInSolution . push ( block ) ;
8786 } else {
8887 inSolution . push ( block ) ;
8988 inSolutionIndexes . push ( index ) ;
9089 }
9190 }
92- var lisIndexes = this . hparsons . grader . inverseLISIndices ( inSolutionIndexes ) ;
91+ var lisIndexes = this . grader . inverseLISIndices ( inSolutionIndexes ) ;
9392 for ( let i = 0 ; i < lisIndexes . length ; i ++ ) {
9493 notInSolution . push ( inSolution [ lisIndexes [ i ] ] ) ;
9594 }
@@ -105,19 +104,19 @@ export default class BlockFeedback extends HParsonsFeedback {
105104
106105 // Feedback UI for Block-based Feedback
107106 clearFeedback ( ) {
108- $ ( this . hparsons . answerArea ) . removeClass ( "incorrect correct" ) ;
109- var children = this . hparsons . answerArea . childNodes ;
107+ $ ( this . answerArea ) . removeClass ( "incorrect correct" ) ;
108+ var children = this . answerArea . childNodes ;
110109 for ( var i = 0 ; i < children . length ; i ++ ) {
111110 $ ( children [ i ] ) . removeClass (
112111 "correctPosition incorrectPosition"
113112 ) ;
114113 }
115- $ ( this . hparsons . messageDiv ) . hide ( ) ;
114+ $ ( this . messageDiv ) . hide ( ) ;
116115
117116 // TODO: might need to change this
118- $ ( this . runButton ) . prop ( "disabled" , false ) ;
119- this . checkCount = 0 ;
120- this . hasSolved = false ;
117+ $ ( this . hparsons . runButton ) . prop ( "disabled" , false ) ;
118+ // this.checkCount = 0;
119+ this . solved = false ;
121120 }
122121
123122}
0 commit comments