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

92
LINES

< > BotCompany Repo | #1026160 // Rules + Inputs Web Bot backup

JavaX module (desktop) [tags: use-pretranspiled]

Download Jar. Libraryless. Click here for Pure Java version (16680L/115K).

!7

concept Rule > ConceptWithGlobalID {
  S input, output, variables /* comma-separated */, comment;
  sS _fieldOrder = "globalID input output variables comment";
}

concept PossibleExample > ConceptWithGlobalID {
  Rule rule;
  S input, output;
  SS mapping;
  sS _fieldOrder = "globalID rule input output mapping";
}

concept Input > ConceptWithGlobalID {
  S input;
}

p {
  db();
  indexConceptFields(PossibleExample, 'rule);
  indexConceptFieldsCI(Input, 'input, Rule, 'input);
  indexConceptFieldsOrdered(Rule, 'globalID);
}

static HCRUD rulesCRUD() {
  ret new HCRUD(rawLink("admin"), new HCRUD_Concepts<Rule>(Rule) {
    MapSO itemToMap(Rule r) {
      ret mapPlus(super.itemToMap(r), "Possible Examples" := countConcepts(PossibleExample, rule := r));
    }
    
    Cl<Rule> listConcepts() {
      ret conceptsSortedByFieldCI(Rule, 'input);
    }
  }.fieldHelp(variables := "comma-separated")
  ) {
    S renderValue(S field, O value) {
      S html = super.renderValue(field, value);
      if (eq(field, 'globalID))
        ret ahref(rawLink(str(value)), html);
      if (eq(field, 'input))
        ret b(html);
      ret html;
    }
  };
}

static HCRUD inputsCRUD() {
  ret new HCRUD(new HCRUD_Concepts<Input>(Input.class));
}

html {
  bool authed = webAuthed(params);
  
  if (eqic(uri = dropSlashPrefix(uri), "admin")) {
    try object checkWebAuthed(params);
    ret rulesCRUD().renderPage(params);
  }

  if (empty(uri))
    ret htitle_h1("Rules")
      + (webAuthed(params) ? p(ahref(rawLink("admin"), "Admin")) : "")
      + ul_noEncode(map(list(Rule), r -> ahref(rawLink(r.globalIDStr()), htmlEncode2(r.input + " => " + r.output))));
    
  // serve rule
  if (possibleGlobalID(uri)) {
    Rule r = conceptWhere(Rule, globalID := GlobalID(uri));
    if (r == null) ret subBot_serve404("Rule not found");
    S html = htitle_h1("Rule " + r.globalID)
      + htmlTable2(mapToTwoElementMaps("Field", "Value", litorderedmap("Input" := r.input, "Output" := r.output, "Variables" := r.variables, "Comment" := r.comment)));
    //html += conceptsWhere Input(rule := r);
    /*if (webAuthed(params)) 
      html += new HCRUD(rawLink(r.globalIDStr()), new HCRUD_Concepts<PossibleInput>(PossibleInput.class).addFilter(rule := r))
      .makeFrame((title, contents) -> h3(title) + contents)
      .renderPage(params);*/
    ret html;  
  }
  
  new Matches m;
  if (swic(uri, "multi/", m))
    ret new HMultiCRUD(rawLink("multi"), Rule, Input, PossibleExample) {
      HCRUD makeCRUD(S className) {
        if (eq(className, "Rule")) ret rulesCRUD();
        if (eq(className, "Input")) ret inputsCRUD();
        null;
      }
    } .mainTitle("Rules + Inputs")
      .mutationRights(authed)
      .renderPage(m.rest(), params);
  
  ret subBot_serve404();
}

Author comment

Began life as a copy of #1026126

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1026160
Snippet name: Rules + Inputs Web Bot backup
Eternal ID of this version: #1026160/1
Text MD5: be4a1288085b1876c32029c4f8112c2c
Transpilation MD5: 0f5dd5a6f1a3d01a66d5aaca88089606
Author: stefan
Category: javax / a.i.
Type: JavaX module (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-27 16:01:54
Source code size: 2860 bytes / 92 lines
Pitched / IR pitched: No / No
Views / Downloads: 364 / 1163
Referenced in: [show references]