@saltcorn/data 0.6.1-beta.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base-plugin/actions.js +172 -1
- package/base-plugin/fieldviews.js +63 -0
- package/base-plugin/fileviews.js +41 -0
- package/base-plugin/index.js +35 -0
- package/base-plugin/types.js +345 -9
- package/base-plugin/viewtemplates/edit.js +107 -0
- package/base-plugin/viewtemplates/feed.js +46 -0
- package/base-plugin/viewtemplates/filter.js +43 -0
- package/base-plugin/viewtemplates/list.js +73 -1
- package/base-plugin/viewtemplates/listshowlist.js +54 -3
- package/base-plugin/viewtemplates/room.js +100 -0
- package/base-plugin/viewtemplates/show.js +86 -0
- package/base-plugin/viewtemplates/viewable_fields.js +124 -0
- package/contracts.js +58 -0
- package/db/connect.js +13 -5
- package/db/db.test.js +0 -154
- package/db/fixtures.js +13 -1
- package/db/index.js +42 -3
- package/db/reset_schema.js +11 -0
- package/db/state.js +105 -36
- package/index.js +13 -0
- package/migrate.js +4 -1
- package/models/backup.js +78 -0
- package/models/config.js +113 -22
- package/models/crash.js +44 -0
- package/models/discovery.js +13 -11
- package/models/email.js +17 -0
- package/models/eventlog.js +51 -0
- package/models/expression.js +49 -1
- package/models/field.js +88 -9
- package/models/fieldrepeat.js +33 -0
- package/models/file.js +23 -4
- package/models/form.js +34 -0
- package/models/index.js +42 -0
- package/models/layout.js +33 -0
- package/models/library.js +44 -0
- package/models/pack.js +88 -0
- package/models/page.js +13 -3
- package/models/plugin.js +9 -2
- package/models/random.js +36 -0
- package/models/role.js +36 -0
- package/models/scheduler.js +28 -0
- package/models/table.js +34 -15
- package/models/table_constraints.js +44 -0
- package/models/tenant.js +46 -9
- package/models/trigger.js +24 -11
- package/models/user.js +33 -8
- package/models/view.js +89 -8
- package/models/workflow.js +31 -0
- package/package.json +7 -5
- package/plugin-helper.js +102 -44
- package/plugin-testing.js +4 -0
- package/tests/exact_views.test.js +5 -5
- package/utils.js +4 -0
- package/db/internal.js +0 -229
- package/db/multi-tenant.js +0 -24
- package/db/pg.js +0 -374
- package/db/single-tenant.js +0 -8
- package/db/sqlite.js +0 -280
- package/db/tenants.js +0 -6
package/base-plugin/types.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Embedded Types definition.
|
|
3
3
|
*
|
|
4
|
-
* More types can be added by plugin store mechanism https://store.saltcorn.com/
|
|
4
|
+
* More types can be added by plugin store mechanism https://store.saltcorn.com/
|
|
5
|
+
* @category saltcorn-data
|
|
6
|
+
* @module base-plugin/types
|
|
7
|
+
* @subcategory base-plugin
|
|
5
8
|
*/
|
|
6
9
|
|
|
7
10
|
const moment = require("moment");
|
|
@@ -28,6 +31,11 @@ const isdef = (x) => (typeof x === "undefined" || x === null ? false : true);
|
|
|
28
31
|
|
|
29
32
|
const eqStr = (x, y) => `${x}` === `${y}`;
|
|
30
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @param {string} v
|
|
36
|
+
* @param {string} optsStr
|
|
37
|
+
* @returns {string[]}
|
|
38
|
+
*/
|
|
31
39
|
const getStrOptions = (v, optsStr) =>
|
|
32
40
|
typeof optsStr === "string"
|
|
33
41
|
? optsStr
|
|
@@ -54,13 +62,22 @@ const getStrOptions = (v, optsStr) =>
|
|
|
54
62
|
)
|
|
55
63
|
: option({ value: o, ...(eqStr(v, o) && { selected: true }) }, o)
|
|
56
64
|
);
|
|
65
|
+
|
|
57
66
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
* string type
|
|
68
|
+
* @namespace
|
|
69
|
+
* @category saltcorn-data
|
|
70
|
+
* @subcategory types / string
|
|
71
|
+
*/
|
|
61
72
|
const string = {
|
|
73
|
+
/** @type {string} */
|
|
62
74
|
name: "String",
|
|
75
|
+
/** @type {string} */
|
|
63
76
|
sql_name: "text",
|
|
77
|
+
/**
|
|
78
|
+
* @param {object} param
|
|
79
|
+
* @returns {object}
|
|
80
|
+
*/
|
|
64
81
|
attributes: ({ table }) => {
|
|
65
82
|
const strFields =
|
|
66
83
|
table &&
|
|
@@ -131,23 +148,58 @@ const string = {
|
|
|
131
148
|
: []),
|
|
132
149
|
];
|
|
133
150
|
},
|
|
151
|
+
/**
|
|
152
|
+
* @param {object} opts
|
|
153
|
+
* @param {string|undefined} opts.options
|
|
154
|
+
* @returns {boolean}
|
|
155
|
+
*/
|
|
134
156
|
contract: ({ options }) =>
|
|
135
157
|
typeof options === "string"
|
|
136
158
|
? is.one_of(options.split(","))
|
|
137
159
|
: typeof options === "undefined"
|
|
138
160
|
? is.str
|
|
139
161
|
: is.one_of(options.map((o) => (typeof o === "string" ? o : o.name))),
|
|
162
|
+
/**
|
|
163
|
+
* @namespace
|
|
164
|
+
* @category saltcorn-data
|
|
165
|
+
* @subcategory types / string
|
|
166
|
+
*/
|
|
140
167
|
fieldviews: {
|
|
168
|
+
/**
|
|
169
|
+
* @namespace
|
|
170
|
+
* @category saltcorn-data
|
|
171
|
+
* @subcategory types / string
|
|
172
|
+
*/
|
|
141
173
|
as_text: { isEdit: false, run: (s) => text_attr(s || "") },
|
|
174
|
+
/**
|
|
175
|
+
* @namespace
|
|
176
|
+
* @category saltcorn-data
|
|
177
|
+
* @subcategory types / string
|
|
178
|
+
*/
|
|
142
179
|
as_link: {
|
|
143
180
|
isEdit: false,
|
|
144
181
|
run: (s) => a({ href: text(s || "") }, text_attr(s || "")),
|
|
145
182
|
},
|
|
183
|
+
/**
|
|
184
|
+
* @namespace
|
|
185
|
+
* @category saltcorn-data
|
|
186
|
+
* @subcategory types / string
|
|
187
|
+
*/
|
|
146
188
|
img_from_url: {
|
|
147
189
|
isEdit: false,
|
|
148
190
|
run: (s, req, attrs) => img({ src: text(s || ""), style: "width:100%" }),
|
|
149
191
|
},
|
|
192
|
+
/**
|
|
193
|
+
* @namespace
|
|
194
|
+
* @category saltcorn-data
|
|
195
|
+
* @subcategory types / string
|
|
196
|
+
*/
|
|
150
197
|
as_header: { isEdit: false, run: (s) => h3(text_attr(s || "")) },
|
|
198
|
+
/**
|
|
199
|
+
* @namespace
|
|
200
|
+
* @category saltcorn-data
|
|
201
|
+
* @subcategory types / string
|
|
202
|
+
*/
|
|
151
203
|
edit: {
|
|
152
204
|
isEdit: true,
|
|
153
205
|
configFields: (field) => [
|
|
@@ -226,6 +278,11 @@ const string = {
|
|
|
226
278
|
...(isdef(v) && { value: text_attr(v) }),
|
|
227
279
|
}),
|
|
228
280
|
},
|
|
281
|
+
/**
|
|
282
|
+
* @namespace
|
|
283
|
+
* @category saltcorn-data
|
|
284
|
+
* @subcategory types / string
|
|
285
|
+
*/
|
|
229
286
|
textarea: {
|
|
230
287
|
isEdit: true,
|
|
231
288
|
run: (nm, v, attrs, cls, required, field) =>
|
|
@@ -241,6 +298,11 @@ const string = {
|
|
|
241
298
|
text(v) || ""
|
|
242
299
|
),
|
|
243
300
|
},
|
|
301
|
+
/**
|
|
302
|
+
* @namespace
|
|
303
|
+
* @category saltcorn-data
|
|
304
|
+
* @subcategory types / string
|
|
305
|
+
*/
|
|
244
306
|
radio_group: {
|
|
245
307
|
isEdit: true,
|
|
246
308
|
configFields: [
|
|
@@ -264,6 +326,11 @@ const string = {
|
|
|
264
326
|
})
|
|
265
327
|
: i("None available"),
|
|
266
328
|
},
|
|
329
|
+
/**
|
|
330
|
+
* @namespace
|
|
331
|
+
* @category saltcorn-data
|
|
332
|
+
* @subcategory types / string
|
|
333
|
+
*/
|
|
267
334
|
password: {
|
|
268
335
|
isEdit: true,
|
|
269
336
|
run: (nm, v, attrs, cls, required, field) =>
|
|
@@ -279,6 +346,10 @@ const string = {
|
|
|
279
346
|
}),
|
|
280
347
|
},
|
|
281
348
|
},
|
|
349
|
+
/**
|
|
350
|
+
* @param {*} v
|
|
351
|
+
* @returns {string|undefined}
|
|
352
|
+
*/
|
|
282
353
|
read: (v) => {
|
|
283
354
|
switch (typeof v) {
|
|
284
355
|
case "string":
|
|
@@ -288,10 +359,29 @@ const string = {
|
|
|
288
359
|
return undefined;
|
|
289
360
|
}
|
|
290
361
|
},
|
|
362
|
+
/**
|
|
363
|
+
* @namespace
|
|
364
|
+
* @category saltcorn-data
|
|
365
|
+
* @subcategory types / string
|
|
366
|
+
*/
|
|
291
367
|
presets: {
|
|
368
|
+
/**
|
|
369
|
+
* @param {object} opts
|
|
370
|
+
* @param {object} opts.req
|
|
371
|
+
* @returns {object}
|
|
372
|
+
*/
|
|
292
373
|
IP: ({ req }) => req.ip,
|
|
374
|
+
/**
|
|
375
|
+
* @param {object} opts
|
|
376
|
+
* @param {object} opts.req
|
|
377
|
+
* @returns {object}
|
|
378
|
+
*/
|
|
293
379
|
SessionID: ({ req }) => req.sessionID || req.cookies["express:sess"],
|
|
294
380
|
},
|
|
381
|
+
/**
|
|
382
|
+
* @param {object} param
|
|
383
|
+
* @returns {object|true}
|
|
384
|
+
*/
|
|
295
385
|
validate: ({ min_length, max_length, regexp, re_invalid_error }) => (x) => {
|
|
296
386
|
if (!x || typeof x !== "string") return true; //{ error: "Not a string" };
|
|
297
387
|
if (isdef(min_length) && x.length < min_length)
|
|
@@ -302,10 +392,20 @@ const string = {
|
|
|
302
392
|
return { error: re_invalid_error || `Does not match regular expression` };
|
|
303
393
|
return true;
|
|
304
394
|
},
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* @param {object} param
|
|
398
|
+
* @returns {object}
|
|
399
|
+
*/
|
|
305
400
|
validate_attributes: ({ min_length, max_length, regexp }) =>
|
|
306
401
|
(!isdef(min_length) || !isdef(max_length) || max_length >= min_length) &&
|
|
307
402
|
(!isdef(regexp) || is_valid_regexp(regexp)),
|
|
308
403
|
};
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* @param {string} s
|
|
407
|
+
* @returns {boolean}
|
|
408
|
+
*/
|
|
309
409
|
const is_valid_regexp = (s) => {
|
|
310
410
|
try {
|
|
311
411
|
new RegExp(s);
|
|
@@ -314,17 +414,43 @@ const is_valid_regexp = (s) => {
|
|
|
314
414
|
return false;
|
|
315
415
|
}
|
|
316
416
|
};
|
|
417
|
+
|
|
317
418
|
/**
|
|
318
419
|
* Integer type
|
|
319
|
-
* @
|
|
420
|
+
* @namespace
|
|
421
|
+
* @category saltcorn-data
|
|
422
|
+
* @subcategory types / int
|
|
320
423
|
*/
|
|
321
424
|
const int = {
|
|
425
|
+
/** @type {string} */
|
|
322
426
|
name: "Integer",
|
|
427
|
+
/** @type {string} */
|
|
323
428
|
sql_name: "int",
|
|
429
|
+
/**
|
|
430
|
+
* @param {object} opts
|
|
431
|
+
* @param {number} opts.min
|
|
432
|
+
* @param {number} opts.max
|
|
433
|
+
* @returns {boolean}
|
|
434
|
+
*/
|
|
324
435
|
contract: ({ min, max }) => is.integer({ lte: max, gte: min }),
|
|
325
436
|
primaryKey: { sql_type: "serial" },
|
|
437
|
+
/**
|
|
438
|
+
* @namespace
|
|
439
|
+
* @category saltcorn-data
|
|
440
|
+
* @subcategory types / int
|
|
441
|
+
*/
|
|
326
442
|
fieldviews: {
|
|
443
|
+
/**
|
|
444
|
+
* @namespace
|
|
445
|
+
* @category saltcorn-data
|
|
446
|
+
* @subcategory types / int
|
|
447
|
+
*/
|
|
327
448
|
show: { isEdit: false, run: (s) => text(s) },
|
|
449
|
+
/**
|
|
450
|
+
* @namespace
|
|
451
|
+
* @category saltcorn-data
|
|
452
|
+
* @subcategory types / int
|
|
453
|
+
*/
|
|
328
454
|
edit: {
|
|
329
455
|
isEdit: true,
|
|
330
456
|
run: (nm, v, attrs, cls, required, field) =>
|
|
@@ -342,12 +468,21 @@ const int = {
|
|
|
342
468
|
}),
|
|
343
469
|
},
|
|
344
470
|
},
|
|
471
|
+
/** @type {object[]} */
|
|
345
472
|
attributes: [
|
|
346
473
|
{ name: "max", type: "Integer", required: false },
|
|
347
474
|
{ name: "min", type: "Integer", required: false },
|
|
348
475
|
],
|
|
476
|
+
/**
|
|
477
|
+
* @param {object} param
|
|
478
|
+
* @returns {boolean}
|
|
479
|
+
*/
|
|
349
480
|
validate_attributes: ({ min, max }) =>
|
|
350
481
|
!isdef(min) || !isdef(max) || max > min,
|
|
482
|
+
/**
|
|
483
|
+
* @param {object} v
|
|
484
|
+
* @returns {object}
|
|
485
|
+
*/
|
|
351
486
|
read: (v) => {
|
|
352
487
|
switch (typeof v) {
|
|
353
488
|
case "number":
|
|
@@ -360,21 +495,43 @@ const int = {
|
|
|
360
495
|
return undefined;
|
|
361
496
|
}
|
|
362
497
|
},
|
|
498
|
+
/**
|
|
499
|
+
* @param {object} param
|
|
500
|
+
* @returns {boolean}
|
|
501
|
+
*/
|
|
363
502
|
validate: ({ min, max }) => (x) => {
|
|
364
503
|
if (isdef(min) && x < min) return { error: `Must be ${min} or higher` };
|
|
365
504
|
if (isdef(max) && x > max) return { error: `Must be ${max} or less` };
|
|
366
505
|
return true;
|
|
367
506
|
},
|
|
368
507
|
};
|
|
508
|
+
|
|
369
509
|
/**
|
|
370
510
|
* Color Type
|
|
371
|
-
* @
|
|
511
|
+
* @namespace color
|
|
512
|
+
* @category saltcorn-data
|
|
513
|
+
* @subcategory types / color
|
|
372
514
|
*/
|
|
373
515
|
const color = {
|
|
516
|
+
/** @type {string} */
|
|
374
517
|
name: "Color",
|
|
518
|
+
/** @type {string} */
|
|
375
519
|
sql_name: "text",
|
|
520
|
+
/**
|
|
521
|
+
* @returns {function}
|
|
522
|
+
*/
|
|
376
523
|
contract: () => is.str,
|
|
524
|
+
/**
|
|
525
|
+
* @namespace
|
|
526
|
+
* @category saltcorn-data
|
|
527
|
+
* @subcategory types / color
|
|
528
|
+
*/
|
|
377
529
|
fieldviews: {
|
|
530
|
+
/**
|
|
531
|
+
* @namespace
|
|
532
|
+
* @category saltcorn-data
|
|
533
|
+
* @subcategory types / color
|
|
534
|
+
*/
|
|
378
535
|
show: {
|
|
379
536
|
isEdit: false,
|
|
380
537
|
run: (s) =>
|
|
@@ -385,6 +542,11 @@ const color = {
|
|
|
385
542
|
})
|
|
386
543
|
: "",
|
|
387
544
|
},
|
|
545
|
+
/**
|
|
546
|
+
* @namespace
|
|
547
|
+
* @category saltcorn-data
|
|
548
|
+
* @subcategory types / color
|
|
549
|
+
*/
|
|
388
550
|
edit: {
|
|
389
551
|
isEdit: true,
|
|
390
552
|
run: (nm, v, attrs, cls, required, field) =>
|
|
@@ -399,7 +561,12 @@ const color = {
|
|
|
399
561
|
}),
|
|
400
562
|
},
|
|
401
563
|
},
|
|
564
|
+
/** @type {object[]} */
|
|
402
565
|
attributes: [],
|
|
566
|
+
/**
|
|
567
|
+
* @param {object} v
|
|
568
|
+
* @returns {object}
|
|
569
|
+
*/
|
|
403
570
|
read: (v) => {
|
|
404
571
|
switch (typeof v) {
|
|
405
572
|
case "string":
|
|
@@ -408,20 +575,49 @@ const color = {
|
|
|
408
575
|
return undefined;
|
|
409
576
|
}
|
|
410
577
|
},
|
|
578
|
+
/**
|
|
579
|
+
* @returns {boolean}
|
|
580
|
+
*/
|
|
411
581
|
validate: () => (x) => {
|
|
412
582
|
return true;
|
|
413
583
|
},
|
|
414
584
|
};
|
|
585
|
+
|
|
415
586
|
/**
|
|
416
587
|
* Float type
|
|
417
|
-
* @
|
|
588
|
+
* @namespace
|
|
589
|
+
* @category saltcorn-data
|
|
590
|
+
* @subcategory types / float
|
|
418
591
|
*/
|
|
419
592
|
const float = {
|
|
593
|
+
/** @type {string} */
|
|
420
594
|
name: "Float",
|
|
595
|
+
/** @type {string} */
|
|
421
596
|
sql_name: "double precision",
|
|
597
|
+
/**
|
|
598
|
+
* @param {object} opts
|
|
599
|
+
* @param {number} opts.min
|
|
600
|
+
* @param {number} opts.max
|
|
601
|
+
* @returns {function}
|
|
602
|
+
*/
|
|
422
603
|
contract: ({ min, max }) => is.number({ lte: max, gte: min }),
|
|
604
|
+
/**
|
|
605
|
+
* @namespace
|
|
606
|
+
* @category saltcorn-data
|
|
607
|
+
* @subcategory types / float
|
|
608
|
+
*/
|
|
423
609
|
fieldviews: {
|
|
610
|
+
/**
|
|
611
|
+
* @namespace
|
|
612
|
+
* @category saltcorn-data
|
|
613
|
+
* @subcategory types / float
|
|
614
|
+
*/
|
|
424
615
|
show: { isEdit: false, run: (s) => text(s) },
|
|
616
|
+
/**
|
|
617
|
+
* @namespace
|
|
618
|
+
* @category saltcorn-data
|
|
619
|
+
* @subcategory types / float
|
|
620
|
+
*/
|
|
425
621
|
edit: {
|
|
426
622
|
isEdit: true,
|
|
427
623
|
run: (nm, v, attrs, cls, required, field) =>
|
|
@@ -441,12 +637,17 @@ const float = {
|
|
|
441
637
|
}),
|
|
442
638
|
},
|
|
443
639
|
},
|
|
640
|
+
/** @type {object[]} */
|
|
444
641
|
attributes: [
|
|
445
642
|
{ name: "max", type: "Float", required: false },
|
|
446
643
|
{ name: "min", type: "Float", required: false },
|
|
447
644
|
{ name: "units", type: "String", required: false },
|
|
448
645
|
{ name: "decimal_places", type: "Integer", required: false },
|
|
449
646
|
],
|
|
647
|
+
/**
|
|
648
|
+
* @param {object} v
|
|
649
|
+
* @returns {number|string|undefined}
|
|
650
|
+
*/
|
|
450
651
|
read: (v) => {
|
|
451
652
|
switch (typeof v) {
|
|
452
653
|
case "number":
|
|
@@ -458,31 +659,63 @@ const float = {
|
|
|
458
659
|
return undefined;
|
|
459
660
|
}
|
|
460
661
|
},
|
|
662
|
+
/**
|
|
663
|
+
* @param {object} param
|
|
664
|
+
* @returns {object|boolean}
|
|
665
|
+
*/
|
|
461
666
|
validate: ({ min, max }) => (x) => {
|
|
462
667
|
if (isdef(min) && x < min) return { error: `Must be ${min} or higher` };
|
|
463
668
|
if (isdef(max) && x > max) return { error: `Must be ${max} or less` };
|
|
464
669
|
return true;
|
|
465
670
|
},
|
|
466
671
|
};
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* @param {object} req
|
|
675
|
+
* @returns {string|undefined}
|
|
676
|
+
*/
|
|
467
677
|
const locale = (req) => {
|
|
468
678
|
//console.log(req && req.getLocale ? req.getLocale() : undefined);
|
|
469
679
|
return req && req.getLocale ? req.getLocale() : undefined;
|
|
470
680
|
};
|
|
471
681
|
|
|
682
|
+
/**
|
|
683
|
+
* @param {*} x
|
|
684
|
+
* @returns {*}
|
|
685
|
+
*/
|
|
472
686
|
const logit = (x) => {
|
|
473
687
|
console.log(x);
|
|
474
688
|
return x;
|
|
475
689
|
};
|
|
690
|
+
|
|
476
691
|
/**
|
|
477
692
|
* Date type
|
|
478
|
-
* @
|
|
693
|
+
* @namespace
|
|
694
|
+
* @category saltcorn-data
|
|
695
|
+
* @subcategory types / date
|
|
479
696
|
*/
|
|
480
697
|
const date = {
|
|
698
|
+
/** @type {string} */
|
|
481
699
|
name: "Date",
|
|
700
|
+
/** @type {string} */
|
|
482
701
|
sql_name: "timestamptz",
|
|
702
|
+
/**
|
|
703
|
+
* @returns {function}
|
|
704
|
+
*/
|
|
483
705
|
contract: () => is.date,
|
|
706
|
+
/** @type {object[]} */
|
|
484
707
|
attributes: [],
|
|
708
|
+
/**
|
|
709
|
+
* @namespace
|
|
710
|
+
* @category saltcorn-data
|
|
711
|
+
* @subcategory types / date
|
|
712
|
+
*/
|
|
485
713
|
fieldviews: {
|
|
714
|
+
/**
|
|
715
|
+
* @namespace
|
|
716
|
+
* @category saltcorn-data
|
|
717
|
+
* @subcategory types / date
|
|
718
|
+
*/
|
|
486
719
|
show: {
|
|
487
720
|
isEdit: false,
|
|
488
721
|
run: (d, req) =>
|
|
@@ -494,6 +727,11 @@ const date = {
|
|
|
494
727
|
: ""
|
|
495
728
|
),
|
|
496
729
|
},
|
|
730
|
+
/**
|
|
731
|
+
* @namespace
|
|
732
|
+
* @category saltcorn-data
|
|
733
|
+
* @subcategory types / date
|
|
734
|
+
*/
|
|
497
735
|
showDay: {
|
|
498
736
|
isEdit: false,
|
|
499
737
|
run: (d, req) =>
|
|
@@ -505,6 +743,11 @@ const date = {
|
|
|
505
743
|
: ""
|
|
506
744
|
),
|
|
507
745
|
},
|
|
746
|
+
/**
|
|
747
|
+
* @namespace
|
|
748
|
+
* @category saltcorn-data
|
|
749
|
+
* @subcategory types / date
|
|
750
|
+
*/
|
|
508
751
|
format: {
|
|
509
752
|
isEdit: false,
|
|
510
753
|
configFields: [
|
|
@@ -521,6 +764,11 @@ const date = {
|
|
|
521
764
|
return text(moment(d).format(options.format));
|
|
522
765
|
},
|
|
523
766
|
},
|
|
767
|
+
/**
|
|
768
|
+
* @namespace
|
|
769
|
+
* @category saltcorn-data
|
|
770
|
+
* @subcategory types / date
|
|
771
|
+
*/
|
|
524
772
|
relative: {
|
|
525
773
|
isEdit: false,
|
|
526
774
|
run: (d, req) => {
|
|
@@ -530,6 +778,11 @@ const date = {
|
|
|
530
778
|
else return text(moment(d).fromNow());
|
|
531
779
|
},
|
|
532
780
|
},
|
|
781
|
+
/**
|
|
782
|
+
* @namespace
|
|
783
|
+
* @category saltcorn-data
|
|
784
|
+
* @subcategory types / date
|
|
785
|
+
*/
|
|
533
786
|
yearsAgo: {
|
|
534
787
|
isEdit: false,
|
|
535
788
|
run: (d, req) => {
|
|
@@ -537,6 +790,11 @@ const date = {
|
|
|
537
790
|
return text(moment.duration(new Date() - d).years());
|
|
538
791
|
},
|
|
539
792
|
},
|
|
793
|
+
/**
|
|
794
|
+
* @namespace
|
|
795
|
+
* @category saltcorn-data
|
|
796
|
+
* @subcategory types / date
|
|
797
|
+
*/
|
|
540
798
|
edit: {
|
|
541
799
|
isEdit: true,
|
|
542
800
|
run: (nm, v, attrs, cls, required, field) =>
|
|
@@ -554,6 +812,11 @@ const date = {
|
|
|
554
812
|
}),
|
|
555
813
|
}),
|
|
556
814
|
},
|
|
815
|
+
/**
|
|
816
|
+
* @namespace
|
|
817
|
+
* @category saltcorn-data
|
|
818
|
+
* @subcategory types / date
|
|
819
|
+
*/
|
|
557
820
|
editDay: {
|
|
558
821
|
isEdit: true,
|
|
559
822
|
run: (nm, v, attrs, cls, required, field) =>
|
|
@@ -572,9 +835,19 @@ const date = {
|
|
|
572
835
|
}),
|
|
573
836
|
},
|
|
574
837
|
},
|
|
838
|
+
/**
|
|
839
|
+
* @namespace
|
|
840
|
+
* @category saltcorn-data
|
|
841
|
+
* @subcategory types / date
|
|
842
|
+
*/
|
|
575
843
|
presets: {
|
|
576
844
|
Now: () => new Date(),
|
|
577
845
|
},
|
|
846
|
+
/**
|
|
847
|
+
* @param {object} v
|
|
848
|
+
* @param {object} attrs
|
|
849
|
+
* @returns {object}
|
|
850
|
+
*/
|
|
578
851
|
read: (v, attrs) => {
|
|
579
852
|
if (v instanceof Date && !isNaN(v)) return v;
|
|
580
853
|
if (typeof v === "string") {
|
|
@@ -587,17 +860,39 @@ const date = {
|
|
|
587
860
|
else return null;
|
|
588
861
|
}
|
|
589
862
|
},
|
|
863
|
+
/**
|
|
864
|
+
* @param {object} param
|
|
865
|
+
* @returns {boolean}
|
|
866
|
+
*/
|
|
590
867
|
validate: ({}) => (v) => v instanceof Date && !isNaN(v),
|
|
591
868
|
};
|
|
869
|
+
|
|
592
870
|
/**
|
|
593
871
|
* Boolean Type
|
|
594
|
-
* @
|
|
872
|
+
* @namespace
|
|
873
|
+
* @category saltcorn-data
|
|
874
|
+
* @subcategory types / bool
|
|
595
875
|
*/
|
|
596
876
|
const bool = {
|
|
877
|
+
/** @type {string} */
|
|
597
878
|
name: "Bool",
|
|
879
|
+
/** @type {string} */
|
|
598
880
|
sql_name: "boolean",
|
|
881
|
+
/**
|
|
882
|
+
* @returns {function}
|
|
883
|
+
*/
|
|
599
884
|
contract: () => is.bool,
|
|
885
|
+
/**
|
|
886
|
+
* @namespace
|
|
887
|
+
* @category saltcorn-data
|
|
888
|
+
* @subcategory types / bool
|
|
889
|
+
*/
|
|
600
890
|
fieldviews: {
|
|
891
|
+
/**
|
|
892
|
+
* @namespace
|
|
893
|
+
* @category saltcorn-data
|
|
894
|
+
* @subcategory types / bool
|
|
895
|
+
*/
|
|
601
896
|
show: {
|
|
602
897
|
isEdit: false,
|
|
603
898
|
run: (v) =>
|
|
@@ -611,6 +906,11 @@ const bool = {
|
|
|
611
906
|
})
|
|
612
907
|
: "",
|
|
613
908
|
},
|
|
909
|
+
/**
|
|
910
|
+
* @namespace
|
|
911
|
+
* @category saltcorn-data
|
|
912
|
+
* @subcategory types / bool
|
|
913
|
+
*/
|
|
614
914
|
checkboxes: {
|
|
615
915
|
isEdit: false,
|
|
616
916
|
run: (v) =>
|
|
@@ -620,10 +920,20 @@ const bool = {
|
|
|
620
920
|
? input({ type: "checkbox", disabled: true })
|
|
621
921
|
: "",
|
|
622
922
|
},
|
|
923
|
+
/**
|
|
924
|
+
* @namespace
|
|
925
|
+
* @category saltcorn-data
|
|
926
|
+
* @subcategory types / bool
|
|
927
|
+
*/
|
|
623
928
|
TrueFalse: {
|
|
624
929
|
isEdit: false,
|
|
625
930
|
run: (v) => (v === true ? "True" : v === false ? "False" : ""),
|
|
626
931
|
},
|
|
932
|
+
/**
|
|
933
|
+
* @namespace
|
|
934
|
+
* @category saltcorn-data
|
|
935
|
+
* @subcategory types / bool
|
|
936
|
+
*/
|
|
627
937
|
edit: {
|
|
628
938
|
isEdit: true,
|
|
629
939
|
run: (nm, v, attrs, cls, required, field) =>
|
|
@@ -637,6 +947,11 @@ const bool = {
|
|
|
637
947
|
...(attrs.disabled && { onclick: "return false;" }),
|
|
638
948
|
}),
|
|
639
949
|
},
|
|
950
|
+
/**
|
|
951
|
+
* @namespace
|
|
952
|
+
* @category saltcorn-data
|
|
953
|
+
* @subcategory types / bool
|
|
954
|
+
*/
|
|
640
955
|
tristate: {
|
|
641
956
|
isEdit: true,
|
|
642
957
|
run: (nm, v, attrs, cls, required, field) =>
|
|
@@ -663,13 +978,23 @@ const bool = {
|
|
|
663
978
|
),
|
|
664
979
|
},
|
|
665
980
|
},
|
|
981
|
+
/** @type {object[]} */
|
|
666
982
|
attributes: [],
|
|
983
|
+
/**
|
|
984
|
+
* @param {*} rec
|
|
985
|
+
* @param {string} name
|
|
986
|
+
* @returns {boolean|null}
|
|
987
|
+
*/
|
|
667
988
|
readFromFormRecord: (rec, name) => {
|
|
668
989
|
if (!rec[name]) return false;
|
|
669
990
|
if (["undefined", "false", "off"].includes(rec[name])) return false;
|
|
670
991
|
if (rec[name] === "?") return null;
|
|
671
992
|
return rec[name] ? true : false;
|
|
672
993
|
},
|
|
994
|
+
/**
|
|
995
|
+
* @param {object} v
|
|
996
|
+
* @returns {boolean|null}
|
|
997
|
+
*/
|
|
673
998
|
read: (v) => {
|
|
674
999
|
switch (typeof v) {
|
|
675
1000
|
case "string":
|
|
@@ -681,8 +1006,19 @@ const bool = {
|
|
|
681
1006
|
return v ? true : false;
|
|
682
1007
|
}
|
|
683
1008
|
},
|
|
1009
|
+
/**
|
|
1010
|
+
* @param {object} v
|
|
1011
|
+
* @returns {object}
|
|
1012
|
+
*/
|
|
684
1013
|
readFromDB: (v) => !!v,
|
|
1014
|
+
/**
|
|
1015
|
+
* @param {object} v
|
|
1016
|
+
* @returns {object}
|
|
1017
|
+
*/
|
|
685
1018
|
listAs: (v) => JSON.stringify(v),
|
|
1019
|
+
/**
|
|
1020
|
+
* @returns {boolean}
|
|
1021
|
+
*/
|
|
686
1022
|
validate: () => (x) => true,
|
|
687
1023
|
};
|
|
688
1024
|
|