@saltcorn/data 1.6.0-alpha.9 → 1.6.0-beta.1

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 (207) hide show
  1. package/dist/base-plugin/actions.d.ts +3 -3
  2. package/dist/base-plugin/actions.d.ts.map +1 -1
  3. package/dist/base-plugin/actions.js +59 -17
  4. package/dist/base-plugin/actions.js.map +1 -1
  5. package/dist/base-plugin/index.d.ts +10 -5
  6. package/dist/base-plugin/index.d.ts.map +1 -1
  7. package/dist/base-plugin/types.d.ts +7 -2
  8. package/dist/base-plugin/types.d.ts.map +1 -1
  9. package/dist/base-plugin/types.js +9 -4
  10. package/dist/base-plugin/types.js.map +1 -1
  11. package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
  12. package/dist/base-plugin/viewtemplates/edit.js +3 -0
  13. package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
  14. package/dist/base-plugin/viewtemplates/filter.d.ts.map +1 -1
  15. package/dist/base-plugin/viewtemplates/filter.js +11 -3
  16. package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
  17. package/dist/base-plugin/viewtemplates/list.d.ts +2 -1
  18. package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
  19. package/dist/base-plugin/viewtemplates/list.js +6 -1
  20. package/dist/base-plugin/viewtemplates/list.js.map +1 -1
  21. package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
  22. package/dist/base-plugin/viewtemplates/show.js +3 -0
  23. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  24. package/dist/db/state.d.ts +4 -0
  25. package/dist/db/state.d.ts.map +1 -1
  26. package/dist/db/state.js +27 -4
  27. package/dist/db/state.js.map +1 -1
  28. package/dist/migrate.d.ts.map +1 -1
  29. package/dist/migrate.js +9 -4
  30. package/dist/migrate.js.map +1 -1
  31. package/dist/migrations/202603101553.d.ts +4 -0
  32. package/dist/migrations/202603101553.d.ts.map +1 -0
  33. package/dist/migrations/202603101553.js +22 -0
  34. package/dist/migrations/202603101553.js.map +1 -0
  35. package/dist/mobile-mocks/node/assert.d.ts +1 -0
  36. package/dist/mobile-mocks/node/assert.d.ts.map +1 -0
  37. package/dist/mobile-mocks/node/assert.js +2 -0
  38. package/dist/mobile-mocks/node/assert.js.map +1 -0
  39. package/dist/models/expression.d.ts +1 -1
  40. package/dist/models/expression.d.ts.map +1 -1
  41. package/dist/models/expression.js +51 -16
  42. package/dist/models/expression.js.map +1 -1
  43. package/dist/models/field.d.ts.map +1 -1
  44. package/dist/models/field.js +67 -10
  45. package/dist/models/field.js.map +1 -1
  46. package/dist/models/index.d.ts +1 -1
  47. package/dist/models/index.d.ts.map +1 -1
  48. package/dist/models/internal/push_message_helper.d.ts.map +1 -1
  49. package/dist/models/internal/push_message_helper.js +5 -2
  50. package/dist/models/internal/push_message_helper.js.map +1 -1
  51. package/dist/models/metadata.d.ts +2 -1
  52. package/dist/models/metadata.d.ts.map +1 -1
  53. package/dist/models/metadata.js +5 -0
  54. package/dist/models/metadata.js.map +1 -1
  55. package/dist/models/page.d.ts.map +1 -1
  56. package/dist/models/page.js +3 -1
  57. package/dist/models/page.js.map +1 -1
  58. package/dist/models/plugin.d.ts +2 -2
  59. package/dist/models/plugin.d.ts.map +1 -1
  60. package/dist/models/plugin.js +2 -2
  61. package/dist/models/plugin.js.map +1 -1
  62. package/dist/models/table.d.ts +8 -0
  63. package/dist/models/table.d.ts.map +1 -1
  64. package/dist/models/table.js +196 -83
  65. package/dist/models/table.js.map +1 -1
  66. package/dist/models/trigger.d.ts.map +1 -1
  67. package/dist/models/trigger.js +20 -9
  68. package/dist/models/trigger.js.map +1 -1
  69. package/dist/models/user.d.ts.map +1 -1
  70. package/dist/models/user.js +4 -0
  71. package/dist/models/user.js.map +1 -1
  72. package/dist/models/workflow.d.ts.map +1 -1
  73. package/dist/models/workflow.js +6 -0
  74. package/dist/models/workflow.js.map +1 -1
  75. package/dist/plugin-helper.d.ts.map +1 -1
  76. package/dist/plugin-helper.js +4 -0
  77. package/dist/plugin-helper.js.map +1 -1
  78. package/dist/viewable_fields.d.ts +2 -2
  79. package/dist/viewable_fields.d.ts.map +1 -1
  80. package/dist/viewable_fields.js +13 -8
  81. package/dist/viewable_fields.js.map +1 -1
  82. package/package.json +8 -8
  83. package/webpack.config.js +1 -0
  84. package/dist/tests/actions.test.d.ts +0 -2
  85. package/dist/tests/actions.test.d.ts.map +0 -1
  86. package/dist/tests/actions.test.js +0 -936
  87. package/dist/tests/actions.test.js.map +0 -1
  88. package/dist/tests/auth.test.d.ts +0 -2
  89. package/dist/tests/auth.test.d.ts.map +0 -1
  90. package/dist/tests/auth.test.js +0 -824
  91. package/dist/tests/auth.test.js.map +0 -1
  92. package/dist/tests/auxtest.test.d.ts +0 -2
  93. package/dist/tests/auxtest.test.d.ts.map +0 -1
  94. package/dist/tests/auxtest.test.js +0 -562
  95. package/dist/tests/auxtest.test.js.map +0 -1
  96. package/dist/tests/base.test.d.ts +0 -2
  97. package/dist/tests/base.test.d.ts.map +0 -1
  98. package/dist/tests/base.test.js +0 -30
  99. package/dist/tests/base.test.js.map +0 -1
  100. package/dist/tests/calc.test.d.ts +0 -2
  101. package/dist/tests/calc.test.d.ts.map +0 -1
  102. package/dist/tests/calc.test.js +0 -1081
  103. package/dist/tests/calc.test.js.map +0 -1
  104. package/dist/tests/composite_pk.test.d.ts +0 -2
  105. package/dist/tests/composite_pk.test.d.ts.map +0 -1
  106. package/dist/tests/composite_pk.test.js +0 -98
  107. package/dist/tests/composite_pk.test.js.map +0 -1
  108. package/dist/tests/config.test.d.ts +0 -2
  109. package/dist/tests/config.test.d.ts.map +0 -1
  110. package/dist/tests/config.test.js +0 -86
  111. package/dist/tests/config.test.js.map +0 -1
  112. package/dist/tests/db.test.d.ts +0 -2
  113. package/dist/tests/db.test.d.ts.map +0 -1
  114. package/dist/tests/db.test.js +0 -178
  115. package/dist/tests/db.test.js.map +0 -1
  116. package/dist/tests/discover.test.d.ts +0 -2
  117. package/dist/tests/discover.test.d.ts.map +0 -1
  118. package/dist/tests/discover.test.js +0 -245
  119. package/dist/tests/discover.test.js.map +0 -1
  120. package/dist/tests/edit.test.d.ts +0 -2
  121. package/dist/tests/edit.test.d.ts.map +0 -1
  122. package/dist/tests/edit.test.js +0 -1161
  123. package/dist/tests/edit.test.js.map +0 -1
  124. package/dist/tests/email.test.d.ts +0 -2
  125. package/dist/tests/email.test.d.ts.map +0 -1
  126. package/dist/tests/email.test.js +0 -255
  127. package/dist/tests/email.test.js.map +0 -1
  128. package/dist/tests/exact_views.test.d.ts +0 -2
  129. package/dist/tests/exact_views.test.d.ts.map +0 -1
  130. package/dist/tests/exact_views.test.js +0 -1363
  131. package/dist/tests/exact_views.test.js.map +0 -1
  132. package/dist/tests/field.test.d.ts +0 -2
  133. package/dist/tests/field.test.d.ts.map +0 -1
  134. package/dist/tests/field.test.js +0 -588
  135. package/dist/tests/field.test.js.map +0 -1
  136. package/dist/tests/fieldviews.test.d.ts +0 -2
  137. package/dist/tests/fieldviews.test.d.ts.map +0 -1
  138. package/dist/tests/fieldviews.test.js +0 -74
  139. package/dist/tests/fieldviews.test.js.map +0 -1
  140. package/dist/tests/file.test.d.ts +0 -2
  141. package/dist/tests/file.test.d.ts.map +0 -1
  142. package/dist/tests/file.test.js +0 -148
  143. package/dist/tests/file.test.js.map +0 -1
  144. package/dist/tests/filter.test.d.ts +0 -2
  145. package/dist/tests/filter.test.d.ts.map +0 -1
  146. package/dist/tests/filter.test.js +0 -496
  147. package/dist/tests/filter.test.js.map +0 -1
  148. package/dist/tests/form.test.d.ts +0 -2
  149. package/dist/tests/form.test.d.ts.map +0 -1
  150. package/dist/tests/form.test.js +0 -264
  151. package/dist/tests/form.test.js.map +0 -1
  152. package/dist/tests/list.test.d.ts +0 -2
  153. package/dist/tests/list.test.d.ts.map +0 -1
  154. package/dist/tests/list.test.js +0 -1037
  155. package/dist/tests/list.test.js.map +0 -1
  156. package/dist/tests/models.test.d.ts +0 -2
  157. package/dist/tests/models.test.d.ts.map +0 -1
  158. package/dist/tests/models.test.js +0 -417
  159. package/dist/tests/models.test.js.map +0 -1
  160. package/dist/tests/page.test.d.ts +0 -2
  161. package/dist/tests/page.test.d.ts.map +0 -1
  162. package/dist/tests/page.test.js +0 -26
  163. package/dist/tests/page.test.js.map +0 -1
  164. package/dist/tests/page_group.test.d.ts +0 -2
  165. package/dist/tests/page_group.test.d.ts.map +0 -1
  166. package/dist/tests/page_group.test.js +0 -51
  167. package/dist/tests/page_group.test.js.map +0 -1
  168. package/dist/tests/plugin.test.d.ts +0 -2
  169. package/dist/tests/plugin.test.d.ts.map +0 -1
  170. package/dist/tests/plugin.test.js +0 -60
  171. package/dist/tests/plugin.test.js.map +0 -1
  172. package/dist/tests/show.test.d.ts +0 -2
  173. package/dist/tests/show.test.d.ts.map +0 -1
  174. package/dist/tests/show.test.js +0 -561
  175. package/dist/tests/show.test.js.map +0 -1
  176. package/dist/tests/state.test.d.ts +0 -2
  177. package/dist/tests/state.test.d.ts.map +0 -1
  178. package/dist/tests/state.test.js +0 -82
  179. package/dist/tests/state.test.js.map +0 -1
  180. package/dist/tests/table.test.d.ts +0 -2
  181. package/dist/tests/table.test.d.ts.map +0 -1
  182. package/dist/tests/table.test.js +0 -2717
  183. package/dist/tests/table.test.js.map +0 -1
  184. package/dist/tests/table_history.test.d.ts +0 -2
  185. package/dist/tests/table_history.test.d.ts.map +0 -1
  186. package/dist/tests/table_history.test.js +0 -413
  187. package/dist/tests/table_history.test.js.map +0 -1
  188. package/dist/tests/tag.test.d.ts +0 -2
  189. package/dist/tests/tag.test.d.ts.map +0 -1
  190. package/dist/tests/tag.test.js +0 -97
  191. package/dist/tests/tag.test.js.map +0 -1
  192. package/dist/tests/user.test.d.ts +0 -2
  193. package/dist/tests/user.test.d.ts.map +0 -1
  194. package/dist/tests/user.test.js +0 -441
  195. package/dist/tests/user.test.js.map +0 -1
  196. package/dist/tests/view.test.d.ts +0 -2
  197. package/dist/tests/view.test.d.ts.map +0 -1
  198. package/dist/tests/view.test.js +0 -699
  199. package/dist/tests/view.test.js.map +0 -1
  200. package/dist/tests/workflow.test.d.ts +0 -2
  201. package/dist/tests/workflow.test.d.ts.map +0 -1
  202. package/dist/tests/workflow.test.js +0 -303
  203. package/dist/tests/workflow.test.js.map +0 -1
  204. package/dist/tests/workflow_run.test.d.ts +0 -2
  205. package/dist/tests/workflow_run.test.d.ts.map +0 -1
  206. package/dist/tests/workflow_run.test.js +0 -922
  207. package/dist/tests/workflow_run.test.js.map +0 -1
