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

70
LINES

< > BotCompany Repo | #1027591 // Generic Multi-CRUD

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (13753L/73K).

!7

concept ObjectType > Named {
  S conceptClassName;
  
  toString { ret "object type " + quote(name); }
}

concept DynamicThing > Named {
  ObjectType type;
  
  toString { ret (type == null ? "?" : type.name) + " " + quote(name); }
}

cmodule DynamicClassesMultiCRUD > DynVoiceMultiCRUD {
  switchable S caseID;
  transient S defaultCmdsSnippetID = #1027616;
  
  L<Table> makeTables() {
    ret itemPlusList(new Table("Object Types", "object type", ObjectType), 
      map(list(cc, ObjectType), type ->
        new Table(plural(type.name), type.name, DynamicThing, litparams(+type))));
  }
    
  transient NameBasedVoiceCRUD<ObjectType> typesCRUD;
  
  void startDB { cc = dm_handleCaseIDField(); }

  start {
    typesCRUD = voiceCRUDs.get(idx(ObjectType));
    
    // Update voice CRUDs when there is a new object type
    onConceptsChange(cc, rWatcher_noRunFirstTime(
      () -> objectTypes(), names -> objectTypesChanged(names)));
  }
  
  void objectTypesChanged(LS names) enter {
    print("Updating voice CRUDs");
    remakeVoiceCRUDs();
    vmBus_send objectTypesChanged(module(), names);
  }
  
  void startSwingCRUDs {
    swingCRUDs = ll(
      pair("Object Types", CRUD(cc, ObjectType)),
      pair("Objects", CRUD(cc, DynamicThing)));
  }
  
  void startFrontEnd enter {
    S frontEnd = dm_showModuleWithParams("#1027602/ChatBotFrontend", backendModuleID := dm_moduleID());
    if (eq(dm_call(frontEnd, 'conceptCount), 0))
      dm_call(frontEnd, 'importCmdsFromSnippet, defaultCmdsSnippetID);
  }
  
  afterVisualize {
    addComponent(firstSwingCRUDButtons(), jbutton("Start front-end", rThread startFrontEnd));
  }
  
  @Override S moreActions(S s) null {
    if "stats"
      ret "You have stored " + nObjects(countConcepts(cc, ObjectType))
        + " of " + nTypes(countConcepts(cc, DynamicThing));
  }
  
  // API
  
  LS objectTypes() {
    ret itemPlus("object type", collect name(list(cc, ObjectType)));
  }
}

Author comment

Began life as a copy of #1027580

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: #1027591
Snippet name: Generic Multi-CRUD
Eternal ID of this version: #1027591/33
Text MD5: 4d907ba40a914cc692ce31a1d7d45b5c
Transpilation MD5: 2ed50b76fc54d7c4e6067e51f16d13ec
Author: stefan
Category: javax / voice crud
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-28 00:22:01
Source code size: 2010 bytes / 70 lines
Pitched / IR pitched: No / No
Views / Downloads: 312 / 42208
Version history: 32 change(s)
Referenced in: #1027610 - Cruddie standalone [old]
#1027612 - Generic Multi-CRUD [stable version]
#1027647 - Cruddie [backup with speech recognition on bottom]
#1027648 - Cruddie v2 [moving speech recognition button in chat popup, not really working]
#1027649 - Cruddie v2.1 [just putting the button in the popup]
#1027650 - Cruddie 2.2 [putting everything in one script]
#1027689 - Cruddie [backup before awesomplete]
#1027691 - Cruddie [adding awesomplete, old]
#1027705 - Cruddie [backup before "all public" notice]
#1027734 - Cruddie [backup before changing cookie handling]
#1028679 - Cruddie Spike [with VAT magic for Chrome]
#1028961 - cruddie.botcompany.de [LIVE]