@saltcorn/server 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.
Files changed (53) hide show
  1. package/app.js +7 -0
  2. package/auth/admin.js +120 -5
  3. package/auth/index.js +7 -0
  4. package/auth/resetpw.js +22 -0
  5. package/auth/roleadmin.js +52 -0
  6. package/auth/routes.js +211 -2
  7. package/auth/testhelp.js +69 -0
  8. package/errors.js +14 -1
  9. package/fixture_persons.js +14 -0
  10. package/index.js +6 -0
  11. package/load_plugins.js +4 -3
  12. package/locales/en.json +7 -1
  13. package/markup/admin.js +97 -1
  14. package/markup/blockly.js +15 -0
  15. package/markup/expression_blurb.js +45 -0
  16. package/markup/forms.js +24 -0
  17. package/markup/index.js +7 -0
  18. package/markup/plugin-store.js +36 -0
  19. package/package.json +6 -6
  20. package/public/saltcorn-builder.css +1 -0
  21. package/public/saltcorn.js +5 -1
  22. package/routes/actions.js +53 -1
  23. package/routes/admin.js +97 -1
  24. package/routes/api.js +45 -10
  25. package/routes/config.js +18 -0
  26. package/routes/crashlog.js +31 -0
  27. package/routes/delete.js +19 -0
  28. package/routes/edit.js +19 -0
  29. package/routes/eventlog.js +65 -1
  30. package/routes/events.js +19 -0
  31. package/routes/fields.js +88 -0
  32. package/routes/files.js +62 -0
  33. package/routes/homepage.js +175 -80
  34. package/routes/index.js +7 -1
  35. package/routes/infoarch.js +56 -0
  36. package/routes/library.js +32 -0
  37. package/routes/list.js +28 -1
  38. package/routes/menu.js +45 -0
  39. package/routes/packs.js +53 -0
  40. package/routes/page.js +26 -0
  41. package/routes/pageedit.js +129 -3
  42. package/routes/plugins.js +156 -5
  43. package/routes/scapi.js +79 -23
  44. package/routes/search.js +51 -0
  45. package/routes/settings.js +27 -0
  46. package/routes/tables.js +148 -19
  47. package/routes/tenant.js +123 -31
  48. package/routes/utils.js +60 -1
  49. package/routes/view.js +37 -0
  50. package/routes/viewedit.js +114 -1
  51. package/serve.js +138 -88
  52. package/systemd.js +18 -1
  53. package/wrapper.js +4 -0
package/routes/tables.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @category server
3
+ * @module routes/tables
4
+ * @subcategory routes
5
+ */
6
+
1
7
  const Router = require("express-promise-router");
2
8
 
3
9
  const db = require("@saltcorn/data/db");
@@ -48,12 +54,19 @@ const {
48
54
  const { getState } = require("@saltcorn/data/db/state");
49
55
  const { cardHeaderTabs } = require("@saltcorn/markup/layout_utils");
50
56
 
57
+ /**
58
+ * @type {object}
59
+ * @const
60
+ * @namespace tablesRouter
61
+ * @category server
62
+ * @subcategory routes
63
+ */
51
64
  const router = new Router();
52
65
  module.exports = router;
53
66
  /**
54
67
  * Show Table Form
55
- * @param table
56
- * @param req
68
+ * @param {object} table
69
+ * @param {object} req
57
70
  * @returns {Promise<Form>}
58
71
  */
59
72
  const tableForm = async (table, req) => {
@@ -148,8 +161,13 @@ const tableForm = async (table, req) => {
148
161
  }
149
162
  return form;
150
163
  };
164
+
151
165
  /**
152
166
  * New table (GET handler)
167
+ * @name get/new
168
+ * @function
169
+ * @memberof module:routes/tables~tablesRouter
170
+ * @function
153
171
  */
154
172
  router.get(
155
173
  "/new/",
@@ -190,8 +208,8 @@ router.get(
190
208
  );
191
209
  /**
192
210
  * Discover Database Tables Form
193
- * @param tables - list of tables
194
- * @param req - HTTP Request
211
+ * @param {object[]} tables list of tables
212
+ * @param {object} req HTTP Request
195
213
  * @returns {Form}
196
214
  */
197
215
  const discoverForm = (tables, req) => {
@@ -213,8 +231,13 @@ const discoverForm = (tables, req) => {
213
231
  })),
214
232
  });
