@opengis/admin 0.3.23 → 0.3.25

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.
Files changed (203) hide show
  1. package/README.md +97 -97
  2. package/config.js +4 -4
  3. package/dist/{add-page-2cPkdIAC.js → add-page-BI4K8Lzk.js} +1 -1
  4. package/dist/{admin-interface-D9Dx7QqK.js → admin-interface-DDP6KpGO.js} +226 -226
  5. package/dist/{admin-view-C_Ecdip-.js → admin-view-C--DkpIG.js} +3 -3
  6. package/dist/admin.js +1 -1
  7. package/dist/admin.umd.cjs +48 -48
  8. package/dist/assets/logo.svg +41 -41
  9. package/dist/{card-view-MuS2Gqq6.js → card-view-CPwz8aJg.js} +1 -1
  10. package/dist/{edit-page-Dr397YuE.js → edit-page-BsDJ8lKP.js} +1 -1
  11. package/dist/{import-file-CcRnsq1s.js → import-file-B8gDejaq.js} +5459 -5452
  12. package/dist/{profile-page-BrKTAsqO.js → profile-page-C5UftUwo.js} +1 -1
  13. package/dist/style.css +1 -1
  14. package/module/settings/card/admin.accounts.table/index.yml +7 -7
  15. package/module/settings/card/admin.accounts.table/rules.hbs +18 -18
  16. package/module/settings/card/admin.accounts.table/users.hbs +13 -13
  17. package/module/settings/card/admin.roles.table/access.hbs +11 -11
  18. package/module/settings/card/admin.roles.table/general_info.hbs +9 -9
  19. package/module/settings/card/admin.roles.table/index.yml +22 -22
  20. package/module/settings/card/admin.roles.table/users.hbs +12 -12
  21. package/module/settings/card/admin.routes.table/general_info.hbs +13 -13
  22. package/module/settings/card/admin.routes.table/groups.hbs +11 -11
  23. package/module/settings/card/admin.routes.table/index.yml +15 -15
  24. package/module/settings/card/admin.routes.table/users.hbs +16 -16
  25. package/module/settings/card/admin.table_properties.table/custom_columns.hbs +22 -22
  26. package/module/settings/card/admin.table_properties.table/index.yml +12 -12
  27. package/module/settings/card/admin.table_properties.table/info.hbs +17 -17
  28. package/module/settings/card/admin.users.table/general_info.hbs +18 -18
  29. package/module/settings/card/admin.users.table/index.yml +20 -20
  30. package/module/settings/card/admin.users.table/last_login.hbs +17 -17
  31. package/module/settings/card/admin.users.table/logs.hbs +16 -16
  32. package/module/settings/card/admin.users.table/routes.hbs +13 -13
  33. package/module/settings/card/admin.users.table/user_roles.hbs +35 -35
  34. package/module/settings/cls/change_type.json +13 -13
  35. package/module/settings/cls/core.actions.json +17 -17
  36. package/module/settings/cls/core.column_type.json +14 -14
  37. package/module/settings/cls/core.scope.json +13 -13
  38. package/module/settings/cls/properties.site_status.json +13 -13
  39. package/module/settings/cls/properties.widget_status.json +13 -13
  40. package/module/settings/cls/users.user_type.json +13 -13
  41. package/module/settings/cls/yes_no.json +11 -11
  42. package/module/settings/form/admin.accounts.form.json +13 -13
  43. package/module/settings/form/admin.custom_column.form.json +55 -55
  44. package/module/settings/form/admin.properties.form.json +15 -15
  45. package/module/settings/form/admin.roles.form.json +21 -21
  46. package/module/settings/form/admin.routes.form.json +25 -25
  47. package/module/settings/form/admin.rules.form.json +30 -30
  48. package/module/settings/form/admin.table_properties.form.json +19 -19
  49. package/module/settings/form/admin.user_properties.form.json +15 -15
  50. package/module/settings/form/admin.user_roles.form.json +24 -24
  51. package/module/settings/form/admin.user_roles_card.form.json +13 -13
  52. package/module/settings/form/admin.users.form.json +177 -177
  53. package/module/settings/form/admin.users_edit.form.json +145 -145
  54. package/module/settings/form/context.account_grants.form.json +24 -24
  55. package/module/settings/form/context.account_users.form.json +12 -12
  56. package/module/settings/form/user.user_roles.form.json +13 -13
  57. package/module/settings/interface/admin.properties.json +4 -4
  58. package/module/settings/interface/admin.roles.json +4 -4
  59. package/module/settings/interface/admin.routes.json +4 -4
  60. package/module/settings/interface/admin.users.json +4 -4
  61. package/module/settings/menu.json +72 -72
  62. package/module/settings/select/core.routes.sql +1 -1
  63. package/module/settings/select/core.user_mentioned.sql +1 -1
  64. package/module/settings/select/core.user_uid.sql +1 -1
  65. package/module/settings/table/admin.accounts.table.json +49 -49
  66. package/module/settings/table/admin.custom_column.table.json +100 -100
  67. package/module/settings/table/admin.properties.table.json +39 -39
  68. package/module/settings/table/admin.roles.table.json +77 -77
  69. package/module/settings/table/admin.routes.table.json +73 -73
  70. package/module/settings/table/admin.rules.table.json +77 -77
  71. package/module/settings/table/admin.table_properties.table.json +37 -37
  72. package/module/settings/table/admin.user_properties.table.json +34 -34
  73. package/module/settings/table/admin.user_roles.table.json +74 -74
  74. package/module/settings/table/admin.users.table.json +135 -135
  75. package/module/settings/table/context.account_grants.table.json +88 -88
  76. package/module/settings/table/context.account_users.table.json +53 -53
  77. package/module/settings/table/log.table_changes.table.json +100 -100
  78. package/package.json +102 -102
  79. package/plugin.js +30 -30
  80. package/server/helpers/core/badge.js +16 -16
  81. package/server/helpers/core/buttonHelper.js +21 -21
  82. package/server/helpers/core/coalesce.js +7 -7
  83. package/server/helpers/core/select.js +48 -48
  84. package/server/helpers/core/token.js +18 -18
  85. package/server/helpers/index.js +40 -40
  86. package/server/helpers/list/buttonHelper.js +21 -21
  87. package/server/helpers/list/descriptionList.js +45 -45
  88. package/server/helpers/list/tableList.js +82 -82
  89. package/server/helpers/list/utils/button.js +5 -5
  90. package/server/helpers/list/utils/buttonDel.js +12 -12
  91. package/server/helpers/list/utils/buttonEdit.js +14 -14
  92. package/server/helpers/temp/contentList.js +58 -58
  93. package/server/helpers/temp/ifCond.js +101 -101
  94. package/server/helpers/utils/button.js +5 -5
  95. package/server/helpers/utils/buttonAdd.js +6 -6
  96. package/server/helpers/utils/buttonDel.js +6 -6
  97. package/server/helpers/utils/buttonEdit.js +5 -5
  98. package/server/helpers/utils/mdToHTML.js +17 -17
  99. package/server/helpers/utils/paddingNumber.js +3 -3
  100. package/server/plugins/access/funcs/getAdminAccess.js +12 -12
  101. package/server/plugins/access/index.mjs +6 -6
  102. package/server/plugins/adminHook.js +81 -81
  103. package/server/plugins/cron.js +10 -10
  104. package/server/plugins/docs.js +28 -28
  105. package/server/plugins/hook.js +276 -276
  106. package/server/plugins/vite.js +77 -77
  107. package/server/routes/access/controllers/access.group.js +29 -29
  108. package/server/routes/access/controllers/access.group.post.js +54 -54
  109. package/server/routes/access/controllers/access.interface.js +33 -33
  110. package/server/routes/access/index.mjs +11 -11
  111. package/server/routes/access/schema.mjs +67 -67
  112. package/server/routes/calendar/controllers/calendar.data.js +125 -125
  113. package/server/routes/calendar/index.mjs +7 -7
  114. package/server/routes/calendar/schema.js +21 -21
  115. package/server/routes/data/controllers/cardData.js +127 -127
  116. package/server/routes/data/controllers/cardTabData.js +49 -49
  117. package/server/routes/data/controllers/funcs/getFilterSQL/index.js +92 -92
  118. package/server/routes/data/controllers/funcs/getFilterSQL/util/formatValue.js +170 -170
  119. package/server/routes/data/controllers/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  120. package/server/routes/data/controllers/funcs/getFilterSQL/util/getFilterQuery.js +64 -64
  121. package/server/routes/data/controllers/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  122. package/server/routes/data/controllers/funcs/getFilterSQL/util/getTableSql.js +34 -34
  123. package/server/routes/data/controllers/tableData.js +31 -31
  124. package/server/routes/data/controllers/tableDataId.js +27 -27
  125. package/server/routes/data/controllers/tableFilter.js +9 -9
  126. package/server/routes/data/controllers/tableInfo.js +112 -112
  127. package/server/routes/data/controllers/tokenInfo.js +9 -9
  128. package/server/routes/data/controllers/utils/assignTokens.js +30 -30
  129. package/server/routes/data/controllers/utils/conditions.js +20 -20
  130. package/server/routes/data/controllers/utils/getColumns.js +8 -8
  131. package/server/routes/data/index.mjs +20 -20
  132. package/server/routes/data/schema.js +54 -54
  133. package/server/routes/dblist/controllers/readItems.js +20 -20
  134. package/server/routes/dblist/controllers/setItem.js +22 -22
  135. package/server/routes/dblist/index.mjs +18 -18
  136. package/server/routes/dblist/utils/formatData.js +7 -7
  137. package/server/routes/menu/controllers/getMenu.js +77 -77
  138. package/server/routes/menu/controllers/interfaces.js +20 -20
  139. package/server/routes/menu/index.mjs +7 -7
  140. package/server/routes/notifications/controllers/readNotifications.js +27 -27
  141. package/server/routes/notifications/controllers/testEmail.js +35 -35
  142. package/server/routes/notifications/controllers/userNotifications.js +53 -53
  143. package/server/routes/notifications/funcs/addNotification.js +21 -21
  144. package/server/routes/notifications/funcs/sendNotification.js +92 -92
  145. package/server/routes/notifications/hook/onWidgetSet.js +56 -56
  146. package/server/routes/notifications/index.mjs +26 -26
  147. package/server/routes/notifications/schema.js +16 -16
  148. package/server/routes/print/controllers/cardPrint.js +135 -135
  149. package/server/routes/print/controllers/printTemplate.add.js +37 -37
  150. package/server/routes/print/controllers/printTemplate.delete.js +29 -29
  151. package/server/routes/print/controllers/printTemplate.edit.js +42 -42
  152. package/server/routes/print/controllers/printTemplate.js +67 -67
  153. package/server/routes/print/controllers/printTemplateList.js +19 -19
  154. package/server/routes/print/controllers/printTemplatePreview.js +87 -87
  155. package/server/routes/print/index.mjs +19 -19
  156. package/server/routes/properties/controllers/admin.properties.get.js +31 -31
  157. package/server/routes/properties/controllers/table.properties.get.js +120 -120
  158. package/server/routes/properties/controllers/table.properties.post.js +115 -115
  159. package/server/routes/properties/controllers/user.properties.get.js +19 -19
  160. package/server/routes/properties/controllers/user.properties.post.js +10 -10
  161. package/server/routes/properties/index.mjs +21 -21
  162. package/server/routes/properties/schema.js +10 -10
  163. package/server/routes/properties/utils/dataInsert.js +26 -26
  164. package/server/routes/properties/utils/getColumnMetaData.js +17 -17
  165. package/server/routes/properties/utils/refreshData.js +128 -128
  166. package/server/routes/report/controllers/data.js +76 -76
  167. package/server/routes/report/controllers/list.js +18 -18
  168. package/server/routes/report/index.mjs +7 -7
  169. package/server/routes/report/utils/formatValue.js +179 -179
  170. package/server/routes/report/utils/getFilterQuery.js +67 -67
  171. package/server/routes/root.mjs +3 -3
  172. package/server/routes/templates/controllers/getTemplate.js +44 -44
  173. package/server/routes/templates/index.mjs +16 -16
  174. package/server/routes/templates/schema.js +8 -8
  175. package/server/routes/user/controllers/user.cls.id.js +14 -14
  176. package/server/routes/user/controllers/user.cls.js +72 -72
  177. package/server/routes/user/controllers/user.cls.post.js +54 -54
  178. package/server/routes/user/controllers/user.info.js +17 -17
  179. package/server/routes/user/schema.js +14 -14
  180. package/server/routes/util/controllers/code.generator.js +89 -89
  181. package/server/routes/util/index.mjs +5 -5
  182. package/server/routes/widget/controllers/widget.del.js +63 -63
  183. package/server/routes/widget/controllers/widget.get.js +125 -125
  184. package/server/routes/widget/controllers/widget.set.js +84 -84
  185. package/server/routes/widget/hook/onWidgetSet.js +12 -12
  186. package/server/routes/widget/index.mjs +16 -16
  187. package/server/routes/widget/schema.js +12 -12
  188. package/server/templates/cls/itree.recrzone_category.json +73 -73
  189. package/server/templates/cls/test.json +9 -9
  190. package/server/templates/form/admin.profile.form.json +31 -31
  191. package/server/templates/form/admin.user_cls.data.form.json +49 -49
  192. package/server/templates/form/admin.user_group_rel.form.json +21 -21
  193. package/server/templates/form/cp_building.form.json +32 -32
  194. package/server/templates/form/form-user-pass.json +10 -10
  195. package/server/templates/form/form-user_group.json +39 -39
  196. package/server/templates/form/form-users.json +156 -156
  197. package/server/templates/form/user_group_access.form.json +22 -22
  198. package/server/templates/pt/card-print.pt.hbs +245 -245
  199. package/server/templates/select/account_id.json +2 -2
  200. package/server/templates/table/gis.dataset.table.json +43 -43
  201. package/server/templates/table/management.user_group.table.json +112 -112
  202. package/server/templates/table/management.users.table.json +126 -126
  203. package/utils.js +26 -26
