Submit show completion

This commit is contained in:
Berkeley Martinez
2015-11-21 19:48:24 -08:00
parent 7593dc4e1b
commit fe659b20f4
5 changed files with 31 additions and 15 deletions

View File

@ -1,10 +1,16 @@
window.common = (function({ $, Rx, common = { init: [] }}) { window.common = (function(global) {
const {
$,
Rx: { Observable },
common = { init: [] }
} = global;
common.ctrlEnterClickHandler = function ctrlEnterClickHandler(e) { common.ctrlEnterClickHandler = function ctrlEnterClickHandler(e) {
// ctrl + enter or cmd + enter // ctrl + enter or cmd + enter
if ( if (
e.metaKey && e.keyCode === 13 || e.keyCode === 13 &&
e.ctrlKey && e.keyCode === 13 e.metaKey ||
e.ctrlKey
) { ) {
$('#complete-courseware-dialog').off('keydown', ctrlEnterClickHandler); $('#complete-courseware-dialog').off('keydown', ctrlEnterClickHandler);
if ($('#submit-challenge').length > 0) { if ($('#submit-challenge').length > 0) {
@ -20,6 +26,10 @@ window.common = (function({ $, Rx, common = { init: [] }}) {
var $marginFix = $('.innerMarginFix'); var $marginFix = $('.innerMarginFix');
$marginFix.css('min-height', $marginFix.height()); $marginFix.css('min-height', $marginFix.height());
common.submitBtn$ = Observable.fromEvent($('#submitButton'), 'click');
common.resetBtn$ = Observable.fromEvent($('#reset-button'), 'click');
// init modal keybindings on open // init modal keybindings on open
$('#complete-courseware-dialog').on('shown.bs.modal', function() { $('#complete-courseware-dialog').on('shown.bs.modal', function() {
$('#complete-courseware-dialog').keydown(common.ctrlEnterClickHandler); $('#complete-courseware-dialog').keydown(common.ctrlEnterClickHandler);
@ -127,10 +137,6 @@ window.common = (function({ $, Rx, common = { init: [] }}) {
} }
}); });
common.submitBtn$ = Rx.Observable.fromEvent($('#submitButton'), 'click');
common.resetBtn$ = Rx.Observable.fromEvent($('#reset-button'), 'click');
if (common.challengeName) { if (common.challengeName) {
window.ga('send', 'event', 'Challenge', 'load', common.challengeName); window.ga('send', 'event', 'Challenge', 'load', common.challengeName);
} }

View File

@ -25,15 +25,25 @@ $(document).ready(function() {
} }
); );
common.submitBtn$ Observable.merge(
common.editorExecute$,
common.submitBtn$
)
.flatMap(() => { .flatMap(() => {
common.appendToOutputDisplay('\n// testing challenge...');
return common.executeChallenge$(); return common.executeChallenge$();
}) })
.map(({ tests, ...rest }) => {
const solved = tests.every(test => !test.err);
return { ...rest, tests, solved };
})
.subscribe( .subscribe(
({ output, original, tests }) => { ({ solved, output, tests }) => {
common.updateOutputDisplay(output); common.updateOutputDisplay(output);
common.codeStorage.updateStorage(challengeName, original);
common.displayTestResults(tests); common.displayTestResults(tests);
if (solved) {
common.showCompletion();
}
} }
); );
@ -58,9 +68,9 @@ $(document).ready(function() {
) { ) {
common.executeChallenge$() common.executeChallenge$()
.subscribe( .subscribe(
({ original }) => { ({ original, tests }) => {
// common.updateOutputDisplay('' + output);
common.codeStorage.updateStorage(challengeName, original); common.codeStorage.updateStorage(challengeName, original);
common.displayTestResults(tests);
}, },
({ err }) => { ({ err }) => {
if (err.stack) { if (err.stack) {

View File

@ -33,7 +33,7 @@ window.common = (function(global) {
* Console.log() -type statements * Console.log() -type statements
* will appear in your browser\'s * will appear in your browser\'s
* DevTools JavaScript console. * DevTools JavaScript console.
*/'`); */`);
codeOutput.setSize('100%', '100%'); codeOutput.setSize('100%', '100%');

View File

@ -6,7 +6,7 @@ window.common = (function(global) {
} = global; } = global;
common.showCompletion = function showCompletion() { common.showCompletion = function showCompletion() {
var time = Math.floor(Date.now()) - window.started; var time = Math.floor(Date.now() - window.started);
ga( ga(
'send', 'send',

View File

@ -20,7 +20,7 @@ function run(code, cb) {
result.type = typeof codeExec; result.type = typeof codeExec;
result.output = stringify(codeExec); result.output = stringify(codeExec);
} catch (e) { } catch (e) {
err = e.mesage; err = e.message;
} }
if (err) { if (err) {