@@ -58944,7 +58944,7 @@ angular.module('javascriptcom', ['ngResource', 'ngAnimate'])
5894458944 $httpProvider.defaults.cache = true;
5894558945 }]);
5894658946
58947- angular.module('javascriptcom').directive('jsChallenge', [function() {
58947+ angular.module('javascriptcom').directive('jsChallenge', ['jsChallengeProgress', function(jsChallengeProgress ) {
5894858948 return {
5894958949 templateUrl: 'javascripts/javascriptcom/templates/challenge.html',
5895058950 replace: true,
@@ -58953,35 +58953,34 @@ angular.module('javascriptcom').directive('jsChallenge', [function() {
5895358953 },
5895458954 bindToController: true,
5895558955 controllerAs: 'ctrl',
58956- controller: function jsChallengeController() {
58957- this.isActive = function() {
58958- return this.challenge.active;
58956+ controller: function jsChallengeController(jsChallengeProgress) {
58957+ this.onSuccess = function onSuccess(challenge) {
58958+ challenge.completed = true;
58959+ jsChallengeProgress.next();
5895958960 }
58960- this.hasStarted = function() {
58961- return this.challenge.started;
58961+
58962+ this.onFailure = function onFailure(challenge) {
58963+ console.log('challenge failure');
58964+ }
58965+
58966+ this.activate = function(challenge) {
58967+ jsChallengeProgress.activate(challenge);
5896258968 }
5896358969 }
5896458970 };
5896558971}]);
5896658972
58967- angular.module('javascriptcom').directive('jsConsole', ['CSConsole', 'jsCommand', 'jsChallengeProgress', function(CSConsole, jsCommand, jsChallengeProgress ) {
58973+ angular.module('javascriptcom').directive('jsConsole', ['CSConsole', 'jsCommand', function(CSConsole, jsCommand) {
5896858974 return {
5896958975 templateUrl: 'javascripts/javascriptcom/templates/console.html',
5897058976 replace: true,
58971- scope: {
58972- challenge: '='
58973- },
58977+ scope: true,
5897458978 bindToController: true,
5897558979 controllerAs: 'ctrl',
58980+ require: '^jsChallenge',
5897658981 link: function(scope, element, attrs, ctrl) {
58977- function onConsoleSuccess() {
58978- ctrl.challenge.completed = true;
58979- jsChallengeProgress.next();
58980- }
58981- function onConsoleError() { }
58982-
5898358982 var el = $(element).find('.console-ui')[0];
58984- var command = new jsCommand(ctrl.challenge, onConsoleSuccess, onConsoleError );
58983+ var command = new jsCommand(ctrl.challenge, ctrl.onSuccess, ctrl.onFailure );
5898558984
5898658985 ctrl.csConsole = new CSConsole(el, {
5898758986 prompt: '> ',
@@ -58991,14 +58990,6 @@ angular.module('javascriptcom').directive('jsConsole', ['CSConsole', 'jsCommand'
5899158990 commandValidate: command.validate,
5899258991 commandHandle: command.handler
5899358992 });
58994-
58995-
58996- $(element).on('click', function(e) {
58997- e.preventDefault();
58998- jsChallengeProgress.activate(ctrl.challenge);
58999- })
59000- },
59001- controller: function jsConsoleController() {
5900258993 }
5900358994 };
5900458995}]);
@@ -59027,14 +59018,10 @@ angular.module('javascriptcom').directive('jsInstructions', ['$compile', 'marked
5902759018 return {
5902859019 templateUrl: 'javascripts/javascriptcom/templates/instructions.html',
5902959020 replace: true,
59030- scope: {
59031- challenge: '='
59032- },
59021+ scope: true,
5903359022 bindToController: true,
5903459023 controllerAs: 'ctrl',
59035- controller: function() {
59036-
59037- }
59024+ require: '^jsChallenge'
5903859025 };
5903959026}]);
5904059027
@@ -59057,14 +59044,6 @@ angular.module('javascriptcom').directive('jsSafeHtml', ['$sce', function SafeHt
5905759044 };
5905859045}]);
5905959046
59060- angular.module('javascriptcom')
59061- .filter('markdown', ['marked', function Markdown(marked) {
59062- return function(text) {
59063- return marked(text);
59064- };
59065- }]
59066- );
59067-
5906859047angular.module('javascriptcom').factory('jsCourseChallengeResource', function($resource) {
5906959048 return $resource('/courses/:course/challenges.json', {}, {});
5907059049});
@@ -59073,6 +59052,14 @@ angular.module('javascriptcom').factory('jsCourseResource', function($resource)
5907359052 return $resource('/courses/:course.json', {}, {});
5907459053});
5907559054
59055+ angular.module('javascriptcom')
59056+ .filter('markdown', ['marked', function Markdown(marked) {
59057+ return function(text) {
59058+ return marked(text);
59059+ };
59060+ }]
59061+ );
59062+
5907659063angular.module('javascriptcom').factory('jsCommand', ['_', 'jsCommandFactory', function(_, jsCommandFactory) {
5907759064 return function jsCommand(challenge, successCallback, errorCallback) {
5907859065 var vm = this;
@@ -59089,10 +59076,10 @@ angular.module('javascriptcom').factory('jsCommand', ['_', 'jsCommandFactory', f
5908959076
5909059077 command(vm.challenge, line).then(function(content) {
5909159078 report(jsReportAdapter(content));
59092- successCallback();
59079+ successCallback(vm.challenge );
5909359080 }, function(content) {
5909459081 report(jsReportAdapter(content));
59095- errorCallback();
59082+ errorCallback(vm.challenge );
5909659083 });
5909759084 }
5909859085
@@ -59220,9 +59207,11 @@ angular.module('javascriptcom').factory('jsChallengeProgress', ['_', function(_)
5922059207 },
5922159208
5922259209 activate: function(challenge) {
59223- this.deactivateAll();
59224- challenge.active = true;
59225- challenge.started = true;
59210+ if(!challenge.active) {
59211+ this.deactivateAll();
59212+ challenge.active = true;
59213+ challenge.started = true;
59214+ }
5922659215 },
5922759216
5922859217 deactivateAll: function() {
0 commit comments