!7 concept Rule { S globalID = aGlobalIDUnlessLoading(); S text; S comments; } // Bug when making cmodule module Rules > DynCRUD { enhanceFrame { internalFrameIcon(f, gazelle_frameIcon()); } start { dbIndexing(Rule, 'globalID); crud.multiLineFields = litset('text, 'comments); crud.dontDuplicateFields = litset('globalID); crud.renderer = func(Rule r) -> Map { litorderedmap("Rule ID" := r.globalID, text := joinWithSpace(tlft(r.text)), comments := escapeNewLines(r.comments)) }; crud.latestFirst = true; onConceptsChange(r { vmBus_sendMessage('gazelleRulesChanged, this) }); // do some logic stuff here for now dm_vmBus_onMessage_q('gazelleRuleCreated, voidfunc(O mod, O rule) { dm_gazelle_wireStatementConditions(getString globalID(rule)); }); } // API Pair addRule(S when, S then) { ret addRule(when + "\n=> " + then); } Pair addRule(S text) { ret addRuleWithComment(text, null); } Pair addRuleWithComment(S text, S comment) { Pair p = uniq2_sync(Rule, text := rtrim(text), comments := nullIfEmpty(rtrim(comment))); if (p.b) vmBus_sendMessage('gazelleRuleCreated, this, p.a); ret pair(p.a.globalID, p.b); } PairS textAndCommentForRule(S ruleID) { Rule r = conceptWhere Rule(globalID := ruleID); ret r == null ? null : pair(r.text, r.comments); } void setRuleText(S ruleID, S text) { cset(conceptWhere Rule(globalID := ruleID), +text); } void setComments(S ruleID, S comments) { cset(conceptWhere Rule(globalID := ruleID), +comments); } void addComments(S ruleID, S comments) { Rule r = conceptWhere Rule(globalID := ruleID); if (r != null) cset(r, comments := lines_rtrim(uniquifyList(concatLists(lines(r.comments), tlft(comments))))); } S latestRuleID() { ret getString globalID(last(concepts())); } }