Skip to content

Commit

Permalink
question editor: if generating variables didn't finish last time the …
Browse files Browse the repository at this point in the history
…page was open, don't autocalculate

When the question editor loads, it sets a local storage key. Once a set
of variables has been generated, that key is removed.

If the key is still set when the page loads, then variable generation
mustn't have finished last time the editor was open at this question, so
don't automatically generate variable values.

This gives authors an opportunity to fix questions with infinite loops
somewhere in a variable's definition.

This doesn't completely solve #713, but makes it possible to get
yourself out of the situation where a set of variables can't be
generated.
  • Loading branch information
christianp committed Dec 13, 2023
1 parent 15c742c commit ee2db92
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions editor/static/js/question/edit.js
Expand Up @@ -605,6 +605,12 @@ $(document).ready(function() {
q.mainTabber.setTab('variables')();
}

this.autocalc_storage_key = 'numbas-editor-question-'+item_json.itemJSON.id+'-autocalc-on-load';
if(window.localStorage && localStorage.getItem(this.autocalc_storage_key)==='false') {
this.autoCalculateVariables(false);
}
localStorage.setItem(this.autocalc_storage_key, 'false');

ko.computed(function() {
if(!this.autoCalculateVariables())
return;
Expand Down Expand Up @@ -1138,6 +1144,10 @@ $(document).ready(function() {
}
this.variablesTest.conditionSatisfied(conditionSatisfied);

if(window.localStorage && this.variables().length) {
localStorage.removeItem(this.autocalc_storage_key);
}

// fill in observables
this.variables().map(function(v) {
if(v.locked.peek()) {
Expand Down

0 comments on commit ee2db92

Please sign in to comment.