@@ -1,126 +1,126 @@
1
- import { getMeta, getTemplate, pgClients, handlebarsSync } from '@opengis/fastify-table/utils.js';
2
-
3
- const isValidDate = (dateStr) => (new Date(dateStr)).toString() !== 'Invalid Date';
4
-
5
- export default async function calendarData({
6
- pg = pgClients.client, params = {}, query = {}, session = {},
7
- }) {
8
- const { name } = params;
9
- const { granularity = 'month' } = query;
10
- const { user = {} } = session.passport || {};
11
-
12
- if (!name) {
13
- return { message: 'not enough params: name', status: 400 };
14
- }
15
-
16
- if (query.granularity && !['day', 'month', 'week', 'year'].includes(granularity)) {
17
- return { message: 'invalid query params: granularity', status: 400 };
18
- }
19
-
20
- const body = await getTemplate('calendar', name);
21
-
22
- if (!body) {
23
- return { message: `calendar not found: ${name}`, status: 404 };
24
- }
25
-
26
- const {
27
- title,
28
- table,
29
- meta = {},
30
- } = body || {};
31
-
32
- if (!table) {
33
- return { message: 'not enough calendar params: table', status: 404 };
34
- }
35
- if (!pg.pk?.[table]) {
36
- return { message: `table pkey not found: ${table}`, status: 404 };
37
- }
38
-
39
- const filterList = (body?.filter || [])
40
- .concat(body?.filterInline || [])
41
- .concat(body?.filterCustom || [])
42
- .concat(body?.filterState || [])
43
- .concat(body?.filterList || [])
44
- .concat(body?.filters || [])
45
- .concat(body?.filter_list || []);
46
-
47
- const { columns = [] } = await getMeta({ pg, table });
48
- const columnList = columns?.map((el) => el?.name);
49
-
50
- const dateColumn = columns?.find((el) => el?.name === (meta?.date || meta?.start))?.name
51
- || columns?.find((el) => el?.name === 'cdate')?.name;
52
-
53
- if (query.date && !dateColumn) {
54
- return { message: 'invalid template params: date column not found', status: 400 };
55
- }
56
-
57
- if (query.date && !isValidDate(query.date)) {
58
- return { message: 'Invalid date: out of range or incorrect format', status: 400 };
59
- }
60
-
61
- const filterWhere = filterList?.length && query.filter?.length
62
- ? filterList
63
- .filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true))
64
- .map((el) => {
65
- const val = query.filter.split(',').find((e) => e?.split('=')?.shift()?.includes(el.column || el.name))?.split('=')?.pop();
66
- if (val) return el.column && val ? `(${[`${el.column}::text='${val.replace(/'/g, "''")}'::text`, el.query].filter((el) => el).join(' and ')})` : el.query;
67
- })
68
- .filter((el) => el)
69
- .join(' and ')
70
- : undefined;
71
-
72
- const queryWhere = handlebarsSync.compile(body.query || '1=1')({ user, uid: user?.uid });
73
- const filterDate = query.date ? `date_trunc('${granularity}', "${dateColumn}"::date)='${query.date}'::date` : undefined;
74
-
75
- const where = [queryWhere, filterDate, filterWhere].filter((el) => el).join(' and ');
76
-
77
- const filtersByColumn = filterList.filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true) && el?.column);
78
-
79
- const filters = [];
80
- if (filtersByColumn?.length) {
81
- await Promise.all(filtersByColumn.map(async (el) => {
82
- const { rows: filterData = [] } = await pg.query(`select ${el.column.replace(/'/g, "''")} as id, count(*) from ${table}
83
- where ${el.query || '1=1'} and ${filterWhere || '1=1'} group by ${el.column.replace(/'/g, "''")}`);
84
- if (!filterData?.length) return;
85
-
86
- const clsData = await getTemplate(['cls', 'select'], el.cls);
87
-
88
- if (!el.cls || !clsData?.length) {
89
- filterData.forEach((item) => filters.push(item));
90
- return;
91
- }
92
-
93
- filterData.forEach((filter) => {
94
- const cls = clsData.find((item) => item.id === filter.id.toString());
95
- Object.assign(filter, { title: cls?.text, color: cls?.color });
96
- filters.push(filter);
97
- });
98
- }));
99
- }
100
-
101
- const filtersByPreparedQuery = filterList.filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true) && !el?.column && el?.query);
102
-
103
- if (filtersByPreparedQuery?.length) {
104
- await Promise.all(filtersByPreparedQuery.map(async (el) => {
105
- const { rows = [] } = await pg.query(`select ${el.query} as id, count(*) from ${table}
106
- where ${filterWhere || '1=1'} group by ${el.query}`);
107
- rows.forEach((item) => filters.push(item));
108
- }));
109
- }
110
-
111
- const metaColumns = Object.keys(meta)
112
- .filter((el) => ['date', 'start', 'end', 'title', 'status'].includes(el) && columnList.includes(meta[el]))
113
- .map((el) => `"${meta[el]}" as ${el}`);
114
-
115
- if (!metaColumns?.length) {
116
- return { message: `calendar param meta is invalid: invalid/empty keys`, status: 404 };
117
- }
118
-
119
- const q = `select ${metaColumns.join(',')} from ${table} where ${where}`;
120
- if (query?.sql && user?.user_type?.includes('admin')) return q;
121
-
122
- const { rows = [] } = await pg.query(q);
123
-
124
- return { title, filters, granularity, sql: user?.user_type?.includes('admin') ? q : undefined, rows };
125
-
1
+ import { getMeta, getTemplate, pgClients, handlebarsSync } from '@opengis/fastify-table/utils.js';
2
+
3
+ const isValidDate = (dateStr) => (new Date(dateStr)).toString() !== 'Invalid Date';
4
+
5
+ export default async function calendarData({
6
+ pg = pgClients.client, params = {}, query = {}, session = {},
7
+ }) {
8
+ const { name } = params;
9
+ const { granularity = 'month' } = query;
10
+ const { user = {} } = session.passport || {};
11
+
12
+ if (!name) {
13
+ return { message: 'not enough params: name', status: 400 };
14
+ }
15
+
16
+ if (query.granularity && !['day', 'month', 'week', 'year'].includes(granularity)) {
17
+ return { message: 'invalid query params: granularity', status: 400 };
18
+ }
19
+
20
+ const body = await getTemplate('calendar', name);
21
+
22
+ if (!body) {
23
+ return { message: `calendar not found: ${name}`, status: 404 };
24
+ }
25
+
26
+ const {
27
+ title,
28
+ table,
29
+ meta = {},
30
+ } = body || {};
31
+
32
+ if (!table) {
33
+ return { message: 'not enough calendar params: table', status: 404 };
34
+ }
35
+ if (!pg.pk?.[table]) {
36
+ return { message: `table pkey not found: ${table}`, status: 404 };
37
+ }
38
+
39
+ const filterList = (body?.filter || [])
40
+ .concat(body?.filterInline || [])
41
+ .concat(body?.filterCustom || [])
42
+ .concat(body?.filterState || [])
43
+ .concat(body?.filterList || [])
44
+ .concat(body?.filters || [])
45
+ .concat(body?.filter_list || []);
46
+
47
+ const { columns = [] } = await getMeta({ pg, table });
48
+ const columnList = columns?.map((el) => el?.name);
49
+
50
+ const dateColumn = columns?.find((el) => el?.name === (meta?.date || meta?.start))?.name
51
+ || columns?.find((el) => el?.name === 'cdate')?.name;
52
+
53
+ if (query.date && !dateColumn) {
54
+ return { message: 'invalid template params: date column not found', status: 400 };
55
+ }
56
+
57
+ if (query.date && !isValidDate(query.date)) {
58
+ return { message: 'Invalid date: out of range or incorrect format', status: 400 };
59
+ }
60
+
61
+ const filterWhere = filterList?.length && query.filter?.length
62
+ ? filterList
63
+ .filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true))
64
+ .map((el) => {
65
+ const val = query.filter.split(',').find((e) => e?.split('=')?.shift()?.includes(el.column || el.name))?.split('=')?.pop();
66
+ if (val) return el.column && val ? `(${[`${el.column}::text='${val.replace(/'/g, "''")}'::text`, el.query].filter((el) => el).join(' and ')})` : el.query;
67
+ })
68
+ .filter((el) => el)
69
+ .join(' and ')
70
+ : undefined;
71
+
72
+ const queryWhere = handlebarsSync.compile(body.query || '1=1')({ user, uid: user?.uid });
73
+ const filterDate = query.date ? `date_trunc('${granularity}', "${dateColumn}"::date)='${query.date}'::date` : undefined;
74
+
75
+ const where = [queryWhere, filterDate, filterWhere].filter((el) => el).join(' and ');
76
+
77
+ const filtersByColumn = filterList.filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true) && el?.column);
78
+
79
+ const filters = [];
80
+ if (filtersByColumn?.length) {
81
+ await Promise.all(filtersByColumn.map(async (el) => {
82
+ const { rows: filterData = [] } = await pg.query(`select ${el.column.replace(/'/g, "''")} as id, count(*) from ${table}
83
+ where ${el.query || '1=1'} and ${filterWhere || '1=1'} group by ${el.column.replace(/'/g, "''")}`);
84
+ if (!filterData?.length) return;
85
+
86
+ const clsData = await getTemplate(['cls', 'select'], el.cls);
87
+
88
+ if (!el.cls || !clsData?.length) {
89
+ filterData.forEach((item) => filters.push(item));
90
+ return;
91
+ }
92
+
93
+ filterData.forEach((filter) => {
94
+ const cls = clsData.find((item) => item.id === filter.id.toString());
95
+ Object.assign(filter, { title: cls?.text, color: cls?.color });
96
+ filters.push(filter);
97
+ });
98
+ }));
99
+ }
100
+
101
+ const filtersByPreparedQuery = filterList.filter((el) => (Object.hasOwn(el, 'enabled') ? el?.enabled : true) && !el?.column && el?.query);
102
+
103
+ if (filtersByPreparedQuery?.length) {
104
+ await Promise.all(filtersByPreparedQuery.map(async (el) => {
105
+ const { rows = [] } = await pg.query(`select ${el.query} as id, count(*) from ${table}
106
+ where ${filterWhere || '1=1'} group by ${el.query}`);
107
+ rows.forEach((item) => filters.push(item));
108
+ }));
109
+ }
110
+
111
+ const metaColumns = Object.keys(meta)
112
+ .filter((el) => ['date', 'start', 'end', 'title', 'status'].includes(el) && columnList.includes(meta[el]))
113
+ .map((el) => `"${meta[el]}" as ${el}`);
114
+
115
+ if (!metaColumns?.length) {
116
+ return { message: `calendar param meta is invalid: invalid/empty keys`, status: 404 };
117
+ }
118
+
119
+ const q = `select ${metaColumns.join(',')} from ${table} where ${where}`;
120
+ if (query?.sql && user?.user_type?.includes('admin')) return q;
121
+
122
+ const { rows = [] } = await pg.query(q);
123
+
124
+ return { title, filters, granularity, sql: user?.user_type?.includes('admin') ? q : undefined, rows };
125
+
126
126
  }
