@saltcorn/data 0.9.4-beta.2 → 0.9.4-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/base-plugin/actions.d.ts +156 -67
  2. package/dist/base-plugin/actions.d.ts.map +1 -1
  3. package/dist/base-plugin/actions.js +147 -27
  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 +27 -10
  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 +5 -2
  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 -7
  15. package/dist/base-plugin/types.js.map +1 -1
  16. package/dist/base-plugin/viewtemplates/edit.d.ts +2 -0
  17. package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
  18. package/dist/base-plugin/viewtemplates/edit.js +194 -58
  19. package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
  20. package/dist/base-plugin/viewtemplates/filter.d.ts.map +1 -1
  21. package/dist/base-plugin/viewtemplates/filter.js +88 -8
  22. package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
  23. package/dist/base-plugin/viewtemplates/list.d.ts +3 -2
  24. package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
  25. package/dist/base-plugin/viewtemplates/list.js +276 -41
  26. package/dist/base-plugin/viewtemplates/list.js.map +1 -1
  27. package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
  28. package/dist/base-plugin/viewtemplates/show.js +130 -64
  29. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  30. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts +4 -3
  31. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
  32. package/dist/base-plugin/viewtemplates/viewable_fields.js +160 -47
  33. package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
  34. package/dist/db/fixtures.d.ts.map +1 -1
  35. package/dist/db/fixtures.js +196 -30
  36. package/dist/db/fixtures.js.map +1 -1
  37. package/dist/db/state.d.ts +5 -0
  38. package/dist/db/state.d.ts.map +1 -1
  39. package/dist/db/state.js +20 -0
  40. package/dist/db/state.js.map +1 -1
  41. package/dist/migrate.d.ts +1 -0
  42. package/dist/migrate.d.ts.map +1 -1
  43. package/dist/migrate.js +6 -3
  44. package/dist/migrate.js.map +1 -1
  45. package/dist/migrations/202402071125.d.ts +2 -0
  46. package/dist/migrations/202402071125.d.ts.map +1 -0
  47. package/dist/migrations/202402071125.js +4 -0
  48. package/dist/migrations/202402071125.js.map +1 -0
  49. package/dist/models/config.d.ts.map +1 -1
  50. package/dist/models/config.js +33 -0
  51. package/dist/models/config.js.map +1 -1
  52. package/dist/models/email.d.ts.map +1 -1
  53. package/dist/models/email.js +6 -2
  54. package/dist/models/email.js.map +1 -1
  55. package/dist/models/expression.d.ts +2 -0
  56. package/dist/models/expression.d.ts.map +1 -1
  57. package/dist/models/expression.js +9 -0
  58. package/dist/models/expression.js.map +1 -1
  59. package/dist/models/field.d.ts +1 -1
  60. package/dist/models/field.d.ts.map +1 -1
  61. package/dist/models/field.js +4 -4
  62. package/dist/models/field.js.map +1 -1
  63. package/dist/models/file.d.ts +2 -0
  64. package/dist/models/file.d.ts.map +1 -1
  65. package/dist/models/file.js +9 -0
  66. package/dist/models/file.js.map +1 -1
  67. package/dist/models/internal/query.d.ts +6 -0
  68. package/dist/models/internal/query.d.ts.map +1 -0
  69. package/dist/models/internal/query.js +77 -0
  70. package/dist/models/internal/query.js.map +1 -0
  71. package/dist/models/page.d.ts.map +1 -1
  72. package/dist/models/page.js +4 -0
  73. package/dist/models/page.js.map +1 -1
  74. package/dist/models/page_group.d.ts +1 -0
  75. package/dist/models/page_group.d.ts.map +1 -1
  76. package/dist/models/page_group.js +1 -0
  77. package/dist/models/page_group.js.map +1 -1
  78. package/dist/models/table.d.ts +18 -4
  79. package/dist/models/table.d.ts.map +1 -1
  80. package/dist/models/table.js +78 -50
  81. package/dist/models/table.js.map +1 -1
  82. package/dist/models/trigger.d.ts +3 -3
  83. package/dist/models/trigger.d.ts.map +1 -1
  84. package/dist/models/trigger.js +69 -7
  85. package/dist/models/trigger.js.map +1 -1
  86. package/dist/models/user.d.ts.map +1 -1
  87. package/dist/models/user.js +5 -4
  88. package/dist/models/user.js.map +1 -1
  89. package/dist/models/view.d.ts +1 -0
  90. package/dist/models/view.d.ts.map +1 -1
  91. package/dist/models/view.js +6 -0
  92. package/dist/models/view.js.map +1 -1
  93. package/dist/plugin-helper.d.ts +8 -20
  94. package/dist/plugin-helper.d.ts.map +1 -1
  95. package/dist/plugin-helper.js +108 -76
  96. package/dist/plugin-helper.js.map +1 -1
  97. package/dist/tests/actions.test.js +143 -2
  98. package/dist/tests/actions.test.js.map +1 -1
  99. package/dist/tests/auth.test.js +101 -1
  100. package/dist/tests/auth.test.js.map +1 -1
  101. package/dist/tests/auxtest.test.js +4 -0
  102. package/dist/tests/auxtest.test.js.map +1 -1
  103. package/dist/tests/calc.test.js +11 -1
  104. package/dist/tests/calc.test.js.map +1 -1
  105. package/dist/tests/edit.test.js +394 -0
  106. package/dist/tests/edit.test.js.map +1 -1
  107. package/dist/tests/filter.test.d.ts +2 -0
  108. package/dist/tests/filter.test.d.ts.map +1 -0
  109. package/dist/tests/filter.test.js +438 -0
  110. package/dist/tests/filter.test.js.map +1 -0
  111. package/dist/tests/list.test.d.ts +2 -0
  112. package/dist/tests/list.test.d.ts.map +1 -0
  113. package/dist/tests/list.test.js +735 -0
  114. package/dist/tests/list.test.js.map +1 -0
  115. package/dist/tests/show.test.d.ts +2 -0
  116. package/dist/tests/show.test.d.ts.map +1 -0
  117. package/dist/tests/show.test.js +325 -0
  118. package/dist/tests/show.test.js.map +1 -0
  119. package/dist/tests/table.test.js +184 -56
  120. package/dist/tests/table.test.js.map +1 -1
  121. package/dist/tests/table_history.test.js +51 -0
  122. package/dist/tests/table_history.test.js.map +1 -1
  123. package/dist/tests/view.test.js +21 -1
  124. package/dist/tests/view.test.js.map +1 -1
  125. package/dist/utils.d.ts +4 -17
  126. package/dist/utils.d.ts.map +1 -1
  127. package/dist/utils.js +33 -32
  128. package/dist/utils.js.map +1 -1
  129. package/package.json +8 -7
