zet-lib 1.0.57 → 1.0.59

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.
@@ -300,6 +300,7 @@ const body = `<div class="">
300
300
  <% for(var i = 0;i < actions.length;i++) { %>
301
301
  <th><%= actions[i] %> <input onclick='checkthis("<%= actions[i] %>")' type="checkbox" id="all<%= actions[i] %>"></th>
302
302
  <% } %>
303
+ <th>Tabs</th>
303
304
  </tr>
304
305
  </thead>
305
306
  <tbody>
@@ -307,14 +308,16 @@ const body = `<div class="">
307
308
  <tr>
308
309
  <td>
309
310
  <% var ename = routes[i];
310
- var titleName = tabs.includes(routes[i]) ? '<a class="handle-access" data-bs-toggle="modal" data-bs-target="#tabaccess" href="#">'+routes[i]+'</a>' : routes[i] %>
311
- <%- titleName %>
311
+ var handleTag = "handleAccess('"+routes[i]+"')";
312
+ var spanRole = tabs.includes(routes[i]) ? '<span class="handle-access icon-small icons-light" onclick="'+handleTag+'" data-bs-toggle="modal" data-bs-target="#tabaccess" ><img class="icons-bg-blue gridview icon-image" src="/assets/icons/lock-access.svg"></span>' : '' %>
313
+ <a href="/<%- ename %>" target="_blank"><%- ename %></a>
312
314
  </td>
313
315
  <% for(var x = 0;x < actions.length;x++) { %>
314
316
  <td><input name="params[<%= ename %>][<%= actions[x] %>]" class="<%= actions[x] %>"
315
317
  <% if(json && json.hasOwnProperty(ename) && json[ename].indexOf(actions[x]) >= 0) { %> <%= 'checked="checked"' %> <% } %> title="Role for <%= routes[i] %> <%= actions[x] %>" type="checkbox">
316
318
  </td>
317
319
  <% } %>
320
+ <td><%- spanRole %></td>
318
321
  </tr>
319
322
  <% } %>
320
323
  </tbody>
@@ -456,7 +459,6 @@ const js = `<script>
456
459
  $(".body-access").html(data);
457
460
  }))
458
461
  }
459
- $(".handle-access").on("click", (e)=> handleAccess(e.target.text));
460
462
  $(".btn-save-tab").on("click",(e) => {
461
463
  let queryform = $("#tabform").serializeArray();
462
464
  ajaxPost('/zrole/post-access', {
package/lib/zRoute.js CHANGED
@@ -1049,6 +1049,34 @@ zRoute.handleSession = async (req, user) => {
1049
1049
  }
1050
1050
  }
1051
1051
 
1052
+ zRoute.selectAllowedField = (req, res, MYMODEL, arr = []) => {
1053
+ let newArr = []
1054
+ let viewRole = []
1055
+ if (MYMODEL.hasOwnProperty('hasTabs') && MYMODEL.hasTabs) {
1056
+ let roles = myCache.get('ROLES') || {}
1057
+ let myrole = roles[res.locals.roleId]
1058
+ let tabsRole = myrole.tabs || {}
1059
+ if (tabsRole.hasOwnProperty(MYMODEL.table) && tabsRole[MYMODEL.table]) {
1060
+ viewRole = tabsRole[MYMODEL.table].view
1061
+ }
1062
+ if (viewRole.length > 0) {
1063
+ viewRole.map((item, index) => {
1064
+ if (!item) {
1065
+ newArr = [...newArr, ...MYMODEL.tabsDetail[`arr${index}`]]
1066
+ }
1067
+ })
1068
+ } else {
1069
+ MYMODEL.tabs.map((_, index) => {
1070
+ newArr = [...newArr, ...MYMODEL.tabsDetail[`arr${index}`]]
1071
+ })
1072
+ }
1073
+ let fixedArr = arr.filter((item) => !newArr.includes(item))
1074
+ arr = fixedArr
1075
+ }
1076
+
1077
+ return arr
1078
+ }
1079
+
1052
1080
  zRoute.excelQuery = async (req, res, MYMODEL) => {
1053
1081
  let virtuals = []
1054
1082
  for (var key in MYMODEL.widgets) {
@@ -1132,7 +1160,9 @@ zRoute.excelQuery = async (req, res, MYMODEL) => {
1132
1160
  if (zall) {
1133
1161
  fields = arr
1134
1162
  }
1135
- console.log(select)
1163
+
1164
+ fields = zRoute.selectAllowedField(req, res, MYMODEL, fields)
1165
+ //console.log('fields::',fields)
1136
1166
 
1137
1167
  const ztype = reqQuery.ztype == 1 ? true : false
1138
1168
  if (ztype) {
@@ -2092,7 +2122,41 @@ zRoute.viewFormsSync = async (req, res, MYMODEL, data = {}) => {
2092
2122
  const MYMODELS = myCache.get('MYMODELS')
2093
2123
  const relations = await zRoute.relations(req, res, MYMODEL.table)
2094
2124
  let forms = zRoute.viewForm(req, res, MYMODEL, relations, data)
2095
- //zRoute.moduleLib(req, res, MYMODEL, relations, forms);
2125
+ //add tabs role
2126
+ if (MYMODEL.hasOwnProperty('hasTabs') && MYMODEL.hasTabs) {
2127
+ let script = ''
2128
+ //MYMODEL.tabs.map((table))
2129
+ script += `$(()=> {
2130
+ ajaxPost('/ztab-access',{table:"${MYMODEL.table}"},(data)=> {
2131
+ let dataTabs = ${MYMODEL.hasOwnProperty('tabs') ? JSON.stringify(MYMODEL.tabs) : []};
2132
+ let viewAccess = data.view || [];
2133
+ let createAccess = data.create || [];
2134
+ let editAccess = data.edit || [];
2135
+ let deleteAccess = data.delete || [];
2136
+ dataTabs.map((_, index)=> {
2137
+ if(!deleteAccess[index]) {
2138
+ setTimeout(function () {$("#arr"+index).find(".icons-danger").remove();},1000)
2139
+ }
2140
+ if(!editAccess[index]) {
2141
+ $("#arr"+index).find("input").attr("disabled",true);
2142
+ $("#arr"+index).find("select").attr("disabled",true);
2143
+ }
2144
+ if(!createAccess[index]) {
2145
+ $("#arr"+index).find(".btn-plus").remove();
2146
+ $("#arr"+index).find("input").attr("disabled",true);
2147
+ $("#arr"+index).find("select").attr("disabled",true);
2148
+ }
2149
+ if(!viewAccess[index]) {
2150
+ $("#arr"+index).remove();
2151
+ $(".arr"+index).remove();
2152
+ }
2153
+ })
2154
+ });
2155
+ });
2156
+ `
2157
+ moduleLib.addScript(req, res, script)
2158
+ }
2159
+
2096
2160
  let tables = []
2097
2161
  for (let key in forms.obj) {
2098
2162
  if (forms.obj[key].type == 'table') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.0.57",
3
+ "version": "1.0.59",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"