zet-lib 1.2.56 → 1.2.57
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 +8 -0
- package/lib/Util.js +12 -0
- package/lib/zRoute.js +35 -0
- package/package.json +1 -1
package/lib/Form.js
CHANGED
|
@@ -423,6 +423,14 @@ Form.field = (obj) => {
|
|
|
423
423
|
displayForm += `<textarea ${classview} ${id} ${name} ${placeholder} ${readonly} ${style} ${htmlOptions} rows="4">${JSON.stringify(obj.value)}</textarea>${information}${append}`
|
|
424
424
|
break
|
|
425
425
|
|
|
426
|
+
case 'json_array':
|
|
427
|
+
displayForm += `<textarea ${classview} ${id} ${name} ${placeholder} ${readonly} ${style} ${htmlOptions} rows="4">${JSON.stringify(obj.value)}</textarea>${information}${append}`
|
|
428
|
+
break
|
|
429
|
+
|
|
430
|
+
case 'array':
|
|
431
|
+
displayForm += `<textarea ${classview} ${id} ${name} ${placeholder} ${readonly} ${style} ${htmlOptions} rows="4">${JSON.stringify(obj.value)}</textarea>${information}${append}`
|
|
432
|
+
break
|
|
433
|
+
|
|
426
434
|
case 'virtual':
|
|
427
435
|
displayForm = `${prepend}<input autocomplete="off" autofocus="" ${tabindex} ${style} type="text" ${classview} readonly ${id} ${placeholder} ${required} value="${value}" ${htmlOptions}>${information}${append}`
|
|
428
436
|
break
|
package/lib/Util.js
CHANGED
|
@@ -1137,6 +1137,18 @@ Util.attributeOptions = (obj = {}, defaultObj = {}) => {
|
|
|
1137
1137
|
return html
|
|
1138
1138
|
}
|
|
1139
1139
|
|
|
1140
|
+
Util.array_to_jsonb = (arr = []) => {
|
|
1141
|
+
let value = ''
|
|
1142
|
+
let myarr = []
|
|
1143
|
+
if (arr.length > 0) {
|
|
1144
|
+
arr.map((item) => {
|
|
1145
|
+
myarr.push(JSON.stringify(item))
|
|
1146
|
+
})
|
|
1147
|
+
}
|
|
1148
|
+
value = JSON.stringify(myarr).replace('[', '{').replaceAll(']', '}')
|
|
1149
|
+
return value
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1140
1152
|
Util.userAvatar = (img = '') => {
|
|
1141
1153
|
return img ? (img.includes('http') ? img : `/uploads/user/${img}`) : `/img/user.png`
|
|
1142
1154
|
}
|
package/lib/zRoute.js
CHANGED
|
@@ -295,6 +295,16 @@ zRoute.post = (req, res, MYMODEL, routeName, body) => {
|
|
|
295
295
|
case 'numeric':
|
|
296
296
|
post[routeName][key] = val ? val : null
|
|
297
297
|
break
|
|
298
|
+
case 'json_array':
|
|
299
|
+
let myval = null
|
|
300
|
+
if (val) {
|
|
301
|
+
let myarr = JSON.parse(val) || []
|
|
302
|
+
if (myarr.length > 0) {
|
|
303
|
+
myval = Util.array_to_jsonb(myarr)
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
post[routeName][key] = myval
|
|
307
|
+
break
|
|
298
308
|
}
|
|
299
309
|
}
|
|
300
310
|
//check if widget have a tag default null
|
|
@@ -927,6 +937,10 @@ zRoute.dataTableData = (key, value, MYMODEL, relations, myid = '') => {
|
|
|
927
937
|
myvalue = value ? JSON.stringify(value).replaceAll('","', '", "') : ''
|
|
928
938
|
break
|
|
929
939
|
|
|
940
|
+
case 'json_array':
|
|
941
|
+
myvalue = value ? JSON.stringify(value).replaceAll('","', '", "') : ''
|
|
942
|
+
break
|
|
943
|
+
|
|
930
944
|
default:
|
|
931
945
|
value = value || ''
|
|
932
946
|
myvalue = value.length > 50 ? value.substring(0, 50) : value
|
|
@@ -1842,6 +1856,7 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
|
1842
1856
|
const select = Util.selectParser(fields, MYMODEL)
|
|
1843
1857
|
const asDate = []
|
|
1844
1858
|
const asJSONb = []
|
|
1859
|
+
const asJSONbArr = []
|
|
1845
1860
|
for (let key in MYMODEL.widgets) {
|
|
1846
1861
|
if (MYMODEL.widgets[key].name == 'datetime') {
|
|
1847
1862
|
asDate.push(key)
|
|
@@ -1855,6 +1870,9 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
|
1855
1870
|
if (MYMODEL.widgets[key].name == 'dropdown_checkbox') {
|
|
1856
1871
|
asJSONb.push(key)
|
|
1857
1872
|
}
|
|
1873
|
+
if (MYMODEL.widgets[key].name == 'json_array') {
|
|
1874
|
+
asJSONbArr.push(key)
|
|
1875
|
+
}
|
|
1858
1876
|
}
|
|
1859
1877
|
let whereArray = []
|
|
1860
1878
|
const columns = body.columns
|
|
@@ -1875,6 +1893,9 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
|
1875
1893
|
if (asJSONb.includes(fields[item.data])) {
|
|
1876
1894
|
astype = 'jsonb'
|
|
1877
1895
|
}
|
|
1896
|
+
if (asJSONbArr.includes(fields[item.data])) {
|
|
1897
|
+
astype = 'json_array'
|
|
1898
|
+
}
|
|
1878
1899
|
if (astype === 'jsonb') {
|
|
1879
1900
|
whereArray.push({
|
|
1880
1901
|
field: fields[item.data],
|
|
@@ -1883,6 +1904,14 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
|
1883
1904
|
operator: 'AND',
|
|
1884
1905
|
type: 'inline',
|
|
1885
1906
|
})
|
|
1907
|
+
} else if (astype === 'json_array') {
|
|
1908
|
+
whereArray.push({
|
|
1909
|
+
field: '',
|
|
1910
|
+
option: '',
|
|
1911
|
+
value: ` ${fields[item.data]}::text ILIKE '${item.search.value}' `,
|
|
1912
|
+
operator: 'AND',
|
|
1913
|
+
type: 'inline',
|
|
1914
|
+
})
|
|
1886
1915
|
} else {
|
|
1887
1916
|
whereArray.push({
|
|
1888
1917
|
field: fields[item.data],
|
|
@@ -2346,6 +2375,12 @@ zRoute.forms = (req, res, MYMODEL, relations, data = {}) => {
|
|
|
2346
2375
|
obj.type = 'json'
|
|
2347
2376
|
obj.data = relations[key]
|
|
2348
2377
|
break
|
|
2378
|
+
case 'json_array':
|
|
2379
|
+
obj.type = 'json_array'
|
|
2380
|
+
break
|
|
2381
|
+
case 'array':
|
|
2382
|
+
obj.type = 'array'
|
|
2383
|
+
break
|
|
2349
2384
|
case 'virtual':
|
|
2350
2385
|
obj.type = 'virtual'
|
|
2351
2386
|
break
|