zet-lib 1.2.18 → 1.2.20
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/zRoute.js +203 -147
- package/package.json +1 -1
package/lib/zRoute.js
CHANGED
|
@@ -290,6 +290,10 @@ zRoute.post = (req, res, MYMODEL, routeName, body) => {
|
|
|
290
290
|
}
|
|
291
291
|
post[routeName][key] = val ? val : null
|
|
292
292
|
break
|
|
293
|
+
|
|
294
|
+
case 'numeric':
|
|
295
|
+
post[routeName][key] = val ? val : null
|
|
296
|
+
break
|
|
293
297
|
}
|
|
294
298
|
}
|
|
295
299
|
//check if widget have a tag default null
|
|
@@ -713,7 +717,7 @@ zRoute.dataTableFilter = (MYMODEL, relations, filter) => {
|
|
|
713
717
|
break
|
|
714
718
|
|
|
715
719
|
case 'datepicker':
|
|
716
|
-
dataTable[key] = `<input type="text" class="form-control search
|
|
720
|
+
dataTable[key] = `<input type="text" class="form-control search" value="${value}" id="data_table_${key}" >`
|
|
717
721
|
types[key] = 'input'
|
|
718
722
|
break
|
|
719
723
|
|
|
@@ -1670,174 +1674,226 @@ zRoute.dataTableSave = async (routeName, userId, body) => {
|
|
|
1670
1674
|
dynamic list Data Table
|
|
1671
1675
|
*/
|
|
1672
1676
|
zRoute.listDataTable = async (req, res, objData = {}) => {
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1677
|
+
const room = res.locals.token || 'aa'
|
|
1678
|
+
try {
|
|
1679
|
+
const body = req.body
|
|
1680
|
+
const MYMODEL = objData.MYMODEL || {}
|
|
1681
|
+
const fields = Object.prototype.hasOwnProperty.call(objData, 'fields') ? objData.fields : req.body.fields
|
|
1682
|
+
const relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
1683
|
+
const select = Object.prototype.hasOwnProperty.call(objData, 'select') ? objData.select : Util.selectParser(fields, MYMODEL)
|
|
1684
|
+
const columns = Object.prototype.hasOwnProperty.call(objData, 'columns') ? objData.columns : body.columns
|
|
1685
|
+
const asDate = []
|
|
1686
|
+
const asJSONb = []
|
|
1687
|
+
for (let key in MYMODEL.widgets) {
|
|
1688
|
+
if (MYMODEL.widgets[key].name == 'datetime') {
|
|
1689
|
+
asDate.push(key)
|
|
1690
|
+
}
|
|
1691
|
+
if (MYMODEL.widgets[key].name == 'datepicker') {
|
|
1692
|
+
asDate.push(key)
|
|
1693
|
+
}
|
|
1694
|
+
if (MYMODEL.widgets[key].name == 'dropdown_multi') {
|
|
1695
|
+
asJSONb.push(key)
|
|
1696
|
+
}
|
|
1697
|
+
if (MYMODEL.widgets[key].name == 'dropdown_checkbox') {
|
|
1698
|
+
asJSONb.push(key)
|
|
1699
|
+
}
|
|
1683
1700
|
}
|
|
1684
|
-
|
|
1685
|
-
|
|
1701
|
+
let whereArray = []
|
|
1702
|
+
if (objData.hasOwnProperty('whereArray')) {
|
|
1703
|
+
whereArray = objData['whereArray']
|
|
1686
1704
|
}
|
|
1705
|
+
whereArray.push({
|
|
1706
|
+
field: 'company_id',
|
|
1707
|
+
option: '=',
|
|
1708
|
+
value: res.locals.companyId,
|
|
1709
|
+
operator: 'AND',
|
|
1710
|
+
})
|
|
1711
|
+
|
|
1712
|
+
columns.forEach(function (item) {
|
|
1713
|
+
if (item.search.value) {
|
|
1714
|
+
let astype = 'text'
|
|
1715
|
+
if (asDate.includes(fields[item.data])) {
|
|
1716
|
+
astype = 'date'
|
|
1717
|
+
}
|
|
1718
|
+
if (asJSONb.includes(fields[item.data])) {
|
|
1719
|
+
astype = 'jsonb'
|
|
1720
|
+
}
|
|
1721
|
+
if (astype === 'jsonb') {
|
|
1722
|
+
whereArray.push({
|
|
1723
|
+
field: fields[item.data],
|
|
1724
|
+
option: ' ',
|
|
1725
|
+
value: ` @> '["${item.search.value}"]'`,
|
|
1726
|
+
operator: 'AND',
|
|
1727
|
+
type: 'inline',
|
|
1728
|
+
})
|
|
1729
|
+
} else {
|
|
1730
|
+
whereArray.push({
|
|
1731
|
+
field: fields[item.data],
|
|
1732
|
+
option: MYMODEL.options[fields[item.data]],
|
|
1733
|
+
value: item.search.value,
|
|
1734
|
+
operator: 'AND',
|
|
1735
|
+
type: astype,
|
|
1736
|
+
})
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
})
|
|
1740
|
+
const orderColumn = fields[body.order[0].column] == 'actionColumn' ? 'id' : fields[body.order[0].column] == 'no' ? 'id' : fields[body.order[0].column] == 'actionColum' ? 'id' : fields[body.order[0].column]
|
|
1741
|
+
const rows = await connection.results({
|
|
1742
|
+
select: select,
|
|
1743
|
+
table: MYMODEL.table,
|
|
1744
|
+
whereArray: whereArray,
|
|
1745
|
+
limit: body.length,
|
|
1746
|
+
offset: body.start,
|
|
1747
|
+
orderBy: [orderColumn, body.order[0].dir],
|
|
1748
|
+
})
|
|
1749
|
+
const count = await connection.result({
|
|
1750
|
+
select: 'count(id) as count',
|
|
1751
|
+
table: MYMODEL.table,
|
|
1752
|
+
whereArray: whereArray,
|
|
1753
|
+
})
|
|
1754
|
+
let datas = []
|
|
1755
|
+
const zRole = objData.zRole || require('./zRole')
|
|
1756
|
+
const levels = objData.hasOwnProperty('levels') ? objData.levels : zRole.myLevel(req, res, MYMODEL.table)
|
|
1757
|
+
if (objData.hasOwnProperty('datas')) {
|
|
1758
|
+
datas = objData.datas(body, rows, fields, relations, levels)
|
|
1759
|
+
} else {
|
|
1760
|
+
rows.forEach(function (row, index) {
|
|
1761
|
+
let arr = []
|
|
1762
|
+
fields.forEach(function (item) {
|
|
1763
|
+
if (item == 'no') {
|
|
1764
|
+
arr.push(index + 1 + parseInt(body.start))
|
|
1765
|
+
} else if (item == 'actionColumn') {
|
|
1766
|
+
let buttons = objData.hasOwnProperty('actionButtons') ? objData.actionButtons(levels, row, MYMODEL.table) : zRoute.actionButtons(levels, row, MYMODEL.table)
|
|
1767
|
+
arr.push(buttons)
|
|
1768
|
+
} else {
|
|
1769
|
+
let data = objData.hasOwnProperty('datas') ? objData.data(item, row[item], MYMODEL, relations) : zRoute.dataTableData(item, row[item], MYMODEL, relations)
|
|
1770
|
+
arr.push(data)
|
|
1771
|
+
}
|
|
1772
|
+
})
|
|
1773
|
+
datas.push(arr)
|
|
1774
|
+
})
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
const data = {
|
|
1778
|
+
draw: body.draw,
|
|
1779
|
+
recordsTotal: count.count || 0,
|
|
1780
|
+
recordsFiltered: count.count || 0,
|
|
1781
|
+
data: datas,
|
|
1782
|
+
}
|
|
1783
|
+
//save grid filter async
|
|
1784
|
+
zRoute.dataTableSave(MYMODEL.routeName, res.locals.userId, body)
|
|
1785
|
+
res.json(data)
|
|
1786
|
+
} catch (err) {
|
|
1787
|
+
console.log(err)
|
|
1788
|
+
io.to(room).emit('error', err + '')
|
|
1687
1789
|
}
|
|
1688
|
-
|
|
1689
|
-
if (objData.hasOwnProperty('whereArray')) {
|
|
1690
|
-
whereArray = objData['whereArray']
|
|
1691
|
-
}
|
|
1692
|
-
whereArray.push({
|
|
1693
|
-
field: 'company_id',
|
|
1694
|
-
option: '=',
|
|
1695
|
-
value: res.locals.companyId,
|
|
1696
|
-
operator: 'AND',
|
|
1697
|
-
})
|
|
1790
|
+
}
|
|
1698
1791
|
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1792
|
+
zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
1793
|
+
const room = res.locals.token || 'aa'
|
|
1794
|
+
try {
|
|
1795
|
+
actionButtonsFn = actionButtonsFn || function () {}
|
|
1796
|
+
const relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
1797
|
+
const body = req.body
|
|
1798
|
+
const fields = body.fields
|
|
1799
|
+
const select = Util.selectParser(fields, MYMODEL)
|
|
1800
|
+
const asDate = []
|
|
1801
|
+
const asJSONb = []
|
|
1802
|
+
for (let key in MYMODEL.widgets) {
|
|
1803
|
+
if (MYMODEL.widgets[key].name == 'datetime') {
|
|
1804
|
+
asDate.push(key)
|
|
1805
|
+
}
|
|
1806
|
+
if (MYMODEL.widgets[key].name == 'datepicker') {
|
|
1807
|
+
asDate.push(key)
|
|
1808
|
+
}
|
|
1809
|
+
if (MYMODEL.widgets[key].name == 'dropdown_multi') {
|
|
1810
|
+
asJSONb.push(key)
|
|
1811
|
+
}
|
|
1812
|
+
if (MYMODEL.widgets[key].name == 'dropdown_checkbox') {
|
|
1813
|
+
asJSONb.push(key)
|
|
1704
1814
|
}
|
|
1815
|
+
}
|
|
1816
|
+
let whereArray = []
|
|
1817
|
+
const columns = body.columns
|
|
1818
|
+
if (MYMODEL.keys.includes('company_id')) {
|
|
1705
1819
|
whereArray.push({
|
|
1706
|
-
field:
|
|
1707
|
-
option:
|
|
1708
|
-
value:
|
|
1820
|
+
field: 'company_id',
|
|
1821
|
+
option: '=',
|
|
1822
|
+
value: res.locals.companyId,
|
|
1709
1823
|
operator: 'AND',
|
|
1710
|
-
type: astype,
|
|
1711
1824
|
})
|
|
1712
1825
|
}
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1826
|
+
columns.forEach(function (item) {
|
|
1827
|
+
if (item.search.value) {
|
|
1828
|
+
let astype = 'text'
|
|
1829
|
+
if (asDate.includes(fields[item.data])) {
|
|
1830
|
+
astype = 'date'
|
|
1831
|
+
}
|
|
1832
|
+
if (asJSONb.includes(fields[item.data])) {
|
|
1833
|
+
astype = 'jsonb'
|
|
1834
|
+
}
|
|
1835
|
+
if (astype === 'jsonb') {
|
|
1836
|
+
whereArray.push({
|
|
1837
|
+
field: fields[item.data],
|
|
1838
|
+
option: ' ',
|
|
1839
|
+
value: ` @> '["${item.search.value}"]'`,
|
|
1840
|
+
operator: 'AND',
|
|
1841
|
+
type: 'inline',
|
|
1842
|
+
})
|
|
1843
|
+
} else {
|
|
1844
|
+
whereArray.push({
|
|
1845
|
+
field: fields[item.data],
|
|
1846
|
+
option: MYMODEL.options[fields[item.data]],
|
|
1847
|
+
value: item.search.value,
|
|
1848
|
+
operator: 'AND',
|
|
1849
|
+
type: astype,
|
|
1850
|
+
})
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
})
|
|
1854
|
+
const orderColumn = fields[body.order[0].column] == 'actionColumn' ? 'id' : fields[body.order[0].column] == 'no' ? 'id' : fields[body.order[0].column] == 'actionColum' ? 'id' : fields[body.order[0].column]
|
|
1855
|
+
const rows = await connection.results({
|
|
1856
|
+
select: select,
|
|
1857
|
+
table: MYMODEL.table,
|
|
1858
|
+
whereArray: whereArray,
|
|
1859
|
+
limit: body.length,
|
|
1860
|
+
offset: body.start,
|
|
1861
|
+
orderBy: [orderColumn, body.order[0].dir],
|
|
1862
|
+
})
|
|
1863
|
+
const count = await connection.result({
|
|
1864
|
+
select: 'count(id) as count',
|
|
1865
|
+
table: MYMODEL.table,
|
|
1866
|
+
whereArray: whereArray,
|
|
1867
|
+
})
|
|
1868
|
+
let datas = []
|
|
1869
|
+
const levels = zRole.myLevel(req, res, MYMODEL.table)
|
|
1734
1870
|
rows.forEach(function (row, index) {
|
|
1735
1871
|
let arr = []
|
|
1736
1872
|
fields.forEach(function (item) {
|
|
1737
1873
|
if (item == 'no') {
|
|
1738
1874
|
arr.push(index + 1 + parseInt(body.start))
|
|
1739
1875
|
} else if (item == 'actionColumn') {
|
|
1740
|
-
let buttons =
|
|
1876
|
+
let buttons = !actionButtonsFn(levels, row, MYMODEL.table) ? zRoute.actionButtons(levels, row, MYMODEL.table) : actionButtonsFn(levels, row, MYMODEL.table)
|
|
1741
1877
|
arr.push(buttons)
|
|
1742
1878
|
} else {
|
|
1743
|
-
|
|
1744
|
-
arr.push(data)
|
|
1879
|
+
arr.push(zRoute.dataTableData(item, row[item], MYMODEL, relations))
|
|
1745
1880
|
}
|
|
1746
1881
|
})
|
|
1747
1882
|
datas.push(arr)
|
|
1748
1883
|
})
|
|
1884
|
+
const data = {
|
|
1885
|
+
draw: body.draw,
|
|
1886
|
+
recordsTotal: count.count || 0,
|
|
1887
|
+
recordsFiltered: count.count || 0,
|
|
1888
|
+
data: datas,
|
|
1889
|
+
}
|
|
1890
|
+
//save grid filter async
|
|
1891
|
+
zRoute.dataTableSave(MYMODEL.routeName, res.locals.userId, body)
|
|
1892
|
+
res.json(data)
|
|
1893
|
+
} catch (err) {
|
|
1894
|
+
console.log(err)
|
|
1895
|
+
io.to(room).emit('error', err + '')
|
|
1749
1896
|
}
|
|
1750
|
-
|
|
1751
|
-
const data = {
|
|
1752
|
-
draw: body.draw,
|
|
1753
|
-
recordsTotal: count.count || 0,
|
|
1754
|
-
recordsFiltered: count.count || 0,
|
|
1755
|
-
data: datas,
|
|
1756
|
-
}
|
|
1757
|
-
//save grid filter async
|
|
1758
|
-
zRoute.dataTableSave(MYMODEL.routeName, res.locals.userId, body)
|
|
1759
|
-
res.json(data)
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
|
|
1763
|
-
actionButtonsFn = actionButtonsFn || function () {}
|
|
1764
|
-
const relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
1765
|
-
const body = req.body
|
|
1766
|
-
const fields = body.fields
|
|
1767
|
-
const select = Util.selectParser(fields, MYMODEL)
|
|
1768
|
-
const asDate = []
|
|
1769
|
-
for (let key in MYMODEL.widgets) {
|
|
1770
|
-
if (MYMODEL.widgets[key].name == 'datetime') {
|
|
1771
|
-
asDate.push(key)
|
|
1772
|
-
}
|
|
1773
|
-
if (MYMODEL.widgets[key].name == 'datepicker') {
|
|
1774
|
-
asDate.push(key)
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
let whereArray = []
|
|
1778
|
-
const columns = body.columns
|
|
1779
|
-
if (MYMODEL.keys.includes('company_id')) {
|
|
1780
|
-
whereArray.push({
|
|
1781
|
-
field: 'company_id',
|
|
1782
|
-
option: '=',
|
|
1783
|
-
value: res.locals.companyId,
|
|
1784
|
-
operator: 'AND',
|
|
1785
|
-
})
|
|
1786
|
-
}
|
|
1787
|
-
columns.forEach(function (item) {
|
|
1788
|
-
if (item.search.value) {
|
|
1789
|
-
let astype = 'text'
|
|
1790
|
-
if (asDate.includes(fields[item.data])) {
|
|
1791
|
-
astype = 'date'
|
|
1792
|
-
}
|
|
1793
|
-
whereArray.push({
|
|
1794
|
-
field: fields[item.data],
|
|
1795
|
-
option: MYMODEL.options[fields[item.data]],
|
|
1796
|
-
value: item.search.value,
|
|
1797
|
-
operator: 'AND',
|
|
1798
|
-
type: astype,
|
|
1799
|
-
})
|
|
1800
|
-
}
|
|
1801
|
-
})
|
|
1802
|
-
const orderColumn = fields[body.order[0].column] == 'actionColumn' ? 'id' : fields[body.order[0].column] == 'no' ? 'id' : fields[body.order[0].column] == 'actionColum' ? 'id' : fields[body.order[0].column]
|
|
1803
|
-
const rows = await connection.results({
|
|
1804
|
-
select: select,
|
|
1805
|
-
table: MYMODEL.table,
|
|
1806
|
-
whereArray: whereArray,
|
|
1807
|
-
limit: body.length,
|
|
1808
|
-
offset: body.start,
|
|
1809
|
-
orderBy: [orderColumn, body.order[0].dir],
|
|
1810
|
-
})
|
|
1811
|
-
const count = await connection.result({
|
|
1812
|
-
select: 'count(id) as count',
|
|
1813
|
-
table: MYMODEL.table,
|
|
1814
|
-
whereArray: whereArray,
|
|
1815
|
-
})
|
|
1816
|
-
let datas = []
|
|
1817
|
-
const levels = zRole.myLevel(req, res, MYMODEL.table)
|
|
1818
|
-
rows.forEach(function (row, index) {
|
|
1819
|
-
let arr = []
|
|
1820
|
-
fields.forEach(function (item) {
|
|
1821
|
-
if (item == 'no') {
|
|
1822
|
-
arr.push(index + 1 + parseInt(body.start))
|
|
1823
|
-
} else if (item == 'actionColumn') {
|
|
1824
|
-
let buttons = !actionButtonsFn(levels, row, MYMODEL.table) ? zRoute.actionButtons(levels, row, MYMODEL.table) : actionButtonsFn(levels, row, MYMODEL.table)
|
|
1825
|
-
arr.push(buttons)
|
|
1826
|
-
} else {
|
|
1827
|
-
arr.push(zRoute.dataTableData(item, row[item], MYMODEL, relations))
|
|
1828
|
-
}
|
|
1829
|
-
})
|
|
1830
|
-
datas.push(arr)
|
|
1831
|
-
})
|
|
1832
|
-
const data = {
|
|
1833
|
-
draw: body.draw,
|
|
1834
|
-
recordsTotal: count.count || 0,
|
|
1835
|
-
recordsFiltered: count.count || 0,
|
|
1836
|
-
data: datas,
|
|
1837
|
-
}
|
|
1838
|
-
//save grid filter async
|
|
1839
|
-
zRoute.dataTableSave(MYMODEL.routeName, res.locals.userId, body)
|
|
1840
|
-
res.json(data)
|
|
1841
1897
|
}
|
|
1842
1898
|
|
|
1843
1899
|
zRoute.actionButtons = (levels, row, table, callback = null) => {
|