@saltcorn/data 0.9.4-beta.8 → 0.9.4

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 (137) hide show
  1. package/dist/base-plugin/actions.d.ts +137 -71
  2. package/dist/base-plugin/actions.d.ts.map +1 -1
  3. package/dist/base-plugin/actions.js +105 -22
  4. package/dist/base-plugin/actions.js.map +1 -1
  5. package/dist/base-plugin/fieldviews.d.ts.map +1 -1
  6. package/dist/base-plugin/fieldviews.js +19 -9
  7. package/dist/base-plugin/fieldviews.js.map +1 -1
  8. package/dist/base-plugin/fileviews.d.ts +13 -0
  9. package/dist/base-plugin/fileviews.js +42 -2
  10. package/dist/base-plugin/fileviews.js.map +1 -1
  11. package/dist/base-plugin/index.d.ts +208 -204
  12. package/dist/base-plugin/index.d.ts.map +1 -1
  13. package/dist/base-plugin/types.d.ts.map +1 -1
  14. package/dist/base-plugin/types.js +25 -10
  15. package/dist/base-plugin/types.js.map +1 -1
  16. package/dist/base-plugin/viewtemplates/edit.d.ts +4 -1
  17. package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
  18. package/dist/base-plugin/viewtemplates/edit.js +181 -81
  19. package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
  20. package/dist/base-plugin/viewtemplates/feed.d.ts.map +1 -1
  21. package/dist/base-plugin/viewtemplates/feed.js +4 -1
  22. package/dist/base-plugin/viewtemplates/feed.js.map +1 -1
  23. package/dist/base-plugin/viewtemplates/filter.d.ts.map +1 -1
  24. package/dist/base-plugin/viewtemplates/filter.js +89 -7
  25. package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
  26. package/dist/base-plugin/viewtemplates/list.d.ts +3 -2
  27. package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
  28. package/dist/base-plugin/viewtemplates/list.js +274 -38
  29. package/dist/base-plugin/viewtemplates/list.js.map +1 -1
  30. package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
  31. package/dist/base-plugin/viewtemplates/show.js +116 -56
  32. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  33. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts +4 -3
  34. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
  35. package/dist/base-plugin/viewtemplates/viewable_fields.js +173 -57
  36. package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
  37. package/dist/db/connect.d.ts.map +1 -1
  38. package/dist/db/connect.js +20 -0
  39. package/dist/db/connect.js.map +1 -1
  40. package/dist/db/fixtures.d.ts.map +1 -1
  41. package/dist/db/fixtures.js +196 -30
  42. package/dist/db/fixtures.js.map +1 -1
  43. package/dist/db/state.d.ts +5 -0
  44. package/dist/db/state.d.ts.map +1 -1
  45. package/dist/db/state.js +20 -0
  46. package/dist/db/state.js.map +1 -1
  47. package/dist/migrate.d.ts +1 -0
  48. package/dist/migrate.d.ts.map +1 -1
  49. package/dist/migrate.js +6 -3
  50. package/dist/migrate.js.map +1 -1
  51. package/dist/migrations/202402071125.d.ts +2 -0
  52. package/dist/migrations/202402071125.d.ts.map +1 -0
  53. package/dist/migrations/202402071125.js +4 -0
  54. package/dist/migrations/202402071125.js.map +1 -0
  55. package/dist/models/config.d.ts.map +1 -1
  56. package/dist/models/config.js +27 -0
  57. package/dist/models/config.js.map +1 -1
  58. package/dist/models/email.d.ts.map +1 -1
  59. package/dist/models/email.js +6 -2
  60. package/dist/models/email.js.map +1 -1
  61. package/dist/models/field.d.ts +1 -1
  62. package/dist/models/field.d.ts.map +1 -1
  63. package/dist/models/field.js +4 -4
  64. package/dist/models/field.js.map +1 -1
  65. package/dist/models/file.d.ts +2 -0
  66. package/dist/models/file.d.ts.map +1 -1
  67. package/dist/models/file.js +9 -0
  68. package/dist/models/file.js.map +1 -1
  69. package/dist/models/index.d.ts +1 -1
  70. package/dist/models/internal/query.d.ts +6 -0
  71. package/dist/models/internal/query.d.ts.map +1 -0
  72. package/dist/models/internal/query.js +86 -0
  73. package/dist/models/internal/query.js.map +1 -0
  74. package/dist/models/page.d.ts.map +1 -1
  75. package/dist/models/page.js +4 -0
  76. package/dist/models/page.js.map +1 -1
  77. package/dist/models/page_group.d.ts +1 -0
  78. package/dist/models/page_group.d.ts.map +1 -1
  79. package/dist/models/page_group.js +1 -0
  80. package/dist/models/page_group.js.map +1 -1
  81. package/dist/models/table.d.ts +18 -4
  82. package/dist/models/table.d.ts.map +1 -1
  83. package/dist/models/table.js +84 -52
  84. package/dist/models/table.js.map +1 -1
  85. package/dist/models/tag_entry.d.ts.map +1 -1
  86. package/dist/models/tag_entry.js +9 -0
  87. package/dist/models/tag_entry.js.map +1 -1
  88. package/dist/models/trigger.d.ts +3 -3
  89. package/dist/models/trigger.d.ts.map +1 -1
  90. package/dist/models/trigger.js +69 -7
  91. package/dist/models/trigger.js.map +1 -1
  92. package/dist/models/user.d.ts.map +1 -1
  93. package/dist/models/user.js +5 -4
  94. package/dist/models/user.js.map +1 -1
  95. package/dist/models/view.d.ts +1 -0
  96. package/dist/models/view.d.ts.map +1 -1
  97. package/dist/models/view.js +6 -0
  98. package/dist/models/view.js.map +1 -1
  99. package/dist/plugin-helper.d.ts +7 -19
  100. package/dist/plugin-helper.d.ts.map +1 -1
  101. package/dist/plugin-helper.js +79 -70
  102. package/dist/plugin-helper.js.map +1 -1
  103. package/dist/tests/actions.test.js +143 -2
  104. package/dist/tests/actions.test.js.map +1 -1
  105. package/dist/tests/auth.test.js +101 -1
  106. package/dist/tests/auth.test.js.map +1 -1
  107. package/dist/tests/auxtest.test.js +4 -0
  108. package/dist/tests/auxtest.test.js.map +1 -1
  109. package/dist/tests/calc.test.js +20 -0
  110. package/dist/tests/calc.test.js.map +1 -1
  111. package/dist/tests/edit.test.js +558 -0
  112. package/dist/tests/edit.test.js.map +1 -1
  113. package/dist/tests/filter.test.d.ts +2 -0
  114. package/dist/tests/filter.test.d.ts.map +1 -0
  115. package/dist/tests/filter.test.js +438 -0
  116. package/dist/tests/filter.test.js.map +1 -0
  117. package/dist/tests/list.test.d.ts +2 -0
  118. package/dist/tests/list.test.d.ts.map +1 -0
  119. package/dist/tests/list.test.js +903 -0
  120. package/dist/tests/list.test.js.map +1 -0
  121. package/dist/tests/show.test.d.ts +2 -0
  122. package/dist/tests/show.test.d.ts.map +1 -0
  123. package/dist/tests/show.test.js +325 -0
  124. package/dist/tests/show.test.js.map +1 -0
  125. package/dist/tests/table.test.js +213 -56
  126. package/dist/tests/table.test.js.map +1 -1
  127. package/dist/tests/table_history.test.js +51 -0
  128. package/dist/tests/table_history.test.js.map +1 -1
  129. package/dist/tests/tag.test.js +1 -1
  130. package/dist/tests/tag.test.js.map +1 -1
  131. package/dist/tests/view.test.js +16 -2
  132. package/dist/tests/view.test.js.map +1 -1
  133. package/dist/utils.d.ts +2 -17
  134. package/dist/utils.d.ts.map +1 -1
  135. package/dist/utils.js +19 -32
  136. package/dist/utils.js.map +1 -1
  137. package/package.json +8 -7
