@saltcorn/server 0.8.0-beta.3 → 0.8.0-beta.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.
package/markup/admin.js CHANGED
@@ -68,14 +68,40 @@ const restore_backup = (csrf, inner, action = `/admin/restore`) =>
68
68
  * @param {*} opts.req
69
69
  * @returns {object}
70
70
  */
71
- const add_edit_bar = ({ role, title, contents, what, url, req }) => {
71
+ const add_edit_bar = ({
72
+ role,
73
+ title,
74
+ contents,
75
+ what,
76
+ url,
77
+ req,
78
+ viewtemplate,
79
+ table,
80
+ cfgUrl,
81
+ }) => {
72
82
  if (role > 1 && req && req.xhr) return { above: [contents] }; //make sure not put in card
73
83
  if (role > 1) return contents;
84
+ let viewSpec = "";
85
+ if (viewtemplate) viewSpec = viewtemplate;
86
+ if (table) {
87
+ const tbl = Table.findOne(table);
88
+ if (tbl)
89
+ viewSpec = `${viewSpec} on <a href="/table/${table}">${tbl.name}</a>`;
90
+ }
91
+
74
92
  const bar = div(
75
93
  { class: "alert alert-light d-print-none admin-edit-bar" },
76
94
  title,
77
- what && span({ class: "ms-1 badge bg-primary" }, what),
78
- a({ class: "ms-4", href: url }, "Edit&nbsp;", i({ class: "fas fa-edit" }))
95
+ what && span({ class: "ms-1 me-2 badge bg-primary" }, what),
96
+ viewSpec,
97
+ a({ class: "ms-2", href: url }, "Edit&nbsp;", i({ class: "fas fa-edit" })),
98
+ cfgUrl
99
+ ? a(
100
+ { class: "ms-1", href: cfgUrl },
101
+ "Configure&nbsp;",
102
+ i({ class: "fas fa-cog" })
103
+ )
104
+ : ""
79
105
  );
80
106
 
81
107
  if (contents.above) {
@@ -113,35 +139,35 @@ const send_settings_page = ({
113
139
  const pillCard = no_nav_pills
114
140
  ? []
115
141
  : [
116
- {
117
- type: "card",
118
- class: "mt-0",
119
- contents: div(
120
- { class: "d-flex" },
121
- ul(
122
- { class: "nav nav-pills plugin-section" },
123
- sub_sections.map(({ text, href }) =>
124
- li(
125
- { class: "nav-item" },
126
- a(
127
- {
128
- href,
129
- class: ["nav-link", active_sub === text && "active"],
130
- },
131
- req.__(text)
142
+ {
143
+ type: "card",
144
+ class: "mt-0",
145
+ contents: div(
146
+ { class: "d-flex" },
147
+ ul(
148
+ { class: "nav nav-pills plugin-section" },
149
+ sub_sections.map(({ text, href }) =>
150
+ li(
151
+ { class: "nav-item" },
152
+ a(
153
+ {
154
+ href,
155
+ class: ["nav-link", active_sub === text && "active"],
156
+ },
157
+ req.__(text)
158
+ )
132
159
  )
133
160
  )
134
161
  )
135
- )
136
- ),
137
- },
138
- ];
162
+ ),
163
+ },
164
+ ];
139
165
  // headers
140
166
  const title = headers
141
167
  ? {
142
- title: req.__(active_sub),
143
- headers,
144
- }
168
+ title: req.__(active_sub),
169
+ headers,
170
+ }
145
171
  : req.__(active_sub);
146
172
  res.sendWrap(title, {
147
173
  above: [
@@ -158,10 +184,10 @@ const send_settings_page = ({
158
184
  },
159
185
  ...(sub2_page
160
186
  ? [
161
- {
162
- text: sub2_page,
163
- },
164
- ]
187
+ {
188
+ text: sub2_page,
189
+ },
190
+ ]
165
191
  : []),
166
192
  ],
167
193
  },
@@ -190,9 +216,9 @@ const send_infoarch_page = (args) => {
190
216
  { text: "Languages", href: "/site-structure/localizer" },
191
217
  ...(tenant_list
192
218
  ? [
193
- { text: "Tenants", href: "/tenant/list" },
194
- { text: "Multitenancy", href: "/tenant/settings" },
195
- ]
219
+ { text: "Tenants", href: "/tenant/list" },
220
+ { text: "Multitenancy", href: "/tenant/settings" },
221
+ ]
196
222
  : []),
197
223
  { text: "Tags", href: "/tag" },
198
224
  { text: "Diagram", href: "/diagram" },
@@ -335,8 +361,8 @@ const flash_restart = (req) => {
335
361
  req.flash(
336
362
  "warning",
337
363
  req.__(`Restart required for changes to take effect.`) +
338
- " " +
339
- a({ href: "/admin/system" }, req.__("Restart here"))
364
+ " " +
365
+ a({ href: "/admin/system" }, req.__("Restart here"))
340
366
  );
341
367
  };
342
368
 
@@ -389,16 +415,16 @@ const config_fields_form = async ({
389
415
  isView || isRole || isTenant
390
416
  ? "String"
391
417
  : configTypes[name].input_type
392
- ? undefined
393
- : configTypes[name].type,
418
+ ? undefined
419
+ : configTypes[name].type,
394
420
  input_type: configTypes[name].input_type,
395
421
  attributes: isView
396
422
  ? await viewAttributes(name)
397
423
  : isRole
398
- ? roleAttribs
399
- : isTenant
400
- ? await getTenants()
401
- : configTypes[name].attributes,
424
+ ? roleAttribs
425
+ : isTenant
426
+ ? await getTenants()
427
+ : configTypes[name].attributes,
402
428
  });
403
429
  }
404
430
  const form = new Form({
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@saltcorn/server",
3
- "version": "0.8.0-beta.3",
3
+ "version": "0.8.0-beta.4",
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
- "@saltcorn/base-plugin": "0.8.0-beta.3",
10
- "@saltcorn/builder": "0.8.0-beta.3",
11
- "@saltcorn/data": "0.8.0-beta.3",
12
- "@saltcorn/admin-models": "0.8.0-beta.3",
13
- "@saltcorn/filemanager": "0.8.0-beta.3",
14
- "@saltcorn/markup": "0.8.0-beta.3",
15
- "@saltcorn/sbadmin2": "0.8.0-beta.3",
9
+ "@saltcorn/base-plugin": "0.8.0-beta.4",
10
+ "@saltcorn/builder": "0.8.0-beta.4",
11
+ "@saltcorn/data": "0.8.0-beta.4",
12
+ "@saltcorn/admin-models": "0.8.0-beta.4",
13
+ "@saltcorn/filemanager": "0.8.0-beta.4",
14
+ "@saltcorn/markup": "0.8.0-beta.4",
15
+ "@saltcorn/sbadmin2": "0.8.0-beta.4",
16
16
  "@socket.io/cluster-adapter": "^0.1.0",
17
17
  "@socket.io/sticky": "^1.0.1",
18
18
  "aws-sdk": "^2.1037.0",
package/routes/tables.js CHANGED
@@ -83,33 +83,33 @@ const tableForm = async (table, req) => {
83
83
  fields: [
84
84
  ...(!table.external
85
85
  ? [
86
- {
87
- label: req.__("Ownership field"),
88
- name: "ownership_field_id",
89
- sublabel: req.__(
90
- "The user referred to in this field will be the owner of the row"
91
- ),
92
- input_type: "select",
93
- options: [
94
- { value: "", label: req.__("None") },
95
- ...userFields,
96
- { value: "_formula", label: req.__("Formula") },
97
- ],
98
- },
99
- {
100
- name: "ownership_formula",
101
- label: req.__("Ownership formula"),
102
- validator: expressionValidator,
103
- type: "String",
104
- class: "validate-expression",
105
- sublabel:
106
- req.__("User is treated as owner if true. In scope: ") +
107
- ["user", ...fields.map((f) => f.name)]
108
- .map((fn) => code(fn))
109
- .join(", "),
110
- showIf: { ownership_field_id: "_formula" },
111
- },
112
- ]
86
+ {
87
+ label: req.__("Ownership field"),
88
+ name: "ownership_field_id",
89
+ sublabel: req.__(
90
+ "The user referred to in this field will be the owner of the row"
91
+ ),
92
+ input_type: "select",
93
+ options: [
94
+ { value: "", label: req.__("None") },
95
+ ...userFields,
96
+ { value: "_formula", label: req.__("Formula") },
97
+ ],
98
+ },
99
+ {
100
+ name: "ownership_formula",
101
+ label: req.__("Ownership formula"),
102
+ validator: expressionValidator,
103
+ type: "String",
104
+ class: "validate-expression",
105
+ sublabel:
106
+ req.__("User is treated as owner if true. In scope: ") +
107
+ ["user", ...fields.map((f) => f.name)]
108
+ .map((fn) => code(fn))
109
+ .join(", "),
110
+ showIf: { ownership_field_id: "_formula" },
111
+ },
112
+ ]
113
113
  : []),
114
114
  // description of table
115
115
  {
@@ -129,29 +129,29 @@ const tableForm = async (table, req) => {
129
129
  name: "min_role_read",
130
130
  input_type: "select",
131
131
  options: roleOptions,
132
- attributes: { asideNext: !table.external }
132
+ attributes: { asideNext: !table.external },
133
133
  },
134
134
  ...(table.external
135
135
  ? []
136
136
  : [
137
- {
138
- label: req.__("Minimum role to write"),
139
- name: "min_role_write",
140
- input_type: "select",
141
- sublabel: req.__(
142
- "User must have this role or higher to edit or create new rows in the table, unless they are the owner"
143
- ),
144
- options: roleOptions,
145
- },
146
- {
147
- label: req.__("Version history"),
148
- sublabel: req.__(
149
- "Version history allows to track table data changes"
150
- ),
151
- name: "versioned",
152
- type: "Bool",
153
- },
154
- ]),
137
+ {
138
+ label: req.__("Minimum role to write"),
139
+ name: "min_role_write",
140
+ input_type: "select",
141
+ sublabel: req.__(
142
+ "User must have this role or higher to edit or create new rows in the table, unless they are the owner"
143
+ ),
144
+ options: roleOptions,
145
+ },
146
+ {
147
+ label: req.__("Version history"),
148
+ sublabel: req.__(
149
+ "Version history allows to track table data changes"
150
+ ),
151
+ name: "versioned",
152
+ type: "Bool",
153
+ },
154
+ ]),
155
155
  ],
156
156
  });
157
157
  if (table) {
@@ -218,11 +218,11 @@ const discoverForm = (tables, req) => {
218
218
  blurb:
219
219
  tables.length > 0
220
220
  ? req.__(
221
- "The following tables in your database can be imported into Saltcorn:"
222
- )
221
+ "The following tables in your database can be imported into Saltcorn:"
222
+ )
223
223
  : req.__(
224
- "There are no tables in the database that can be imported into Saltcorn."
225
- ),
224
+ "There are no tables in the database that can be imported into Saltcorn."
225
+ ),
226
226
  submitLabel: req.__("Import"),
227
227
  fields: tables.map((t) => ({
228
228
  name: t.table_name,
@@ -328,7 +328,7 @@ router.get(
328
328
  name: "name",
329
329
  input_type: "text",
330
330
  },
331
- // todo implement file mask filter like , accept: "text/csv"
331
+ // todo implement file mask filter like , accept: "text/csv"
332
332
  { label: req.__("File"), name: "file", input_type: "file" },
333
333
  ],
334
334
  }),
@@ -516,7 +516,12 @@ const attribBadges = (f) => {
516
516
  let s = "";
517
517
  if (f.attributes) {
518
518
  Object.entries(f.attributes).forEach(([k, v]) => {
519
- if (["summary_field", "default"].includes(k)) return;
519
+ if (
520
+ ["summary_field", "default", "on_delete_cascade", "on_delete"].includes(
521
+ k
522
+ )
523
+ )
524
+ return;
520
525
  if (v || v === 0) s += badge("secondary", k);
521
526
  });
522
527
  }
@@ -575,11 +580,11 @@ router.get(
575
580
  key: (r) =>
576
581
  r.type === "Key"
577
582
  ? `Key to ` +
578
- a({ href: `/table/${r.reftable_name}` }, r.reftable_name)
583
+ a({ href: `/table/${r.reftable_name}` }, r.reftable_name)
579
584
  : (r.type && r.type.name) ||
580
- r.type ||
581
- r.typename +
582
- span({ class: "badge bg-danger ms-1" }, "Unknown type"),
585
+ r.type ||
586
+ r.typename +
587
+ span({ class: "badge bg-danger ms-1" }, "Unknown type"),
583
588
  },
584
589
  {
585
590
  label: "",
@@ -593,23 +598,23 @@ router.get(
593
598
  ...(table.external
594
599
  ? []
595
600
  : [
596
- {
597
- label: req.__("Edit"),
598
- key: (r) => link(`/field/${r.id}`, req.__("Edit")),
599
- },
600
- ]),
601
+ {
602
+ label: req.__("Edit"),
603
+ key: (r) => link(`/field/${r.id}`, req.__("Edit")),
604
+ },
605
+ ]),
601
606
  ...(table.external || db.isSQLite
602
607
  ? []
603
608
  : [
604
- {
605
- label: req.__("Delete"),
606
- key: (r) =>
607
- (table.name === "users" && r.name === "email") ||
609
+ {
610
+ label: req.__("Delete"),
611
+ key: (r) =>
612
+ (table.name === "users" && r.name === "email") ||
608
613
  r.primary_key
609
- ? ""
610
- : post_delete_btn(`/field/delete/${r.id}`, req, r.name),
611
- },
612
- ]),
614
+ ? ""
615
+ : post_delete_btn(`/field/delete/${r.id}`, req, r.name),
616
+ },
617
+ ]),
613
618
  ],
614
619
  fields,
615
620
  { hover: true }
@@ -618,17 +623,17 @@ router.get(
618
623
  tableHtml,
619
624
  inbound_refs.length > 0
620
625
  ? req.__("Inbound keys: ") +
621
- inbound_refs.map((tnm) => link(`/table/${tnm}`, tnm)).join(", ") +
622
- "<br>"
626
+ inbound_refs.map((tnm) => link(`/table/${tnm}`, tnm)).join(", ") +
627
+ "<br>"
623
628
  : "",
624
629
  !table.external &&
625
- a(
626
- {
627
- href: `/field/new/${table.id}`,
628
- class: "btn btn-primary add-field mt-2",
629
- },
630
- req.__("Add field")
631
- ),
630
+ a(
631
+ {
632
+ href: `/field/new/${table.id}`,
633
+ class: "btn btn-primary add-field mt-2",
634
+ },
635
+ req.__("Add field")
636
+ ),
632
637
  ];
633
638
  }
634
639
  var viewCard;
@@ -700,8 +705,8 @@ router.get(
700
705
  table.name === "users"
701
706
  ? `/useradmin/`
702
707
  : fields.length === 1
703
- ? `javascript:;` // Fix problem with edition of table with only one column ID / Primary Key
704
- : `/list/${table.name}`,
708
+ ? `javascript:;` // Fix problem with edition of table with only one column ID / Primary Key
709
+ : `/list/${table.name}`,
705
710
  },
706
711
  i({ class: "fas fa-2x fa-edit" }),
707
712
  "<br/>",
@@ -721,75 +726,75 @@ router.get(
721
726
  )
722
727
  ),
723
728
  !table.external &&
724
- div(
725
- { class: "mx-auto" },
726
- form(
727
- {
728
- method: "post",
729
- action: `/table/upload_to_table/${table.name}`,
730
- encType: "multipart/form-data",
731
- acceptCharset: "UTF-8",
732
- },
733
- input({ type: "hidden", name: "_csrf", value: req.csrfToken() }),
734
- label(
735
- { class: "btn-link", for: "upload_to_table" },
736
- i({ class: "fas fa-2x fa-upload" }),
737
- "<br/>",
738
- req.__("Upload CSV")
739
- ),
740
- input({
741
- id: "upload_to_table",
742
- name: "file",
743
- type: "file",
744
- accept: "text/csv,.csv",
745
- onchange: "this.form.submit();",
746
- })
747
- )
748
- ),
749
- // only if table is not external
750
- !table.external &&
751
- div(
752
- { class: "mx-auto" },
753
- settingsDropdown(`dataMenuButton`, [
754
- a(
729
+ div(
730
+ { class: "mx-auto" },
731
+ form(
755
732
  {
756
- class: "dropdown-item",
757
- href: `/table/constraints/${table.id}`,
733
+ method: "post",
734
+ action: `/table/upload_to_table/${table.name}`,
735
+ encType: "multipart/form-data",
736
+ acceptCharset: "UTF-8",
758
737
  },
759
- '<i class="fas fa-ban"></i>&nbsp;' + req.__("Constraints")
760
- ),
761
- // rename table doesnt supported for sqlite
762
- !db.isSQLite &&
763
- table.name !== "users" &&
764
- a(
765
- {
766
- class: "dropdown-item",
767
- href: `/table/rename/${table.id}`,
768
- },
769
- '<i class="fas fa-edit"></i>&nbsp;' + req.__("Rename table")
770
- ),
771
- post_dropdown_item(
772
- `/table/recalc-stored/${table.name}`,
773
- '<i class="fas fa-sync"></i>&nbsp;' +
774
- req.__("Recalculate stored fields"),
775
- req
776
- ),
777
- post_dropdown_item(
778
- `/table/delete-all-rows/${table.name}`,
779
- '<i class="far fa-trash-alt"></i>&nbsp;' +
780
- req.__("Delete all rows"),
781
- req,
782
- true
783
- ),
784
- table.name !== "users" &&
785
- post_dropdown_item(
786
- `/table/forget-table/${table.id}`,
787
- '<i class="fas fa-recycle"></i>&nbsp;' + req.__("Forget table"),
788
- req,
789
- true
790
- ),
791
- ])
792
- )
738
+ input({ type: "hidden", name: "_csrf", value: req.csrfToken() }),
739
+ label(
740
+ { class: "btn-link", for: "upload_to_table" },
741
+ i({ class: "fas fa-2x fa-upload" }),
742
+ "<br/>",
743
+ req.__("Upload CSV")
744
+ ),
745
+ input({
746
+ id: "upload_to_table",
747
+ name: "file",
748
+ type: "file",
749
+ accept: "text/csv,.csv",
750
+ onchange: "this.form.submit();",
751
+ })
752
+ )
753
+ ),
754
+ // only if table is not external
755
+ !table.external &&
756
+ div(
757
+ { class: "mx-auto" },
758
+ settingsDropdown(`dataMenuButton`, [
759
+ a(
760
+ {
761
+ class: "dropdown-item",
762
+ href: `/table/constraints/${table.id}`,
763
+ },
764
+ '<i class="fas fa-ban"></i>&nbsp;' + req.__("Constraints")
765
+ ),
766
+ // rename table doesnt supported for sqlite
767
+ !db.isSQLite &&
768
+ table.name !== "users" &&
769
+ a(
770
+ {
771
+ class: "dropdown-item",
772
+ href: `/table/rename/${table.id}`,
773
+ },
774
+ '<i class="fas fa-edit"></i>&nbsp;' + req.__("Rename table")
775
+ ),
776
+ post_dropdown_item(
777
+ `/table/recalc-stored/${table.name}`,
778
+ '<i class="fas fa-sync"></i>&nbsp;' +
779
+ req.__("Recalculate stored fields"),
780
+ req
781
+ ),
782
+ post_dropdown_item(
783
+ `/table/delete-all-rows/${table.name}`,
784
+ '<i class="far fa-trash-alt"></i>&nbsp;' +
785
+ req.__("Delete all rows"),
786
+ req,
787
+ true
788
+ ),
789
+ table.name !== "users" &&
790
+ post_dropdown_item(
791
+ `/table/forget-table/${table.id}`,
792
+ '<i class="fas fa-recycle"></i>&nbsp;' + req.__("Forget table"),
793
+ req,
794
+ true
795
+ ),
796
+ ])
797
+ )
793
798
  );
