44
55angular . module ( 'app' ) . controller ( 'trainingCtrl' , function ( $scope , $state , mainService ) {
66
7+ /** Create text areas **/
78 var textarea1 = document . getElementById ( 'solution-input' ) ;
89 var solutionsCode = CodeMirror . fromTextArea ( textarea1 , {
910 lineNumbers : true ,
@@ -30,28 +31,52 @@ angular.module('app').controller('trainingCtrl', function($scope, $state, mainSe
3031 $scope . showInstructions = function ( ) {
3132 $scope . showOutputShow = true ;
3233 $scope . showInstructionsShow = false ;
33- } //comment
34+ }
35+
36+ // GET KATA INFORMATION
37+ $scope . getKataById = ( kataid ) => {
38+ mainService . getKataById ( kataid ) . then ( ( response ) => {
39+ console . log ( response . data ) ;
40+ $scope . name = response . data . name ;
41+ $scope . instructions = response . data . description ;
42+ $scope . kyu = response . data . kyu ;
43+ $scope . starter = response . data . starter_code ;
44+ $scope . examples = response . data . examples . map ( ( example ) => { return example . test } ) ;
45+ $scope . kataid = response . data . id ;
46+ } ) . then ( ( ) => {
47+ solutionsCode . setValue ( $scope . starter ) ;
48+ examplesCode . setValue ( $scope . examples . join ( / \n / ) ) ;
49+ } ) ;
50+ }
51+
52+ $scope . getKataById ( 2 ) ;
53+
54+
3455
3556 //Examples should be an array of objects. Returned results will be an array with the different tests and their results.
3657 $scope . testExamples = function ( ) {
37- let solutions = solutionsCode . getValue ( ) ;
38- let examples = examplesCode . getValue ( ) ;
58+ var solutions = solutionsCode . getValue ( ) ;
59+ var examples = examplesCode . getValue ( ) ;
3960 $scope . showOutput ( ) ;
4061 solutions = solutions . replace ( / \n / g, " " ) ;
4162 solutions = solutions . replace ( / \s + / g, " " ) ;
42- let examplesArr = [ ] ;
63+ var examplesArr = [ ] ;
4364 console . log ( "solutions: " , solutions , " examples: " , examples ) ;
4465 examples = examples . split ( / \n / ) ;
4566 console . log ( examples ) ;
46- // examples.forEach(example => examplesArr.push({test: example}));
47- // mainService.testExamples(solutions, examplesArr).then((response) => $scope.output.push(response.data[0]));
67+ examples . forEach ( example => examplesArr . push ( { test : example } ) ) ;
68+ var t0 = performance . now ( )
69+ mainService . testExamples ( solutions , examplesArr ) . then ( ( response ) => $scope . output . push ( response . data [ 0 ] ) ) ;
70+ var t1 = performance . now ( ) ;
71+ $scope . time = "Time: " + Math . round ( ( t1 - t0 ) * 1000 ) + " ms" ;
4872 }
4973
50-
51- $scope . testSuite = function ( solutions ) {
74+ $scope . testSuite = function ( ) {
75+ var solutions = solutionsCode . getValue ( ) ;
5276 $scope . showOutput ( ) ;
5377 solutions = solutions . replace ( / \n / g, " " ) ;
54- // mainService.testSuite(solutions, kataid).then((response) => console.log(response));
78+ solutions = solutions . replace ( / \s + / g, " " ) ;
79+ // mainService.testSuite(solutions, $scope.kataid).then((response) => console.log(response));
5580 }
5681
5782 // this function needs to call the kata by id when the user selects train on the home page -getKataById
0 commit comments