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A,kBAAAwB,GAAsB,EAM1B,SAASC,EAAWC,EAAGvD,GACnB,GAAIwD,YAAYxE,qBAAsB,CAClC,IAAIyE,EAAQ/E,OAAOsB,EAAK2C,WAAWe,YAAYC,QAAQ,SAAU,KAC7DF,GACAA,EAAMhC,sBAAsBzB,GAC5ByD,EAAMV,oBAEN7C,QAAQC,IACJ,wCAAwCH,EAAK2C,WAAWe,cAGpE,CACJ,CAEA,SAASE,EAAeL,EAAGvD,GACvB,GAAIwD,YAAYxE,qBAAsB,CAClC,IAAIyE,EAAQ/E,OAAOsB,EAAK2C,WAAWe,YAAYC,QAAQ,SAAU,KAC7DF,EACAA,EAAMR,aAAa,CACfC,MAAO,UACPC,OAAQnD,EAAK2C,WAAWe,YACxBN,IAAK,SAGTlD,QAAQC,IACJ,wCAAwCH,EAAK2C,WAAWe,cAGpE,CACJ,MAIwC,IAA7BjF,OAAOoF,oBACdpF,OAAOoF,kBAAoB,CAAC,GAGhCpF,OAAOoF,kBAAkBC,QAAU,SAAUjF,GACzC,OAAO,IAAIF,EAAQE,EACvB,EAEAkF,GAAE,WACEA,EAAE,QAAQC,GAAG,qBAAsBV,GACnCS,EAAE,QAAQC,GAAG,yBAA0BJ,EAC3C,IAEAG,EAAEE,UAAUD,GAAG,4BAA4B,WACvCD,EAAE,4BAA4BG,MAAK,SAAUC,GAEzC,IAAItF,EAAO,CACPM,KAAMJ,KACNC,qBAAsBwE,YAAYxE,sBAE4B,GAA9D+E,EAAEhF,MAAMqF,QAAQ,oCAAoC3D,SAEpDhC,OAAOC,OAAOK,KAAKK,IAAM,IAAIT,EAAQE,GAE7C,GACJ,G","sources":["webpack://WebComponents/./runestone/webwork/js/webwork.js"],"sourcesContent":["import RunestoneBase from \"../../common/js/runestonebase\";\n\nwindow.wwList = {}; // Multiple Choice dictionary\n\nclass WebWork extends RunestoneBase {\n constructor(opts) {\n super(opts);\n this.useRunestoneServices = true;\n this.multipleanswers = false;\n this.divid = opts.orig.id;\n this.correct = null;\n this.optional = false;\n this.answerList = [];\n this.correctList = [];\n this.question = null;\n this.caption = \"WebWork\";\n this.containerDiv = opts.orig;\n this.answers = {};\n this.percent = 0;\n //this.addCaption(\"runestone\");\n if (this.divid !== \"fakeww-ww-rs\") {\n this.checkServer(\"webwork\", true);\n }\n window.wwList[this.divid] = this;\n }\n\n restoreAnswers(data) {\n // Restore answers from storage retrieval done in RunestoneBase\n // sometimes data.answer can be null\n if (!data.answer) {\n data.answer = \"\";\n }\n // data.answers comes from postgresql as a JSON column type so no need to parse it.\n\n this.answers = data.answer;\n this.correct = data.correct;\n this.percent = data.percent;\n console.log(\n `about to decorate the status of WW ${this.divid} ${this.correct}`\n );\n this.decorateStatus();\n }\n\n checkLocalStorage() {\n // Repopulates MCMA questions with a user's previous answers,\n // which were stored into local storage.\n var storedData;\n var answers;\n if (this.graderactive) {\n return;\n }\n var len = localStorage.length;\n var ex = localStorage.getItem(this.localStorageKey());\n\n if (ex !== null) {\n try {\n storedData = JSON.parse(ex);\n // Save the answers so that when the question is activated we can restore.\n this.answers = storedData.answer;\n this.correct = storedData.correct;\n this.percent = storedData.percent;\n // We still decorate the webwork question even if it is not active.\n this.decorateStatus();\n } catch (err) {\n // error while parsing; likely due to bad value stored in storage\n console.log(err.message);\n localStorage.removeItem(this.localStorageKey());\n return;\n }\n }\n }\n\n setLocalStorage(data) {\n var timeStamp = new Date();\n var storageObj = {\n answer: data.answer,\n timestamp: timeStamp,\n correct: data.correct,\n };\n localStorage.setItem(\n this.localStorageKey(),\n JSON.stringify(storageObj)\n );\n }\n\n // This is called when the runestone_ww_check event is triggered by the webwork problem\n // Note the webwork problem is in an iframe so we rely on this event and the data\n // compiled and passed along with the event to \"grade\" the answer.\n processCurrentAnswers(data) {\n let correctCount = 0;\n let qCount = 0;\n let actString = \"check:\";\n this.answerObj = {};\n this.lastAnswerRaw = data;\n this.answerObj.answers = {};\n this.answerObj.mqAnswers = {};\n // data.inputs_\n for (let k of Object.keys(data.rh_result.answers)) {\n qCount += 1;\n if (data.rh_result.answers[k].score == 1) {\n correctCount += 1;\n }\n // mostly grab original_student_ans, but grab student_value for MC exercises\n let student_ans = ['Value (parserRadioButtons)', 'Value (PopUp)', 'Value (CheckboxList)'].includes(data.rh_result.answers[k].type)\n ? data.rh_result.answers[k].student_value\n : data.rh_result.answers[k].original_student_ans;\n this.answerObj.answers[\n k\n ] = `${student_ans}`;\n let mqKey = `MaThQuIlL_${k}`;\n this.answerObj.mqAnswers[mqKey] = data.inputs_ref[mqKey];\n actString += `actual:${student_ans}:expected:${data.rh_result.answers[k].correct_value}:`;\n }\n let pct = correctCount / qCount;\n // If this.percent is set, then runestonebase will transmit it as part of\n // the logBookEvent API.\n this.percent = pct;\n this.actString =\n actString + `correct:${correctCount}:count:${qCount}:pct:${pct}`;\n if (pct == 1.0) {\n this.correct = true;\n } else {\n this.correct = false;\n }\n let ls = {};\n ls.answer = this.answerObj;\n ls.correct = this.correct;\n ls.percent = this.percent;\n this.setLocalStorage(ls);\n this.decorateStatus();\n }\n\n async logCurrentAnswer(sid) {\n this.logBookEvent({\n event: \"webwork\",\n div_id: this.divid, //todo unmangle problemid\n act: this.actString,\n correct: this.correct,\n answer: JSON.stringify(this.answerObj),\n });\n }\n\n checkCurrentAnswer() {}\n}\n\n//\n// These are functions that get called in response to webwork generated events.\n// submitting the work, or showing an answer.\nfunction logWebWork(e, data) {\n if (eBookConfig.useRunestoneServices) {\n let wwObj = wwList[data.inputs_ref.problemUUID.replace(\"-ww-rs\", \"\")];\n if (wwObj) {\n wwObj.processCurrentAnswers(data);\n wwObj.logCurrentAnswer();\n } else {\n console.log(\n `Error: Could not find webwork object ${data.inputs_ref.problemUUID}`\n );\n }\n }\n}\n\nfunction logShowCorrect(e, data) {\n if (eBookConfig.useRunestoneServices) {\n let wwObj = wwList[data.inputs_ref.problemUUID.replace(\"-ww-rs\", \"\")];\n if (wwObj) {\n wwObj.logBookEvent({\n event: \"webwork\",\n div_id: data.inputs_ref.problemUUID,\n act: \"show\",\n });\n } else {\n console.log(\n `Error: Could not find webwork object ${data.inputs_ref.problemUUID}`\n );\n }\n }\n}\n\nasync function getScores(sid, wwId) {}\n\nif (typeof window.component_factory === \"undefined\") {\n window.component_factory = {};\n}\n\nwindow.component_factory.webwork = function (opts) {\n return new WebWork(opts);\n};\n\n$(function () {\n $(\"body\").on(\"runestone_ww_check\", logWebWork);\n $(\"body\").on(\"runestone_show_correct\", logShowCorrect);\n});\n\n$(document).on(\"runestone:login-complete\", function () {\n $(\"[data-component=webwork]\").each(function (index) {\n // MC\n var opts = {\n orig: this,\n useRunestoneServices: eBookConfig.useRunestoneServices,\n };\n if ($(this).closest(\"[data-component=timedAssessment]\").length == 0) {\n // If this element exists within a timed component, don't render it here\n window.wwList[this.id] = new WebWork(opts);\n }\n });\n});\n"],"names":["window","wwList","WebWork","constructor","opts","super","this","useRunestoneServices","multipleanswers","divid","orig","id","correct","optional","answerList","correctList","question","caption","containerDiv","answers","percent","checkServer","restoreAnswers","data","answer","console","log","decorateStatus","checkLocalStorage","storedData","graderactive","localStorage","length","ex","getItem","localStorageKey","JSON","parse","err","message","removeItem","setLocalStorage","timeStamp","Date","storageObj","timestamp","setItem","stringify","processCurrentAnswers","correctCount","qCount","actString","answerObj","lastAnswerRaw","mqAnswers","k","Object","keys","rh_result","score","student_ans","includes","type","student_value","original_student_ans","mqKey","inputs_ref","correct_value","pct","ls","logCurrentAnswer","sid","logBookEvent","event","div_id","act","checkCurrentAnswer","logWebWork","e","eBookConfig","wwObj","problemUUID","replace","logShowCorrect","component_factory","webwork","$","on","document","each","index","closest"],"sourceRoot":""}