@@ -1,7 +1,7 @@
1
- import calendarData from "./controllers/calendar.data.js";
2
-
3
- import { calendarDataSchema } from './schema.js';
4
-
5
- export default async function route(fastify) {
6
- fastify.get('/calendar/:name', { schema: calendarDataSchema }, calendarData);
7
- }
1
+ import calendarData from "./controllers/calendar.data.js";
2
+
3
+ import { calendarDataSchema } from './schema.js';
4
+
5
+ export default async function route(fastify) {
6
+ fastify.get('/calendar/:name', { schema: calendarDataSchema }, calendarData);
7
+ }
@@ -1,22 +1,22 @@
1
- const calendarDataSchema = {
2
- params: {
3
- name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
4
- },
5
- querystring: {
6
- date: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$' },
7
- sql: { type: 'string', pattern: '^(\\d)$' },
8
- },
9
-
10
- // query: {
11
- // type: 'object',
12
- // properties: {
13
- // date: {
14
- // type: 'string',
15
- // format: 'date',
16
- // },
17
- // },
18
- // },
19
- };
20
-
21
- export { calendarDataSchema }
1
+ const calendarDataSchema = {
2
+ params: {
3
+ name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
4
+ },
5
+ querystring: {
6
+ date: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$' },
7
+ sql: { type: 'string', pattern: '^(\\d)$' },
8
+ },
9
+
10
+ // query: {
11
+ // type: 'object',
12
+ // properties: {
13
+ // date: {
14
+ // type: 'string',
15
+ // format: 'date',
16
+ // },
17
+ // },
18
+ // },
19
+ };
20
+
21
+ export { calendarDataSchema }
22
22
  export default null;
