Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 0220293

Browse files
author
Brad Miller
committed
color autograded cells
1 parent 3a2bd15 commit 0220293

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

runestone/spreadsheet/js/spreadsheet.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ class SpreadSheet extends RunestoneBase {
4747
}
4848

4949
this.table = jexcel(div, opts);
50+
51+
// Set background of cells that are autograded
52+
if (this.suffix) {
53+
for (let test of this.suffix) {
54+
let assert, loc, oper, expected;
55+
[assert, loc, oper, expected] = test.split(/\s+/);
56+
$(`#${this.div_id}_sheet`).find(this.getCellSelector(loc)).css("background-color","#d4e3ff");
57+
}
58+
}
5059
}
5160

5261
addAutoGradeButton() {
@@ -74,8 +83,8 @@ class SpreadSheet extends RunestoneBase {
7483
this.passed = 0;
7584
this.failed = 0;
7685
// Tests should be of the form
77-
// assert row,col oper value for example
78-
// assert 4,4 == 3
86+
// assert cell oper value for example
87+
// assert A4 == 3
7988
let result = "";
8089
tests = tests.filter(function(s) {
8190
return s.indexOf('assert') > -1;
@@ -119,9 +128,11 @@ class SpreadSheet extends RunestoneBase {
119128
let output = "";
120129
if (res) {
121130
output = `Pass: ${actual} ${oper} ${expected} in ${cell}`;
131+
$(`#${this.div_id}_sheet`).find(this.getCellSelector(cell)).css("background-color","#ccffcc");
122132
this.passed++;
123133
} else {
124134
output = `Failed ${actual} ${oper} ${expected} in cell ${cell}`;
135+
$(`#${this.div_id}_sheet`).find(this.getCellSelector(cell)).css("background-color","#ff9980");
125136
this.failed++;
126137
}
127138
return output;
@@ -136,13 +147,16 @@ class SpreadSheet extends RunestoneBase {
136147

137148
// If the cell contains a formula this call will return the computed value
138149
getCellDisplayValue(cell) {
150+
let res = this.table.el.querySelector(this.getCellSelector(cell));
151+
return res.innerText;
152+
}
153+
154+
getCellSelector(cell) {
139155
let parts = cell.match(/\$?([A-Z]+)\$?([0-9]+)/);
140156
let x = this.columnToIndex(parts[1]);
141157
let y = parts[2] - 1;
142-
let res = this.table.el.querySelector(`[data-x="${x}"][data-y="${y}"]`);
143-
return res.innerText;
158+
return `[data-x="${x}"][data-y="${y}"]`;
144159
}
145-
146160
columnToIndex(colName) {
147161
// Convert the column name to a number A = 0 AA = 26 BA = 52, etc
148162
let base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

0 commit comments

Comments
 (0)