215
233
  };
234
+
216
235
  /**
217
236
  * Table Discover (GET handler)
237
+ * @name get/discover
238
+ * @function
239
+ * @memberof module:routes/tables~tablesRouter
240
+ * @function
218
241
  */
219
242
  router.get(
220
243
  "/discover",
@@ -243,8 +266,13 @@ router.get(
243
266
  });
244
267
  })
245
268
  );
269
+
246
270
  /**
247
271
  * Table Discover (post)
272
+ * @name post/discover
273
+ * @function
274
+ * @memberof module:routes/tables~tablesRouter
275
+ * @function
248
276
  */
249
277
  router.post(
250
278
  "/discover",
@@ -266,8 +294,13 @@ router.post(
266
294
  res.redirect("/table");
267
295
  })
268
296
  );
297
+
269
298
  /**
270
299
  * Create Table from CSV file (get)
300
+ * @name get/create-from-csv
301
+ * @function
302
+ * @memberof module:routes/tables~tablesRouter
303
+ * @function
271
304
  */
272
305
  router.get(
273
306
  "/create-from-csv",
@@ -313,8 +346,13 @@ router.get(
313
346
  });
314
347
  })
315
348
  );
349
+
316
350
  /**
317
351
  * Create Table from CSV file (post)
352
+ * @name post/create-from-csv
353
+ * @function
354
+ * @memberof module:routes/tables~tablesRouter
355
+ * @function
318
356
  */
319
357
  router.post(
320
358
  "/create-from-csv",
@@ -357,8 +395,13 @@ router.post(
357
395
  }
358
396
  })
359
397
  );
398
+
360
399
  /**
361
400
  * Show Relational Diagram (get)
401
+ * @name get/relationship-diagram
402
+ * @function
403
+ * @memberof module:routes/tables~tablesRouter
404
+ * @function
362
405
  */
363
406
  router.get(
364
407
  "/relationship-diagram",
@@ -445,8 +488,19 @@ router.get(
445
488
  })
446
489
  );
447
490
 
491
+ /**
492
+ * @param {string} col
493
+ * @param {string} lbl
494
+ * @returns {string}
495
+ */
448
496
  const badge = (col, lbl) =>
449
497
  `<span class="badge badge-${col}">${lbl}</span>&nbsp;`;
498
+
499
+ /**
500
+ * @param {object} f
501
+ * @param {object} req
502
+ * @returns {string}
503
+ */
450
504
  const typeBadges = (f, req) => {
451
505
  let s = "";
452
506
  if (f.primary_key) s += badge("warning", req.__("Primary key"));
@@ -456,6 +510,11 @@ const typeBadges = (f, req) => {
456
510
  if (f.stored) s += badge("warning", req.__("Stored"));
457
511
  return s;
458
512
  };
513
+
514
+ /**
515
+ * @param {object} f
516
+ * @returns {string}
517
+ */
459
518
  const attribBadges = (f) => {
460
519
  let s = "";
461
520
  if (f.attributes) {
@@ -466,8 +525,13 @@ const attribBadges = (f) => {
466
525
  }
467
526
  return s;
468
527
  };
528
+
469
529
  /**
470
530
  * Table Constructor (GET Handler)
531
+ * @name get/:idorname
532
+ * @function
533
+ * @memberof module:routes/tables~tablesRouter
534
+ * @function
471
535
  */
472
536
  router.get(
473
537
  "/:idorname",
@@ -698,6 +762,7 @@ router.get(
698
762
  ),
699
763
  // rename table doesnt supported for sqlite
700
764
  !db.isSQLite &&
765
+ table.name !== "users" &&
701
766
  a(
702
767
  {
703
768
  class: "dropdown-item",
@@ -718,12 +783,13 @@ router.get(
718
783
  req,
719
784
  true
720
785
  ),
721
- post_dropdown_item(
722
- `/table/forget-table/${table.id}`,
723
- '<i class="fas fa-recycle"></i>&nbsp;' + req.__("Forget table"),
724
- req,
725
- true
726
- ),
786
+ table.name !== "users" &&
787
+ post_dropdown_item(
788
+ `/table/forget-table/${table.id}`,
789
+ '<i class="fas fa-recycle"></i>&nbsp;' + req.__("Forget table"),
790
+ req,
791
+ true
792
+ ),
727
793
  ])
728
794
  )
729
795
  );
@@ -768,8 +834,12 @@ router.get(
768
834
  });