@@ -1,128 +1,128 @@
1
- import path from 'node:path';
2
-
3
- import { getAccess, handlebars, setOpt, setToken, getTemplate, handlebarsSync, applyHook } from "@opengis/fastify-table/utils.js";
4
- //import { setOpt, setToken } from "../../../../../fastify-table/utils.js";
5
- // import yaml from 'js-yaml';
6
- import getTableData from "./tableData.js";
7
- import conditions from './utils/conditions.js';
8
-
9
- const components = {
10
- 'vs-widget-file': `select 'vs-widget-file' as component, count(*) from crm.files where entity_id=$1 and file_status<>3`,
11
- 'vs-widget-comments': `select 'vs-widget-comments' as component, count(*) from crm.communications where entity_id=$1`
12
- };
13
-
14
- export default async function getCardData(req) {
15
-
16
- const {
17
- pg, params = {}, session = {}, user
18
- } = req;
19
- const { table, id } = params;
20
- const uid = session.passport?.user?.uid;
21
-
22
- const res = await applyHook('cardData', { table, id, user });
23
- if (res) return res;
24
-
25
-
26
- const time = Date.now();
27
-
28
- const template = await getTemplate('card', table);
29
- const access = await getAccess({ table, user });
30
-
31
- const tableTemplate = await getTemplate('table', table);
32
-
33
- const index = template?.find(el => el[0] === 'index.yml')?.[1] || {};
34
-
35
- const { message, rows = [] } = index.table && index.query ? await pg.query(`select * from ${index.table} where ${handlebarsSync.compile(index.query)({ uid, user })}`) :
36
- await getTableData({ pg, params: { table, id }, session, user });
37
-
38
- if (message) return { message };
39
-
40
- // conditions
41
- index.panels?.filter(el => el.items).forEach(el => {
42
- el.items = el.items?.filter(el => conditions(el.conditions, rows[0]));
43
- })
44
-
45
- // title, count
46
- index.panels?.filter(el => el.items).forEach(async el => {
47
- const filtered = el.items.filter(el => el.count?.toLowerCase?.().includes('select'));
48
- const data = await Promise.all(filtered.map(el => pg.query(el.count).then(el => el.rows[0] || {})))
49
- filtered.forEach((el, i) => {
50
- Object.assign(el, data[i] || {}, data[i].count ? {} : { count: undefined })
51
- });
52
- const q = el.items.map((el) => el.component ? components[el.component] : null).filter(el => el).join(' union all ');
53
- const counts = q && id
54
- ? await pg.query(q, [id])
55
- .then(e => e.rows.reduce((acc, curr) => Object.assign(acc, { [curr.component]: curr.count }), {}))
56
- : {};
57
- el.items?.filter?.(item => item.component)?.forEach(item => Object.assign(item, { count: counts?.[item.component] }));
58
- })
59
-
60
-
61
- // tokens result
62
- const tokens = {};
63
- if (index?.tokens && typeof index?.tokens === 'object' && !Array.isArray(index?.tokens)) {
64
- Object.keys(index.tokens || {})
65
- .filter(key => index?.tokens[key]?.public
66
- || access.actions?.includes?.('edit')
67
- || access.actions?.includes?.('add')
68
- || !index?.tokens[key]?.table
69
- )
70
- .forEach(key => {
71
- const item = index?.tokens[key];
72
- Object.keys(item).filter(el => item[el]?.includes?.('{{')).forEach(el => {
73
- item[el] = handlebarsSync.compile(item[el])({ user, uid: user?.uid, id, data: rows[0] });
74
- });
75
-
76
- const token = item.form && item.table ? setToken({
77
- ids: [JSON.stringify(item)],
78
- uid,
79
- array: 1,
80
- })[0] : setOpt(item, user.uid);
81
- tokens[key] = token;
82
- });
83
- }
84
-
85
- // vue result
86
- const vue = template?.filter((el) => el[0].endsWith('.vue'))
87
- .reduce((acc, curr) => Object.assign(acc, { [path.parse(curr[0]).name]: curr[1].match(/<template[^>]*>([\s\S]*?)<\/template>/)[1].trim() }), {});
88
-
89
- // data result
90
- const data = {};
91
- const route = await pg.query(`select route_id as path, title from admin.routes where enabled and alias=$1 limit 1`, [table])
92
- .then(el => el.rows?.[0] || {});
93
- Object.assign(route, { tableTitle: tableTemplate?.title });
94
- if (index?.data && index?.data?.[0]?.name) {
95
- await Promise.all(index.data.filter((el) => el?.name && el?.sql).map(async (el) => {
96
- const q = handlebarsSync.compile(el.sql)({ data: rows[0], user, uid: user?.uid, id });
97
- const { rows: sqlData } = await pg.query(q);
98
- data[el.name] = sqlData;
99
- }));
100
- }
101
-
102
-
103
-
104
- // html result
105
- const html = {};
106
- if (template) {
107
- await Promise.all(template.filter(el => el[0].includes('.hbs')).map(async (el) => {
108
- const htmlContent = await handlebars.compile(el[1])({ ...rows[0], user, data, tokens });
109
- const name = el[0].substring(0, el[0].lastIndexOf('.'))
110
- html[name] = htmlContent;
111
- }));
112
- }
113
-
114
- return {
115
- time: Date.now() - time,
116
- ...index,
117
- tokens,
118
- vue,
119
- data,
120
- route,
121
- html,
122
- rows,
123
- columns: tableTemplate?.columns || tableTemplate?.colModel,
124
- table: undefined,
125
- query: undefined,
126
- };
127
-
1
+ import path from 'node:path';
2
+
3
+ import { getAccess, handlebars, setOpt, setToken, getTemplate, handlebarsSync, applyHook } from "@opengis/fastify-table/utils.js";
4
+ //import { setOpt, setToken } from "../../../../../fastify-table/utils.js";
5
+ // import yaml from 'js-yaml';
6
+ import getTableData from "./tableData.js";
7
+ import conditions from './utils/conditions.js';
8
+
9
+ const components = {
10
+ 'vs-widget-file': `select 'vs-widget-file' as component, count(*) from crm.files where entity_id=$1 and file_status<>3`,
11
+ 'vs-widget-comments': `select 'vs-widget-comments' as component, count(*) from crm.communications where entity_id=$1`
12
+ };
13
+
14
+ export default async function getCardData(req) {
15
+
16
+ const {
17
+ pg, params = {}, session = {}, user
18
+ } = req;
19
+ const { table, id } = params;
20
+ const uid = session.passport?.user?.uid;
21
+
22
+ const res = await applyHook('cardData', { table, id, user });
23
+ if (res) return res;
24
+
25
+
26
+ const time = Date.now();
27
+
28
+ const template = await getTemplate('card', table);
29
+ const access = await getAccess({ table, user });
30
+
31
+ const tableTemplate = await getTemplate('table', table);
32
+
33
+ const index = template?.find(el => el[0] === 'index.yml')?.[1] || {};
34
+
35
+ const { message, rows = [] } = index.table && index.query ? await pg.query(`select * from ${index.table} where ${handlebarsSync.compile(index.query)({ uid, user })}`) :
36
+ await getTableData({ pg, params: { table, id }, session, user });
37
+
38
+ if (message) return { message };
39
+
40
+ // conditions
41
+ index.panels?.filter(el => el.items).forEach(el => {
42
+ el.items = el.items?.filter(el => conditions(el.conditions, rows[0]));
43
+ })
44
+
45
+ // title, count
46
+ index.panels?.filter(el => el.items).forEach(async el => {
47
+ const filtered = el.items.filter(el => el.count?.toLowerCase?.().includes('select'));
48
+ const data = await Promise.all(filtered.map(el => pg.query(el.count).then(el => el.rows[0] || {})))
49
+ filtered.forEach((el, i) => {
50
+ Object.assign(el, data[i] || {}, data[i].count ? {} : { count: undefined })
51
+ });
52
+ const q = el.items.map((el) => el.component ? components[el.component] : null).filter(el => el).join(' union all ');
53
+ const counts = q && id
54
+ ? await pg.query(q, [id])
55
+ .then(e => e.rows.reduce((acc, curr) => Object.assign(acc, { [curr.component]: curr.count }), {}))
56
+ : {};
57
+ el.items?.filter?.(item => item.component)?.forEach(item => Object.assign(item, { count: counts?.[item.component] }));
58
+ })
59
+
60
+
61
+ // tokens result
62
+ const tokens = {};
63
+ if (index?.tokens && typeof index?.tokens === 'object' && !Array.isArray(index?.tokens)) {
64
+ Object.keys(index.tokens || {})
65
+ .filter(key => index?.tokens[key]?.public
66
+ || access.actions?.includes?.('edit')
67
+ || access.actions?.includes?.('add')
68
+ || !index?.tokens[key]?.table
69
+ )
70
+ .forEach(key => {
71
+ const item = index?.tokens[key];
72
+ Object.keys(item).filter(el => item[el]?.includes?.('{{')).forEach(el => {
73
+ item[el] = handlebarsSync.compile(item[el])({ user, uid: user?.uid, id, data: rows[0] });
74
+ });
75
+
76
+ const token = item.form && item.table ? setToken({
77
+ ids: [JSON.stringify(item)],
78
+ uid,
79
+ array: 1,
80
+ })[0] : setOpt(item, user.uid);
81
+ tokens[key] = token;
82
+ });
83
+ }
84
+
85
+ // vue result
86
+ const vue = template?.filter((el) => el[0].endsWith('.vue'))
87
+ .reduce((acc, curr) => Object.assign(acc, { [path.parse(curr[0]).name]: curr[1].match(/<template[^>]*>([\s\S]*?)<\/template>/)[1].trim() }), {});
88
+
89
+ // data result
90
+ const data = {};
91
+ const route = await pg.query(`select route_id as path, title from admin.routes where enabled and alias=$1 limit 1`, [table])
92
+ .then(el => el.rows?.[0] || {});
93
+ Object.assign(route, { tableTitle: tableTemplate?.title });
94
+ if (index?.data && index?.data?.[0]?.name) {
95
+ await Promise.all(index.data.filter((el) => el?.name && el?.sql).map(async (el) => {
96
+ const q = handlebarsSync.compile(el.sql)({ data: rows[0], user, uid: user?.uid, id });
97
+ const { rows: sqlData } = await pg.query(q);
98
+ data[el.name] = sqlData;
99
+ }));
100
+ }
101
+
102
+
103
+
104
+ // html result
105
+ const html = {};
106
+ if (template) {
107
+ await Promise.all(template.filter(el => el[0].includes('.hbs')).map(async (el) => {
108
+ const htmlContent = await handlebars.compile(el[1])({ ...rows[0], user, data, tokens });
109
+ const name = el[0].substring(0, el[0].lastIndexOf('.'))
110
+ html[name] = htmlContent;
111
+ }));
112
+ }
113
+
114
+ return {
115
+ time: Date.now() - time,
116
+ ...index,
117
+ tokens,
118
+ vue,
119
+ data,
120
+ route,
121
+ html,
122
+ rows,
123
+ columns: tableTemplate?.columns || tableTemplate?.colModel,
124
+ table: undefined,
125
+ query: undefined,
126
+ };
127
+
128
128
  }