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

67
LINES

< > BotCompany Repo | #1026136 // HMultiCRUD - HTML CRUD for multiple concept classes

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

Libraryless. Click here for Pure Java version (17345L/126K).

sclass HMultiCRUD extends HAbstractRenderable {
  Concepts cc = db_mainConcepts();
  L<Class<? extends Concept>> classes;
  bool mutationRights, downloadRights = true;
  S mainTitle = "CRUD";
  
  *(S *baseLink, Class<? extends Concept>... classes) {
    this(classes);
  }
  
  *(Class<? extends Concept>... classes) {
    this.classes = asList(classes);
  }
  
  S renderNavi() {
    ret p(joinWithVBar(naviComponents()));
  }
  
  LS naviComponents() {
    LS l = map(classes, c -> ahref(baseLinkPlus(shortName(c)),
      appendBracketedCountUnlessZero(countConcepts(cc, c),
        shortName(c))));
    if (downloadRights) l.add(ahref(baseLinkPlus("download"), "download"));
    ret l;
  }

  O renderPage(S uri, SS params) {
    LS parts = tok_splitAtSlash_nempties(uri);
    S html = renderNavi() + renderMsgs(params);
    params = mapMinus(params, 'msg);
    Var<S> title = new(mainTitle);
    if (nempty(parts)) {
      if (eq(parts, ll("download"))) {
        if (!downloadRights) ret "No download rights";
        ret serveText(javaTokWordWrap(cc.xfullgrab()));
      }
      
      HCRUD crud = makeCRUD(first(parts));
      if (crud != null) {
        crud.mutationRights = mutationRights;
        crud.baseLink = baseLinkPlus(first(parts));
        crud.makeFrame = (title2, contents) -> {
          title.set(title! + " | " + title2);
          ret h3(title2) + contents;
        };
        html += crud.renderPage(params);
      }
    }
    //ret "parts: " + sfu(parts);
    ret frame(title!, html);
  }
  
  selfType mutationRights(bool mutationRights) {
    this.mutationRights = mutationRights;
    this;
  }
  
  // override me
  HCRUD makeCRUD(S className) {
    null;
  }
  
  selfType mainTitle(S mainTitle) {
    this.mainTitle = mainTitle;
    this;
  }
}

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: #1026136
Snippet name: HMultiCRUD - HTML CRUD for multiple concept classes
Eternal ID of this version: #1026136/20
Text MD5: 37a94cd35d369e22c8a15b0f6035bbb9
Transpilation MD5: 081d0b7acc53f3ce007e9b1ee1590e62
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-27 17:42:47
Source code size: 1845 bytes / 67 lines
Pitched / IR pitched: No / No
Views / Downloads: 249 / 704
Version history: 19 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)