zet-lib 1.2.39 → 1.2.40

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/lib/Form.js CHANGED
@@ -854,8 +854,38 @@ Form.modal = (obj, LANGUAGE = {}) => {
854
854
  <img src="/assets/icons/send.svg" class="icons-bg-white"> ${LANGUAGE.apply || 'Apply'}
855
855
  </button>`,
856
856
  })
857
+
858
+ let modalFields2 = `
859
+ <div class="modal fade" id="grid-lock" tabindex="-1" aria-labelledby="grid-lock-label" aria-hidden="true">
860
+ <div class="modal-dialog">
861
+ <div class="modal-content">
862
+ <div class="modal-header">
863
+ <h1 class="modal-title fs-5" id="exampleModalLabel">Lock/Unlock</h1>
864
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
865
+ </div>
866
+ <div class="modal-body">
867
+ <form>
868
+ <fieldset>
869
+ <div class="mb-3">
870
+ <div class="form-check">
871
+ <input class="form-check-input" type="checkbox" id="check-all-grid">
872
+ <label class="form-check-label" for="check-all-grid">
873
+ Lock/UnLock All
874
+ </label>
875
+ </div>
876
+ </div>
877
+ </fieldset>
878
+ </form>
879
+
880
+ </div>
881
+ <div class="modal-footer">
882
+ <button type="button" class="btn btn-primary btn-save-lock"> ${LANGUAGE.apply || 'Apply'}</button>
883
+ </div>
884
+ </div>
885
+ </div>
886
+ </div>`
857
887
  try {
858
- return modalFields
888
+ return modalFields + modalFields2
859
889
  } catch (err) {
860
890
  console.log(err)
861
891
  }
package/lib/Util.js CHANGED
@@ -1124,7 +1124,7 @@ Util.userAvatar = (img = '') => {
1124
1124
  MYSQL HELPER
1125
1125
  */
1126
1126
  Util.selectParser = (fields = [], MYMODEL = {}) => {
1127
- fields = fields.filter((e) => e !== 'actionColumn')
1127
+ //fields = fields.filter((e) => e !== 'actionColumn')
1128
1128
  let virtuals = []
1129
1129
  let select = ''
1130
1130
  for (var key in MYMODEL.widgets) {
@@ -1138,6 +1138,8 @@ Util.selectParser = (fields = [], MYMODEL = {}) => {
1138
1138
  select += MYMODEL.widgets[item].fields + ','
1139
1139
  } else if (item === 'no') {
1140
1140
  arr.push('id')
1141
+ } else if (item === 'actionColumn') {
1142
+ arr.push('lock')
1141
1143
  } else {
1142
1144
  arr.push(item)
1143
1145
  }
package/lib/zAppRouter.js CHANGED
@@ -1296,4 +1296,82 @@ router.get('/zdownload/zgenerator/:table', async (req, res) => {
1296
1296
  })
1297
1297
  })
1298
1298
 
1299
+ router.post('/zlock-unlock/:table', async (req, res) => {
1300
+ let json = Util.jsonSuccess('Success')
1301
+ var table = req.params.table
1302
+ let cacheRoles = myCache.get('ROLES')
1303
+ let roleId = res.locals.roleId
1304
+ let myrole = cacheRoles[roleId]
1305
+ let tableRole = myrole.params[table] || []
1306
+ let hasAccess = tableRole.includes('lock') ? true : false
1307
+ if (hasAccess) {
1308
+ let datas = req.body.datas || []
1309
+ if (datas.length > 0) {
1310
+ for (const data of datas) {
1311
+ let id = data.name.replace('lock[', '').replace(']', '')
1312
+ let value = data.value
1313
+ await connection.update({
1314
+ table: table,
1315
+ data: {
1316
+ lock: value,
1317
+ },
1318
+ where: {
1319
+ id: id,
1320
+ },
1321
+ })
1322
+ }
1323
+ } else {
1324
+ json = Util.flashError('No Data')
1325
+ }
1326
+ } else {
1327
+ json = Util.flashError('No Access')
1328
+ }
1329
+
1330
+ res.json(json)
1331
+ })
1332
+
1333
+ router.get('/addlock-fields', async (req, res) => {
1334
+ let tables = await connection.query(connection.showTables)
1335
+ for (const table of tables) {
1336
+ let tablename = table.tablename
1337
+ let sql = `ALTER TABLE ${tablename} ADD COLUMN "lock" smallint DEFAULT 0 `
1338
+ try {
1339
+ await connection.query(sql)
1340
+ } catch (e) {
1341
+ console.log(e)
1342
+ }
1343
+ }
1344
+ res.send(tables)
1345
+ })
1346
+
1347
+ router.get('/addlock-models', async (req, res) => {
1348
+ let text = ''
1349
+ let results = await connection.results({
1350
+ table: 'zfields',
1351
+ })
1352
+ for (const result of results) {
1353
+ let labels = result.labels
1354
+ let arr = Object.keys(labels)
1355
+ if (!Util.in_array('lock', arr)) {
1356
+ text += result.id + ' tidak ada'
1357
+ labels.lock = 'Lock/Unlock'
1358
+ try {
1359
+ await connection.update({
1360
+ table: 'zfields',
1361
+ data: {
1362
+ labels: JSON.stringify(labels),
1363
+ },
1364
+ where: {
1365
+ id: result.id,
1366
+ },
1367
+ })
1368
+ } catch (err) {
1369
+ console.log(err)
1370
+ }
1371
+ }
1372
+ }
1373
+
1374
+ res.send(text)
1375
+ })
1376
+
1299
1377
  module.exports = router
package/lib/zRole.js CHANGED
@@ -23,7 +23,7 @@ if (cacheRoutes && cacheRoutes.length) {
23
23
  Default actions
24
24
  you can additional here
25
25
  */
26
- a.actions = ['index', 'create', 'update', 'delete', 'view', 'import', 'export', 'approval']
26
+ a.actions = ['index', 'create', 'update', 'delete', 'view', 'import', 'export', 'approval', 'lock']
27
27
 
28
28
  /*
29
29
  all in table roles
package/lib/zRoute.js CHANGED
@@ -859,88 +859,94 @@ zRoute.dataTableFilter = (MYMODEL, relations, filter) => {
859
859
  return dataTable
860
860
  }
861
861
 
862
- zRoute.dataTableData = (key, value, MYMODEL, relations) => {
862
+ zRoute.dataTableData = (key, value, MYMODEL, relations, myid = '') => {
863
863
  relations = relations || {}
864
864
  var keyFields = key + 'Fields'
865
865
  var keyObject = key + 'Object'
866
866
  let myvalue = value
867
867
  var widgetName = MYMODEL.widgets[key] ? MYMODEL.widgets[key].name : ''
868
- if (widgetName) {
869
- switch (widgetName) {
870
- case 'switch':
871
- myvalue = relations[keyFields][value] || ''
872
- break
868
+ if (key == 'lock') {
869
+ let selected1 = value != 1 ? 'selected' : ''
870
+ let selected2 = value == 1 ? 'selected' : ''
871
+ myvalue = `<select name="lock[${myid}]" class="lockdatagrid" id="lock${myid}"><option value="0" ${selected1}>Unlock</option><option value="1" ${selected2}>Lock</option></select>`
872
+ } else {
873
+ if (widgetName) {
874
+ switch (widgetName) {
875
+ case 'switch':
876
+ myvalue = relations[keyFields][value] || ''
877
+ break
873
878
 
874
- case 'color':
875
- myvalue = `<input type="color" value="${value}">`
876
- break
879
+ case 'color':
880
+ myvalue = `<input type="color" value="${value}">`
881
+ break
877
882
 
878
- case 'relation':
879
- myvalue = relations[keyObject][value] || ''
880
- break
883
+ case 'relation':
884
+ myvalue = relations[keyObject][value] || ''
885
+ break
881
886
 
882
- case 'dropdown_multi':
883
- let arr = value ? value : []
884
- if (arr.length) {
885
- let myarr = []
886
- arr.forEach(function (item) {
887
- myarr.push(relations[keyObject][item])
888
- })
889
- myvalue = myarr.length ? myarr.join(', ') : ''
890
- }
891
- break
887
+ case 'dropdown_multi':
888
+ let arr = value ? value : []
889
+ if (arr.length) {
890
+ let myarr = []
891
+ arr.forEach(function (item) {
892
+ myarr.push(relations[keyObject][item])
893
+ })
894
+ myvalue = myarr.length ? myarr.join(', ') : ''
895
+ }
896
+ break
892
897
 
893
- case 'dropdown_chain':
894
- myvalue = relations[key][value] || ''
895
- break
898
+ case 'dropdown_chain':
899
+ myvalue = relations[key][value] || ''
900
+ break
896
901
 
897
- case 'select':
898
- myvalue = relations[keyFields][value] || ''
899
- break
902
+ case 'select':
903
+ myvalue = relations[keyFields][value] || ''
904
+ break
900
905
 
901
- case 'radio':
902
- myvalue = relations[keyFields][value] || ''
903
- break
906
+ case 'radio':
907
+ myvalue = relations[keyFields][value] || ''
908
+ break
904
909
 
905
- case 'typeahead':
906
- myvalue = relations[keyObject][value] || ''
907
- break
910
+ case 'typeahead':
911
+ myvalue = relations[keyObject][value] || ''
912
+ break
908
913
 
909
- case 'datetime':
910
- myvalue = Util.timeSql(moment(value).utc(false))
911
- break
914
+ case 'datetime':
915
+ myvalue = Util.timeSql(moment(value).utc(false))
916
+ break
912
917
 
913
- case 'datepicker':
914
- myvalue = Util.dateFormat(value, MYMODEL.widgets[key].format)
915
- break
918
+ case 'datepicker':
919
+ myvalue = Util.dateFormat(value, MYMODEL.widgets[key].format)
920
+ break
916
921
 
917
- case 'number':
918
- myvalue = Util.formatNumber(value)
919
- break
922
+ case 'number':
923
+ myvalue = Util.formatNumber(value)
924
+ break
920
925
 
921
- case 'integer':
922
- myvalue = value + ''
923
- break
926
+ case 'integer':
927
+ myvalue = value + ''
928
+ break
924
929
 
925
- case 'image':
926
- myvalue = Util.fileView('/uploads/' + MYMODEL.routeName + '/', value, { width: 60 })
927
- break
930
+ case 'image':
931
+ myvalue = Util.fileView('/uploads/' + MYMODEL.routeName + '/', value, { width: 60 })
932
+ break
928
933
 
929
- case 'file':
930
- myvalue = Util.fileView('/uploads/' + MYMODEL.routeName + '/', value)
931
- break
934
+ case 'file':
935
+ myvalue = Util.fileView('/uploads/' + MYMODEL.routeName + '/', value)
936
+ break
932
937
 
933
- case 'password':
934
- myvalue = 'xxxxxx'
935
- break
938
+ case 'password':
939
+ myvalue = 'xxxxxx'
940
+ break
936
941
 
937
- case 'json':
938
- myvalue = value ? JSON.stringify(value).replaceAll('","', '", "') : ''
939
- break
942
+ case 'json':
943
+ myvalue = value ? JSON.stringify(value).replaceAll('","', '", "') : ''
944
+ break
940
945
 
941
- default:
942
- value = value || ''
943
- myvalue = value.length > 50 ? value.substring(0, 50) : value
946
+ default:
947
+ value = value || ''
948
+ myvalue = value.length > 50 ? value.substring(0, 50) : value
949
+ }
944
950
  }
945
951
  }
946
952
  return myvalue
@@ -1819,7 +1825,7 @@ zRoute.listDataTable = async (req, res, objData = {}) => {
1819
1825
  let buttons = objData.hasOwnProperty('actionButtons') ? objData.actionButtons(levels, row, MYMODEL.table) : zRoute.actionButtons(levels, row, MYMODEL.table)
1820
1826
  arr.push(buttons)
1821
1827
  } else {
1822
- let data = objData.hasOwnProperty('datas') ? objData.data(item, row[item], MYMODEL, relations) : zRoute.dataTableData(item, row[item], MYMODEL, relations)
1828
+ let data = objData.hasOwnProperty('datas') ? objData.data(item, row[item], MYMODEL, relations) : zRoute.dataTableData(item, row[item], MYMODEL, relations, row.id)
1823
1829
  arr.push(data)
1824
1830
  }
1825
1831
  })
@@ -1929,7 +1935,7 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
1929
1935
  let buttons = !actionButtonsFn(levels, row, MYMODEL.table) ? zRoute.actionButtons(levels, row, MYMODEL.table) : actionButtonsFn(levels, row, MYMODEL.table)
1930
1936
  arr.push(buttons)
1931
1937
  } else {
1932
- arr.push(zRoute.dataTableData(item, row[item], MYMODEL, relations))
1938
+ arr.push(zRoute.dataTableData(item, row[item], MYMODEL, relations, row.id))
1933
1939
  }
1934
1940
  })
1935
1941
  datas.push(arr)
@@ -1953,14 +1959,30 @@ zRoute.actionButtons = (levels, row, table, callback = null) => {
1953
1959
  let arr = []
1954
1960
  let obj = {}
1955
1961
  if (levels.delete) {
1956
- let icon_delete = `<span class="icon-small icons-danger" title="${LANGUAGE.delete}" ><img data-id="${row.id}" class="icons-bg-white griddelete icon-image" src="/assets/icons/trash-filled.svg"></span>`
1957
- arr.push(icon_delete)
1958
- obj['delete'] = icon_delete
1962
+ if (row.hasOwnProperty('lock')) {
1963
+ if (row.lock != 1) {
1964
+ let icon_delete = `<span class="icon-small icons-danger" title="${LANGUAGE.delete}" ><img data-id="${row.id}" class="icons-bg-white griddelete icon-image" src="/assets/icons/trash-filled.svg"></span>`
1965
+ arr.push(icon_delete)
1966
+ obj['delete'] = icon_delete
1967
+ }
1968
+ } else {
1969
+ let icon_delete = `<span class="icon-small icons-danger" title="${LANGUAGE.delete}" ><img data-id="${row.id}" class="icons-bg-white griddelete icon-image" src="/assets/icons/trash-filled.svg"></span>`
1970
+ arr.push(icon_delete)
1971
+ obj['delete'] = icon_delete
1972
+ }
1959
1973
  }
1960
1974
  if (levels.update) {
1961
- let icon_update = `<span class="icon-small icons-primary" title="${LANGUAGE.update}" ><img data-id="${row.id}" class="icons-bg-white gridupdate icon-image" src="/assets/icons/edit.svg"></span>`
1962
- arr.push(icon_update)
1963
- obj['update'] = icon_update
1975
+ if (row.hasOwnProperty('lock')) {
1976
+ if (row.lock != 1) {
1977
+ let icon_update = `<span class="icon-small icons-primary" title="${LANGUAGE.update}" ><img data-id="${row.id}" class="icons-bg-white gridupdate icon-image" src="/assets/icons/edit.svg"></span>`
1978
+ arr.push(icon_update)
1979
+ obj['update'] = icon_update
1980
+ }
1981
+ } else {
1982
+ let icon_update = `<span class="icon-small icons-primary" title="${LANGUAGE.update}" ><img data-id="${row.id}" class="icons-bg-white gridupdate icon-image" src="/assets/icons/edit.svg"></span>`
1983
+ arr.push(icon_update)
1984
+ obj['update'] = icon_update
1985
+ }
1964
1986
  }
1965
1987
  if (levels.view) {
1966
1988
  let icon_view = `<span class="icon-small icons-light" title="${LANGUAGE.view}" ><img data-id="${row.id}" class="icons-bg-black gridview icon-image" src="/assets/icons/eye.svg"></span>`
@@ -3402,8 +3424,12 @@ zRoute.deleteSQL = async (table, id, company_id) => {
3402
3424
  where: where,
3403
3425
  })
3404
3426
  if (results.length) {
3405
- await connection.delete({ table: table, where: where })
3406
- zRoute.modelsCacheRenew(table, company_id)
3427
+ if (results[0].lock == 1) {
3428
+ throw Error('Data is locked')
3429
+ } else {
3430
+ await connection.delete({ table: table, where: where })
3431
+ zRoute.modelsCacheRenew(table, company_id)
3432
+ }
3407
3433
  } else {
3408
3434
  throw Error('Data not found')
3409
3435
  }
package/lib/zdataTable.js CHANGED
@@ -86,8 +86,11 @@ class dataTable {
86
86
  if (this.levels.create) {
87
87
  html += `<button title="${LANGUAGE.create_info}" class="btn create gridadd image-button boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/plus.svg" class="icons-bg-black"> ${LANGUAGE.create}</button>`
88
88
  }
89
- if (this.levels.import) {
90
- html += `<button title="${LANGUAGE.import_info}" class="btn buttons-copy buttons-html5 copy gridimport boxy-small dimens2x image-button" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/database-import.svg" class="icons-bg-black"> ${LANGUAGE.import}</span></span></button>`
89
+ if (this.levels.lock) {
90
+ html += `<button title="Lock/Unlock" style="background-color: #3B71CA; color:white" class="btn btn-danger buttons-lock buttons-html5 copy gridlock boxy-small dimens2x image-button" tabindex="0" data-bs-toggle="modal" data-bs-target="#grid-lock" type="button"><img src="/assets/icons/cloud-lock.svg" class="icons-bg-white"> Lock/Unlock</span></span></button>`
91
+ }
92
+ if (this.levels.lock) {
93
+ html += `<button title="Lock/Unlock" style="background-color: #3B71CA; color:white" class="btn btn-danger buttons-lock buttons-html5 copy gridlock boxy-small dimens2x image-button" tabindex="0" style="color: " type="button"><img src="/assets/icons/cloud-lock.svg" class="icons-bg-white"> Lock/Unlock</span></span></button>`
91
94
  }
92
95
  html += `<button title="${LANGUAGE.settings}" class="btn buttons-excel buttons-html5 setting gridsettings boxy-small dimens2x image-button" tabindex="0" aria-controls="DataTables_Table_0" type="button" data-bs-toggle="modal" data-bs-target="#grid-modal"><img src="/assets/icons/settings.svg" class="icons-bg-black"> ${LANGUAGE.settings}</button>`
93
96
  html += `<button class="btn refresh gridreload boxy-small dimens2x image-button" title="${LANGUAGE.grid_refresh}" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/refresh.svg" class="icons-bg-black"></button>`
@@ -117,9 +120,12 @@ class dataTable {
117
120
  html += `<button title="${LANGUAGE.create_info}" class="btn create gridadd image-button boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/plus.svg" class="icons-bg-black"> ${LANGUAGE.create}</button>`
118
121
  }
119
122
  if (this.levels.import) {
120
- html += `<button title="${LANGUAGE.import_info}" class="btn buttons-copy buttons-html5 copy gridimport boxy-small dimens2x image-button" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/database-import.svg" class="icons-bg-black"> ${LANGUAGE.import}</span></span></button>`
123
+ html += `<button title="${LANGUAGE.import_info}" class="btn buttons-copy buttons-html5 copy gridimport boxy-small dimens2x image-button" tabindex="0" type="button"><img src="/assets/icons/database-import.svg" class="icons-bg-black"> ${LANGUAGE.import}</span></span></button>`
121
124
  }
122
- html += `<button title="${LANGUAGE.settings}" class="btn buttons-excel buttons-html5 setting gridsettings boxy-small dimens2x image-button" tabindex="0" aria-controls="DataTables_Table_0" type="button" data-bs-toggle="modal" data-bs-target="#grid-modal"><img src="/assets/icons/settings.svg" class="icons-bg-black"> ${LANGUAGE.settings}</button>`
125
+ if (this.levels.lock) {
126
+ html += `<button title="Lock/Unlock" style="background-color: #3B71CA; color:white" class="btn btn-danger buttons-lock buttons-html5 copy gridlock boxy-small dimens2x image-button" tabindex="0" data-bs-toggle="modal" data-bs-target="#grid-lock" type="button"><img src="/assets/icons/cloud-lock.svg" class="icons-bg-white"> Lock/Unlock</span></span></button>`
127
+ }
128
+ html += `<button title="${LANGUAGE.settings}" class="btn buttons-excel buttons-html5 setting gridsettings boxy-small dimens2x image-button" tabindex="0" type="button" data-bs-toggle="modal" data-bs-target="#grid-modal"><img src="/assets/icons/settings.svg" class="icons-bg-black"> ${LANGUAGE.settings}</button>`
123
129
  html += `<button class="btn refresh gridreload boxy-small dimens2x image-button" title="${LANGUAGE.grid_refresh}" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/refresh.svg" class="icons-bg-black"></button>`
124
130
  if (this.levels.export) {
125
131
  html += `<div class="btn-group" role="group">
@@ -173,10 +179,29 @@ class dataTable {
173
179
  `
174
180
  }
175
181
  }
176
-
177
182
  if (typeaheadScript) {
178
183
  script += `<script type="text/javascript">$(function () {${typeaheadScript}})</script>${Util.newLine}`
179
184
  }
185
+ script += `<script type="text/javascript">
186
+ function checkthisgrid() {$(".lockdatagrid").val("1");}
187
+ function uncheckthisgrid() {$(".lockdatagrid").val("0");}
188
+ $(function () {$("#check-all-grid").on('click', function () {
189
+ if($(this).is(':checked')) {
190
+ checkthisgrid();
191
+ } else {
192
+ uncheckthisgrid();
193
+ }
194
+ })
195
+ $(".btn-save-lock").on("click", function () {
196
+ ajaxPost('/zlock-unlock/${this.MYMODEL.table}', {
197
+ datas: $(".lockdatagrid").serializeArray()
198
+ }, function (data) {
199
+ toastrForm(data);
200
+ if(data.status ==1) {
201
+ location.href='';
202
+ }
203
+ })
204
+ })})</script>${Util.newLine}`
180
205
 
181
206
  return script
182
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.2.39",
3
+ "version": "1.2.40",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"