@saltcorn/data 1.6.0-rc.2 → 1.6.0-rc.3

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