@@ -1,1037 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const table_1 = __importDefault(require("../models/table"));
7
- const field_1 = __importDefault(require("../models/field"));
8
- const view_1 = __importDefault(require("../models/view"));
9
- const db_1 = __importDefault(require("../db"));
10
- const mocks_1 = __importDefault(require("./mocks"));
11
- const { mockReqRes } = mocks_1.default;
12
- const { getState } = require("../db/state");
13
- const globals_1 = require("@jest/globals");
14
- const assertions_1 = require("./assertions");
15
- let remoteQueries = false;
16
- getState().registerPlugin("base", require("../base-plugin"));
17
- (0, globals_1.afterAll)(db_1.default.close);
18
- (0, globals_1.beforeAll)(async () => {
19
- await require("../db/reset_schema")();
20
- await require("../db/fixtures")();
21
- });
22
- const mkViewWithCfg = async (viewCfg) => {
23
- return await view_1.default.create({
24
- viewtemplate: "List",
25
- description: "",
26
- min_role: 1,
27
- name: `someView${Math.round(Math.random() * 100000)}`,
28
- table_id: viewCfg.table_id || table_1.default.findOne("books")?.id,
29
- default_render_page: "",
30
- slug: {
31
- label: "",
32
- steps: [],
33
- },
34
- attributes: {
35
- page_title: "",
36
- popup_title: "",
37
- popup_width: null,
38
- popup_link_out: false,
39
- popup_minwidth: null,
40
- page_description: "",
41
- popup_width_units: null,
42
- popup_minwidth_units: null,
43
- popup_save_indicator: false,
44
- },
45
- ...viewCfg,
46
- });
47
- };
48
- (0, globals_1.describe)("Misc List views", () => {
49
- (0, globals_1.it)("interpolates HTML", async () => {
50
- const view = await mkViewWithCfg({
51
- configuration: {
52
- layout: {
53
- besides: [
54
- {
55
- contents: {
56
- type: "blank",
57
- isHTML: true,
58
- contents: "{{ author}}: {{pages+10}}",
59
- },
60
- alignment: "Default",
61
- col_width_units: "px",
62
- },
63
- ],
64
- list_columns: true,
65
- },
66
- columns: [],
67
- },
68
- });
69
- const vres1 = await view.run({}, mockReqRes);
70
- (0, globals_1.expect)(vres1).toContain("<td>Herman Melville: 977</td>");
71
- });
72
- (0, globals_1.it)("show if true", async () => {
73
- const view = await mkViewWithCfg({
74
- configuration: {
75
- layout: {
76
- besides: [
77
- {
78
- showif: "pages<800",
79
- contents: {
80
- type: "field",
81
- block: false,
82
- fieldview: "as_text",
83
- textStyle: "",
84
- field_name: "author",
85
- configuration: {},
86
- },
87
- alignment: "Default",
88
- col_width_units: "px",
89
- },
90
- ],
91
- list_columns: true,
92
- },
93
- columns: [
94
- {
95
- type: "Field",
96
- block: false,
97
- fieldview: "as_text",
98
- textStyle: "",
99
- field_name: "author",
100
- configuration: {},
101
- },
102
- ],
103
- },
104
- });
105
- const vres1 = await view.run({}, mockReqRes);
106
- (0, globals_1.expect)(vres1).not.toContain("Herman Melville");
107
- (0, globals_1.expect)(vres1).toContain("Leo Tolstoy");
108
- });
109
- (0, globals_1.it)("show if true with joinfield", async () => {
110
- const view = await mkViewWithCfg({
111
- configuration: {
112
- layout: {
113
- besides: [
114
- {
115
- showif: 'publisher?.name === "AK Press"',
116
- contents: {
117
- type: "field",
118
- block: false,
119
- fieldview: "as_text",
120
- textStyle: "",
121
- field_name: "author",
122
- configuration: {},
123
- },
124
- alignment: "Default",
125
- col_width_units: "px",
126
- },
127
- ],
128
- list_columns: true,
129
- },
130
- columns: [
131
- {
132
- type: "Field",
133
- block: false,
134
- fieldview: "as_text",
135
- textStyle: "",
136
- field_name: "author",
137
- configuration: {},
138
- },
139
- ],
140
- },
141
- });
142
- const vres1 = await view.run({}, mockReqRes);
143
- (0, globals_1.expect)(vres1).not.toContain("Herman Melville");
144
- (0, globals_1.expect)(vres1).toContain("Leo Tolstoy");
145
- });
146
- (0, globals_1.it)("list view with dropdown menu", async () => {
147
- const view = await mkViewWithCfg({
148
- configuration: {
149
- layout: {
150
- besides: [
151
- {
152
- contents: {
153
- type: "dropdown_menu",
154
- block: false,
155
- label: "Menu",
156
- contents: {
157
- above: [
158
- {
159
- type: "view_link",
160
- view: "show_publisher",
161
- block: false,
162
- minRole: 100,
163
- relation: ".books.publisher",
164
- isFormula: {
165
- label: true,
166
- },
167
- link_icon: "",
168
- view_label: "publisher.name",
169
- },
170
- {
171
- type: "action",
172
- block: false,
173
- rndid: "f729aa",
174
- nsteps: 1,
175
- confirm: false,
176
- minRole: 100,
177
- isFormula: {},
178
- action_icon: "",
179
- action_name: "Delete",
180
- action_label: "",
181
- configuration: {},
182
- },
183
- ],
184
- },
185
- action_icon: "",
186
- },
187
- alignment: "Default",
188
- col_width_units: "px",
189
- },
190
- ],
191
- list_columns: true,
192
- },
193
- columns: [
194
- {
195
- type: "ViewLink",
196
- view: "show_publisher",
197
- block: false,
198
- label: "publisher.name",
199
- minRole: 100,
200
- relation: ".books.publisher",
201
- link_icon: "",
202
- },
203
- {
204
- type: "Action",
205
- rndid: "f729aa",
206
- nsteps: 1,
207
- confirm: false,
208
- minRole: 100,
209
- isFormula: {},
210
- action_icon: "",
211
- action_name: "Delete",
212
- action_label: "",
213
- configuration: {},
214
- },
215
- ],
216
- },
217
- });
218
- const vres1 = await view.run({}, mockReqRes);
219
- (0, globals_1.expect)(vres1).toContain(`ajax_post_btn('/delete/books/1?redirect=/view/${view.name}', true)`);
220
- (0, globals_1.expect)(vres1).toContain('<a href="/view/show_publisher?id=1">AK Press</a>');
221
- (0, globals_1.expect)(vres1).toContain("dropdown-menu");
222
- });
223
- (0, globals_1.it)("with label formula viewlink", async () => {
224
- const view = await mkViewWithCfg({
225
- configuration: {
226
- layout: {
227
- besides: [
228
- {
229
- contents: {
230
- type: "field",
231
- fieldview: "as_text",
232
- field_name: "author",
233
- configuration: {},
234
- },
235
- alignment: "Default",
236
- header_label: "Author",
237
- col_width_units: "px",
238
- },
239
- {
240
- contents: {
241
- type: "view_link",
242
- view: "show_publisher",
243
- block: false,
244
- minRole: 100,
245
- relation: ".books.publisher",
246
- isFormula: {
247
- label: true,
248
- },
249
- link_icon: "",
250
- view_label: "publisher.name",
251
- },
252
- alignment: "Default",
253
- header_label: "Publisher",
254
- col_width_units: "px",
255
- },
256
- ],
257
- list_columns: true,
258
- },
259
- columns: [
260
- {
261
- type: "Field",
262
- fieldview: "as_text",
263
- field_name: "author",
264
- configuration: {},
265
- },
266
- {
267
- type: "ViewLink",
268
- view: "show_publisher",
269
- block: false,
270
- label: "publisher.name",
271
- minRole: 100,
272
- relation: ".books.publisher",
273
- link_icon: "",
274
- },
275
- ],
276
- },
277
- });
278
- const vres1 = await view.run({}, mockReqRes);
279
- (0, globals_1.expect)(vres1).toContain('<a href="/view/show_publisher?id=1">AK Press</a>');
280
- });
281
- (0, globals_1.it)("with label formula viewlink and join field", async () => {
282
- const view = await mkViewWithCfg({
283
- configuration: {
284
- layout: {
285
- besides: [
286
- {
287
- contents: {
288
- type: "field",
289
- fieldview: "as_text",
290
- field_name: "author",
291
- configuration: {},
292
- },
293
- alignment: "Default",
294
- header_label: "Author",
295
- col_width_units: "px",
296
- },
297
- {
298
- contents: {
299
- type: "view_link",
300
- view: "show_publisher",
301
- block: false,
302
- minRole: 100,
303
- relation: ".books.publisher",
304
- isFormula: {
305
- label: true,
306
- },
307
- link_icon: "",
308
- view_label: "publisher.name",
309
- },
310
- alignment: "Default",
311
- header_label: "Publisher",
312
- col_width_units: "px",
313
- },
314
- {
315
- contents: {
316
- type: "join_field",
317
- block: false,
318
- fieldview: "as_text",
319
- textStyle: "",
320
- join_field: "publisher.name",
321
- configuration: {},
322
- },
323
- alignment: "Default",
324
- col_width_units: "px",
325
- },
326
- ],
327
- list_columns: true,
328
- },
329
- columns: [
330
- {
331
- type: "Field",
332
- fieldview: "as_text",
333
- field_name: "author",
334
- configuration: {},
335
- },
336
- {
337
- type: "ViewLink",
338
- view: "show_publisher",
339
- block: false,
340
- label: "publisher.name",
341
- minRole: 100,
342
- relation: ".books.publisher",
343
- link_icon: "",
344
- },
345
- {
346
- type: "JoinField",
347
- block: false,
348
- fieldview: "as_text",
349
- textStyle: "",
350
- join_field: "publisher.name",
351
- configuration: {},
352
- },
353
- ],
354
- },
355
- });
356
- const vres1 = await view.run({}, mockReqRes);
357
- (0, globals_1.expect)(vres1).toContain('<a href="/view/show_publisher?id=1">AK Press</a>');
358
- (0, globals_1.expect)(vres1).toContain("<td>AK Press</td>");
359
- });
360
- (0, globals_1.it)("row inclusion", async () => {
361
- const view = await mkViewWithCfg({
362
- configuration: {
363
- layout: {
364
- besides: [
365
- {
366
- contents: {
367
- type: "field",
368
- block: false,
369
- fieldview: "as_text",
370
- textStyle: "",
371
- field_name: "author",
372
- configuration: {},
373
- },
374
- alignment: "Default",
375
- col_width_units: "px",
376
- },
377
- {
378
- contents: {
379
- type: "field",
380
- block: false,
381
- fieldview: "show",
382
- textStyle: "",
383
- field_name: "pages",
384
- configuration: {},
385
- },
386
- alignment: "Default",
387
- col_width_units: "px",
388
- },
389
- ],
390
- list_columns: true,
391
- },
392
- columns: [
393
- {
394
- type: "Field",
395
- block: false,
396
- fieldview: "as_text",
397
- textStyle: "",
398
- field_name: "author",
399
- configuration: {},
400
- },
401
- {
402
- type: "Field",
403
- block: false,
404
- fieldview: "show",
405
- textStyle: "",
406
- field_name: "pages",
407
- configuration: {},
408
- },
409
- ],
410
- default_state: {
411
- include_fml: "pages>800",
412
- },
413
- },
414
- });
415
- const vres1 = await view.run({}, mockReqRes);
416
- (0, globals_1.expect)(vres1).toContain("<td>Herman Melville</td>");
417
- (0, globals_1.expect)(vres1).not.toContain("<td>Leo Tolstoy</td>");
418
- });
419
- (0, globals_1.it)("row exclusion and click url", async () => {
420
- const view = await mkViewWithCfg({
421
- configuration: {
422
- layout: {
423
- besides: [
424
- {
425
- contents: {
426
- type: "field",
427
- block: false,
428
- fieldview: "as_text",
429
- textStyle: "",
430
- field_name: "author",
431
- configuration: {},
432
- },
433
- alignment: "Default",
434
- col_width_units: "px",
435
- },
436
- {
437
- contents: {
438
- type: "field",
439
- block: false,
440
- fieldview: "show",
441
- textStyle: "",
442
- field_name: "pages",
443
- configuration: {},
444
- },
445
- alignment: "Default",
446
- col_width_units: "px",
447
- },
448
- ],
449
- list_columns: true,
450
- },
451
- columns: [
452
- {
453
- type: "Field",
454
- block: false,
455
- fieldview: "as_text",
456
- textStyle: "",
457
- field_name: "author",
458
- configuration: {},
459
- },
460
- {
461
- type: "Field",
462
- block: false,
463
- fieldview: "show",
464
- textStyle: "",
465
- field_name: "pages",
466
- configuration: {},
467
- },
468
- ],
469
- default_state: {
470
- exclusion_where: "parent === user.id",
471
- exclusion_relation: "patients.favbook",
472
- _row_click_url_formula: "`/view/authorshow?id=${id}`",
473
- },
474
- },
475
- });
476
- const vres1 = await view.run({}, mockReqRes);
477
- (0, globals_1.expect)(vres1).toContain("<td>Herman Melville</td>");
478
- (0, globals_1.expect)(vres1).not.toContain("<td>Leo Tolstoy</td>");
479
- (0, globals_1.expect)(vres1).toContain(`<tr data-row-id="1" onclick="location.href='/view/authorshow?id=1'">`);
480
- });
481
- (0, globals_1.it)("field with fieldview config", async () => {
482
- const view = await mkViewWithCfg({
483
- configuration: {
484
- layout: {
485
- besides: [
486
- {
487
- contents: {
488
- type: "field",
489
- block: false,
490
- fieldview: "show_with_html",
491
- textStyle: "",
492
- field_name: "author",
493
- configuration: {
494
- code: "Low:{{it.toLowerCase()}}",
495
- },
496
- },
497
- alignment: "Default",
498
- col_width_units: "px",
499
- },
500
- ],
501
- list_columns: true,
502
- },
503
- columns: [
504
- {
505
- type: "Field",
506
- block: false,
507
- fieldview: "show_with_html",
508
- textStyle: "",
509
- field_name: "author",
510
- configuration: {
511
- code: "Low:{{it.toLowerCase()}}",
512
- },
513
- },
514
- ],
515
- },
516
- });
517
- const vres1 = await view.run({}, mockReqRes);
518
- (0, globals_1.expect)(vres1).toContain("<td>Low:herman melville</td>");
519
- });
520
- (0, globals_1.it)("joinfield with fieldview config", async () => {
521
- const view = await mkViewWithCfg({
522
- configuration: {
523
- layout: {
524
- besides: [
525
- {
526
- contents: {
527
- type: "join_field",
528
- block: false,
529
- fieldview: "show_with_html",
530
- textStyle: "",
531
- join_field: "publisher.name",
532
- configuration: {
533
- code: 'pub:{{ (it||"").toLowerCase()}}',
534
- },
535
- },
536
- alignment: "Default",
537
- col_width_units: "px",
538
- },
539
- ],
540
- list_columns: true,
541
- },
542
- columns: [
543
- {
544
- type: "JoinField",
545
- block: false,
546
- fieldview: "show_with_html",
547
- textStyle: "",
548
- join_field: "publisher.name",
549
- configuration: {
550
- code: 'pub:{{ (it||"").toLowerCase()}}',
551
- },
552
- },
553
- ],
554
- },
555
- });
556
- const vres1 = await view.run({}, mockReqRes);
557
- (0, globals_1.expect)(vres1).toContain("<td>pub:ak press</td>");
558
- });
559
- (0, globals_1.it)("aggregation with int fieldview config", async () => {
560
- const view = await mkViewWithCfg({
561
- configuration: {
562
- layout: {
563
- besides: [
564
- {
565
- contents: {
566
- stat: "Max",
567
- type: "aggregation",
568
- block: false,
569
- aggwhere: "",
570
- agg_field: "id",
571
- textStyle: "",
572
- agg_relation: "patients.favbook",
573
- agg_fieldview: "show_with_html",
574
- configuration: {
575
- code: "MAX:{{it}}",
576
- },
577
- },
578
- alignment: "Default",
579
- col_width_units: "px",
580
- },
581
- ],
582
- list_columns: true,
583
- },
584
- columns: [
585
- {
586
- stat: "Max",
587
- type: "Aggregation",
588
- block: false,
589
- aggwhere: "",
590
- agg_field: "id",
591
- textStyle: "",
592
- agg_relation: "patients.favbook",
593
- agg_fieldview: "show_with_html",
594
- configuration: {
595
- code: "MAX:{{it}}",
596
- },
597
- },
598
- ],
599
- },
600
- });
601
- const vres1 = await view.run({}, mockReqRes);
602
- (0, globals_1.expect)(vres1).toContain("<td>MAX:2</td>");
603
- });
604
- (0, globals_1.it)("aggregation in view_link with formula", async () => {
605
- const view = await mkViewWithCfg({
606
- configuration: {
607
- layout: {
608
- besides: [
609
- {
610
- contents: {
611
- type: "view_link",
612
- view: "patientlist",
613
- block: false,
614
- minRole: 100,
615
- relation: ".books.patients$favbook",
616
- isFormula: {
617
- label: true,
618
- },
619
- link_icon: "",
620
- view_label: "patients$favbook$id$count+' patients'",
621
- },
622
- alignment: "Default",
623
- col_width_units: "px",
624
- },
625
- ],
626
- list_columns: true,
627
- },
628
- columns: [
629
- {
630
- type: "ViewLink",
631
- view: "show_publisher",
632
- block: false,
633
- label: "publisher.name",
634
- minRole: 100,
635
- relation: ".books.publisher",
636
- link_icon: "",
637
- },
638
- ],
639
- },
640
- });
641
- const vres1 = await view.run({}, mockReqRes);
642
- (0, globals_1.expect)(vres1).toContain('<td><a href="/view/patientlist?favbook=1">1 patients</a></td>');
643
- });
644
- (0, globals_1.it)("aggregation with int fieldview config", async () => {
645
- const view = await mkViewWithCfg({
646
- configuration: {
647
- layout: {
648
- besides: [
649
- {
650
- contents: {
651
- stat: "Max",
652
- type: "aggregation",
653
- block: false,
654
- aggwhere: "",
655
- agg_field: "name",
656
- textStyle: "",
657
- agg_relation: "patients.favbook",
658
- agg_fieldview: "code",
659
- configuration: {
660
- code: "MAX:{{it}}",
661
- },
662
- },
663
- alignment: "Default",
664
- col_width_units: "px",
665
- },
666
- ],
667
- list_columns: true,
668
- },
669
- columns: [
670
- {
671
- stat: "Max",
672
- type: "Aggregation",
673
- block: false,
674
- aggwhere: "",
675
- agg_field: "name",
676
- textStyle: "",
677
- agg_relation: "patients.favbook",
678
- agg_fieldview: "code",
679
- configuration: {
680
- code: "MAX:{{it}}",
681
- },
682
- },
683
- ],
684
- },
685
- });
686
- const vres1 = await view.run({}, mockReqRes);
687
- (0, globals_1.expect)(vres1).toContain("<code>Michael Douglas</code>");
688
- });
689
- (0, globals_1.it)("runs button action", async () => {
690
- const view = await mkViewWithCfg({
691
- configuration: {
692
- layout: {
693
- besides: [
694
- {
695
- contents: {
696
- type: "action",
697
- block: false,
698
- rndid: "d5af6d",
699
- nsteps: 1,
700
- confirm: false,
701
- minRole: 100,
702
- isFormula: {},
703
- action_icon: "",
704
- action_name: "toast",
705
- action_label: "",
706
- configuration: {
707
- text: "Hello from {{ author }}",
708
- notify_type: "Notify",
709
- },
710
- },
711
- alignment: "Default",
712
- col_width_units: "px",
713
- },
714
- ],
715
- list_columns: true,
716
- },
717
- columns: [
718
- {
719
- type: "Action",
720
- rndid: "d5af6d",
721
- nsteps: 1,
722
- confirm: false,
723
- minRole: 100,
724
- isFormula: {},
725
- action_icon: "",
726
- action_name: "toast",
727
- action_label: "",
728
- configuration: {
729
- text: "Hello from {{ author}}",
730
- notify_type: "Notify",
731
- },
732
- },
733
- ],
734
- },
735
- });
736
- const vres1 = await view.run({}, mockReqRes);
737
- (0, globals_1.expect)(vres1).toContain(`<a href="javascript:void(0)" class="btn btn-primary " onclick="view_post('${view.name}', 'run_action', {rndid:'d5af6d', id:'1'});">toast</a>`);
738
- mockReqRes.reset();
739
- const body = { action_name: "toast", id: "1" };
740
- await view.runRoute("run_action", body, mockReqRes.res, { req: { ...mockReqRes.req, body }, res: mockReqRes.res }, false);
741
- (0, globals_1.expect)(mockReqRes.getStored().json).toStrictEqual({
742
- notify: "Hello from Herman Melville",
743
- success: "ok",
744
- });
745
- });
746
- });
747
- (0, globals_1.describe)("List sort options", () => {
748
- (0, globals_1.it)("sorts according to default sort options", async () => {
749
- const layoutColumns = {
750
- layout: {
751
- besides: [
752
- {
753
- contents: {
754
- type: "field",
755
- block: false,
756
- fieldview: "as_text",
757
- textStyle: "",
758
- field_name: "author",
759
- configuration: {},
760
- },
761
- alignment: "Default",
762
- col_width_units: "px",
763
- },
764
- ],
765
- list_columns: true,
766
- },
767
- columns: [
768
- {
769
- type: "Field",
770
- block: false,
771
- fieldview: "as_text",
772
- textStyle: "",
773
- field_name: "author",
774
- configuration: {},
775
- },
776
- ],
777
- };
778
- const viewAsc = await mkViewWithCfg({
779
- configuration: {
780
- ...layoutColumns,
781
- default_state: {
782
- _order_field: "author",
783
- },
784
- },
785
- name: "BookSortAsc",
786
- });
787
- const viewDesc = await mkViewWithCfg({
788
- configuration: {
789
- ...layoutColumns,
790
- default_state: {
791
- _order_field: "author",
792
- _descending: true,
793
- },
794
- },
795
- name: "BookSortDesc",
796
- });
797
- const tBodyAuthors = (authors) => `<tbody>${authors
798
- .map(({ nm, ix }) => `<tr data-row-id="${ix}"><td>${nm}</td></tr>`)
799
- .join("")}</tbody>`;
800
- const vres1 = await viewAsc.run({}, mockReqRes);
801
- (0, globals_1.expect)(vres1).toContain(tBodyAuthors([
802
- { nm: "Herman Melville", ix: 1 },
803
- { nm: "Leo Tolstoy", ix: 2 },
804
- ]));
805
- const vres2 = await viewDesc.run({}, mockReqRes);
806
- (0, globals_1.expect)(vres2).toContain(tBodyAuthors([
807
- { nm: "Leo Tolstoy", ix: 2 },
808
- { nm: "Herman Melville", ix: 1 },
809
- ]));
810
- const vres3 = await viewDesc.run({ _28084_sortby: "pages" }, mockReqRes);
811
- (0, globals_1.expect)(vres3).toContain(tBodyAuthors([
812
- { nm: "Leo Tolstoy", ix: 2 },
813
- { nm: "Herman Melville", ix: 1 },
814
- ]));
815
- const vres3a = await viewAsc.run({ _8a82a_sortby: "pages" }, mockReqRes);
816
- (0, globals_1.expect)(vres3a).toContain(tBodyAuthors([
817
- { nm: "Leo Tolstoy", ix: 2 },
818
- { nm: "Herman Melville", ix: 1 },
819
- ]));
820
- const vres4 = await viewDesc.run({ _28084_sortby: "pages", _28084_sortdesc: true }, mockReqRes);
821
- (0, globals_1.expect)(vres4).toContain(tBodyAuthors([
822
- { nm: "Herman Melville", ix: 1 },
823
- { nm: "Leo Tolstoy", ix: 2 },
824
- ]));
825
- });
826
- });
827
- (0, globals_1.describe)("List fieldviews", () => {
828
- (0, globals_1.it)("sets up new fields", async () => {
829
- const table = table_1.default.findOne({ name: "books" });
830
- (0, assertions_1.assertIsSet)(table);
831
- await field_1.default.create({
832
- table,
833
- name: "published",
834
- label: "Published",
835
- type: "Date",
836
- });
837
- await field_1.default.create({
838
- table,
839
- name: "cover_pic",
840
- label: "Cover Pic",
841
- type: "File",
842
- });
843
- await table.updateRow({ published: new Date("1971-05.04"), cover_pic: "magrite.png" }, 1);
844
- });
845
- (0, globals_1.it)("shows image thumbnail", async () => {
846
- const view = await mkViewWithCfg({
847
- configuration: {
848
- layout: {
849
- besides: [
850
- {
851
- contents: {
852
- type: "field",
853
- block: false,
854
- fieldview: "Thumbnail",
855
- textStyle: "",
856
- field_name: "cover_pic",
857
- configuration: {
858
- width: "66",
859
- expand: true,
860
- height: "66",
861
- },
862
- },
863
- alignment: "Default",
864
- col_width_units: "px",
865
- },
866
- ],
867
- list_columns: true,
868
- },
869
- columns: [
870
- {
871
- type: "Field",
872
- block: false,
873
- fieldview: "Thumbnail",
874
- textStyle: "",
875
- field_name: "cover_pic",
876
- configuration: {
877
- width: "66",
878
- expand: true,
879
- height: "66",
880
- },
881
- },
882
- ],
883
- },
884
- });
885
- const vres1 = await view.run({}, mockReqRes);
886
- (0, globals_1.expect)(vres1).toContain(`<img src="/files/resize/66/66/magrite.png" onclick="expand_thumbnail('magrite.png', 'magrite.png')">`);
887
- });
888
- (0, globals_1.it)("relative date", async () => {
889
- const view = await mkViewWithCfg({
890
- configuration: {
891
- layout: {
892
- besides: [
893
- {
894
- contents: {
895
- type: "field",
896
- block: false,
897
- fieldview: "relative",
898
- textStyle: "",
899
- field_name: "published",
900
- configuration: {
901
- width: "66",
902
- expand: true,
903
- height: "66",
904
- },
905
- },
906
- alignment: "Default",
907
- col_width_units: "px",
908
- },
909
- {
910
- contents: {
911
- type: "field",
912
- block: false,
913
- fieldview: "format",
914
- textStyle: "",
915
- field_name: "published",
916
- configuration: {
917
- format: "YYYY",
918
- },
919
- },
920
- alignment: "Default",
921
- col_width_units: "px",
922
- },
923
- ],
924
- list_columns: true,
925
- },
926
- columns: [
927
- {
928
- type: "Field",
929
- block: false,
930
- fieldview: "relative",
931
- textStyle: "",
932
- field_name: "published",
933
- configuration: {
934
- width: "66",
935
- expand: true,
936
- height: "66",
937
- },
938
- },
939
- {
940
- type: "Field",
941
- block: false,
942
- fieldview: "format",
943
- textStyle: "",
944
- field_name: "published",
945
- configuration: {
946
- format: "YYYY",
947
- },
948
- },
949
- ],
950
- },
951
- });
952
- const vres1 = await view.run({}, mockReqRes);
953
- (0, globals_1.expect)(vres1).toContain(`years ago<`);
954
- (0, globals_1.expect)(vres1).toContain(`>1971</time>`);
955
- });
956
- });
957
- (0, globals_1.describe)("one-to-one joinfields", () => {
958
- (0, globals_1.it)("should setup", async () => {
959
- const parents = await table_1.default.create("O2O Parent");
960
- const children = await table_1.default.create("O2O Child");
961
- await field_1.default.create({
962
- name: "name",
963
- label: "Name",
964
- type: "String",
965
- table: parents,
966
- });
967
- await field_1.default.create({
968
- name: "name",
969
- label: "Name",
970
- type: "String",
971
- table: children,
972
- });
973
- await field_1.default.create({
974
- name: "other",
975
- label: "Other",
976
- type: "Key to O2O Parent",
977
- is_unique: true,
978
- table: children,
979
- });
980
- const parid = await parents.insertRow({ name: "TheParent" });
981
- await children.insertRow({ name: "TheChild", other: parid });
982
- await mkViewWithCfg({
983
- name: "list_o2o",
984
- table_id: parents.id,
985
- configuration: {
986
- layout: {
987
- besides: [
988
- {
989
- contents: {
990
- type: "field",
991
- fieldview: "as_text",
992
- field_name: "name",
993
- configuration: {},
994
- },
995
- header_label: "name",
996
- },
997
- {
998
- contents: {
999
- type: "join_field",
1000
- block: false,
1001
- fieldview: "as_text",
1002
- textStyle: "",
1003
- join_field: "O2O Child.other->name",
1004
- configuration: {},
1005
- },
1006
- alignment: "Default",
1007
- col_width_units: "px",
1008
- },
1009
- ],
1010
- list_columns: true,
1011
- },
1012
- columns: [
1013
- {
1014
- type: "Field",
1015
- fieldview: "as_text",
1016
- field_name: "name",
1017
- configuration: {},
1018
- },
1019
- {
1020
- type: "JoinField",
1021
- block: false,
1022
- fieldview: "as_text",
1023
- textStyle: "",
1024
- join_field: "O2O Child.other->name",
1025
- configuration: {},
1026
- },
1027
- ],
1028
- },
1029
- });
1030
- const view = view_1.default.findOne({ name: "list_o2o" });
1031
- (0, assertions_1.assertIsSet)(view);
1032
- const vres1 = await view.run({ id: 1 }, mockReqRes);
1033
- (0, globals_1.expect)(vres1).toContain("TheChild");
1034
- });
1035
- });
1036
- //sorting
1037
- //# sourceMappingURL=list.test.js.map