zet-lib 1.5.30 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/lib/Modal.js +85 -30
  2. package/lib/Model.js +118 -2
  3. package/lib/config_generator.js +24 -0
  4. package/lib/generatorApi.js +1328 -0
  5. package/lib/generatorApp.js +1342 -0
  6. package/lib/generatorModel.js +733 -0
  7. package/lib/lang_en.js +115 -0
  8. package/lib/routes/api.js +52 -0
  9. package/lib/routes/index.js +9 -0
  10. package/lib/views/error.ejs +3 -0
  11. package/lib/views/zgenerator/bootstrap3/_form.ejs +24 -0
  12. package/lib/views/zgenerator/bootstrap3/create.ejs +9 -0
  13. package/lib/views/zgenerator/bootstrap3/createjs.ejs +3 -0
  14. package/lib/views/zgenerator/bootstrap3/import.ejs +52 -0
  15. package/lib/views/zgenerator/bootstrap3/importjs.ejs +3 -0
  16. package/lib/views/zgenerator/bootstrap3/index.ejs +29 -0
  17. package/lib/views/zgenerator/bootstrap3/indexcss.ejs +1 -0
  18. package/lib/views/zgenerator/bootstrap3/indexjs.ejs +307 -0
  19. package/lib/views/zgenerator/bootstrap3/update.ejs +8 -0
  20. package/lib/views/zgenerator/bootstrap3/updatejs.ejs +3 -0
  21. package/lib/views/zgenerator/bootstrap3/view.ejs +57 -0
  22. package/lib/views/zgenerator/head.ejs +12 -0
  23. package/lib/views/zgenerator/index.ejs +271 -0
  24. package/lib/views/zgenerator/indexcss.ejs +87 -0
  25. package/lib/views/zgenerator/indexjs.ejs +705 -0
  26. package/lib/views/zgenerator/layout.ejs +198 -0
  27. package/lib/views/zgenerator/manual_basic.ejs +2 -0
  28. package/lib/views/zgenerator/manual_dropdown.ejs +126 -0
  29. package/lib/views/zgenerator/manual_modules.ejs +192 -0
  30. package/lib/views/zgenerator/manual_virtual.ejs +143 -0
  31. package/lib/views/zgenerator/mini.ejs +341 -0
  32. package/lib/views/zgenerator/routerApp.ejs +359 -0
  33. package/lib/views/zgenerator/views/_form.ejs +25 -0
  34. package/lib/views/zgenerator/views/approval.ejs +42 -0
  35. package/lib/views/zgenerator/views/create.ejs +7 -0
  36. package/lib/views/zgenerator/views/createjs.ejs +16 -0
  37. package/lib/views/zgenerator/views/import.ejs +49 -0
  38. package/lib/views/zgenerator/views/importjs.ejs +4 -0
  39. package/lib/views/zgenerator/views/index.ejs +9 -0
  40. package/lib/views/zgenerator/views/indexcss.ejs +2 -0
  41. package/lib/views/zgenerator/views/indexjs.ejs +2 -0
  42. package/lib/views/zgenerator/views/preview.ejs +34 -0
  43. package/lib/views/zgenerator/views/update.ejs +7 -0
  44. package/lib/views/zgenerator/views/updatejs.ejs +16 -0
  45. package/lib/views/zgenerator/views/view.ejs +36 -0
  46. package/lib/zGeneratorRouter.js +46 -22
  47. package/lib/zRoute.js +14 -3
  48. package/package.json +1 -1
