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).

1  
sclass HMultiCRUD extends HAbstractRenderable {
2  
  Concepts cc = db_mainConcepts();
3  
  L<Class<? extends Concept>> classes;
4  
  bool mutationRights, downloadRights = true;
5  
  S mainTitle = "CRUD";
6  
  
7  
  *(S *baseLink, Class<? extends Concept>... classes) {
8  
    this(classes);
9  
  }
10  
  
11  
  *(Class<? extends Concept>... classes) {
12  
    this.classes = asList(classes);
13  
  }
14  
  
15  
  S renderNavi() {
16  
    ret p(joinWithVBar(naviComponents()));
17  
  }
18  
  
19  
  LS naviComponents() {
20  
    LS l = map(classes, c -> ahref(baseLinkPlus(shortName(c)),
21  
      appendBracketedCountUnlessZero(countConcepts(cc, c),
22  
        shortName(c))));
23  
    if (downloadRights) l.add(ahref(baseLinkPlus("download"), "download"));
24  
    ret l;
25  
  }
26  
27  
  O renderPage(S uri, SS params) {
28  
    LS parts = tok_splitAtSlash_nempties(uri);
29  
    S html = renderNavi() + renderMsgs(params);
30  
    params = mapMinus(params, 'msg);
31  
    Var<S> title = new(mainTitle);
32  
    if (nempty(parts)) {
33  
      if (eq(parts, ll("download"))) {
34  
        if (!downloadRights) ret "No download rights";
35  
        ret serveText(javaTokWordWrap(cc.xfullgrab()));
36  
      }
37  
      
38  
      HCRUD crud = makeCRUD(first(parts));
39  
      if (crud != null) {
40  
        crud.mutationRights = mutationRights;
41  
        crud.baseLink = baseLinkPlus(first(parts));
42  
        crud.makeFrame = (title2, contents) -> {
43  
          title.set(title! + " | " + title2);
44  
          ret h3(title2) + contents;
45  
        };
46  
        html += crud.renderPage(params);
47  
      }
48  
    }
49  
    //ret "parts: " + sfu(parts);
50  
    ret frame(title!, html);
51  
  }
52  
  
53  
  selfType mutationRights(bool mutationRights) {
54  
    this.mutationRights = mutationRights;
55  
    this;
56  
  }
57  
  
58  
  // override me
59  
  HCRUD makeCRUD(S className) {
60  
    null;
61  
  }
62  
  
63  
  selfType mainTitle(S mainTitle) {
64  
    this.mainTitle = mainTitle;
65  
    this;
66  
  }
67  
}

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: 250 / 705
Version history: 19 change(s)
Referenced in: [show references]