From 291b9962b1bc68a27e338a7a3d2353a2939313dc Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 24 Sep 2021 20:00:08 +0200 Subject: [PATCH 01/62] doc(ordoFeedbackMessage): improve function description --- ordo/ordo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 63ffd6d..e56a0a5 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -379,10 +379,10 @@ define([ } /** - * returns the div containing the - * @param {boolean} correct - if the submitted solutions was correct or not + * returns the feedback div. + * @param {boolean} correct - indicates if the solution was correct or not * @param {string} success_msg - the success message for the current cell, if defined - * @param {string} failure_msg - the failure message for the current cell, if defined + * @param {string} failure_msg - the failure message for the current cell, if defined */ var ordoFeedbackMessage = function(correct,success_msg,failure_msg) { if(correct) { From f7f77144c1d1a018256eb6d6a4519d81850c3c3e Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 24 Sep 2021 20:17:54 +0200 Subject: [PATCH 02/62] refactor(ordoFeedbackMessage): simplify if statements. --- ordo/ordo.js | 79 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index e56a0a5..eb21e1e 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -384,42 +384,63 @@ define([ * @param {string} success_msg - the success message for the current cell, if defined * @param {string} failure_msg - the failure message for the current cell, if defined */ - var ordoFeedbackMessage = function(correct,success_msg,failure_msg) { + var ordoFeedbackMessage = function(correct, success_msg, failure_msg) { if(correct) { if (success_msg == undefined && defaultSuccess == "") { feedback = "" - } else if (success_msg == undefined && defaultSuccess) { - feedback = "" - } else { - feedback = "" + " " + + "Well Done! That was the correct response. " + + " "; + + return feedback; } - } else { - if (failure_msg == undefined) { - feedback = "" - } else if (failure_msg == undefined && defaultFailure) { - feedback = "" - } else { - feedback = "" return feedback; } From bc49dd45ce6893a2a30b3be867486cc363b864f6 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 24 Sep 2021 21:02:40 +0200 Subject: [PATCH 05/62] fix tab setting --- ordo/ordo.js | 97 ++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 3b2512a..fd3e602 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -390,64 +390,63 @@ define([ * @param {string} success_msg - the success message for the current cell, if defined * @param {string} failure_msg - the failure message for the current cell, if defined */ - var ordoFeedbackMessage = function(correct, success_msg, failure_msg) { - if(correct) { - if (success_msg == undefined && defaultSuccess == "") { - feedback = ""; - - return feedback; - } - - if (success_msg == undefined && defaultSuccess) { - feedback = "" - - return feedback; - } + var ordoFeedbackMessage = function(correct, success_msg, failure_msg) { + if(correct) { + if (success_msg == undefined && defaultSuccess == "") { + feedback = ""; + + return feedback; + } + + if (success_msg == undefined && defaultSuccess) { + feedback = "" + + return feedback; + } + + feedback = "" + + return feedback; + } - feedback = "" - return feedback; - } - + /* + Solution was wrong. + */ - /* - Solution was wrong. - */ + if (failure_msg == undefined) { + feedback = "" - if (failure_msg == undefined) { - feedback = "" - - return feedback; - } - - if (failure_msg == undefined && defaultFailure) { - feedback = "" + return feedback; + } - return feedback; - } + if (failure_msg == undefined && defaultFailure) { + feedback = "" + return feedback; + } - feedback = "" return feedback; - } + } /** * tests two metadata objects for equality From 657d7b920bdff3c036cbb44161019a8b959e7786 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 24 Sep 2021 21:04:12 +0200 Subject: [PATCH 07/62] fix tab setting --- ordo/ordo.js | 92 ++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index cd3ddef..474d5cd 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -331,53 +331,53 @@ define([ */ var onCodeCellExecuted = async function(evt, obj) { - outputs = obj.cell.output_area.outputs; - solution = obj.cell.metadata.ordo_solution; - - if (solution !== undefined) { - console.debug("ordo feedback ?", obj.cell.element.find('.output_area')); - - if (obj.cell.metadata.ordo_verify === undefined) { - var res; - - if (solution['python'] !== undefined) { - console.debug("executePython AWAIT ", solution); - - res = await executePython(solution["python"]).then((result) => { console.debug("3. executePython", result); return result }) - obj.cell.metadata.ordo_solution = {...obj.cell.metadata.ordo_solution, ...res}; - - - } else { - res = solution; - } - - console.debug("executePython SOL xxxxx: ", res, outputs, outputs[outputs.length-1]); - feedback = ordoFeedbackMessage( - equals(res, outputs[outputs.length-1].data), - obj.cell.metadata.ordo_success, - obj.cell.metadata.ordo_failure); - } else { - if(solution['python'] != undefined) { - console.debug("executePython AWAIT ", solution); - - solution = await executePython(solution["python"]).then((result) => console.debug("3. executePython2" + result)) - } - - console.debug("executePython SOL 2 ", solution); - feedback = obj.cell.metadata.ordo_verify( - outputs[outputs.length-1].data, - obj.cell.metadata.ordo_success, - obj.cell.metadata.ordo_failure); - } + outputs = obj.cell.output_area.outputs; + solution = obj.cell.metadata.ordo_solution; + + if (solution !== undefined) { + console.debug("ordo feedback ?", obj.cell.element.find('.output_area')); + + if (obj.cell.metadata.ordo_verify === undefined) { + var res; + + if (solution['python'] !== undefined) { + console.debug("executePython AWAIT ", solution); + + res = await executePython(solution["python"]).then((result) => { console.debug("3. executePython", result); return result }) + obj.cell.metadata.ordo_solution = {...obj.cell.metadata.ordo_solution, ...res}; + + + } else { + res = solution; + } + + console.debug("executePython SOL xxxxx: ", res, outputs, outputs[outputs.length-1]); + feedback = ordoFeedbackMessage( + equals(res, outputs[outputs.length-1].data), + obj.cell.metadata.ordo_success, + obj.cell.metadata.ordo_failure); + } else { + if(solution['python'] != undefined) { + console.debug("executePython AWAIT ", solution); + + solution = await executePython(solution["python"]).then((result) => console.debug("3. executePython2" + result)) + } + + console.debug("executePython SOL 2 ", solution); + feedback = obj.cell.metadata.ordo_verify( + outputs[outputs.length-1].data, + obj.cell.metadata.ordo_success, + obj.cell.metadata.ordo_failure); + } - obj.cell.output_area.append_output({ - "output_type" : "display_data", - "data" : { - "text/html": feedback - }, - "metadata" : {} - }); - } + obj.cell.output_area.append_output({ + "output_type" : "display_data", + "data" : { + "text/html": feedback + }, + "metadata" : {} + }); + } }; var ordoFeedback = function () { From 09d1cda7b5c07f95b329a248803edb6bddfd5cf7 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 24 Sep 2021 21:06:40 +0200 Subject: [PATCH 08/62] refactor(onCodeCellExecuted): remove blank line --- ordo/ordo.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 474d5cd..be0762c 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -329,7 +329,6 @@ define([ * if result incorrect: * append the failure message */ - var onCodeCellExecuted = async function(evt, obj) { outputs = obj.cell.output_area.outputs; solution = obj.cell.metadata.ordo_solution; From 3ccc8e800ded2d99ad960930ae55d0ad3f182c63 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 24 Sep 2021 21:08:55 +0200 Subject: [PATCH 09/62] doc(ordoFeedbackMessage): add return description --- ordo/ordo.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ordo/ordo.js b/ordo/ordo.js index be0762c..3d4d4f6 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -388,6 +388,7 @@ define([ * @param {boolean} correct - indicates if the solution was correct or not * @param {string} success_msg - the success message for the current cell, if defined * @param {string} failure_msg - the failure message for the current cell, if defined + * @returns {string} the feedback div container as a string */ var ordoFeedbackMessage = function(correct, success_msg, failure_msg) { if(correct) { From 238ef0d8cdc475f7d81e9de85f5ad2e48eabf8ad Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sat, 25 Sep 2021 17:15:49 +0200 Subject: [PATCH 10/62] doc(onCodeCellExecuted): update to current implementation --- ordo/ordo.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 3d4d4f6..4dfde57 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -317,17 +317,10 @@ define([ /** - * Capture output_appended.OutputArea event for the result value - * Capture finished_execute.CodeCell event for the data value - * check for a solution in cell metadata - * if exists: - * check only one area appended (ends recursion) - * if true: - * check result against solution - * if result correct: - * append the success message - * if result incorrect: - * append the failure message + * executes the solution upon the event finished_execute.CodeCell and appends the result + * to the output area called + * @param {object} evt the event finished_execute.CodeCell. not used withing the function + * @param {object} obj an objectwhich provides access to the cell via property cell */ var onCodeCellExecuted = async function(evt, obj) { outputs = obj.cell.output_area.outputs; @@ -380,7 +373,7 @@ define([ }; var ordoFeedback = function () { - events.on('finished_execute.CodeCell', onCodeCellExecuted); + events.on('finished_execute.CodeCell', onCodeCellExecuted); } /** From 23e5b24e36ed07341b396bace7748905774f4002 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sat, 25 Sep 2021 17:17:37 +0200 Subject: [PATCH 11/62] doc(ordoFeedback): add description --- ordo/ordo.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 4dfde57..09eb14b 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -371,7 +371,11 @@ define([ }); } }; - + + /** + * registers function onCodeCellExecuted to event finished_execute.CodeCell. This function is hence + * called after the current code cell is executed + */ var ordoFeedback = function () { events.on('finished_execute.CodeCell', onCodeCellExecuted); } From ea619e3a72871eab51f25a43ecf8dc13c6975526 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sat, 25 Sep 2021 21:49:06 +0200 Subject: [PATCH 12/62] refactor(makeOutputButton): simplify if statements and add proper intendation --- ordo/ordo.js | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 09eb14b..76c3ebd 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -485,31 +485,37 @@ define([ * make ordo_solution = output_area.outputs[0] */ var makeOutputButton = function () { - var currCell = undefined; + events.on('select.Cell', function(event, data) { newCell = data.cell; - if(newCell == currCell){ - return; - } else if($('.ordo_edit_mode').length == 0) { + + if(data.cell == undefined) { return; - } else { - $(".show-ordo-solution").remove(); - $(".make-ordo-solution").remove(); - currCell = newCell; - if(currCell.cell_type == "code") { - if(currCell.output_area.outputs.length > 0){ - if(currCell.output_area.outputs[0].output_type == "execute_result") { - $(".selected .output_area") - .first() - .append(""); - $(".make-ordo-solution").on("click", function() { - console.debug("updated metadata"); - currCell.metadata.ordo_solution = currCell.output_area.outputs[0].data; - }); - } - } - } } + + if($('.ordo_edit_mode').length == 0) { + return; + } + + + $(".show-ordo-solution").remove(); + $(".make-ordo-solution").remove(); + + if(data.cell.cell_type == "code") { + if(data.cell.output_area.outputs.length > 0){ + if(data.cell.output_area.outputs[0].output_type == "execute_result") { + $(".selected .output_area") + .first() + .append(""); + + + $(".make-ordo-solution").on("click", function() { + console.debug("updated metadata"); + data.cell.metadata.ordo_solution = data.cell.output_area.outputs[0].data; + }); + } + } + } }); } From 23b997122dc6b7b8f9067003ec48962683521273 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sat, 25 Sep 2021 21:53:49 +0200 Subject: [PATCH 13/62] fix tab issue --- ordo/ordo.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 76c3ebd..8aa1a70 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -486,16 +486,16 @@ define([ */ var makeOutputButton = function () { - events.on('select.Cell', function(event, data) { - newCell = data.cell; + events.on('select.Cell', function(event, data) { + newCell = data.cell; - if(data.cell == undefined) { - return; - } + if(data.cell == undefined) { + return; + } if($('.ordo_edit_mode').length == 0) { - return; - } + return; + } $(".show-ordo-solution").remove(); @@ -516,8 +516,8 @@ define([ } } } - }); - } + }); + } /** * @param {Object} solution - From 9fa60c43854c593a36c892871cc9be86cd86c2f1 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sat, 25 Sep 2021 21:54:55 +0200 Subject: [PATCH 14/62] fix tab issue --- ordo/ordo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 8aa1a70..66f44f7 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -484,7 +484,7 @@ define([ * append a button for the user to click which will: * make ordo_solution = output_area.outputs[0] */ - var makeOutputButton = function () { + var makeOutputButton = function () { events.on('select.Cell', function(event, data) { newCell = data.cell; From d173e26bc47acfadf86529afb57cd723f8f63b52 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sun, 26 Sep 2021 20:45:27 +0200 Subject: [PATCH 15/62] fix(solutionToString): delete redundant definition of solutionToString --- ordo/ordo.js | 72 ++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 66f44f7..563d88f 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -523,53 +523,31 @@ define([ * @param {Object} solution - * returns the correct solution in the appropriate format */ - var solutionToString = function (solution) { - var outStr = ""; - console.debug(solution) - for (var key in solution) { - switch (key){ - case 'text/html': - outStr = solution[key]; - break; - case 'text/plain': - outStr = solution[key]; - break; - case 'python': - outStr = solution[key]; - break; - default: - outStr = 'N/A'; - } - } - console.debug(outStr); - return outStr; - } - - var solutionToString = function (solution) { - var outStr = ""; - var mimeTypes = Object.keys(solution); - console.debug("mimeTypes", mimeTypes); - /* TODO: change to "text/x-..." later */ - if (mimeTypes.includes("python")) { - outStr = solution["python"]; - } else { - for (var mt of mimeTypes) { - console.debug("mt", mt); - switch (mt) { - case "text/html": - outStr = solution[mt]; - break; - case "text/plain": - outStr = solution[mt]; - break; - default: - outStr = null; - } - } - } - console.debug(outStr); - return outStr; - } + var solutionToString = function (solution) { + var outStr = ""; + var mimeTypes = Object.keys(solution); + console.debug("mimeTypes", mimeTypes); + /* TODO: change to "text/x-..." later */ + if (mimeTypes.includes("python")) { + outStr = solution["python"]; + } else { + for (var mt of mimeTypes) { + console.debug("mt", mt); + switch (mt) { + case "text/html": + outStr = solution[mt]; + break; + case "text/plain": + outStr = solution[mt]; + break; + default: + outStr = null; + } + } + } + console.debug(outStr); + return outStr; + } /** * From 6a8b21cf264ab14174ac8c5e7bd6724bf4579d7b Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sun, 26 Sep 2021 20:49:15 +0200 Subject: [PATCH 16/62] refactor(solutionToString): add appropriate code formating --- ordo/ordo.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 563d88f..dbc7ddb 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -523,28 +523,30 @@ define([ * @param {Object} solution - * returns the correct solution in the appropriate format */ - var solutionToString = function (solution) { + var solutionToString = function(solution) { var outStr = ""; var mimeTypes = Object.keys(solution); console.debug("mimeTypes", mimeTypes); + /* TODO: change to "text/x-..." later */ if (mimeTypes.includes("python")) { - outStr = solution["python"]; + outStr = solution["python"]; } else { - for (var mt of mimeTypes) { - console.debug("mt", mt); - switch (mt) { - case "text/html": - outStr = solution[mt]; - break; - case "text/plain": - outStr = solution[mt]; - break; - default: - outStr = null; + for (var mt of mimeTypes) { + console.debug("mt", mt); + switch (mt) { + case "text/html": + outStr = solution[mt]; + break; + case "text/plain": + outStr = solution[mt]; + break; + default: + outStr = null; + } } } - } + console.debug(outStr); return outStr; } From 9f4392591f13d5624d833f8318fe0bec0b6e4a9a Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sun, 26 Sep 2021 20:51:14 +0200 Subject: [PATCH 17/62] doc(solutionToString): fix and expand description --- ordo/ordo.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index dbc7ddb..21d4806 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -520,8 +520,9 @@ define([ } /** - * @param {Object} solution - - * returns the correct solution in the appropriate format + * returns the solution as a string + * @param {Object} solution + * @returns {String} solution */ var solutionToString = function(solution) { var outStr = ""; From fc3cfb3ef3b7e4b247400a335e613618f3c84f6f Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sun, 26 Sep 2021 21:06:38 +0200 Subject: [PATCH 18/62] refactor(solutionToString): simplify logic by deleting unnecassary for and switch statements --- ordo/ordo.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 21d4806..d6e37f1 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -525,31 +525,30 @@ define([ * @returns {String} solution */ var solutionToString = function(solution) { - var outStr = ""; + var mimeTypes = Object.keys(solution); console.debug("mimeTypes", mimeTypes); /* TODO: change to "text/x-..." later */ if (mimeTypes.includes("python")) { outStr = solution["python"]; - } else { - for (var mt of mimeTypes) { - console.debug("mt", mt); - switch (mt) { - case "text/html": - outStr = solution[mt]; - break; - case "text/plain": - outStr = solution[mt]; - break; - default: - outStr = null; - } - } + console.debug(outStr); + return outStr; + } + + if (mimeTypes.includes("text/html")) { + outStr = solution["text/html"]; + console.debug(outStr); + return outStr; + } + + if (mimeTypes.includes["text/plain"]) { + outStr = solution["text/plain"]; + console.debug(outStr); + return outStr; } - console.debug(outStr); - return outStr; + return null; } /** From f9dedf4cb9f0cee573c91578feb224e333af0d60 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sun, 26 Sep 2021 21:07:18 +0200 Subject: [PATCH 19/62] doc(solutionToString): add use case --- ordo/ordo.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index d6e37f1..ff6dbca 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -520,7 +520,8 @@ define([ } /** - * returns the solution as a string + * returns the solution as a string for display purposes. this is used when the user clicks on + * Edit Solutions * @param {Object} solution * @returns {String} solution */ From 82b928cec857c490e753795bb9f3ba911901f3df Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sun, 26 Sep 2021 21:08:49 +0200 Subject: [PATCH 20/62] fix tabs --- ordo/ordo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index ff6dbca..6e6d313 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -519,12 +519,12 @@ define([ }); } - /** + /** * returns the solution as a string for display purposes. this is used when the user clicks on * Edit Solutions - * @param {Object} solution + * @param {Object} solution * @returns {String} solution - */ + */ var solutionToString = function(solution) { var mimeTypes = Object.keys(solution); From cfae35e5963ff9a5b1ecc9226303666e002de171 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Sun, 26 Sep 2021 21:19:36 +0200 Subject: [PATCH 21/62] refactor(solutionToString): change to for loop that iterates over the accepted mime types --- ordo/ordo.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 6e6d313..93dbc40 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -527,26 +527,20 @@ define([ */ var solutionToString = function(solution) { + /* TODO: change to "text/x-..." later */ + var acceptedMimeTypes = ["python", "text/html", "text/plain"]; + + var mimeTypes = Object.keys(solution); console.debug("mimeTypes", mimeTypes); - /* TODO: change to "text/x-..." later */ - if (mimeTypes.includes("python")) { - outStr = solution["python"]; - console.debug(outStr); - return outStr; - } - - if (mimeTypes.includes("text/html")) { - outStr = solution["text/html"]; - console.debug(outStr); - return outStr; - } - if (mimeTypes.includes["text/plain"]) { - outStr = solution["text/plain"]; - console.debug(outStr); - return outStr; + for(acceptedMimeType in acceptedMimeTypes) { + if (mimeTypes.includes(acceptedMimeType)) { + outStr = solution[acceptedMimeType]; + console.debug(outStr); + return outStr; + } } return null; From 9feb59b3067d7f6ab75edb6103ffc02810e69d50 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 8 Oct 2021 17:42:22 +0200 Subject: [PATCH 22/62] doc(showSolutionButton): add responsibility to documentation that was not there --- ordo/ordo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 93dbc40..1a0d888 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -548,7 +548,7 @@ define([ /** * - * creates a button to show the current solution to the user + * creates and appends a button to show the current solution to the user. */ var showSolutionButton = function () { var currCell = undefined; From 9478d4c48015b006bac996208beabae5f99237f9 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 8 Oct 2021 17:52:16 +0200 Subject: [PATCH 23/62] refactor(showSolutionButton): start clean up --- ordo/ordo.js | 111 ++++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 51 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 1a0d888..c46390c 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -546,57 +546,66 @@ define([ return null; } - /** - * - * creates and appends a button to show the current solution to the user. - */ - var showSolutionButton = function () { - var currCell = undefined; - events.on('select.Cell', function(event, data) { - newCell = data.cell; - if(newCell == currCell){ - return; - } else if($('.ordo_feedback_mode').length == 0) { - return; - } else { - $(".show-ordo-solution").remove(); - currCell = newCell; - if(currCell.cell_type === "code" && currCell.metadata && currCell.metadata.ordo_solution) { - if(currCell.output_area.outputs.length > 0) { - console.debug("Show solution button"); - console.debug(currCell.output_area.outputs[0].output_type); - if(["execute_result", "stream"].includes(currCell.output_area.outputs[0].output_type)) { - $(".selected .input") - .after("
"); - $(".show-ordo-solution").one("click", function() { - //currCell.metadata.ordo_solution = currCell.output_area.outputs[0].data; - // solution = solutionToString(currCell.metadata.ordo_solution) - console.debug(currCell.metadata.ordo_solution); - - /* TODO: - * - Improve retrieval here based on a parametric solutionToString - * - Make sure that we escape text/plain content here, as feedback requires markup! - */ - - solution = currCell.metadata.ordo_solution['text/plain'] - console.debug("Current solution => " + solution); - feedback = "" - currCell.output_area.append_output({ - "output_type" : "display_data", - "data" : { - "text/html": feedback - }, - "metadata" : {} - }); - }); - } - } - } - } - }); - } + /** + * + * creates and appends a button to show the current solution to the user. + */ + var showSolutionButton = function () { + + events.on('select.Cell', function(event, data) { + + if(data.cell == undefined){ + return; + } + + if($('.ordo_feedback_mode').length == 0) { + return; + } + + + $(".show-ordo-solution").remove(); + + currCell = data.cell; + if(currCell.cell_type === "code" && currCell.metadata && currCell.metadata.ordo_solution) { + + if(currCell.output_area.outputs.length > 0) { + console.debug("Show solution button"); + console.debug(currCell.output_area.outputs[0].output_type); + + if(["execute_result", "stream"].includes(currCell.output_area.outputs[0].output_type)) { + $(".selected .input") + .after("
"); + + $(".show-ordo-solution").one("click", function() { + //currCell.metadata.ordo_solution = currCell.output_area.outputs[0].data; + // solution = solutionToString(currCell.metadata.ordo_solution) + console.debug(currCell.metadata.ordo_solution); + + /* TODO: + * - Improve retrieval here based on a parametric solutionToString + * - Make sure that we escape text/plain content here, as feedback requires markup! + */ + + solution = currCell.metadata.ordo_solution['text/plain']; + console.debug("Current solution => " + solution); + + feedback = ""; + + currCell.output_area.append_output({ + "output_type" : "display_data", + "data" : { + "text/html": feedback + }, + "metadata" : {} + }); + }); + } + } + } + }); + } /** * sets the solution for the current cell to be the solution for all cells in the notebook From 3fbe9b1a1c48ffdb7b4db81ac4a8d17f47f1dfb1 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 11:45:19 +0200 Subject: [PATCH 24/62] refactor(showSolutionButton): finish refactor --- ordo/ordo.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index c46390c..77e09d2 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -565,40 +565,38 @@ define([ $(".show-ordo-solution").remove(); - currCell = data.cell; - if(currCell.cell_type === "code" && currCell.metadata && currCell.metadata.ordo_solution) { + + if(data.cell.cell_type === "code" && data.cell.metadata && data.cell.metadata.ordo_solution) { - if(currCell.output_area.outputs.length > 0) { + if(data.cell.output_area.outputs.length > 0) { console.debug("Show solution button"); - console.debug(currCell.output_area.outputs[0].output_type); + console.debug(data.cell.output_area.outputs[0].output_type); - if(["execute_result", "stream"].includes(currCell.output_area.outputs[0].output_type)) { + if(["execute_result", "stream"].includes(data.cell.output_area.outputs[0].output_type)) { $(".selected .input") .after("
"); $(".show-ordo-solution").one("click", function() { - //currCell.metadata.ordo_solution = currCell.output_area.outputs[0].data; - // solution = solutionToString(currCell.metadata.ordo_solution) - console.debug(currCell.metadata.ordo_solution); + console.debug(data.cell.metadata.ordo_solution); /* TODO: - * - Improve retrieval here based on a parametric solutionToString - * - Make sure that we escape text/plain content here, as feedback requires markup! - */ + * - Improve retrieval here based on a parametric solutionToString + * - Make sure that we escape text/plain content here, as feedback requires markup! + */ - solution = currCell.metadata.ordo_solution['text/plain']; + solution = data.cell.metadata.ordo_solution['text/plain']; console.debug("Current solution => " + solution); feedback = ""; - currCell.output_area.append_output({ - "output_type" : "display_data", - "data" : { - "text/html": feedback - }, - "metadata" : {} + currCell.output_area.append_output({ + "output_type" : "display_data", + "data" : { + "text/html": feedback + }, + "metadata" : {} }); }); } From cabe14f0ad79865941b283d92f5f2dd7cacdecf4 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 11:46:56 +0200 Subject: [PATCH 25/62] doc(allOutputsButton: improve doc --- ordo/ordo.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 77e09d2..7e8ecfe 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -605,8 +605,10 @@ define([ }); } + + /** - * sets the solution for the current cell to be the solution for all cells in the notebook + * sets the solution of the current cell to be the solution for all cells in the notebook */ var allOutputsButton = function() { var myFunc = function () { From bfef43dc7ca4731b73433312e5b4590cd87b2df0 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 11:52:52 +0200 Subject: [PATCH 26/62] refactor(allOutputsButton): start refactor --- ordo/ordo.js | 74 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 7e8ecfe..38772bb 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -608,37 +608,49 @@ define([ /** - * sets the solution of the current cell to be the solution for all cells in the notebook - */ - var allOutputsButton = function() { - var myFunc = function () { - cells = Jupyter.notebook.get_cells(); - for(i=0;i < cells.length;i++) { - if(cells[i].cell_type == "code") { - if(cells[i].output_area != undefined) { - if(cells[i].output_area.outputs.length > 0) { - if(cells[i].output_area.outputs[0].output_type == "execute_result") { - cells[i].metadata.ordo_solution = cells[i].output_area.outputs[0].data - console.debug("updated metadata"); - } - } - } - } - } - }; - var action = { - icon: 'fa-lightbulb-o', - help: 'Make all outputs solutions', - help_index: 'zz', - handler: myFunc - }; - var prefix = 'allOutputsButton'; - var action_name = 'show-button'; - var full_action_name = Jupyter.actions.register(action, action_name,prefix); - if($("[data-jupyter-action*='allOutputsButton']").length == 0) { - Jupyter.toolbar.add_buttons_group([full_action_name]); - } - } + * Sets the solution of the current cell to be the solution for all cells in the notebook + */ + var allOutputsButton = function() { + + var myFunc = function () { + cells = Jupyter.notebook.get_cells(); + + for(i=0; i < cells.length; i++) { + + if(cells[i].cell_type == "code") { + + if(cells[i].output_area != undefined) { + + if(cells[i].output_area.outputs.length > 0) { + + if(cells[i].output_area.outputs[0].output_type == "execute_result") { + cells[i].metadata.ordo_solution = cells[i].output_area.outputs[0].data + console.debug("updated metadata"); + } + } + } + } + } + }; + + + var action = { + icon: 'fa-lightbulb-o', + help: 'Make all outputs solutions', + help_index: 'zz', + handler: myFunc + }; + + + var prefix = 'allOutputsButton'; + var action_name = 'show-button'; + var full_action_name = Jupyter.actions.register(action, action_name, prefix); + + + if($("[data-jupyter-action*='allOutputsButton']").length == 0) { + Jupyter.toolbar.add_buttons_group([full_action_name]); + } + } /** * toggles the cell mode between editing/creating solutions and giving feedback From cf05d25923a0d98329dcb6b87373e4ff04817e0f Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 11:53:19 +0200 Subject: [PATCH 27/62] doc(allOutputsButton): fix --- ordo/ordo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 38772bb..8f202ec 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -608,7 +608,7 @@ define([ /** - * Sets the solution of the current cell to be the solution for all cells in the notebook + * Sets the solution of each cell to the output of the cell. */ var allOutputsButton = function() { From 9dfe61c4d4ab260c130821c4c3cabd8fa147ba27 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 11:56:45 +0200 Subject: [PATCH 28/62] refactor(allOutputsButton): rename myFunc to a more descriptive name --- ordo/ordo.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 8f202ec..6c52768 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -612,10 +612,9 @@ define([ */ var allOutputsButton = function() { - var myFunc = function () { - cells = Jupyter.notebook.get_cells(); + var setAllCellOutputsAsCellSolutions = function () { - for(i=0; i < cells.length; i++) { + for(i=0; i < Jupyter.notebook.get_cells().length; i++) { if(cells[i].cell_type == "code") { @@ -624,7 +623,7 @@ define([ if(cells[i].output_area.outputs.length > 0) { if(cells[i].output_area.outputs[0].output_type == "execute_result") { - cells[i].metadata.ordo_solution = cells[i].output_area.outputs[0].data + cells[i].metadata.ordo_solution = cells[i].output_area.outputs[0].data; console.debug("updated metadata"); } } @@ -638,7 +637,7 @@ define([ icon: 'fa-lightbulb-o', help: 'Make all outputs solutions', help_index: 'zz', - handler: myFunc + handler: setAllCellOutputsAsCellSolutions }; From 85b686f52383f7d3d6ed9e32cda1b4aa00457192 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 13:50:48 +0200 Subject: [PATCH 29/62] refactor(ordoEditFeedbackToggle): add refactored function --- ordo/ordo.js | 176 ++++++++++++++++++++++++++------------------------- 1 file changed, 90 insertions(+), 86 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 6c52768..f6b8f07 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -651,94 +651,98 @@ define([ } } - /** - * toggles the cell mode between editing/creating solutions and giving feedback - */ - var ordoEditFeedbackToggle = function() { - var editMode = function() { - $('.command_mode').removeClass('ordo_feedback_mode'); - $('.command_mode').addClass('ordo_edit_mode'); - $("[data-jupyter-action*='feedbackToggle']").removeClass('active'); - $("[data-jupyter-action*='editModeToggle']").addClass('active'); - makeOutputButton(); - allOutputsButton(); - }; - var eMaction = { - icon: 'fa-pencil', - help: 'Enter ordo-edit mode', - help_index: 'zy', - handler: editMode - }; - var eMprefix = 'editModeToggle'; - var eMaction_name = 'EnterEditMode'; - var eM_action_name = Jupyter.actions.register(eMaction, eMaction_name, eMprefix); - - var feedbackMode = function() { - $('.command_mode').removeClass('ordo_edit_mode'); - $('.command_mode').addClass('ordo_feedback_mode'); - $("[data-jupyter-action*='editModeToggle']").removeClass('active'); - $("[data-jupyter-action*='feedbackToggle']").addClass('active'); - $("[data-jupyter-action*='allOutputsButton']").remove(); - $(".make-ordo-solution").remove(); - $(".ordo-user-input").remove(); - }; - var fMaction = { - icon: 'fa-check', - help: 'Enter feedback-only mode', - help_index: 'zx', - handler: feedbackMode - }; - var fMprefix = 'feedbackToggle'; - var fMaction_name = 'EnterFeedbackMode'; - var fM_action_name = Jupyter.actions.register(fMaction, fMaction_name, fMprefix); - - /* Jupyter.toolbar.add_buttons_group([fM_action_name,eM_action_name]) */ - var eMaction = { - icon: 'fa-pencil', - help: 'Enter ordo-edit mode', - help_index: 'zy', - handler: editMode - }; - var eMprefix = 'editModeToggle'; - var eMaction_name = 'EnterEditMode'; - var eM_action_name = Jupyter.actions.register(eMaction, eMaction_name, eMprefix); - - var toggleAdmonitions = function() { - var r = $("[data-jupyter-action*='toggleAdmonitions']").toggleClass('active'); - console.debug("toggleAdmonitions 'em!!!!"); - - Jupyter.notebook.get_cells(). - forEach(function (cell, idx, cells) { - var elem; - if (r.hasClass('active')) { - elem = cell.element.find("div.ordo-admonition-controls button.ordo-admonition-btn.active"); - } else { - elem = cell.element.find("div.ordo-admonition-controls :not(button.ordo-admonition-btn.active)"); - } - - if (elem.length > 0) { - onClickAdmonitionButton(cell, elem); - elem.toggleClass("active"); - } - }); - }; - - var admAction = { - icon: 'fa-window-close-o', - help: 'Open/ close all admonitions cells', - help_index: 'zz', - handler: toggleAdmonitions - }; - - var admPrefix = 'toggleAdmonitions'; - var admAction_name = 'OpenCloseAdmonitions'; - var adm_action_name = Jupyter.actions.register(admAction, admAction_name, admPrefix); - - Jupyter.toolbar.add_buttons_group([fM_action_name,eM_action_name,adm_action_name]) - $("[data-jupyter-action*='feedbackToggle']").addClass('active'); - } + /** + * toggles the cell mode between editing/creating solutions and giving feedback + */ + var ordoEditFeedbackToggle = function() { + var editMode = function() { + $('.command_mode').removeClass('ordo_feedback_mode'); + $('.command_mode').addClass('ordo_edit_mode'); + $("[data-jupyter-action*='feedbackToggle']").removeClass('active'); + $("[data-jupyter-action*='editModeToggle']").addClass('active'); + makeOutputButton(); + allOutputsButton(); + }; + + var eMaction = { + icon: 'fa-pencil', + help: 'Enter ordo-edit mode', + help_index: 'zy', + handler: editMode + }; + + + var eMprefix = 'editModeToggle'; + var eMaction_name = 'EnterEditMode'; + var eM_action_name = Jupyter.actions.register(eMaction, eMaction_name, eMprefix); + + + + + var feedbackMode = function() { + $('.command_mode').removeClass('ordo_edit_mode'); + $('.command_mode').addClass('ordo_feedback_mode'); + $("[data-jupyter-action*='editModeToggle']").removeClass('active'); + $("[data-jupyter-action*='feedbackToggle']").addClass('active'); + $("[data-jupyter-action*='allOutputsButton']").remove(); + $(".make-ordo-solution").remove(); + $(".ordo-user-input").remove(); + }; + + + var fMaction = { + icon: 'fa-check', + help: 'Enter feedback-only mode', + help_index: 'zx', + handler: feedbackMode + }; + + + var fMprefix = 'feedbackToggle'; + var fMaction_name = 'EnterFeedbackMode'; + var fM_action_name = Jupyter.actions.register(fMaction, fMaction_name, fMprefix); + + + + var toggleAdmonitions = function() { + var r = $("[data-jupyter-action*='toggleAdmonitions']").toggleClass('active'); + console.debug("toggleAdmonitions 'em!!!!"); + + + Jupyter.notebook.get_cells().forEach(function (cell, idx, cells) { + + if (r.hasClass('active')) { + var elem = cell.element.find("div.ordo-admonition-controls button.ordo-admonition-btn.active"); + } else { + var elem = cell.element.find("div.ordo-admonition-controls :not(button.ordo-admonition-btn.active)"); + } + + if (elem.length > 0) { + onClickAdmonitionButton(cell, elem); + elem.toggleClass("active"); + } + }); + }; + + var admAction = { + icon: 'fa-window-close-o', + help: 'Open/ close all admonitions cells', + help_index: 'zz', + handler: toggleAdmonitions + }; + + var admPrefix = 'toggleAdmonitions'; + var admAction_name = 'OpenCloseAdmonitions'; + var adm_action_name = Jupyter.actions.register(admAction, admAction_name, admPrefix); + + Jupyter.toolbar.add_buttons_group([fM_action_name, eM_action_name, adm_action_name]); + + $("[data-jupyter-action*='feedbackToggle']").addClass('active'); + }; + + var onEditSol = function(cell) { dialog.modal({ From 7a86561cec3d914c75132009c51b13f646fa6db8 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 14:00:44 +0200 Subject: [PATCH 30/62] refactor(onEditSol): add refactored function --- ordo/ordo.js | 87 ++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index f6b8f07..7e4269f 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -742,51 +742,58 @@ define([ $("[data-jupyter-action*='feedbackToggle']").addClass('active'); }; - + /** + * Invokes the edit solution modal for a given cell + * @param {object} A jupyter notebook cell object + */ var onEditSol = function(cell) { - dialog.modal({ - 'title': 'Edit Solutions', - 'body': makeSolutionInputArea(cell), - 'buttons': { - 'Cancel': {}, - 'Save New Solution': { - 'id': 'save-solution-btn', - 'class': 'btn-primary', - 'click': function() { - sol = {} - sol[$('#output_type').val()] = $('#solution_text_area').val() - cell.metadata.ordo_solution = sol - } - }, - }, - 'keyboard_manager': Jupyter.notebook.keyboard_manager, - 'notebook': Jupyter.notebook - }) + dialog.modal({ + 'title': 'Edit Solutions', + 'body': makeSolutionInputArea(cell), + 'buttons': { + 'Cancel': {}, + 'Save New Solution': { + 'id': 'save-solution-btn', + 'class': 'btn-primary', + 'click': function() { + sol = {}; + sol[$('#output_type').val()] = $('#solution_text_area').val(); + cell.metadata.ordo_solution = sol; + } + }, + }, + 'keyboard_manager': Jupyter.notebook.keyboard_manager, + 'notebook': Jupyter.notebook + }); }; + + + var onEditSuccMsg = function(cell) { - dialog.modal({ - 'title': 'Edit Success Messages', - 'body': makeMessageInputArea(cell), - 'buttons': { - 'Cancel': {}, - 'Save New Message': { - 'id': 'save-success-msg-btn', - 'class': 'btn-primary', - 'click': function() { - if($('#styling').val() == "bold") { - sol = "" + $('#message_text_area').val() + "" - } else { - sol = $('#message_text_area').val() - } - cell.metadata.ordo_success = sol - } - }, - }, - 'keyboard_manager': Jupyter.notebook.keyboard_manager, - 'notebook': Jupyter.notebook - }) + dialog.modal({ + 'title': 'Edit Success Messages', + 'body': makeMessageInputArea(cell), + 'buttons': { + 'Cancel': {}, + 'Save New Message': { + 'id': 'save-success-msg-btn', + 'class': 'btn-primary', + 'click': function() { + if($('#styling').val() == "bold") { + sol = "" + $('#message_text_area').val() + ""; + } else { + sol = $('#message_text_area').val(); + } + + cell.metadata.ordo_success = sol; + } + }, + }, + 'keyboard_manager': Jupyter.notebook.keyboard_manager, + 'notebook': Jupyter.notebook + }) }; var onEditFailMsg = function(cell) { From 6314ca9d251b09768d043469bf2b745acb1a6dce Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 14:02:24 +0200 Subject: [PATCH 31/62] doc(onEditSuccMsg): add doc to function --- ordo/ordo.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 7e4269f..68d06c7 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -770,7 +770,10 @@ define([ - + /** + * Invokes the edit success message model for a given cell + * @param {object} A jupyter notebook cell object + */ var onEditSuccMsg = function(cell) { dialog.modal({ 'title': 'Edit Success Messages', From 0f9aee7682eaa40e52b3e1528137f8614416dcea Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 14:07:19 +0200 Subject: [PATCH 32/62] doc(onEditFailMsg): add doc to function --- ordo/ordo.js | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 68d06c7..78ac0b1 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -799,28 +799,34 @@ define([ }) }; + + + /** + * Invokes the edit fail message model for a given cell + * @param {object} A jupyter notebook cell object + */ var onEditFailMsg = function(cell) { - dialog.modal({ - 'title': 'Edit Failure Message', - 'body': makeMessageInputArea(cell), - 'buttons': { - 'Cancel': {}, - 'Save New Message': { - 'id': 'save-failure-msg-btn', - 'class': 'btn-primary', - 'click': function() { - if($('#styling').val() == "bold") { - sol = "" + $('#message_text_area').val() + "" - } else { - sol = $('#message_text_area').val() - } - cell.metadata.ordo_failure = sol - } - }, - }, - 'keyboard_manager': Jupyter.notebook.keyboard_manager, - 'notebook': Jupyter.notebook - }) + dialog.modal({ + 'title': 'Edit Failure Message', + 'body': makeMessageInputArea(cell), + 'buttons': { + 'Cancel': {}, + 'Save New Message': { + 'id': 'save-failure-msg-btn', + 'class': 'btn-primary', + 'click': function() { + if($('#styling').val() == "bold") { + sol = "" + $('#message_text_area').val() + "" + } else { + sol = $('#message_text_area').val() + } + cell.metadata.ordo_failure = sol + } + }, + }, + 'keyboard_manager': Jupyter.notebook.keyboard_manager, + 'notebook': Jupyter.notebook + }) } From 39d22f926f28e89face0a0e1e057476fc17b52a5 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 14:09:30 +0200 Subject: [PATCH 33/62] refactor(onEditFailMsg): add refactored function --- ordo/ordo.js | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 78ac0b1..f13aa32 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -806,28 +806,29 @@ define([ * @param {object} A jupyter notebook cell object */ var onEditFailMsg = function(cell) { - dialog.modal({ - 'title': 'Edit Failure Message', - 'body': makeMessageInputArea(cell), - 'buttons': { - 'Cancel': {}, - 'Save New Message': { - 'id': 'save-failure-msg-btn', - 'class': 'btn-primary', - 'click': function() { - if($('#styling').val() == "bold") { - sol = "" + $('#message_text_area').val() + "" - } else { - sol = $('#message_text_area').val() - } - cell.metadata.ordo_failure = sol - } - }, - }, - 'keyboard_manager': Jupyter.notebook.keyboard_manager, - 'notebook': Jupyter.notebook - }) - } + dialog.modal({ + 'title': 'Edit Failure Message', + 'body': makeMessageInputArea(cell), + 'buttons': { + 'Cancel': {}, + 'Save New Message': { + 'id': 'save-failure-msg-btn', + 'class': 'btn-primary', + 'click': function() { + if($('#styling').val() == "bold") { + sol = "" + $('#message_text_area').val() + ""; + } else { + sol = $('#message_text_area').val(); + } + + cell.metadata.ordo_failure = sol; + } + }, + }, + 'keyboard_manager': Jupyter.notebook.keyboard_manager, + 'notebook': Jupyter.notebook + }) + }; /** From b7f55b3de9c875f84a61abaab82d983e2229bd0b Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 14:14:07 +0200 Subject: [PATCH 34/62] refactor(editMetadataButtons): add refactored function --- ordo/ordo.js | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index f13aa32..ba45783 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -771,7 +771,7 @@ define([ /** - * Invokes the edit success message model for a given cell + * Invokes the edit success message modal for a given cell * @param {object} A jupyter notebook cell object */ var onEditSuccMsg = function(cell) { @@ -802,7 +802,7 @@ define([ /** - * Invokes the edit fail message model for a given cell + * Invokes the edit fail message modal for a given cell * @param {object} A jupyter notebook cell object */ var onEditFailMsg = function(cell) { @@ -835,25 +835,30 @@ define([ * creates the buttons and handles the functionality related to editing a solution */ var editMetadataButtons = function() { - var currCell = undefined; - events.on('select.Cell', function(event, data) { - newCell = data.cell; - if(newCell == currCell){ - return; - } else if($('.ordo_edit_mode').length == 0) { - return; - } else { - $(".ordo-user-input").remove(); - currCell = newCell; - if(currCell.cell_type == "code") { - $(".selected > .output_wrapper .output").append(ordoEditButtons); - $(".ordo-add-solution").on('click', (evt) => onEditSol(currCell)); - $(".ordo-add-success-msg").on('click', (evt) => onEditSuccMsg(currCell)); - $(".ordo-add-failure-msg").on('click', (evt) => onFailureSuccMsg(currCell)); - } - } - }); - } + + events.on('select.Cell', function(event, data) { + + if(data.cell == undefined){ + return; + } + + if($('.ordo_edit_mode').length == 0) { + return; + } + + + + $(".ordo-user-input").remove(); + + if(data.cell.cell_type == "code") { + $(".selected > .output_wrapper .output").append(ordoEditButtons); + $(".ordo-add-solution").on('click', (evt) => onEditSol(data.cell)); + $(".ordo-add-success-msg").on('click', (evt) => onEditSuccMsg(data.cell)); + $(".ordo-add-failure-msg").on('click', (evt) => onFailureSuccMsg(data.cell)); + } + + }); + }; /** * html for the feedback buttons on a cell From bc46bf13e62e19701a1786d28c8c40335f7fb39e Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 14:35:10 +0200 Subject: [PATCH 35/62] refactor(ordoEditButtons): refactor string for ordo edit buttons --- ordo/ordo.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index ba45783..18b0c1f 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -860,15 +860,16 @@ define([ }); }; - /** - * html for the feedback buttons on a cell - */ - var ordoEditButtons = - "
" + - "" + - "" + - "" + - "
"; + + /** + * html for the feedback buttons on a cell + */ + var ordoEditButtons = + "
" + + "" + + "" + + "" + + "
"; /** * html for the input box to create a feedback message From 916281f498c9f5b127ef080fb40e98ff810c3228 Mon Sep 17 00:00:00 2001 From: Stefan Bachhofner Date: Fri, 15 Oct 2021 14:50:25 +0200 Subject: [PATCH 36/62] refactor(makeMessageInputArea): add refactored function --- ordo/ordo.js | 103 ++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 54 deletions(-) diff --git a/ordo/ordo.js b/ordo/ordo.js index 18b0c1f..d8e3c0e 100644 --- a/ordo/ordo.js +++ b/ordo/ordo.js @@ -870,61 +870,56 @@ define([ "" + "" + ""; - - /** - * html for the input box to create a feedback message - */ - var makeMessageInputArea = function() { - var styles= [ - 'bold', - 'plain text', - 'html' - ] - - $sel = $('', { + 'class': "form-control", + 'id': "styling", + 'title': 'Select the styling for the following text' + }); + + $.each(styles, function(index, type) { + $sel.append("") + }); + + + + var inputArea = + $('
', {'class': 'inputArea'}).append( + $('
', {'title': 'Message Input Area'}).append( + $('
', {'class': "form-inline"}).append($sel).append( + $('