Warning: session_start(): open(/var/lib/php/sessions/sess_l8i0qvdnb3fnketu6erqa6se8l, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
concept G22LeftArrowScript > ConceptWithChangeListeners {
settableWithVar S description;
// the script (last "saved" version)
settableWithVar S text;
// the latest code that has been cleared to auto-run (if any)
settableWithVar ClearForAutoRun clearedForAutoRun;
// text currently being modified in an editor (or null)
// Note that "" doesn't count as null.
settableWithVar S editingText;
settableWithVar S importNote;
// auto-run when project is opened
bool runOnProjectOpen;
// only when runOnProjectOpen is seT:
// when to run in sequence (sorted with alphanumIC)
S runOrder;
// run stats
long runCount;
// info about last result (or error) of script run by mode
Map>> lastResultByMode;
// is there a newer version of this script?
new Ref supercededBy;
@Override void _doneLoading2() {
//print("_doneLoading " + this);
cMigrateField(this, "code", "text");
}
S myType() { ret dropPrefix("G22", shortClassName(this)); }
toString { ret or2(description, myType() + " " + id); }
void initEditingText {
editingText(unnull(or(editingText, text)));
}
void receiveEditingText(S text) {
//printVars_shorten("receiveEditingText", +text);
editingText(text);
}
S stableText() { ret text; }
void completeEdit aka save() {
S t = editingText;
//printVars_shorten("completeEdit", +t);
if (t != null) {
setTextWithHistory(t);
//printVars_shorten("completeEdit", +editingText);
}
}
void setTextWithHistory(S text) {
if (eq(this.text, text)) ret;
text(text);
saveTextToHistory();
}
void discardEdit {
S text = editedText();
if (text == null) ret;
saveFieldToHistory("discardingEdit", text);
editingText(null);
}
S textForEditing() {
initEditingText();
ret editingText;
}
File historyFile() {
ret fileInConceptsDir("History/" + shortDynName(this) + id + ".history");
}
void saveTextToHistory() {
saveFieldToHistory("text", text);
}
void saveFieldToHistory(S field, S value) {
File historyFile = historyFile();
if (historyFile == null) ret;
S contents = value == null ? " empty" : " (" + nLines(value) + ", " + nChars(value) + "):\n" +
indentx(value) + "\n" +
"\n";
appendToTextFile(historyFile,
"\n===\n" +
"Concept ID: " + id + "\n" +
"Date: " + dateWithMSUTC() + "\n" +
firstToUpper(field) + contents +
"===" + "\n");
}
bool isSaved() { ret text != null; }
bool isSavedDistinctFromAutoRunVersion() { ret isSaved() && !eq(text, codeForAutoRun()); }
bool isEditing() { ret editedText() != null; }
bool isClearForAutoRun() { ret clearedForAutoRun != null; }
S editedText() { ret eq(editingText, text) ? null : editingText; }
S codeForAutoRun() { ret getVar(clearedForAutoRun()); }
// return code clear for auto run if available
// otherwise returns saved code if available
// in all other cases returns null
// (never returns text being edited)
S safestCode() { ret or(codeForAutoRun(), stableText()); }
void clearForAutoRun {
if (!isSaved()) ret;
S text = text();
saveFieldToHistory("Auto-runnable code", text);
clearedForAutoRun(new ClearForAutoRun(text));
}
void forgetAutoRunCode {
if (!isClearForAutoRun()) ret;
saveFieldToHistory("Auto-runnable code", null);
clearedForAutoRun(null);
compileResultForAutoRun = null;
}
void forgetCompileResults {
compileResultForAutoRun = compileResultForSaved = null;
}
G22Utils g22utils() {
ret assertNotNull(g22utils := main g22utils(_concepts()));
}
GazelleV_LeftArrowScriptParser makeParser() { ret g22utils().leftArrowParser(); }
LASCompileResult newCompileResult() { ret new LASCompileResult; }
transient LASCompileResult compileResultForAutoRun;
LASCompileResult compileForAutoRun() {
S code = codeForAutoRun();
if (code == null) null;
var cr = compileResultForAutoRun;
if (g22utils().compileResultValid(cr, code))
ret cr;
cr = newCompileResult();
cr.script(code);
var parser = makeParser();
cr.parser(parser);
cr.compile();
ret compileResultForAutoRun = cr;
}
transient LASCompileResult compileResultForSaved;
LASCompileResult compileSaved() {
S code = stableText();
if (code == null) null;
var cr = compileResultForSaved;
if (g22utils().compileResultValid(cr, code))
ret cr;
cr = newCompileResult();
cr.script(code);
var parser = makeParser();
cr.parser(parser);
cr.compile();
ret compileResultForSaved = cr;
}
LASCompileResult safestCompileResult() {
try object compileForAutoRun();
ret compileSaved();
}
O evaluateWithoutTimeout() {
var cr = safestCompileResult();
if (cr == null)
fail("Not saved: " + this);
temp g22utils().enter(); // enter module
ret cr.parsedScriptMandatory()!;
}
O evaluateAutoRunWithoutTimeout() {
var cr = compileForAutoRun();
if (cr == null)
fail("Not cleared for auto-run: " + this);
temp g22utils().enter(); // enter module
ret cr.parsedScriptMandatory()!;
}
S renderRunOnProjectOpenStatus() {
ret runOnProjectOpen
? "Yes" + appendBracketed(appendPrefixIfNempty("prio ", runOrder))
: null;
}
Set allTexts() {
ret asSet(llNonNulls(text(), editedText(), codeForAutoRun()));
}
}