@@ -0,0 +1,735 @@
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)("runs button action", async () => {
482
+ const view = await mkViewWithCfg({
483
+ configuration: {
484
+ layout: {
485
+ besides: [
486
+ {
487
+ contents: {
488
+ type: "action",
489
+ block: false,
490
+ rndid: "d5af6d",
491
+ nsteps: 1,
492
+ confirm: false,
493
+ minRole: 100,
494
+ isFormula: {},
495
+ action_icon: "",
496
+ action_name: "toast",
497
+ action_label: "",
498
+ configuration: {
499
+ text: "Hello from {{ author }}",
500
+ notify_type: "Notify",
501
+ },
502
+ },
503
+ alignment: "Default",
504
+ col_width_units: "px",
505
+ },
506
+ ],
507
+ list_columns: true,
508
+ },
509
+ columns: [
510
+ {
511
+ type: "Action",
512
+ rndid: "d5af6d",
513
+ nsteps: 1,
514
+ confirm: false,
515
+ minRole: 100,
516
+ isFormula: {},
517
+ action_icon: "",
518
+ action_name: "toast",
519
+ action_label: "",
520
+ configuration: {
521
+ text: "Hello from {{ author}}",
522
+ notify_type: "Notify",
523
+ },
524
+ },
525
+ ],
526
+ },
527
+ });
528
+ const vres1 = await view.run({}, mockReqRes);
529
+ (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>`);
530
+ mockReqRes.reset();
531
+ const body = { action_name: "toast", id: "1" };
532
+ await view.runRoute("run_action", body, mockReqRes.res, { req: { body } }, false);
533
+ (0, globals_1.expect)(mockReqRes.getStored().json).toStrictEqual({
534
+ notify: "Hello from Herman Melville",
535
+ success: "ok",
536
+ });
537
+ });
538
+ });
539
+ (0, globals_1.describe)("List sort options", () => {
540
+ (0, globals_1.it)("sorts according to default sort options", async () => {
541
+ const layoutColumns = {
542
+ layout: {
543
+ besides: [
544
+ {
545
+ contents: {
546
+ type: "field",
547
+ block: false,
548
+ fieldview: "as_text",
549
+ textStyle: "",
550
+ field_name: "author",
551
+ configuration: {},
552
+ },
553
+ alignment: "Default",
554
+ col_width_units: "px",
555
+ },
556
+ ],
557
+ list_columns: true,
558
+ },
559
+ columns: [
560
+ {
561
+ type: "Field",
562
+ block: false,
563
+ fieldview: "as_text",
564
+ textStyle: "",
565
+ field_name: "author",
566
+ configuration: {},
567
+ },
568
+ ],
569
+ };
570
+ const viewAsc = await mkViewWithCfg({
571
+ configuration: {
572
+ ...layoutColumns,
573
+ default_state: {
574
+ _order_field: "author",
575
+ },
576
+ },
577
+ name: "BookSortAsc",
578
+ });
579
+ const viewDesc = await mkViewWithCfg({
580
+ configuration: {
581
+ ...layoutColumns,
582
+ default_state: {
583
+ _order_field: "author",
584
+ _descending: true,
585
+ },
586
+ },
587
+ name: "BookSortDesc",
588
+ });
589
+ const tBodyAuthors = (authors) => `<tbody>${authors
590
+ .map((nm) => `<tr><td>${nm}</td></tr>`)
591
+ .join("")}</tbody>`;
592
+ const vres1 = await viewAsc.run({}, mockReqRes);
593
+ (0, globals_1.expect)(vres1).toContain(tBodyAuthors(["Herman Melville", "Leo Tolstoy"]));
594
+ const vres2 = await viewDesc.run({}, mockReqRes);
595
+ (0, globals_1.expect)(vres2).toContain(tBodyAuthors(["Leo Tolstoy", "Herman Melville"]));
596
+ const vres3 = await viewDesc.run({ _28084_sortby: "pages" }, mockReqRes);
597
+ (0, globals_1.expect)(vres3).toContain(tBodyAuthors(["Leo Tolstoy", "Herman Melville"]));
598
+ const vres3a = await viewAsc.run({ _8a82a_sortby: "pages" }, mockReqRes);
599
+ (0, globals_1.expect)(vres3a).toContain(tBodyAuthors(["Leo Tolstoy", "Herman Melville"]));
600
+ const vres4 = await viewDesc.run({ _28084_sortby: "pages", _28084_sortdesc: true }, mockReqRes);
601
+ (0, globals_1.expect)(vres4).toContain(tBodyAuthors(["Herman Melville", "Leo Tolstoy"]));
602
+ });
603
+ });
604
+ (0, globals_1.describe)("List fieldviews", () => {
605
+ (0, globals_1.it)("sets up new fields", async () => {
606
+ const table = table_1.default.findOne({ name: "books" });
607
+ (0, assertions_1.assertIsSet)(table);
608
+ await field_1.default.create({
609
+ table,
610
+ name: "published",
611
+ label: "Published",
612
+ type: "Date",
613
+ });
614
+ await field_1.default.create({
615
+ table,
616
+ name: "cover_pic",
617
+ label: "Cover Pic",
618
+ type: "File",
619
+ });
620
+ await table.updateRow({ published: new Date("1971-05.04"), cover_pic: "magrite.png" }, 1);
621
+ });
622
+ (0, globals_1.it)("shows image thumbnail", async () => {
623
+ const view = await mkViewWithCfg({
624
+ configuration: {
625
+ layout: {
626
+ besides: [
627
+ {
628
+ contents: {
629
+ type: "field",
630
+ block: false,
631
+ fieldview: "Thumbnail",
632
+ textStyle: "",
633
+ field_name: "cover_pic",
634
+ configuration: {
635
+ width: "66",
636
+ expand: true,
637
+ height: "66",
638
+ },
639
+ },
640
+ alignment: "Default",
641
+ col_width_units: "px",
642
+ },
643
+ ],
644
+ list_columns: true,
645
+ },
646
+ columns: [
647
+ {
648
+ type: "Field",
649
+ block: false,
650
+ fieldview: "Thumbnail",
651
+ textStyle: "",
652
+ field_name: "cover_pic",
653
+ configuration: {
654
+ width: "66",
655
+ expand: true,
656
+ height: "66",
657
+ },
658
+ },
659
+ ],
660
+ },
661
+ });
662
+ const vres1 = await view.run({}, mockReqRes);
663
+ (0, globals_1.expect)(vres1).toContain(`<img src="/files/resize/66/66/magrite.png" onclick="expand_thumbnail('magrite.png', 'magrite.png')">`);
664
+ });
665
+ (0, globals_1.it)("relative date", async () => {
666
+ const view = await mkViewWithCfg({
667
+ configuration: {
668
+ layout: {
669
+ besides: [
670
+ {
671
+ contents: {
672
+ type: "field",
673
+ block: false,
674
+ fieldview: "relative",
675
+ textStyle: "",
676
+ field_name: "published",
677
+ configuration: {
678
+ width: "66",
679
+ expand: true,
680
+ height: "66",
681
+ },
682
+ },
683
+ alignment: "Default",
684
+ col_width_units: "px",
685
+ },
686
+ {
687
+ contents: {
688
+ type: "field",
689
+ block: false,
690
+ fieldview: "format",
691
+ textStyle: "",
692
+ field_name: "published",
693
+ configuration: {
694
+ format: "YYYY",
695
+ },
696
+ },
697
+ alignment: "Default",
698
+ col_width_units: "px",
699
+ },
700
+ ],
701
+ list_columns: true,
702
+ },
703
+ columns: [
704
+ {
705
+ type: "Field",
706
+ block: false,
707
+ fieldview: "relative",
708
+ textStyle: "",
709
+ field_name: "published",
710
+ configuration: {
711
+ width: "66",
712
+ expand: true,
713
+ height: "66",
714
+ },
715
+ },
716
+ {
717
+ type: "Field",
718
+ block: false,
719
+ fieldview: "format",
720
+ textStyle: "",
721
+ field_name: "published",
722
+ configuration: {
723
+ format: "YYYY",
724
+ },
725
+ },
726
+ ],
727
+ },
728
+ });
729
+ const vres1 = await view.run({}, mockReqRes);
730
+ (0, globals_1.expect)(vres1).toContain(`years ago<`);
731
+ (0, globals_1.expect)(vres1).toContain(`>1971</time>`);
732
+ });
733
+ });
734
+ //sorting
735
+ //# sourceMappingURL=list.test.js.map