zet-lib 1.0.4 → 1.0.6

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.
package/README.md CHANGED
@@ -1,4 +1,15 @@
1
1
  <h1 align="center">Zet</h1>
2
2
  <div align="center">
3
- Zet is a library that can help you develop faster. Made with ExpressJS.
3
+ Zet is a library that part of zet generator. It can help you develop faster. Made with ExpressJS.
4
4
  </div>
5
+
6
+
7
+ [![npm Package](https://img.shields.io/npm/v/zet-lib.svg)](https://www.npmjs.org/package/zet-lib)
8
+ [![License](https://img.shields.io/npm/l/zet-lib.svg)](https://github.com/sintret/zet/blob/master/LICENSE)
9
+ [![downloads per month](http://img.shields.io/npm/dm/zet-lib.svg)](https://www.npmjs.org/package/zet-lib)
10
+ [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
11
+
12
+ Installation
13
+ ------------
14
+
15
+ npm install zet-lib
@@ -17,7 +17,7 @@ const zRole = require('./zRole');
17
17
  const moduleLib = require('./moduleLib');
18
18
 
19
19
  router.get('/', csrfProtection, async function (req, res, next) {
20
- let dirname = './';
20
+ let dirname = path.resolve(__dirname);
21
21
  let id = req.query.id;
22
22
  if (id == undefined) {
23
23
  id = 1;
@@ -44,13 +44,10 @@ router.get('/', csrfProtection, async function (req, res, next) {
44
44
  results: results,
45
45
  csrfToken: req.csrfToken()
46
46
  }
47
-
48
- const bodyHTML = ejs.render(Util.readFile(path.join(dirname,'views/zrole/index.ejs')),datas);
49
- const endBody = ejs.render(Util.readFile(path.join(dirname,'views/zrole/indexjs.ejs')), datas);
47
+ const bodyHTML = ejs.render(body,datas);
48
+ const endBody = ejs.render(js, datas);
50
49
  datas.bodyHTML = bodyHTML;
51
- moduleLib.addModule(req,res,endBody)
52
-
53
- //moduleLib.addModule(req, res, Util.readFile(path.join(dirname,'views/zrole/indexjs.ejs')));
50
+ moduleLib.addModule(req,res,endBody);
54
51
  res.render("layouts/"+layout, datas);
55
52
  });
56
53
 
@@ -158,4 +155,186 @@ router.delete('/delete/:id', async (req,res) => {
158
155
  res.json(json);
159
156
  });
160
157
 
158
+
159
+ const body = `<div class="">
160
+ <div class="page-header"><h1>Roles</h1></div>
161
+ <div class="card panel panel-info boxy">
162
+ <div class="panel-heading">
163
+ <div class="float-end">
164
+ <div class="summary">
165
+ <% if(levels.delete) {%>
166
+ <span
167
+ class="icon-small icons-danger" title="Delete role" onclick="deleterole()"><img class="icons-bg-white icon-image"
168
+ src="/assets/icons/trash.svg"></span>
169
+ <%}%>
170
+ <% if(levels.update) {%>
171
+ <span class="icon-small icons-primary" data-bs-toggle="modal"
172
+ data-bs-target="#renameModal" title="rename"><img
173
+ class="icons-bg-white icon-image" src="/assets/icons/edit.svg"></span>
174
+ <%}%>
175
+ <% if(levels.create) {%>
176
+ <span
177
+ class="icon-small icons-success" title="Add a new role" data-bs-toggle="modal"
178
+ data-bs-target="#addModal"><img class="icons-bg-white icon-image"
179
+ src="/assets/icons/plus.svg"></span>
180
+ <%}%>
181
+
182
+
183
+ </div>
184
+ </div>
185
+ <h3 class="panel-title"><i class="fa fa-cog"></i> Settings</h3>
186
+ <div class="clearfix"></div>
187
+ </div>
188
+ <div class="kv-panel-before">
189
+ <div class="row">
190
+ <form id="role-form" class="form-horizontal kv-form-horizontal" method="post"><input type="hidden"
191
+ name="_csrf"
192
+ value="<%- csrfToken %>">
193
+ <div class="form-group field-role-role_name"><label class="control-label col-md-2"
194
+ for="role-role_name">Role Name</label>
195
+ <div class="col-md-10"><select id="roleName" class="form-control form-select mb-3" name="name">
196
+ <% for(var i = 0;i < results.length;i++){ %>
197
+ <option value="<%- results[i].id %>"
198
+ <% if(id == results[i].id){ %> selected=""
199
+ <% } %>
200
+ ><%- results[i].name %></option>
201
+ <% } %>
202
+ </select></div>
203
+ </div>
204
+ <table class="table table-responsive">
205
+ <thead>
206
+ <tr>
207
+ <th>Name</th>
208
+ <% for(var i = 0;i < actions.length;i++) { %>
209
+ <th><%= actions[i] %> <input onclick='checkthis("<%= actions[i] %>")' type="checkbox"
210
+ id="all<%= actions[i] %>"></th>
211
+ <% } %>
212
+ </tr>
213
+ </thead>
214
+ <tbody>
215
+ <% for(var i = 0;i < routes.length;i++) { %>
216
+ <tr>
217
+ <td>
218
+ <% var ename = routes[i] %>
219
+ <%= ename %></td>
220
+ <% for(var x = 0;x < actions.length;x++) { %>
221
+ <td><input name="params[<%= ename %>][<%= actions[x] %>]" class="<%= actions[x] %>"
222
+ <% if(json && json.hasOwnProperty(ename) && json[ename].indexOf(actions[x]) >= 0) { %> <%= 'checked="checked"' %>
223
+ <% } %>
224
+ title="Role for <%= routes[i] %> <%= actions[x] %>" type="checkbox"></td>
225
+ <% } %>
226
+ </tr>
227
+ <% } %>
228
+ </tbody>
229
+ </table>
230
+ <div class="row">
231
+ <div class="col-md-10 col-md-offset-1">
232
+ <% if(levels.update) {%>
233
+ <button type="submit" class="btn btn-primary">Update</button>
234
+ <%}%>
235
+ </div>
236
+ </div>
237
+ </form>
238
+ </div>
239
+ </div>
240
+ </div>
241
+ </div><!-- Modal -->
242
+ <div class="modal fade" id="renameModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
243
+ <div class="modal-dialog">
244
+ <div class="modal-content">
245
+ <div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">Rename title</h5>
246
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
247
+ </div>
248
+ <div class="modal-body"><input type="text" class="form-control" id="rename" name="rename"
249
+ value="<%- model[0].name %>"></div>
250
+ <div class="modal-footer">
251
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
252
+ <button type="button" class="btn btn-primary btn-update">Save changes</button>
253
+ </div>
254
+ </div>
255
+ </div>
256
+ </div><!-- Modal -->
257
+ <div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="addModalLabel" aria-hidden="true">
258
+ <div class="modal-dialog">
259
+ <div class="modal-content">
260
+ <div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">Add a New Role</h5>
261
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
262
+ </div>
263
+ <div class="modal-body">
264
+ <div class="form-group mb-3"><label for="ruas_sk">Role Name</label> <input type="text"
265
+ class="form-control"
266
+ id="role_name"
267
+ name="role_name"
268
+ placeholder="Role Name">
269
+ </div>
270
+ </div>
271
+ <div class="modal-footer">
272
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
273
+ <button type="button" class="btn btn-primary btn-add">Save changes</button>
274
+ </div>
275
+ </div>
276
+ </div>
277
+ </div>
278
+
279
+
280
+ `;
281
+ const js = `<script>
282
+ function checkthis(elm) {
283
+ var cElem = $("#all" + elm);
284
+ if (cElem.is(":checked")) {
285
+ $("input." + elm).prop("checked", true);
286
+ } else {
287
+ $("input." + elm).prop("checked", false);
288
+ }
289
+ }
290
+ $("#roleName").on('change', function () {
291
+ location.href = "/zrole?id=" + $(this).val();
292
+ });
293
+ var form = document.getElementById("role-form");
294
+ form.onsubmit = function (ev) {
295
+ ev.preventDefault();
296
+ var url = '/zrole/update/<%= id%>';
297
+ ajaxPost(url, $(this).serialize(), function (data) {
298
+ if (data.status == 1) {
299
+ toastr.success('Success', 'Updated Role');
300
+ } else {
301
+ toastr.error('Error!',data.data);
302
+ }
303
+ });
304
+ }
305
+ $(".btn-update").on("click", function () {
306
+ ajaxPost('/zrole/rename/<%= id%>',{
307
+ rename : $("#rename").val()
308
+ }, function (data) {
309
+ toastrForm(data);
310
+ setTimeout(function () {
311
+ location.href= '';
312
+ },2000);
313
+ })
314
+ })
315
+
316
+ $(".btn-add").on("click", function () {
317
+ ajaxPost('/zrole/create/',{
318
+ name : $("#role_name").val()
319
+ }, function (data) {
320
+ toastrForm(data);
321
+ setTimeout(function () {
322
+ location.href= '';
323
+ },2000);
324
+ })
325
+ })
326
+ function deleterole() {
327
+ if(window.confirm('delete role selected ? ')) {
328
+ let id = "<%= id%>";
329
+ ajaxDelete('/zrole/delete/<%= id%>',{id:id}, function (data) {
330
+ toastrForm(data);
331
+ setTimeout(function () {
332
+ location.href= '/zrole';
333
+ },2000);
334
+ })
335
+ }
336
+ }
337
+ </script>
338
+ `;
339
+
161
340
  module.exports = router;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -1,121 +0,0 @@
1
- <div class="">
2
- <div class="page-header"><h1>Roles</h1></div>
3
- <div class="card panel panel-info boxy">
4
- <div class="panel-heading">
5
- <div class="float-end">
6
- <div class="summary">
7
- <% if(levels.delete) {%>
8
- <span
9
- class="icon-small icons-danger" title="Delete role" onclick="deleterole()"><img class="icons-bg-white icon-image"
10
- src="/assets/icons/trash.svg"></span>
11
- <%}%>
12
- <% if(levels.update) {%>
13
- <span class="icon-small icons-primary" data-bs-toggle="modal"
14
- data-bs-target="#renameModal" title="rename"><img
15
- class="icons-bg-white icon-image" src="/assets/icons/edit.svg"></span>
16
- <%}%>
17
- <% if(levels.create) {%>
18
- <span
19
- class="icon-small icons-success" title="Add a new role" data-bs-toggle="modal"
20
- data-bs-target="#addModal"><img class="icons-bg-white icon-image"
21
- src="/assets/icons/plus.svg"></span>
22
- <%}%>
23
-
24
-
25
- </div>
26
- </div>
27
- <h3 class="panel-title"><i class="fa fa-cog"></i> Settings</h3>
28
- <div class="clearfix"></div>
29
- </div>
30
- <div class="kv-panel-before">
31
- <div class="row">
32
- <form id="role-form" class="form-horizontal kv-form-horizontal" method="post"><input type="hidden"
33
- name="_csrf"
34
- value="<%- csrfToken %>">
35
- <div class="form-group field-role-role_name"><label class="control-label col-md-2"
36
- for="role-role_name">Role Name</label>
37
- <div class="col-md-10"><select id="roleName" class="form-control form-select mb-3" name="name">
38
- <% for(var i = 0;i < results.length;i++){ %>
39
- <option value="<%- results[i].id %>"
40
- <% if(id == results[i].id){ %> selected=""
41
- <% } %>
42
- ><%- results[i].name %></option>
43
- <% } %>
44
- </select></div>
45
- </div>
46
- <table class="table table-responsive">
47
- <thead>
48
- <tr>
49
- <th>Name</th>
50
- <% for(var i = 0;i < actions.length;i++) { %>
51
- <th><%= actions[i] %> <input onclick='checkthis("<%= actions[i] %>")' type="checkbox"
52
- id="all<%= actions[i] %>"></th>
53
- <% } %>
54
- </tr>
55
- </thead>
56
- <tbody>
57
- <% for(var i = 0;i < routes.length;i++) { %>
58
- <tr>
59
- <td>
60
- <% var ename = routes[i] %>
61
- <%= ename %></td>
62
- <% for(var x = 0;x < actions.length;x++) { %>
63
- <td><input name="params[<%= ename %>][<%= actions[x] %>]" class="<%= actions[x] %>"
64
- <% if(json && json.hasOwnProperty(ename) && json[ename].indexOf(actions[x]) >= 0) { %> <%= 'checked="checked"' %>
65
- <% } %>
66
- title="Role for <%= routes[i] %> <%= actions[x] %>" type="checkbox"></td>
67
- <% } %>
68
- </tr>
69
- <% } %>
70
- </tbody>
71
- </table>
72
- <div class="row">
73
- <div class="col-md-10 col-md-offset-1">
74
- <% if(levels.update) {%>
75
- <button type="submit" class="btn btn-primary">Update</button>
76
- <%}%>
77
- </div>
78
- </div>
79
- </form>
80
- </div>
81
- </div>
82
- </div>
83
- </div><!-- Modal -->
84
- <div class="modal fade" id="renameModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
85
- <div class="modal-dialog">
86
- <div class="modal-content">
87
- <div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">Rename title</h5>
88
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
89
- </div>
90
- <div class="modal-body"><input type="text" class="form-control" id="rename" name="rename"
91
- value="<%- model[0].name %>"></div>
92
- <div class="modal-footer">
93
- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
94
- <button type="button" class="btn btn-primary btn-update">Save changes</button>
95
- </div>
96
- </div>
97
- </div>
98
- </div><!-- Modal -->
99
- <div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="addModalLabel" aria-hidden="true">
100
- <div class="modal-dialog">
101
- <div class="modal-content">
102
- <div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">Add a New Role</h5>
103
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
104
- </div>
105
- <div class="modal-body">
106
- <div class="form-group mb-3"><label for="ruas_sk">Role Name</label> <input type="text"
107
- class="form-control"
108
- id="role_name"
109
- name="role_name"
110
- placeholder="Role Name">
111
- </div>
112
- </div>
113
- <div class="modal-footer">
114
- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
115
- <button type="button" class="btn btn-primary btn-add">Save changes</button>
116
- </div>
117
- </div>
118
- </div>
119
- </div>
120
-
121
-
@@ -1,57 +0,0 @@
1
- <script>
2
- function checkthis(elm) {
3
- var cElem = $("#all" + elm);
4
- if (cElem.is(":checked")) {
5
- $("input." + elm).prop("checked", true);
6
- } else {
7
- $("input." + elm).prop("checked", false);
8
- }
9
- }
10
- $("#roleName").on('change', function () {
11
- location.href = "/zrole?id=" + $(this).val();
12
- });
13
- var form = document.getElementById("role-form");
14
- form.onsubmit = function (ev) {
15
- ev.preventDefault();
16
- var url = '/zrole/update/<%= id%>';
17
- ajaxPost(url, $(this).serialize(), function (data) {
18
- if (data.status == 1) {
19
- toastr.success('Success', 'Updated Role');
20
- } else {
21
- toastr.error('Error!',data.data);
22
- }
23
- });
24
- }
25
- $(".btn-update").on("click", function () {
26
- ajaxPost('/zrole/rename/<%= id%>',{
27
- rename : $("#rename").val()
28
- }, function (data) {
29
- toastrForm(data);
30
- setTimeout(function () {
31
- location.href= '';
32
- },2000);
33
- })
34
- })
35
-
36
- $(".btn-add").on("click", function () {
37
- ajaxPost('/zrole/create/',{
38
- name : $("#role_name").val()
39
- }, function (data) {
40
- toastrForm(data);
41
- setTimeout(function () {
42
- location.href= '';
43
- },2000);
44
- })
45
- })
46
- function deleterole() {
47
- if(window.confirm('delete role selected ? ')) {
48
- let id = "<%= id%>";
49
- ajaxDelete('/zrole/delete/<%= id%>',{id:id}, function (data) {
50
- toastrForm(data);
51
- setTimeout(function () {
52
- location.href= '/zrole';
53
- },2000);
54
- })
55
- }
56
- }
57
- </script>