769
835
  })
770
836
  );
837
+
771
838
  /**
772
- *
839
+ * @name post
840
+ * @function
841
+ * @memberof module:routes/tables~tablesRouter
842
+ * @function
773
843
  */
774
844
  router.post(
775
845
  "/",
@@ -837,9 +907,14 @@ router.post(
837
907
  }
838
908
  })
839
909
  );
910
+
840
911
  /**
841
912
  * Delete Table Route Handler definition
842
913
  * /delete:/id, where id is table id in _sc_tables
914
+ * @name post/delete/:id
915
+ * @function
916
+ * @memberof module:routes/tables~tablesRouter
917
+ * @function
843
918
  */
844
919
  router.post(
845
920
  "/delete/:id",
@@ -904,9 +979,9 @@ router.post(
904
979
  * - Owned - if ownership_field_id? What is it?
905
980
  * - History - if table has versioning
906
981
  * - External - if this is external table
907
- * @param t - table object
908
- * @param req - http request
909
- * @returns {string} - html string with list of badges
982
+ * @param {object} t table object
983
+ * @param {object} req http request
984
+ * @returns {string} html string with list of badges
910
985
  */
911
986
  const tableBadges = (t, req) => {
912
987
  let s = "";
@@ -915,9 +990,13 @@ const tableBadges = (t, req) => {
915
990
  if (t.external) s += badge("info", req.__("External"));
916
991
  return s;
917
992
  };
993
+
918
994
  /**
919
995
  * List Views of Tables (GET Handler)
920
- *
996
+ * @name get
997
+ * @function
998
+ * @memberof module:routes/tables~tablesRouter
999
+ * @function
921
1000
  */
922
1001
  router.get(
923
1002
  "/",
@@ -1006,8 +1085,13 @@ router.get(
1006
1085
  });
1007
1086
  })
1008
1087
  );
1088
+
1009
1089
  /**
1010
1090
  * Download CSV file
1091
+ * @name get/download/:name
1092
+ * @function
1093
+ * @memberof module:routes/tables~tablesRouter
1094
+ * @function
1011
1095
  */
1012
1096
  router.get(
1013
1097
  "/download/:name",
@@ -1031,8 +1115,13 @@ router.get(
1031
1115
  }).pipe(res);
1032
1116
  })
1033
1117
  );
1118
+
1034
1119
  /**
1035
1120
  * Show list of Constraints for Table (GET Handler)
1121
+ * @name get/constraints/:id
1122
+ * @function
1123
+ * @memberof module:routes/tables~tablesRouter
1124
+ * @function
1036
1125
  */
1037
1126
  router.get(
1038
1127
  "/constraints/:id",
@@ -1087,8 +1176,8 @@ router.get(
1087
1176
  /**
1088
1177
  * Constraint Fields Edition Form
1089
1178
  * Choosing fields for adding to contrain
1090
- * @param table_id
1091
- * @param fields
1179
+ * @param {string} table_id
1180
+ * @param {object[]} fields
1092
1181
  * @returns {Form}
1093
1182
  */
1094
1183
  const constraintForm = (req, table_id, fields) =>
@@ -1103,9 +1192,14 @@ const constraintForm = (req, table_id, fields) =>
1103
1192
  type: "Bool",
1104
1193
  })),
1105
1194
  });
1195
+
1106
1196
  /**
1107
1197
  * Add constraint GET handler
1108
1198
  * ${base_url}/table/add-constraint/:id
1199
+ * @name get/add-constraint/:id
1200
+ * @function
1201
+ * @memberof module:routes/tables~tablesRouter
1202
+ * @function
1109
1203
  */