794
799
  // add table form
795
800
  if (table.ownership_formula && !table.ownership_field_id)
@@ -812,12 +817,12 @@ router.get(
812
817
  },
813
818
  ...(fields.length > 0
814
819
  ? [
815
- {
816
- type: "card",
817
- title: req.__("Table data"),
818
- contents: dataCard,
819
- },
820
- ]
820
+ {
821
+ type: "card",
822
+ title: req.__("Table data"),
823
+ contents: dataCard,
824
+ },
825
+ ]
821
826
  : []),
822
827
  ...(viewCard ? [viewCard] : []),
823
828
  {
@@ -864,7 +869,7 @@ router.post(
864
869
  // todo check that works after where change
865
870
  // todo findOne can be have parameter for external table here
866
871
  //we can only save min role
867
- const table = await Table.findOne( { name : v.name });
872
+ const table = await Table.findOne({ name: v.name });
868
873
  if (table) {
869
874
  const exttables_min_role_read = getState().getConfigCopy(
870
875
  "exttables_min_role_read",
@@ -883,13 +888,13 @@ router.post(
883
888
  const table = await Table.findOne({ id: parseInt(id) });
884
889
  const old_versioned = table.versioned;
885
890
  let hasError = false;
886
- let notify = ""
891
+ let notify = "";
887
892
  if (!rest.versioned) rest.versioned = false;
888
893
  if (rest.ownership_field_id === "_formula") {
889
894
  rest.ownership_field_id = null;
890
895
  const fmlValidRes = expressionValidator(rest.ownership_formula);
891
896
  if (typeof fmlValidRes === "string") {
892
- notify = req.__(`Invalid ownership formula: %s`, fmlValidRes)
897
+ notify = req.__(`Invalid ownership formula: %s`, fmlValidRes);
893
898
  hasError = true;
894
899
  }
895
900
  } else rest.ownership_formula = null;
@@ -1023,16 +1028,18 @@ router.get(
1023
1028
  req.__("Create from CSV upload")
1024
1029
  ),
1025
1030
  !db.isSQLite &&
1026
- a(
1027
- {
1028
- href: `/table/discover`,
1029
- class: "btn btn-secondary mt-1",
1030
- title: req.__("Discover tables that are already in the Database, but not known to Saltcorn"),
1031
- },
1032
- i({ class: "fas fa-map-signs me-1" }),
1031
+ a(
1032
+ {
1033
+ href: `/table/discover`,
1034
+ class: "btn btn-secondary mt-1",
1035
+ title: req.__(
1036
+ "Discover tables that are already in the Database, but not known to Saltcorn"
1037
+ ),
1038
+ },
1039
+ i({ class: "fas fa-map-signs me-1" }),
1033
1040
 
1034
- req.__("Discover tables")
1035
- )
1041
+ req.__("Discover tables")
1042
+ )
1036
1043
  );
1037
1044
  res.sendWrap(req.__("Tables"), {
1038
1045
  above: [
package/routes/view.js CHANGED
@@ -71,8 +71,11 @@ router.get(
71
71
  title: view.name,
72
72
  what: req.__("View"),
73
73
  url: `/viewedit/edit/${encodeURIComponent(view.name)}`,
74
+ cfgUrl: `/viewedit/config/${encodeURIComponent(view.name)}`,
74
75
  contents,
75
76
  req,
77
+ viewtemplate: view.viewtemplate,
78
+ table: view.table_id || view.exttable_name,
76
79
  })
77
80
  );
78
81
  })
@@ -104,13 +107,17 @@ router.post(
104
107
  if (!row) {
105
108
  if (!table)
106
109
  // todo check after where change
107
- table = await Table.findOne(view.table_id ? { id : view.table_id } : {name: view.exttable_name});
110
+ table = await Table.findOne(
111
+ view.table_id
112
+ ? { id: view.table_id }
113
+ : { name: view.exttable_name }
114
+ );
108
115
  row = await table.getRow({});
109
116
  }
110
117
  if (row) query[sf.name] = row[sf.name];
111
118
  }
112
119
  }
113
- const contents = await view.run(query, { req, res });
120
+ const contents = await view.run(query, { req, res, isPreview: true });
114
121
 
115
122
  res.send(contents);
116
123
  })