@@ -40,6 +40,111 @@ angular.module('myApp', ['ui.router', 'ui.ace', 'ngWebworker'])
4040
4141} ] ) // end config
4242
43+ angular . module ( 'myApp' )
44+
45+ . controller ( 'assessmentController' , [ "$scope" , "assessmentService" , "workerService" , function ( $scope , assessmentService , workerService ) {
46+
47+ assessmentService . getAssessment ( ) . then ( function ( response ) {
48+ var list = [ ] ;
49+ _ . each ( response , function ( item ) {
50+ for ( var i = 0 ; i < item . questions . length ; i ++ ) {
51+ list . push ( item . questions [ i ] ) ;
52+ }
53+ } )
54+ // console.log(list);
55+ $scope . questions = list ;
56+ } ) ;
57+
58+ $scope . eval = function ( q , userCode ) {
59+
60+
61+ let qId = q . _id ;
62+ let answer = q . answer ;
63+
64+ workerService . worker ( qId , answer , userCode ) . then ( function ( result ) {
65+ assessmentService . ticker ( result ) ;
66+ } )
67+
68+ }
69+
70+ $scope . submitAssessment = ( length ) => {
71+ assessmentService . submitAssessment ( length ) ;
72+ }
73+
74+ $scope . doSomeStuff = function ( q ) {
75+ q . disabled = true ;
76+ }
77+
78+
79+ } ] ) ;
80+
81+ angular . module ( 'myApp' )
82+
83+ . service ( 'assessmentService' , [ "$q" , "$http" , function ( $q , $http ) {
84+
85+
86+
87+ this . getAssessment = ( ) => {
88+ return $http ( {
89+ method : 'GET' ,
90+ url : '/api/assessment/js'
91+ } ) . then ( ( response ) => {
92+
93+ return response . data ;
94+ } )
95+ }
96+
97+ var tick = 0 ;
98+ this . ticker = ( result ) => {
99+ if ( result === true ) {
100+ tick += 1 ;
101+ } else {
102+ return 0 ;
103+ }
104+ console . log ( "tick count" , tick ) ;
105+ }
106+
107+ this . submitAssessment = ( length ) => {
108+ var totalScore = ( tick / length ) * 100 ;
109+ totalScore = totalScore . toString ( ) ;
110+ console . log ( totalScore ) ;
111+ return $http ( {
112+ method : 'PUT' ,
113+ url : '/api/users' ,
114+ data : {
115+ progress : {
116+ jsAssessment : totalScore
117+ }
118+ }
119+ } ) . success ( function ( resp ) {
120+ console . log ( resp ) ;
121+ } )
122+ }
123+
124+ } ] )
125+
126+ angular . module ( 'myApp' ) . service ( 'workerService' , [ "Webworker" , function ( Webworker ) {
127+
128+ this . worker = ( qId , answer , userCode ) => {
129+
130+ function isSame ( userCode , answer ) {
131+ if ( userCode === answer ) {
132+ return true ;
133+ } else {
134+ return false ;
135+ }
136+ }
137+
138+ var myWorker = Webworker . create ( isSame , {
139+ isSame : true ,
140+ onReturn : function ( data ) { return data ; }
141+ } ) ;
142+
143+ var result = myWorker . run ( userCode , answer ) ;
144+ return result ;
145+ }
146+ } ] )
147+
43148angular . module ( 'myApp' )
44149
45150 . directive ( 'bars' , function ( ) {
@@ -418,111 +523,6 @@ angular.module('myApp')
418523
419524angular . module ( 'myApp' )
420525
421- . controller ( 'assessmentController' , [ "$scope" , "assessmentService" , "workerService" , function ( $scope , assessmentService , workerService ) {
422-
423- assessmentService . getAssessment ( ) . then ( function ( response ) {
424- var list = [ ] ;
425- _ . each ( response , function ( item ) {
426- for ( var i = 0 ; i < item . questions . length ; i ++ ) {
427- list . push ( item . questions [ i ] ) ;
428- }
429- } )
430- // console.log(list);
431- $scope . questions = list ;
432- } ) ;
433-
434- $scope . eval = function ( q , userCode ) {
435-
436-
437- let qId = q . _id ;
438- let answer = q . answer ;
439-
440- workerService . worker ( qId , answer , userCode ) . then ( function ( result ) {
441- assessmentService . ticker ( result ) ;
442- } )
443-
444- }
445-
446- $scope . submitAssessment = ( length ) => {
447- assessmentService . submitAssessment ( length ) ;
448- }
449-
450- $scope . doSomeStuff = function ( q ) {
451- q . disabled = true ;
452- }
453-
454-
455- } ] ) ;
456-
457- angular . module ( 'myApp' )
458-
459- . service ( 'assessmentService' , [ "$q" , "$http" , function ( $q , $http ) {
460-
461-
462-
463- this . getAssessment = ( ) => {
464- return $http ( {
465- method : 'GET' ,
466- url : '/api/assessment/js'
467- } ) . then ( ( response ) => {
468-
469- return response . data ;
470- } )
471- }
472-
473- var tick = 0 ;
474- this . ticker = ( result ) => {
475- if ( result === true ) {
476- tick += 1 ;
477- } else {
478- return 0 ;
479- }
480- console . log ( "tick count" , tick ) ;
481- }
482-
483- this . submitAssessment = ( length ) => {
484- var totalScore = ( tick / length ) * 100 ;
485- totalScore = totalScore . toString ( ) ;
486- console . log ( totalScore ) ;
487- return $http ( {
488- method : 'PUT' ,
489- url : '/api/users' ,
490- data : {
491- progress : {
492- jsAssessment : totalScore
493- }
494- }
495- } ) . success ( function ( resp ) {
496- console . log ( resp ) ;
497- } )
498- }
499-
500- } ] )
501-
502- angular . module ( 'myApp' ) . service ( 'workerService' , [ "Webworker" , function ( Webworker ) {
503-
504- this . worker = ( qId , answer , userCode ) => {
505-
506- function isSame ( userCode , answer ) {
507- if ( userCode === answer ) {
508- return true ;
509- } else {
510- return false ;
511- }
512- }
513-
514- var myWorker = Webworker . create ( isSame , {
515- isSame : true ,
516- onReturn : function ( data ) { return data ; }
517- } ) ;
518-
519- var result = myWorker . run ( userCode , answer ) ;
520- return result ;
521- }
522- } ] )
523-
524- angular . module ( 'myApp' )
525-
526526. controller ( 'lessonTestsController' , [ "$scope" , function ( $scope ) {
527527
528528
0 commit comments