@@ -0,0 +1,143 @@
1
+ <h3>Zvirtual</h3>
2
+ <hr>
3
+ <p class="mb-4">Ada kalanya kita tidak perlu <code>hard code / coding</code> di suatu page. Atau kita ingin membuat satu atau
4
+ beberapa fields di table CRUD, dimana field tersebut tidak perlu dimasukkan ke dalam table</p>
5
+ <p class="mb-4">Sebagai contoh ditable <code>employee</code> adalah field <code>age</code>, dimana field <code>age</code> dihitung berdasarkan tanggal lahir <code>birthDate</code> dan field <code>age</code>
6
+ tidak perlu dimasukkan ke dalam table <code>employee</code>, tetapi field <code>age</code> ditampilkan di semua CRUD tapi perhitungan berdasarkan otomatis dari javascript</p>
7
+
8
+ <hr>
9
+ <h2>Appendix</h2>
10
+ <hr>
11
+
12
+ <ul class="list-group">
13
+ <li class="list-group-item"><strong>Table</strong>
14
+ <p class="mb-4">* Wajib, Dimasukkan ke dalam table generator yang dipilih</p>
15
+ </li>
16
+ <li class="list-group-item"><strong>Is Script Only</strong>
17
+ <p class="mb-4">OFF kan kalau tidak ada field yg akan dimasukkan ke dalam table sebagai virtual field</p>
18
+ </li>
19
+ <li class="list-group-item"><strong>Field Name</strong>
20
+ <p class="mb-4">Penambahan virtual field yg tidak ada di table.</p>
21
+ </li>
22
+ <li class="list-group-item"><strong>Field Parent</strong>
23
+ <p class="mb-4">* Wajib diisi sebagai sort. //TODO<br>
24
+ * Tergantung dari type jika type date maka diformat sebagai tanggal</p>
25
+ </li>
26
+ <li class="list-group-item"><strong>Field Alias</strong>
27
+ <p class="mb-4">Lupa //TODO</p>
28
+ </li>
29
+ <li class="list-group-item"><strong>Type</strong>
30
+ <p class="mb-4">Text : sebagai text<br>
31
+ Date : convert ke date format</p>
32
+
33
+ </li>
34
+ <li class="list-group-item"><strong>Formula SQL</strong>
35
+ <p class="mb-4">SQL query yang akan ditambahkan, di grid list, excel export. tidak support join hanya subquery dll</p>
36
+ </li>
37
+ <li class="list-group-item"><strong>Javascript</strong>
38
+ <p class="mb-4">Penambahan javascript di form</p>
39
+ </li>
40
+ <li class="list-group-item"><strong>Formula Grid Query</strong>
41
+ <p class="mb-4">Penambahan query di Grid List<br>Diawali dengan <code>query</code> <br><code>query.NAMA_FIELD_ANDA = NILAI_QUERY_ANDA</code>
42
+ <br>
43
+ Contoh : <br><code>query.companyId = req.session.user.companyIds</code>
44
+ </p>
45
+
46
+ </li>
47
+ <li class="list-group-item"><strong>Formula Grid Option</strong>
48
+ <p class="mb-4">Penambahan option di Grid List<br>Diawali dengan <code>option </code>
49
+ <br><code>option.NAMA_FIELD_ANDA = OPERATAOR_SQL</code><br>Diawali dengan <code>option</code> <br><code>option.NAMA_FIELD_ANDA = NILAI_QUERY_ANDA</code>
50
+ <br>
51
+ Contoh : <br><code>option.companyId = "IN"</code>
52
+ </p>
53
+ </li>
54
+
55
+
56
+ </ul>
57
+
58
+ <hr>
59
+ <h2>Contoh 1</h2>
60
+ <img src="/img/age.png" class="img-fluid" alt="Responsive image">
61
+ <hr>
62
+ <ul class="list-group">
63
+ <li class="list-group-item">Table : <strong>employee</strong>, karena di generate di table employee</li>
64
+ <li class="list-group-item">Is Script Only : <strong>OFF</strong>, karena ada field age</li>
65
+ <li class="list-group-item">Field Name : <strong>age</strong></li>
66
+ <li class="list-group-item">Field Parent : <strong>birthDate</strong> *wajib diisi. Untuk sort di grid list</li>
67
+ <li class="list-group-item">Field Alias : <strong></strong></li>
68
+ <li class="list-group-item">Type : <strong>Text</strong></li>
69
+ <li class="list-group-item">Formula SQL : <code>YEAR(CURDATE()) - YEAR(birthDate)</code>
70
+ <br>
71
+ <p class="red-text">Formula SQL adalah formula untuk menghitung di grid, excel dan view</p>
72
+ </li>
73
+ <li class="list-group-item">Javascript (Form) : <br><code>$("#birthDate").change(function () {<br>
74
+ var dob = new Date ($("#birthDate").val());<br>
75
+ var year = dob.getFullYear();<br>
76
+ var month = dob.getMonth();<br>
77
+ var day = dob.getDay();<br>
78
+ var today = new Date();<br>
79
+ var age1 = today.getFullYear() - year;<br>
80
+ if (today.getMonth() < month || (today.getMonth() == month && today.getDate() < day)) {<br>
81
+ age1--;<br>
82
+ }<br>
83
+ $("#age").val(age1);<br>
84
+ });</code></li>
85
+ </ul>
86
+
87
+ <hr>
88
+ <h2>Contoh 2</h2>
89
+
90
+ <p class="mb-4">Manipulasi Form untuk field tertentu tanpa ada tambahan field lagi seperti contoh 1</p>
91
+ <p class="mb-4">Contoh saya akan membuat table nomor invoice dimana nomor invoice tsb berdasarkan tanggal invoice hanya sewaktu create saja, update tidak perlu <code> INV-2019/10/16-1</code> </p>
92
+ <p class="mb-4">Nomor invoice adalah <code>code</code> field, dan tanggal adalah <code>date</code> dengan urutan berdasarkan sudah keberapa invoice tsb</p>
93
+
94
+ <img src="/img/invoice.png" class="img-fluid" alt="Responsive image">
95
+ <hr>
96
+ <ul class="list-group">
97
+ <li class="list-group-item">Table : <strong>invoice</strong>, karena di generate di table invoice</li>
98
+ <li class="list-group-item">Is Script Only : <strong>ON</strong> karena tidak ada field virtual </li>
99
+ <li class="list-group-item">Javascript (Form) : <br><code>$("#date").on("change", function () {<br>
100
+ var date1 = new Date($("#date").val());<br>
101
+ var code1 = date1.getFullYear();<br>
102
+ var code2 = date1.getMonth()+1;<br>
103
+ var code3 = date1.getDate();<br>
104
+ var url = window.location.href;<br>
105
+ var code4 = url.split("/").pop();<br>
106
+ if (code4 == "create") {<br>
107
+ $.ajax({<br>
108
+ url: '/ajax',<br>
109
+ type: "post",<br>
110
+ data: {select:" COALESCE(MAX(id), 0) + 1 as id ", table:"invoice", model:"text", field:"id"},<br>
111
+ success: function (data) {<br>
112
+ var codeInvoice= "INV-" + code1 + "/" + code2 + "/" + code3 + "-" + data;<br>
113
+ $("#code").val(codeInvoice)<br>
114
+ }<br>
115
+ })<br>
116
+ } else {<br>
117
+ var codeInvoice = "INV-" + code1 + "/" + code2 + "/" + code3 + "-" + code4;<br>
118
+ $("#code").val(codeInvoice);<br>
119
+ }<br>
120
+ });<br>
121
+ $("#code").attr("readonly",true);</code></li>
122
+ </ul>
123
+
124
+
125
+ <hr>
126
+ <h2>Contoh 3</h2>
127
+ <h4>Contoh Join table</h4>
128
+ <p class="mb-4">Menampilkan field division di table user, dimana table <code>user</code> relasi ke table <code>user_company</code> dan table <code>user_company</code> relasi ke table <code>division</code></p>
129
+ <img src="/img/join.png" class="img-fluid" alt="Responsive image">
130
+ <hr>
131
+ <ul class="list-group">
132
+ <li class="list-group-item">Table : <strong>user</strong>, karena di generate di table user</li>
133
+ <li class="list-group-item">Is Script Only : <strong>OFF</strong> karena ada field virtual </li>
134
+ <li class="list-group-item">Javascript (Form) : </li>
135
+ <li class="list-group-item">Field Name : <strong>division</strong> Nama field jadi division</li>
136
+ <li class="list-group-item">Field Parent : <strong>username</strong> *wajib diisi.</li>
137
+ <li class="list-group-item">Field Alias : <strong>divisionId</strong> *wajib nama table harus tidak ada di table yg sudah ada</li>
138
+ <li class="list-group-item">Type : <strong>Text</strong></li>
139
+ <li class="list-group-item">Formula SQL : <code>SELECT division.name FROM division <br>
140
+ LEFT JOIN `user_company` ON (division.id = user_company.divisionId) <br>
141
+ LEFT JOIN `user` ON (user_company.userId = user.id) <br>
142
+ WHERE user.id = user_company.userId</code></li>
143
+ </ul>
@@ -0,0 +1,341 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6
+ <meta http-equiv="x-ua-compatible" content="ie=edge">
7
+ <title>SINTRET GENERATOR</title>
8
+ <!-- Font Awesome -->
9
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
10
+ <!-- Bootstrap core CSS -->
11
+ <link href="/mdb/css/bootstrap.min.css" rel="stylesheet">
12
+ <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
13
+
14
+ <!-- Material Design Bootstrap -->
15
+ <link href="/mdb/css/mdb.min.css" rel="stylesheet">
16
+ <!-- Your custom styles (optional) -->
17
+ <link href="/mdb/css/style.css" rel="stylesheet">
18
+ <style type="text/css">
19
+ #modalpopup {
20
+ display: none;
21
+ position: fixed;
22
+ z-index: 1000;
23
+ top: 0;
24
+ left: 0;
25
+ height: 100%;
26
+ width: 100%;
27
+ background: rgba(255, 255, 255, .8) url('/img/cms.gif') 50% 50% no-repeat;
28
+ opacity: 0.80;
29
+ -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80);
30
+ filter: alpha(opacity=80)
31
+ }
32
+
33
+ .divbox {
34
+ border: 1px solid green;
35
+ min-height: 300px;
36
+ margin: 30px 1px 30px 1px;
37
+ padding-top: 10px;
38
+ padding-bottom: 5px;
39
+ }
40
+ .tab-content {
41
+ width:100%;
42
+ }
43
+ .tab-pane {
44
+ width:100%;
45
+ }
46
+
47
+ .divboxlittle {
48
+ border: 1px solid green;
49
+ min-height: 50px;
50
+ width: 100%;
51
+ padding-top: 10px;
52
+ padding-bottom: 5px;
53
+ }
54
+
55
+ ol.mydragable li {
56
+ cursor: grabbing;
57
+ }
58
+
59
+ body.dragging, body.dragging * {
60
+ cursor: move !important;
61
+ }
62
+
63
+ .dragged {
64
+ position: absolute;
65
+ opacity: 0.5;
66
+ z-index: 2000;
67
+ }
68
+
69
+ ol.mydragable li.placeholder {
70
+ position: relative;
71
+ }
72
+
73
+ ol.mydragable li.placeholder:before {
74
+ position: absolute;
75
+ }
76
+ </style>
77
+ </head>
78
+
79
+ <body class="grey lighten-3">
80
+
81
+ <!--Main Navigation-->
82
+ <header>
83
+ <!-- Navbar -->
84
+
85
+ <!-- Navbar -->
86
+
87
+ </header>
88
+ <!--Main Navigation-->
89
+
90
+ <!--Main layout-->
91
+ <main>
92
+ <div class="container-fluid">
93
+ <!--Section: Post-->
94
+ <section class="mt-4">
95
+ <!--Grid row-->
96
+ <div class="row">
97
+ <!--Grid column-->
98
+ <div class="col-md-12 mb-2">
99
+ <!--Card-->
100
+
101
+ <!--Generator-->
102
+ <div class="card mb-3 wow fadeIn">
103
+ <div class="card-header bg-success text-white font-weight-bold">Generator</div>
104
+ <div class="card-body">
105
+
106
+ <!-- Default form reply -->
107
+ <form id="formgenerator" method="post" action="/generator">
108
+
109
+ <input type="hidden" name="table" id="table" value="<%- table%>">
110
+ <input type="hidden" name="route" id="route" value="<%- table%>">
111
+ <input type="hidden" name="bootstrap" id="bootstrap" value="bootstrap3">
112
+ <input type="hidden" name="layout" id="layout" value="bootstrap3">
113
+
114
+ <div class="form-group">
115
+ <label for="route">Tabs</label>
116
+ <div class="input-group mb-3">
117
+ <input type="text" class="form-control" id="tabname"
118
+ placeholder="Enter tab name" aria-label="Enter tab name"
119
+ aria-describedby="button-addon2">
120
+ <div class="input-group-append">
121
+ <button class="btn btn-md btn-secondary m-0 px-3" type="button" id="add"><i
122
+ class="fas fa-plus"></i></button>
123
+ </div>
124
+ </div>
125
+ </div>
126
+ <div id="tabs"></div>
127
+ <div class="text-center mt-4">
128
+ <button class="btn btn-info" id="savetab" type="button">Save Tab</button>
129
+ <button class="btn btn-success" id="generate" type="button">Generate</button>
130
+ </div>
131
+ </form>
132
+ <!-- Default form reply -->
133
+ </div>
134
+ </div>
135
+ <!--/Generator-->
136
+
137
+ <div class="card mb-4 wow fadeIn" id="results" style="display: none">
138
+ <!--Card content-->
139
+ <div class="card-body">
140
+ <div id="resultsbody"></div>
141
+ <div id="resutlstable"></div>
142
+ </div>
143
+ </div>
144
+ <!--/.Card-->
145
+
146
+ <!--Generator-->
147
+ <div class="card mb-3 wow fadeIn" id="divfields" style="display: none">
148
+ <div class="card-header secondary-color-dark text-white font-weight-bold">Fields</div>
149
+ <div class="card-body">
150
+
151
+ <!-- Default form reply -->
152
+ <form id="formfields" method="post" action="/generator/fields">
153
+
154
+ <div id="divtablist" class="row"></div>
155
+ <div id="contentfields" class="row"></div>
156
+
157
+ <div class="text-center mt-4">
158
+ <button class="btn secondary-color-dark text-white" id="save" type="button">Save
159
+ </button>
160
+ </div>
161
+ </form>
162
+ <!-- Default form reply -->
163
+ </div>
164
+ </div>
165
+ <!--/Generator-->
166
+
167
+ <!--Card-->
168
+
169
+ <!--/.Card-->
170
+ </div>
171
+ <!--Grid column-->
172
+
173
+ <!--Grid column-->
174
+
175
+ <!--Grid column-->
176
+ </div>
177
+ <!--Grid row-->
178
+ </section>
179
+ <!--Section: Post-->
180
+
181
+ </div>
182
+ </main>
183
+ <!--Main layout-->
184
+
185
+ <!--Footer-->
186
+ <footer class="page-footer text-center font-small mdb-color darken-2 mt-4 wow fadeIn">
187
+
188
+
189
+
190
+ <hr class="my-4">
191
+
192
+ <!--Copyright-->
193
+ <div class="footer-copyright py-3">
194
+ © 2019 Copyright:
195
+ <a href="https://sintret.com" target="_blank"> sintret.com </a>
196
+ </div>
197
+ <!--/.Copyright-->
198
+
199
+ </footer>
200
+ <div id="modalpopup"><!-- Place at bottom of page --></div>
201
+
202
+ <!--/.Footer-->
203
+
204
+ <!-- SCRIPTS -->
205
+ <!-- JQuery -->
206
+ <script type="text/javascript" src="/mdb/js/jquery-3.4.1.min.js"></script>
207
+ <!-- Bootstrap tooltips -->
208
+ <script type="text/javascript" src="/mdb/js/popper.min.js"></script>
209
+ <!-- Bootstrap core JavaScript -->
210
+ <script type="text/javascript" src="/mdb/js/bootstrap.min.js"></script>
211
+ <!-- MDB core JavaScript -->
212
+ <script type="text/javascript" src="/mdb/js/mdb.min.js"></script>
213
+ <script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
214
+ <script src="/js/jquery-sortable.js"></script>
215
+
216
+ <script>
217
+ $(function () {
218
+ var counter = $(".divtabs").length || 1;
219
+
220
+ function selectTable(table) {
221
+ if (!table) return false;
222
+ $("#route").val(table);
223
+ $.ajax({
224
+ url: '/generator/fields',
225
+ type: 'POST',
226
+ data: {table: table},
227
+ success: function (json) {
228
+ $("#divfields").show();
229
+ $("#results").hide();
230
+ $("#contentfields").html(json.html);
231
+ $("#tabs").html(json.tabview);
232
+ $("#divtablist").html(json.tabBox)
233
+ counter = json.count;
234
+ $("ol.mydragable").sortable({
235
+ group: 'mydragable',
236
+ isValidTarget: function ($item, container) {
237
+ /* if ($item.is(".disabled"))
238
+ return false;
239
+ else*/
240
+ return true;
241
+ },
242
+ onDrop: function ($item, container, _super) {
243
+ var getidname = $item.parents().attr('id') || "";
244
+ var iname = $item.find('input[type=text]').attr('data-name');
245
+ var containertype = $item.parents().data('name');
246
+ var newname = getidname ? iname + "___" + getidname : iname;
247
+ var leftright = $item.find('input[type=hidden]').attr('name');
248
+ $item.find('input[type=text]').attr('name', newname);
249
+ $item.find('input[type=hidden]').attr('name', containertype);
250
+
251
+ _super($item, container);
252
+ }
253
+ });
254
+ }
255
+ })
256
+ }
257
+
258
+ $("#table").on("change", function () {
259
+ //selectTable($(this).val());
260
+ location.href = '/generator/mini?table=' + $(this).val();
261
+ });
262
+ $("#generate").on("click", function () {
263
+ $.ajax({
264
+ url: '/generator',
265
+ type: 'POST',
266
+ data: {
267
+ table: $("#table").val(),
268
+ route: $("#route").val(),
269
+ layout: $("#layout").val(),
270
+ bootstrap: $("#bootstrap").val()
271
+ },
272
+ success: function (data) {
273
+ if (data.status == 0) {
274
+ $("#results").hide();
275
+ toastr.error(data.message, data.title);
276
+ } else {
277
+ toastr.success(data.title, data.message);
278
+ }
279
+ }
280
+ })
281
+ });
282
+
283
+ $("#add").on("click", function () {
284
+ var tabname = $("#tabname");
285
+ var tabsvalue = $("#tabsvalue");
286
+ if (tabname.val() == "") {
287
+ alert("tab name is empty!");
288
+ return false;
289
+ }
290
+ $("#tabs").append("<div class='divtabs'> " + counter + ". " + tabname.val() + " <input type='hidden' name='tabs[]' value='" + tabname.val() + "' /> <button type='button' onclick='$(this).parent().remove();' class='trashtab'><i class='fas fa-trash'></i> </button></div><br>");
291
+ tabname.val("");
292
+ counter++;
293
+ });
294
+
295
+ $("#savetab").on("click", function () {
296
+ $.ajax({
297
+ url: '/generator/tabs',
298
+ method: "POST",
299
+ data: $("#formgenerator").serializeArray(),
300
+ success: function (data) {
301
+ if (data.status == 1)
302
+ location.href = "";
303
+ else alert(data.title);
304
+ }
305
+ });
306
+ });
307
+
308
+ $("#save").on("click", function () {
309
+ $.ajax({
310
+ url: '/generator/savetabs',
311
+ method: "POST",
312
+ data: {details: $("#formfields").serializeArray(), table: $("#table").val()},
313
+ success: function (data) {
314
+ if (data.status == 0) {
315
+ toastr.error(data.message, data.title);
316
+ } else {
317
+ toastr.success(data.title, data.message);
318
+ }
319
+ }
320
+ });
321
+ });
322
+
323
+ selectTable($("#table").val());
324
+
325
+ function changeUrl(title, url) {
326
+ var origin = window.location.origin;
327
+ if (typeof (history.pushState) != "undefined") {
328
+ var obj = {Title: title, Url: origin + '/generator?table=' + url};
329
+ window.history.pushState(obj, obj.Title, obj.Url);
330
+ } else {
331
+ alert("Browser does not support HTML5.");
332
+ }
333
+ }
334
+
335
+ $("#bootstrap").on("change", function () {
336
+ $("#layout").val($(this).val());
337
+ })
338
+ });
339
+ </script>
340
+ </body>
341
+ </html>