Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

63
LINES

< > BotCompany Repo | #1027571 // NameBasedVoiceCRUD [backup v1 without scoping]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (12974L/88K).

1  
// assumes there is a S name field in the concept
2  
sclass NameBasedVoiceCRUD<A extends Concept> {
3  
  transient Concepts cc = db_mainConcepts();
4  
  Class<A> conceptClass;
5  
  S concept, concepts; // singular & plural of what we are managing
6  
  
7  
  transient A selected;
8  
  
9  
  *() {}
10  
  *(Class<A> *conceptClass, S conceptName) {
11  
    concept = conceptName;
12  
    concepts = plural(conceptName);
13  
  }
14  
  
15  
  S answer(S s) null {
16  
    new Matches m;
17  
    if (match("how many \*concepts*/", s))
18  
      ret str(countConcepts(cc, conceptClass));
19  
    if (match("delete \*concept*/ *", s, m)) {
20  
      S name = $1;
21  
      select(null);
22  
      A sc = findConceptWithName(name);
23  
      if (sc == null)
24  
ret format("\*firstToUpper(concept)*/ * not found", name);
25  
      unregisterConcept(sc);
26  
      addUndo(new UndoDeleteConcept(sc));
27  
      ret format("Scenario * deleted", name);
28  
    }
29  
    if (match("new \*concept*/ *", s, m)) {
30  
      S name = $1;
31  
      A sc = conceptWhereCI(cc, conceptClass, +name);
32  
      if (sc != null)
33  
        ret format("\*firstToUpper(concept)*/ * exists", name);
34  
      A a = uniqCI(cc, conceptClass, +name);
35  
      select(a);
36  
      addUndo(new UndoCreateConcept(a.id));
37  
      ret format("\*firstToUpper(concept)*/ * created", name);
38  
    }
39  
    if (match("list \*concepts*/", s))
40  
      ret or2(joinWithComma(collect name(list(cc, conceptClass))), "No \*concepts*/ defined");
41  
    if (match("rename \*concept*/ * to *", s, m)) {
42  
      S name1 = $1, name2 = $2;
43  
      if (!eqic(name1, name2)
44  
        && conceptWhereCI(conceptClass, name := name2) != null)
45  
        ret format("A \*concept*/ named * exists", name2);
46  
      A sc = findConceptWithName(name1);
47  
      if (sc == null)
48  
        ret format("\*firstToUpper(concept)*/ * not found", name1);
49  
      addUndo(new UndoSetConceptField(sc.id, 'name, name1, name2));
50  
      cset(sc, name := name2);
51  
      ret format("\*firstToUpper(concept)*/ * renamed to *", name1, name2);
52  
    }
53  
  }
54  
  
55  
  // this is more of a search function, not an exact name lookup
56  
  swappable A findConceptWithName(S name) {
57  
    ret conceptWhereCI(cc, conceptClass, +name);
58  
  }
59  
  
60  
  swappable void addUndo(UndoableWithAnswer undo) {}
61  
  
62  
  swappable void select(A a) { selected = a; }
63  
}

Author comment

Began life as a copy of #1027561

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027571
Snippet name: NameBasedVoiceCRUD [backup v1 without scoping]
Eternal ID of this version: #1027571/1
Text MD5: 384fd649b628d23f83c49f1e12415403
Transpilation MD5: 418712348543cef60bd0ce962c04ad93
Author: stefan
Category: javax / scenarios
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-24 01:27:32
Source code size: 2253 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 210 / 270
Referenced in: [show references]