@saltcorn/server 0.9.5-beta.24 → 0.9.5-beta.25

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/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@saltcorn/server",
3
- "version": "0.9.5-beta.24",
3
+ "version": "0.9.5-beta.25",
4
4
  "description": "Server app for Saltcorn, open-source no-code platform",
5
5
  "homepage": "https://saltcorn.com",
6
6
  "main": "index.js",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
9
  "@aws-sdk/client-s3": "^3.451.0",
10
- "@saltcorn/base-plugin": "0.9.5-beta.24",
11
- "@saltcorn/builder": "0.9.5-beta.24",
12
- "@saltcorn/data": "0.9.5-beta.24",
13
- "@saltcorn/admin-models": "0.9.5-beta.24",
14
- "@saltcorn/filemanager": "0.9.5-beta.24",
15
- "@saltcorn/markup": "0.9.5-beta.24",
16
- "@saltcorn/plugins-loader": "0.9.5-beta.24",
17
- "@saltcorn/sbadmin2": "0.9.5-beta.24",
10
+ "@saltcorn/base-plugin": "0.9.5-beta.25",
11
+ "@saltcorn/builder": "0.9.5-beta.25",
12
+ "@saltcorn/data": "0.9.5-beta.25",
13
+ "@saltcorn/admin-models": "0.9.5-beta.25",
14
+ "@saltcorn/filemanager": "0.9.5-beta.25",
15
+ "@saltcorn/markup": "0.9.5-beta.25",
16
+ "@saltcorn/plugins-loader": "0.9.5-beta.25",
17
+ "@saltcorn/sbadmin2": "0.9.5-beta.25",
18
18
  "@socket.io/cluster-adapter": "^0.2.1",
19
19
  "@socket.io/sticky": "^1.0.1",
20
20
  "adm-zip": "0.5.10",
package/routes/fields.js CHANGED
@@ -251,6 +251,16 @@ const fieldFlow = (req) =>
251
251
  : ""
252
252
  }row).${model_output}`;
253
253
  }
254
+ if (context.expression_type === "Aggregation") {
255
+ expression = "__aggregation";
256
+ attributes.agg_relation = context.agg_relation;
257
+ attributes.agg_field = context.agg_field;
258
+ attributes.aggwhere = context.aggwhere;
259
+ attributes.aggregate = context.aggregate;
260
+ const [table, ref] = context.agg_relation.split(".");
261
+ attributes.table = table;
262
+ attributes.ref = ref;
263
+ }
254
264
  const { reftable_name, type } = calcFieldType(context.type);
255
265
  const fldRow = {
256
266
  table_id,
@@ -421,6 +431,50 @@ const fieldFlow = (req) =>
421
431
  );
422
432
  output_options[model.name] = outputs.map((o) => o.name);
423
433
  }
434
+ const aggStatOptions = {};
435
+
436
+ const { child_field_list, child_relations } =
437
+ await table.get_child_relations(true);
438
+ const agg_field_opts = child_relations.map(
439
+ ({ table, key_field, through }) => {
440
+ const aggKey =
441
+ (through ? `${through.name}->` : "") +
442
+ `${table.name}.${key_field.name}`;
443
+ aggStatOptions[aggKey] = [
444
+ "Count",
445
+ "CountUnique",
446
+ "Avg",
447
+ "Sum",
448
+ "Max",
449
+ "Min",
450
+ "Array_Agg",
451
+ ];
452
+ table.fields.forEach((f) => {
453
+ if (f.type && f.type.name === "Date") {
454
+ aggStatOptions[aggKey].push(`Latest ${f.name}`);
455
+ aggStatOptions[aggKey].push(`Earliest ${f.name}`);
456
+ }
457
+ });
458
+ return {
459
+ name: `agg_field`,
460
+ label: req.__("On Field"),
461
+ type: "String",
462
+ required: true,
463
+ attributes: {
464
+ options: table.fields
465
+ .filter((f) => !f.calculated || f.stored)
466
+ .map((f) => ({
467
+ label: f.name,
468
+ name: `${f.name}@${f.type_name}`,
469
+ })),
470
+ },
471
+ showIf: {
472
+ agg_relation: aggKey,
473
+ expression_type: "Aggregation",
474
+ },
475
+ };
476
+ }
477
+ );
424
478
  return new Form({
425
479
  fields: [
426
480
  {
@@ -429,9 +483,41 @@ const fieldFlow = (req) =>
429
483
  input_type: "select",
430
484
  options: [
431
485
  "JavaScript expression",
486
+ ...(child_relations.length ? ["Aggregation"] : []),
432
487
  ...(models.length ? ["Model prediction"] : []),
433
488
  ],
434
489
  },
490
+ {
491
+ name: "agg_relation",
492
+ label: req.__("Relation"),
493
+ type: "String",
494
+ required: true,
495
+ attributes: {
496
+ options: child_field_list,
497
+ },
498
+ showIf: { expression_type: "Aggregation" },
499
+ },
500
+ ...agg_field_opts,
501
+ {
502
+ name: "aggregate",
503
+ label: req.__("Statistic"),
504
+ type: "String",
505
+ required: true,
506
+ attributes: {
507
+ calcOptions: ["agg_relation", aggStatOptions],
508
+ },
509
+
510
+ showIf: { expression_type: "Aggregation" },
511
+ },
512
+ {
513
+ name: "aggwhere",
514
+ label: req.__("Where"),
515
+ sublabel: req.__("Formula"),
516
+ class: "validate-expression",
517
+ type: "String",
518
+ required: false,
519
+ showIf: { expression_type: "Aggregation" },
520
+ },
435
521
  {
436
522
  name: "model",
437
523
  label: req.__("Model"),
@@ -487,7 +573,9 @@ const fieldFlow = (req) =>
487
573
  new Field({
488
574
  name: "test_btn",
489
575
  label: req.__("Test"),
490
- showIf: { expression_type: "JavaScript expression" },
576
+ showIf: {
577
+ expression_type: ["JavaScript expression", "Aggregation"],
578
+ },
491
579
  // todo sublabel
492
580
  input_type: "custom_html",
493
581
  attributes: {
@@ -652,6 +740,9 @@ router.get(
652
740
  {
653
741
  ...field.toJson,
654
742
  ...field.attributes,
743
+ ...(field.expression === "__aggregation"
744
+ ? { expression_type: "Aggregation" }
745
+ : {}),
655
746
  },
656
747
  req
657
748
  );
package/systemd.js CHANGED
@@ -43,7 +43,7 @@ const watchDog = (interval, notify, { port }) => {
43
43
  });
44
44
  }
45
45
  } else {
46
- getState().log(5, `watchdog with no test`);
46
+ getState().log(6, `watchdog with no test`);
47
47
  notify.watchdog();
48
48
  return;
49
49
  }