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EvB,CACA,aAAAE,CAAcC,GAEV,IACI3B,EAAS,EAEb,IACI,IAAI3B,EAAI,EAAGuD,EAAID,EAAQE,OAAS,EAChCxD,EAAIsD,EAAQE,OACZxD,GAAK,EAAGuD,GAAK,EAEb5B,GAAU8B,KAAKC,IAAIC,GAAaJ,IARzB,6BAQoCzB,QAAQwB,EAAQtD,IAAM,GAGrE,OAAO2B,EAAS,CACpB,EAGJnD,EAAEa,UAAUuE,GAAG,4BAA4B,WACvCpF,EAAE,gCAAgCqF,MAAK,SAAUC,GAE7C,IAAIhG,EAAO,CACPE,KAAMC,KACN8F,qBAAsBxB,YAAYwB,sBAEtC,IACIrF,OAAOsF,aAAa/F,KAAKE,IAAM,IAAIP,YAAYE,EACnD,CAAE,MAAOmG,GACLC,QAAQC,IAAI,uCAAuClG,KAAKE,yCAChC8F,KACxBC,QAAQC,IAAIF,EAAIG,MACpB,CACJ,GACJ,SAEwC,IAA7B1F,OAAO2F,oBACd3F,OAAO2F,kBAAoB,CAAC,GAEhC3F,OAAO2F,kBAAkBC,YAAc,SAAUxG,GAC7C,OAAO,IAAIF,YAAYE,EAC3B,C","sources":["webpack://WebComponents/./runestone/spreadsheet/js/spreadsheet.js"],"sourcesContent":["\"use strict\";\n\nimport RunestoneBase from \"../../common/js/runestonebase\";\nimport jexcel from \"jexcel\";\nimport \"../css/spreadsheet.css\";\nimport \"../css/spreadsheet.css\";\nimport \"jexcel/dist/jexcel.css\";\n\nclass SpreadSheet extends RunestoneBase {\n constructor(opts) {\n super(opts);\n let orig = opts.orig;\n this.div_id = orig.id;\n this.sheet_id = `${this.div_id}_sheet`;\n this.data = eval(`${this.div_id}_data`);\n this.autograde = $(orig).data(\"autograde\");\n this.suffix = window[`${this.div_id}_asserts`];\n this.mindimensions = $(orig).data(\"mindimensions\");\n this.colwidths = $(orig).data(\"colwidths\");\n this.coltitles = eval($(orig).data(\"coltitles\"));\n this.maxHeight = 50;\n // Render the components\n this.renderSheet();\n\n if (this.autograde) {\n this.addAutoGradeButton();\n this.addOutput();\n }\n\n this.caption = \"Spreadsheet\";\n this.divid = this.div_id;\n this.containerDiv = document.getElementById(this.div_id);\n this.addCaption(\"runestone\");\n this.indicate_component_ready();\n }\n\n renderSheet() {\n let div = document.getElementById(this.sheet_id);\n let opts = { data: this.data, tableHeight: this.maxHeight };\n if (this.mindimensions) {\n opts.minDimensions = this.mindimensions;\n }\n opts.columns = [];\n if (this.colwidths) {\n for (let w of this.colwidths) {\n opts.columns.push({ width: w });\n }\n }\n if (this.coltitles) {\n for (let i in this.coltitles) {\n if (opts.columns[i]) {\n opts.columns[i].title = unescape(this.coltitles[i]);\n } else {\n opts.columns.push({ title: this.coltitles[i] });\n }\n }\n }\n\n this.table = jexcel(div, opts);\n\n // Set background of cells that are autograded\n if (this.suffix) {\n for (let test of this.suffix) {\n let assert, loc, oper, expected;\n [assert, loc, oper, expected] = test.split(/\\s+/);\n $(`#${this.div_id}_sheet`)\n .find(this.getCellSelector(loc))\n .css(\"background-color\", \"#d4e3ff\");\n }\n }\n }\n\n addAutoGradeButton() {\n let div = document.getElementById(this.div_id);\n var butt = document.createElement(\"button\");\n $(butt).text(\"Check\");\n $(butt).addClass(\"btn btn-success run-button\");\n div.appendChild(butt);\n this.gradeButton = butt;\n $(butt).click(this.doAutoGrade.bind(this));\n $(butt).attr(\"type\", \"button\");\n $(butt).css(\"display\", \"block\");\n }\n\n addOutput() {\n this.output = document.createElement(\"pre\");\n this.output.id = `${this.div_id}_stdout`;\n $(this.output).css(\"visibility\", \"hidden\");\n let div = document.getElementById(this.div_id);\n div.appendChild(this.output);\n }\n\n doAutoGrade() {\n let tests = this.suffix;\n this.passed = 0;\n this.failed = 0;\n // Tests should be of the form\n // assert cell oper value for example\n // assert A4 == 3\n let result = \"\";\n tests = tests.filter(function (s) {\n return s.indexOf(\"assert\") > -1;\n });\n for (let test of tests) {\n let assert, loc, oper, expected;\n [assert, loc, oper, expected] = test.split(/\\s+/);\n result += this.testOneAssert(loc, oper, expected);\n result += \"\\n\";\n }\n let pct = (100 * this.passed) / (this.passed + this.failed);\n pct = pct.toLocaleString(undefined, { maximumFractionDigits: 2 });\n result += `You passed ${this.passed} out of ${\n this.passed + this.failed\n } tests for ${pct}%`;\n this.logBookEvent({\n event: \"unittest\",\n div_id: this.div_id,\n course: eBookConfig.course,\n act: `percent:${pct}:passed:${this.passed}:failed:${this.failed}`,\n });\n $(this.output).css(\"visibility\", \"visible\");\n $(this.output).text(result);\n }\n\n testOneAssert(cell, oper, expected) {\n let actual = this.getCellDisplayValue(cell);\n const operators = {\n \"==\": function (operand1, operand2) {\n return operand1 == operand2;\n },\n \"!=\": function (operand1, operand2) {\n return operand1 != operand2;\n },\n \">\": function (operand1, operand2) {\n return operand1 > operand2;\n },\n \"<\": function (operand1, operand2) {\n return operand1 > operand2;\n },\n };\n\n let res = operators[oper](actual, expected);\n let output = \"\";\n if (res) {\n output = `Pass: ${actual} ${oper} ${expected} in ${cell}`;\n $(`#${this.div_id}_sheet`)\n .find(this.getCellSelector(cell))\n .css(\"background-color\", \"#ccffcc\");\n this.passed++;\n } else {\n output = `Failed ${actual} ${oper} ${expected} in cell ${cell}`;\n $(`#${this.div_id}_sheet`)\n .find(this.getCellSelector(cell))\n .css(\"background-color\", \"#ff9980\");\n this.failed++;\n }\n return output;\n }\n\n // If the cell contains a formula, this call will return the formula not the computed value\n getCellSource(cell) {\n return this.table.getValue(cell);\n }\n\n // If the cell contains a formula this call will return the computed value\n getCellDisplayValue(cell) {\n let res = this.table.el.querySelector(this.getCellSelector(cell));\n return res.innerText;\n }\n\n getCellSelector(cell) {\n let parts = cell.match(/\\$?([A-Z]+)\\$?([0-9]+)/);\n let x = this.columnToIndex(parts[1]);\n let y = parts[2] - 1;\n return `[data-x=\"${x}\"][data-y=\"${y}\"]`;\n }\n columnToIndex(colName) {\n // Convert the column name to a number A = 0 AA = 26 BA = 52, etc\n let base = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n let result = 0;\n\n for (\n let i = 0, j = colName.length - 1;\n i < colName.length;\n i += 1, j -= 1\n ) {\n result += Math.pow(base.length, j) * (base.indexOf(colName[i]) + 1);\n }\n\n return result - 1;\n }\n}\n\n$(document).on(\"runestone:login-complete\", function () {\n $(\"[data-component=spreadsheet]\").each(function (index) {\n // MC\n var opts = {\n orig: this,\n useRunestoneServices: eBookConfig.useRunestoneServices,\n };\n try {\n window.componentMap[this.id] = new SpreadSheet(opts);\n } catch (err) {\n console.log(`Error rendering SpreadSheet Problem ${this.id}\n Details: ${err}`);\n console.log(err.stack);\n }\n });\n});\n\nif (typeof window.component_factory === \"undefined\") {\n window.component_factory = {};\n}\nwindow.component_factory.spreadsheet = function (opts) {\n return new SpreadSheet(opts);\n};\n"],"names":["SpreadSheet","constructor","opts","super","orig","this","div_id","id","sheet_id","data","eval","autograde","$","suffix","window","mindimensions","colwidths","coltitles","maxHeight","renderSheet","addAutoGradeButton","addOutput","caption","divid","containerDiv","document","getElementById","addCaption","indicate_component_ready","div","tableHeight","minDimensions","columns","w","push","width","i","title","unescape","table","test","assert","loc","oper","expected","split","find","getCellSelector","css","butt","createElement","text","addClass","appendChild","gradeButton","click","doAutoGrade","bind","attr","output","tests","passed","failed","result","filter","s","indexOf","testOneAssert","pct","toLocaleString","undefined","maximumFractionDigits","logBookEvent","event","course","eBookConfig","act","cell","actual","getCellDisplayValue","operand1","operand2","getCellSource","getValue","el","querySelector","innerText","parts","match","columnToIndex","colName","j","length","Math","pow","base","on","each","index","useRunestoneServices","componentMap","err","console","log","stack","component_factory","spreadsheet"],"sourceRoot":""}