Submit show completion
This commit is contained in:
@ -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) {
|
||||
// ctrl + enter or cmd + enter
|
||||
if (
|
||||
e.metaKey && e.keyCode === 13 ||
|
||||
e.ctrlKey && e.keyCode === 13
|
||||
e.keyCode === 13 &&
|
||||
e.metaKey ||
|
||||
e.ctrlKey
|
||||
) {
|
||||
$('#complete-courseware-dialog').off('keydown', ctrlEnterClickHandler);
|
||||
if ($('#submit-challenge').length > 0) {
|
||||
@ -20,6 +26,10 @@ window.common = (function({ $, Rx, common = { init: [] }}) {
|
||||
var $marginFix = $('.innerMarginFix');
|
||||
$marginFix.css('min-height', $marginFix.height());
|
||||
|
||||
common.submitBtn$ = Observable.fromEvent($('#submitButton'), 'click');
|
||||
|
||||
common.resetBtn$ = Observable.fromEvent($('#reset-button'), 'click');
|
||||
|
||||
// init modal keybindings on open
|
||||
$('#complete-courseware-dialog').on('shown.bs.modal', function() {
|
||||
$('#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) {
|
||||
window.ga('send', 'event', 'Challenge', 'load', common.challengeName);
|
||||
}
|
||||
|
@ -25,15 +25,25 @@ $(document).ready(function() {
|
||||
}
|
||||
);
|
||||
|
||||
common.submitBtn$
|
||||
Observable.merge(
|
||||
common.editorExecute$,
|
||||
common.submitBtn$
|
||||
)
|
||||
.flatMap(() => {
|
||||
common.appendToOutputDisplay('\n// testing challenge...');
|
||||
return common.executeChallenge$();
|
||||
})
|
||||
.map(({ tests, ...rest }) => {
|
||||
const solved = tests.every(test => !test.err);
|
||||
return { ...rest, tests, solved };
|
||||
})
|
||||
.subscribe(
|
||||
({ output, original, tests }) => {
|
||||
({ solved, output, tests }) => {
|
||||
common.updateOutputDisplay(output);
|
||||
common.codeStorage.updateStorage(challengeName, original);
|
||||
common.displayTestResults(tests);
|
||||
if (solved) {
|
||||
common.showCompletion();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@ -58,9 +68,9 @@ $(document).ready(function() {
|
||||
) {
|
||||
common.executeChallenge$()
|
||||
.subscribe(
|
||||
({ original }) => {
|
||||
// common.updateOutputDisplay('' + output);
|
||||
({ original, tests }) => {
|
||||
common.codeStorage.updateStorage(challengeName, original);
|
||||
common.displayTestResults(tests);
|
||||
},
|
||||
({ err }) => {
|
||||
if (err.stack) {
|
||||
|
@ -33,7 +33,7 @@ window.common = (function(global) {
|
||||
* Console.log() -type statements
|
||||
* will appear in your browser\'s
|
||||
* DevTools JavaScript console.
|
||||
*/'`);
|
||||
*/`);
|
||||
|
||||
codeOutput.setSize('100%', '100%');
|
||||
|
||||
|
@ -6,7 +6,7 @@ window.common = (function(global) {
|
||||
} = global;
|
||||
|
||||
common.showCompletion = function showCompletion() {
|
||||
var time = Math.floor(Date.now()) - window.started;
|
||||
var time = Math.floor(Date.now() - window.started);
|
||||
|
||||
ga(
|
||||
'send',
|
||||
|
@ -20,7 +20,7 @@ function run(code, cb) {
|
||||
result.type = typeof codeExec;
|
||||
result.output = stringify(codeExec);
|
||||
} catch (e) {
|
||||
err = e.mesage;
|
||||
err = e.message;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
|
Reference in New Issue
Block a user