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,aAAa,CACdC,MAAO,UACPC,OAAQrE,KAAKG,MACbmE,IAAKtE,KAAK6C,UACVvC,QAASN,KAAKM,QACdY,OAAQY,KAAKW,UAAUzC,KAAK8C,YAEpC,CAEA,kBAAAyB,GAAsB,EAM1B,SAASC,EAAWC,EAAGxD,GACnB,GAAIyD,YAAYzE,qBAAsB,CAClC,IAAI0E,EAAQhF,OAAOsB,EAAK2C,WAAWgB,YAAYC,QAAQ,SAAU,KAC7DF,GACAA,EAAMjC,sBAAsBzB,GAC5B0D,EAAMV,oBAEN9C,QAAQC,IACJ,wCAAwCH,EAAK2C,WAAWgB,cAGpE,CACJ,CAEA,SAASE,EAAeL,EAAGxD,GACvB,GAAIyD,YAAYzE,qBAAsB,CAClC,IAAI0E,EAAQhF,OAAOsB,EAAK2C,WAAWgB,YAAYC,QAAQ,SAAU,KAC7DF,EACAA,EAAMR,aAAa,CACfC,MAAO,UACPC,OAAQpD,EAAK2C,WAAWgB,YACxBN,IAAK,SAGTnD,QAAQC,IACJ,wCAAwCH,EAAK2C,WAAWgB,cAGpE,CACJ,MAIwC,IAA7BlF,OAAOqF,oBACdrF,OAAOqF,kBAAoB,CAAC,GAGhCrF,OAAOqF,kBAAkBC,QAAU,SAAUlF,GACzC,OAAO,IAAIF,EAAQE,EACvB,EAEAmF,GAAE,WACEA,EAAE,QAAQC,GAAG,qBAAsBV,GACnCS,EAAE,QAAQC,GAAG,yBAA0BJ,EAC3C,IAEAG,EAAEE,UAAUD,GAAG,4BAA4B,WACvCD,EAAE,4BAA4BG,MAAK,SAAUC,GAEzC,IAAIvF,EAAO,CACPM,KAAMJ,KACNC,qBAAsByE,YAAYzE,sBAE4B,GAA9DgF,EAAEjF,MAAMsF,QAAQ,oCAAoC5D,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;\n            if (\n                !(\"ww_version\" in data) ||\n                data.ww_version.includes(\"2.16\") ||\n                data.ww_version.includes(\"2.17\") ||\n                data.ww_version.includes(\"2.18\")\n            ) {\n                // Mostly grab original_student_ans, but grab student_value for MC exercises\n                student_ans = [\n                    \"Value (parserRadioButtons)\",\n                    \"Value (PopUp)\",\n                    \"Value (CheckboxList)\",\n                ].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            } else {\n                // Literally get the input refs\n                // data.inputs_ref[k] will usually be a string, the @value of the answer input field that was submitted\n                // However in at least the case of checkboxes, data.inputs_ref[k] will be an array\n                // So however this is ultimately stored in the Runestone database should respect ans preserve this as an array, not stringified\n                student_ans = data.inputs_ref[k];\n            }\n            this.answerObj.answers[k] = 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","student_ans","score","ww_version","includes","type","student_value","original_student_ans","inputs_ref","mqKey","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":""}