@@ -0,0 +1,903 @@
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: 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)("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(`<form action="/delete/books/1?redirect=/view/${view.name}" method="post">`);
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 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 with int fieldview config", async () => {
605
+ const view = await mkViewWithCfg({
606
+ configuration: {
607
+ layout: {
608
+ besides: [
609
+ {
610
+ contents: {
611
+ stat: "Max",
612
+ type: "aggregation",
613
+ block: false,
614
+ aggwhere: "",
615
+ agg_field: "name",
616
+ textStyle: "",
617
+ agg_relation: "patients.favbook",
618
+ agg_fieldview: "code",
619
+ configuration: {
620
+ code: "MAX:{{it}}",
621
+ },
622
+ },
623
+ alignment: "Default",
624
+ col_width_units: "px",
625
+ },
626
+ ],
627
+ list_columns: true,
628
+ },
629
+ columns: [
630
+ {
631
+ stat: "Max",
632
+ type: "Aggregation",
633
+ block: false,
634
+ aggwhere: "",
635
+ agg_field: "name",
636
+ textStyle: "",
637
+ agg_relation: "patients.favbook",
638
+ agg_fieldview: "code",
639
+ configuration: {
640
+ code: "MAX:{{it}}",
641
+ },
642
+ },
643
+ ],
644
+ },
645
+ });
646
+ const vres1 = await view.run({}, mockReqRes);
647
+ (0, globals_1.expect)(vres1).toContain("<code>Michael Douglas</code>");
648
+ });
649
+ (0, globals_1.it)("runs button action", async () => {
650
+ const view = await mkViewWithCfg({
651
+ configuration: {
652
+ layout: {
653
+ besides: [
654
+ {
655
+ contents: {
656
+ type: "action",
657
+ block: false,
658
+ rndid: "d5af6d",
659
+ nsteps: 1,
660
+ confirm: false,
661
+ minRole: 100,
662
+ isFormula: {},
663
+ action_icon: "",
664
+ action_name: "toast",
665
+ action_label: "",
666
+ configuration: {
667
+ text: "Hello from {{ author }}",
668
+ notify_type: "Notify",
669
+ },
670
+ },
671
+ alignment: "Default",
672
+ col_width_units: "px",
673
+ },
674
+ ],
675
+ list_columns: true,
676
+ },
677
+ columns: [
678
+ {
679
+ type: "Action",
680
+ rndid: "d5af6d",
681
+ nsteps: 1,
682
+ confirm: false,
683
+ minRole: 100,
684
+ isFormula: {},
685
+ action_icon: "",
686
+ action_name: "toast",
687
+ action_label: "",
688
+ configuration: {
689
+ text: "Hello from {{ author}}",
690
+ notify_type: "Notify",
691
+ },
692
+ },
693
+ ],
694
+ },
695
+ });
696
+ const vres1 = await view.run({}, mockReqRes);
697
+ (0, globals_1.expect)(vres1).toContain(`<a href="javascript:view_post('${view.name}', 'run_action', {action_name:'toast', id:'1'});" class="btn btn-primary ">toast</a>`);
698
+ mockReqRes.reset();
699
+ const body = { action_name: "toast", id: "1" };
700
+ await view.runRoute("run_action", body, mockReqRes.res, { req: { body } }, false);
701
+ (0, globals_1.expect)(mockReqRes.getStored().json).toStrictEqual({
702
+ notify: "Hello from Herman Melville",
703
+ success: "ok",
704
+ });
705
+ });
706
+ });
707
+ (0, globals_1.describe)("List sort options", () => {
708
+ (0, globals_1.it)("sorts according to default sort options", async () => {
709
+ const layoutColumns = {
710
+ layout: {
711
+ besides: [
712
+ {
713
+ contents: {
714
+ type: "field",
715
+ block: false,
716
+ fieldview: "as_text",
717
+ textStyle: "",
718
+ field_name: "author",
719
+ configuration: {},
720
+ },
721
+ alignment: "Default",
722
+ col_width_units: "px",
723
+ },
724
+ ],
725
+ list_columns: true,
726
+ },
727
+ columns: [
728
+ {
729
+ type: "Field",
730
+ block: false,
731
+ fieldview: "as_text",
732
+ textStyle: "",
733
+ field_name: "author",
734
+ configuration: {},
735
+ },
736
+ ],
737
+ };
738
+ const viewAsc = await mkViewWithCfg({
739
+ configuration: {
740
+ ...layoutColumns,
741
+ default_state: {
742
+ _order_field: "author",
743
+ },
744
+ },
745
+ name: "BookSortAsc",
746
+ });
747
+ const viewDesc = await mkViewWithCfg({
748
+ configuration: {
749
+ ...layoutColumns,
750
+ default_state: {
751
+ _order_field: "author",
752
+ _descending: true,
753
+ },
754
+ },
755
+ name: "BookSortDesc",
756
+ });
757
+ const tBodyAuthors = (authors) => `<tbody>${authors
758
+ .map((nm) => `<tr><td>${nm}</td></tr>`)
759
+ .join("")}</tbody>`;
760
+ const vres1 = await viewAsc.run({}, mockReqRes);
761
+ (0, globals_1.expect)(vres1).toContain(tBodyAuthors(["Herman Melville", "Leo Tolstoy"]));
762
+ const vres2 = await viewDesc.run({}, mockReqRes);
763
+ (0, globals_1.expect)(vres2).toContain(tBodyAuthors(["Leo Tolstoy", "Herman Melville"]));
764
+ const vres3 = await viewDesc.run({ _28084_sortby: "pages" }, mockReqRes);
765
+ (0, globals_1.expect)(vres3).toContain(tBodyAuthors(["Leo Tolstoy", "Herman Melville"]));
766
+ const vres3a = await viewAsc.run({ _8a82a_sortby: "pages" }, mockReqRes);
767
+ (0, globals_1.expect)(vres3a).toContain(tBodyAuthors(["Leo Tolstoy", "Herman Melville"]));
768
+ const vres4 = await viewDesc.run({ _28084_sortby: "pages", _28084_sortdesc: true }, mockReqRes);
769
+ (0, globals_1.expect)(vres4).toContain(tBodyAuthors(["Herman Melville", "Leo Tolstoy"]));
770
+ });
771
+ });
772
+ (0, globals_1.describe)("List fieldviews", () => {
773
+ (0, globals_1.it)("sets up new fields", async () => {
774
+ const table = table_1.default.findOne({ name: "books" });
775
+ (0, assertions_1.assertIsSet)(table);
776
+ await field_1.default.create({
777
+ table,
778
+ name: "published",
779
+ label: "Published",
780
+ type: "Date",
781
+ });
782
+ await field_1.default.create({
783
+ table,
784
+ name: "cover_pic",
785
+ label: "Cover Pic",
786
+ type: "File",
787
+ });
788
+ await table.updateRow({ published: new Date("1971-05.04"), cover_pic: "magrite.png" }, 1);
789
+ });
790
+ (0, globals_1.it)("shows image thumbnail", async () => {
791
+ const view = await mkViewWithCfg({
792
+ configuration: {
793
+ layout: {
794
+ besides: [
795
+ {
796
+ contents: {
797
+ type: "field",
798
+ block: false,
799
+ fieldview: "Thumbnail",
800
+ textStyle: "",
801
+ field_name: "cover_pic",
802
+ configuration: {
803
+ width: "66",
804
+ expand: true,
805
+ height: "66",
806
+ },
807
+ },
808
+ alignment: "Default",
809
+ col_width_units: "px",
810
+ },
811
+ ],
812
+ list_columns: true,
813
+ },
814
+ columns: [
815
+ {
816
+ type: "Field",
817
+ block: false,
818
+ fieldview: "Thumbnail",
819
+ textStyle: "",
820
+ field_name: "cover_pic",
821
+ configuration: {
822
+ width: "66",
823
+ expand: true,
824
+ height: "66",
825
+ },
826
+ },
827
+ ],
828
+ },
829
+ });
830
+ const vres1 = await view.run({}, mockReqRes);
831
+ (0, globals_1.expect)(vres1).toContain(`<img src="/files/resize/66/66/magrite.png" onclick="expand_thumbnail('magrite.png', 'magrite.png')">`);
832
+ });
833
+ (0, globals_1.it)("relative date", async () => {
834
+ const view = await mkViewWithCfg({
835
+ configuration: {
836
+ layout: {
837
+ besides: [
838
+ {
839
+ contents: {
840
+ type: "field",
841
+ block: false,
842
+ fieldview: "relative",
843
+ textStyle: "",
844
+ field_name: "published",
845
+ configuration: {
846
+ width: "66",
847
+ expand: true,
848
+ height: "66",
849
+ },
850
+ },
851
+ alignment: "Default",
852
+ col_width_units: "px",
853
+ },
854
+ {
855
+ contents: {
856
+ type: "field",
857
+ block: false,
858
+ fieldview: "format",
859
+ textStyle: "",
860
+ field_name: "published",
861
+ configuration: {
862
+ format: "YYYY",
863
+ },
864
+ },
865
+ alignment: "Default",
866
+ col_width_units: "px",
867
+ },
868
+ ],
869
+ list_columns: true,
870
+ },
871
+ columns: [
872
+ {
873
+ type: "Field",
874
+ block: false,
875
+ fieldview: "relative",
876
+ textStyle: "",
877
+ field_name: "published",
878
+ configuration: {
879
+ width: "66",
880
+ expand: true,
881
+ height: "66",
882
+ },
883
+ },
884
+ {
885
+ type: "Field",
886
+ block: false,
887
+ fieldview: "format",
888
+ textStyle: "",
889
+ field_name: "published",
890
+ configuration: {
891
+ format: "YYYY",
892
+ },
893
+ },
894
+ ],
895
+ },
896
+ });
897
+ const vres1 = await view.run({}, mockReqRes);
898
+ (0, globals_1.expect)(vres1).toContain(`years ago<`);
899
+ (0, globals_1.expect)(vres1).toContain(`>1971</time>`);
900
+ });
901
+ });
902
+ //sorting
903
+ //# sourceMappingURL=list.test.js.map