1110
1204
  router.get(
1111
1205
  "/add-constraint/:id",
@@ -1144,8 +1238,13 @@ router.get(
1144
1238
  });
1145
1239
  })
1146
1240
  );
1241
+
1147
1242
  /**
1148
1243
  * Add constraint POST handler
1244
+ * @name post/add-constraint/:id
1245
+ * @function
1246
+ * @memberof module:routes/tables~tablesRouter
1247
+ * @function
1149
1248
  */
1150
1249
  router.post(
1151
1250
  "/add-constraint/:id",
@@ -1178,8 +1277,8 @@ router.post(
1178
1277
  /**
1179
1278
  * Rename Table Form
1180
1279
  * Allows to set up new table name
1181
- * @param table_id
1182
- * @param req
1280
+ * @param {string} table_id
1281
+ * @param {object} req
1183
1282
  * @returns {Form}
1184
1283
  */
1185
1284
  const renameForm = (table_id, req) =>
@@ -1194,8 +1293,13 @@ const renameForm = (table_id, req) =>
1194
1293
  },
1195
1294
  ],
1196
1295
  });
1296
+
1197
1297
  /**
1198
1298
  * Rename Table GET handler
1299
+ * @name get/rename/:id
1300
+ * @function
1301
+ * @memberof module:routes/tables~tablesRouter
1302
+ * @function
1199
1303
  */
1200
1304
  router.get(
1201
1305
  "/rename/:id",
@@ -1227,8 +1331,13 @@ router.get(
1227
1331
  });
1228
1332
  })
1229
1333
  );
1334
+
1230
1335
  /**
1231
1336
  * Rename Table POST Handler
1337
+ * @name post/rename/:id
1338
+ * @function
1339
+ * @memberof module:routes/tables~tablesRouter
1340
+ * @function
1232
1341
  */
1233
1342
  router.post(
1234
1343
  "/rename/:id",
@@ -1247,8 +1356,13 @@ router.post(
1247
1356
  res.redirect(`/table/${table.id}`);
1248
1357
  })
1249
1358
  );
1359
+
1250
1360
  /**
1251
1361
  * Delete constraint POST handler
1362
+ * @name post/delete-constraint/:id",
1363
+ * @function
1364
+ * @memberof module:routes/tables~tablesRouter
1365
+ * @function
1252
1366
  */
1253
1367
  router.post(
1254
1368
  "/delete-constraint/:id",
@@ -1261,8 +1375,13 @@ router.post(
1261
1375
  res.redirect(`/table/constraints/${cons.table_id}`);
1262
1376
  })
1263
1377
  );
1378
+
1264
1379
  /**
1265
1380
  * Import Table Data from CSV POST handler
1381
+ * @name post/upload_to_table/:name,
1382
+ * @function
1383
+ * @memberof module:routes/tables~tablesRouter
1384
+ * @function
1266
1385
  */
1267
1386
  router.post(
1268
1387
  "/upload_to_table/:name",
@@ -1292,8 +1411,13 @@ router.post(
1292
1411
  res.redirect(`/table/${table.id}`);
1293
1412
  })
1294
1413
  );
1414
+
1295
1415
  /**
1296
1416
  * Delete All rows from Table
1417
+ * @name post/delete-all-rows/:name,
1418
+ * @function
1419
+ * @memberof module:routes/tables~tablesRouter
1420
+ * @function
1297
1421
  */
1298
1422
  router.post(
1299
1423
  "/delete-all-rows/:name",
@@ -1313,8 +1437,13 @@ router.post(
1313
1437
  res.redirect(`/table/${table.id}`);
1314
1438
  })
1315
1439
  );
1440
+
1316
1441
  /**
1317
1442
  * Call for Recalculate table columns that stored in db (POST Handler)
1443
+ * @name post/recalc-stored/:name,
1444
+ * @function
1445
+ * @memberof module:routes/tables~tablesRouter
1446
+ * @function
1318
1447
  */
1319
1448
  router.post(
1320
1449
  "/recalc-stored/:name",