@saltcorn/server 0.9.0-beta.5 → 0.9.0-beta.7
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/app.js +9 -3
- package/errors.js +15 -4
- package/locales/en.json +6 -1
- package/package.json +8 -8
- package/public/saltcorn-common.js +32 -3
- package/public/saltcorn.js +11 -2
- package/routes/admin.js +12 -0
- package/routes/fields.js +15 -3
- package/routes/packs.js +134 -9
- package/routes/viewedit.js +13 -0
- package/tests/admin.test.js +2 -2
package/app.js
CHANGED
|
@@ -128,17 +128,23 @@ const getApp = async (opts = {}) => {
|
|
|
128
128
|
app.use(helmet());
|
|
129
129
|
// TODO ch find a better solution
|
|
130
130
|
app.use(cors());
|
|
131
|
+
const bodyLimit = getState().getConfig("body_limit");
|
|
131
132
|
app.use(
|
|
132
133
|
express.json({
|
|
133
|
-
limit: "5mb",
|
|
134
|
+
limit: bodyLimit ? `${bodyLimit}kb` : "5mb",
|
|
134
135
|
verify: (req, res, buf) => {
|
|
135
136
|
req.rawBody = buf;
|
|
136
137
|
},
|
|
137
138
|
})
|
|
138
139
|
);
|
|
139
|
-
|
|
140
|
+
const urlencodedLimit = getState().getConfig("url_encoded_limit");
|
|
141
|
+
// extended url encoding in use
|
|
140
142
|
app.use(
|
|
141
|
-
express.urlencoded({
|
|
143
|
+
express.urlencoded({
|
|
144
|
+
limit: urlencodedLimit ? `${urlencodedLimit}kb` : "5mb",
|
|
145
|
+
extended: true,
|
|
146
|
+
parameterLimit: 50000,
|
|
147
|
+
})
|
|
142
148
|
);
|
|
143
149
|
|
|
144
150
|
// cookies
|
package/errors.js
CHANGED
|
@@ -46,10 +46,10 @@ module.exports =
|
|
|
46
46
|
? text(err.message)
|
|
47
47
|
: req.__("An error occurred")
|
|
48
48
|
);
|
|
49
|
-
} else
|
|
50
|
-
res
|
|
51
|
-
|
|
52
|
-
.sendWrap(
|
|
49
|
+
} else {
|
|
50
|
+
const _res = res.status(code);
|
|
51
|
+
if (_res.sendWrap)
|
|
52
|
+
_res.sendWrap(
|
|
53
53
|
req.__(headline),
|
|
54
54
|
devmode ? pre(text(err.stack)) : h3(req.__(headline)),
|
|
55
55
|
role === 1 && !devmode ? pre(text(err.message)) : "",
|
|
@@ -61,4 +61,15 @@ module.exports =
|
|
|
61
61
|
)
|
|
62
62
|
: ""
|
|
63
63
|
);
|
|
64
|
+
else
|
|
65
|
+
_res.send(
|
|
66
|
+
`<h2>${
|
|
67
|
+
err.message
|
|
68
|
+
? err.message
|
|
69
|
+
: req.__
|
|
70
|
+
? req.__("An error occurred")
|
|
71
|
+
: "An error occurred"
|
|
72
|
+
}</h2>`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
64
75
|
};
|
package/locales/en.json
CHANGED
|
@@ -1261,5 +1261,10 @@
|
|
|
1261
1261
|
"Module up-to-date": "Module up-to-date",
|
|
1262
1262
|
"Module '%s' not found": "Module '%s' not found",
|
|
1263
1263
|
"Module %s not found": "Module %s not found",
|
|
1264
|
-
"
|
|
1264
|
+
"Include Event Logs": "Include Event Logs",
|
|
1265
|
+
"Backup with event logs": "Backup with event logs",
|
|
1266
|
+
"Initially open": "Initially open",
|
|
1267
|
+
"Not a valid pack": "Not a valid pack",
|
|
1268
|
+
"Pack file": "Pack file",
|
|
1269
|
+
"Upload a pack file": "Upload a pack file"
|
|
1265
1270
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/server",
|
|
3
|
-
"version": "0.9.0-beta.
|
|
3
|
+
"version": "0.9.0-beta.7",
|
|
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.9.0-beta.
|
|
10
|
-
"@saltcorn/builder": "0.9.0-beta.
|
|
11
|
-
"@saltcorn/data": "0.9.0-beta.
|
|
12
|
-
"@saltcorn/admin-models": "0.9.0-beta.
|
|
13
|
-
"@saltcorn/filemanager": "0.9.0-beta.
|
|
14
|
-
"@saltcorn/markup": "0.9.0-beta.
|
|
15
|
-
"@saltcorn/sbadmin2": "0.9.0-beta.
|
|
9
|
+
"@saltcorn/base-plugin": "0.9.0-beta.7",
|
|
10
|
+
"@saltcorn/builder": "0.9.0-beta.7",
|
|
11
|
+
"@saltcorn/data": "0.9.0-beta.7",
|
|
12
|
+
"@saltcorn/admin-models": "0.9.0-beta.7",
|
|
13
|
+
"@saltcorn/filemanager": "0.9.0-beta.7",
|
|
14
|
+
"@saltcorn/markup": "0.9.0-beta.7",
|
|
15
|
+
"@saltcorn/sbadmin2": "0.9.0-beta.7",
|
|
16
16
|
"@socket.io/cluster-adapter": "^0.2.1",
|
|
17
17
|
"@socket.io/sticky": "^1.0.1",
|
|
18
18
|
"adm-zip": "0.5.10",
|
|
@@ -51,6 +51,7 @@ const nubBy = (prop, xs) => {
|
|
|
51
51
|
});
|
|
52
52
|
};
|
|
53
53
|
function apply_showif() {
|
|
54
|
+
const isNode = typeof parent?.saltcorn?.data?.state === "undefined";
|
|
54
55
|
$("[data-show-if]").each(function (ix, element) {
|
|
55
56
|
var e = $(element);
|
|
56
57
|
try {
|
|
@@ -272,10 +273,12 @@ function apply_showif() {
|
|
|
272
273
|
|
|
273
274
|
if (typeof cache[recS] !== "undefined") {
|
|
274
275
|
e.html(cache[recS]);
|
|
276
|
+
e.prop("data-source-url-current", recS);
|
|
275
277
|
activate_onchange_coldef();
|
|
276
278
|
return;
|
|
277
279
|
}
|
|
278
|
-
|
|
280
|
+
|
|
281
|
+
const cb = {
|
|
279
282
|
success: (data) => {
|
|
280
283
|
e.html(data);
|
|
281
284
|
const cacheNow = e.prop("data-source-url-cache") || {};
|
|
@@ -295,7 +298,11 @@ function apply_showif() {
|
|
|
295
298
|
});
|
|
296
299
|
e.html("");
|
|
297
300
|
},
|
|
298
|
-
}
|
|
301
|
+
};
|
|
302
|
+
if (isNode) ajax_post_json(e.attr("data-source-url"), rec, cb);
|
|
303
|
+
else {
|
|
304
|
+
local_post_json(e.attr("data-source-url"), rec, cb);
|
|
305
|
+
}
|
|
299
306
|
});
|
|
300
307
|
const locale =
|
|
301
308
|
navigator.userLanguage ||
|
|
@@ -518,6 +525,11 @@ function initialize_page() {
|
|
|
518
525
|
});
|
|
519
526
|
|
|
520
527
|
$("form").change(apply_showif);
|
|
528
|
+
// also change if we select same
|
|
529
|
+
$("form select").on("blur", (e) => {
|
|
530
|
+
if (!e || !e.target) return;
|
|
531
|
+
$(e.target).closest("form").trigger("change");
|
|
532
|
+
});
|
|
521
533
|
apply_showif();
|
|
522
534
|
apply_showif();
|
|
523
535
|
$("[data-inline-edit-dest-url]").each(function () {
|
|
@@ -539,6 +551,7 @@ function initialize_page() {
|
|
|
539
551
|
var ajax = !!$(this).attr("data-inline-edit-ajax");
|
|
540
552
|
var type = $(this).attr("data-inline-edit-type");
|
|
541
553
|
var schema = $(this).attr("data-inline-edit-schema");
|
|
554
|
+
var decimalPlaces = $(this).attr("data-inline-edit-decimal-places");
|
|
542
555
|
if (schema) {
|
|
543
556
|
schema = JSON.parse(decodeURIComponent(schema));
|
|
544
557
|
}
|
|
@@ -561,6 +574,7 @@ function initialize_page() {
|
|
|
561
574
|
type,
|
|
562
575
|
is_key,
|
|
563
576
|
schema,
|
|
577
|
+
...(decimalPlaces ? { decimalPlaces } : {}),
|
|
564
578
|
})
|
|
565
579
|
);
|
|
566
580
|
const doAjaxOptionsFetch = (tblName, target) => {
|
|
@@ -613,7 +627,17 @@ function initialize_page() {
|
|
|
613
627
|
}
|
|
614
628
|
<input type="${
|
|
615
629
|
type === "Integer" || type === "Float" ? "number" : "text"
|
|
616
|
-
}"
|
|
630
|
+
}" ${
|
|
631
|
+
type === "Float"
|
|
632
|
+
? `step="${
|
|
633
|
+
decimalPlaces
|
|
634
|
+
? Math.round(
|
|
635
|
+
Math.pow(10, -decimalPlaces) * Math.pow(10, decimalPlaces)
|
|
636
|
+
) / Math.pow(10, decimalPlaces)
|
|
637
|
+
: "any"
|
|
638
|
+
}"`
|
|
639
|
+
: ""
|
|
640
|
+
} name="${key}" value="${escapeHtml(current)}">
|
|
617
641
|
<button type="submit" class="btn btn-sm btn-primary">OK</button>
|
|
618
642
|
<button onclick="cancel_inline_edit(event, '${opts}')" type="button" class="btn btn-sm btn-danger"><i class="fas fa-times"></i></button>
|
|
619
643
|
</form>`
|
|
@@ -780,6 +804,11 @@ function inline_submit_success(e, form, opts) {
|
|
|
780
804
|
: ""
|
|
781
805
|
}
|
|
782
806
|
${opts.current_label ? `data-inline-edit-current-label="${val}"` : ""}
|
|
807
|
+
${
|
|
808
|
+
opts.decimalPlaces
|
|
809
|
+
? `data-inline-edit-decimal-places="${opts.decimalPlaces}"`
|
|
810
|
+
: ""
|
|
811
|
+
}
|
|
783
812
|
data-inline-edit-dest-url="${opts.url}">
|
|
784
813
|
<span class="current">${val}</span>
|
|
785
814
|
<i class="editicon ${!isNode ? "visible" : ""} fas fa-edit ms-1"></i>
|
package/public/saltcorn.js
CHANGED
|
@@ -356,6 +356,15 @@ function selectVersionError(res, btnId) {
|
|
|
356
356
|
restore_old_button(btnId);
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
+
function submitWithAjax(e) {
|
|
360
|
+
saveAndContinue(e, (res) => {
|
|
361
|
+
if (res && res.responseJSON && res.responseJSON.url_when_done)
|
|
362
|
+
window.location.href = res.responseJSON.url_when_done;
|
|
363
|
+
if (res && res.responseJSON && res.responseJSON.error)
|
|
364
|
+
notifyAlert({ type: "danger", text: res.responseJSON.error });
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
359
368
|
function saveAndContinue(e, k) {
|
|
360
369
|
var form = $(e).closest("form");
|
|
361
370
|
const valres = form[0].reportValidity();
|
|
@@ -404,8 +413,8 @@ function saveAndContinue(e, k) {
|
|
|
404
413
|
}
|
|
405
414
|
ajax_indicate_error(e, request);
|
|
406
415
|
},
|
|
407
|
-
complete: function () {
|
|
408
|
-
if (k) k();
|
|
416
|
+
complete: function (res) {
|
|
417
|
+
if (k) k(res);
|
|
409
418
|
},
|
|
410
419
|
});
|
|
411
420
|
|
package/routes/admin.js
CHANGED
|
@@ -285,6 +285,9 @@ router.get(
|
|
|
285
285
|
backupForm.values.auto_backup_expire_days = getState().getConfig(
|
|
286
286
|
"auto_backup_expire_days"
|
|
287
287
|
);
|
|
288
|
+
backupForm.values.backup_with_event_log = getState().getConfig(
|
|
289
|
+
"backup_with_event_log"
|
|
290
|
+
);
|
|
288
291
|
//
|
|
289
292
|
const aSnapshotForm = snapshotForm(req);
|
|
290
293
|
aSnapshotForm.values.snapshots_enabled =
|
|
@@ -721,6 +724,15 @@ const autoBackupForm = (req) =>
|
|
|
721
724
|
auto_backup_destination: "Local directory",
|
|
722
725
|
},
|
|
723
726
|
},
|
|
727
|
+
{
|
|
728
|
+
type: "Bool",
|
|
729
|
+
label: req.__("Include Event Logs"),
|
|
730
|
+
sublabel: req.__("Backup with event logs"),
|
|
731
|
+
name: "backup_with_event_log",
|
|
732
|
+
showIf: {
|
|
733
|
+
auto_backup_frequency: ["Daily", "Weekly"],
|
|
734
|
+
},
|
|
735
|
+
},
|
|
724
736
|
],
|
|
725
737
|
});
|
|
726
738
|
|
package/routes/fields.js
CHANGED
|
@@ -409,7 +409,7 @@ const fieldFlow = (req) =>
|
|
|
409
409
|
instance_options[model.name].push(...instances.map((i) => i.name));
|
|
410
410
|
|
|
411
411
|
const outputs = await applyAsync(
|
|
412
|
-
model.templateObj
|
|
412
|
+
model.templateObj?.prediction_outputs || [], // unit tests can have templateObj undefined
|
|
413
413
|
{ table, configuration: model.configuration }
|
|
414
414
|
);
|
|
415
415
|
output_options[model.name] = outputs.map((o) => o.name);
|
|
@@ -840,6 +840,11 @@ router.post(
|
|
|
840
840
|
const table = Table.findOne({ name: tableName });
|
|
841
841
|
const role = req.user && req.user.id ? req.user.role_id : 100;
|
|
842
842
|
|
|
843
|
+
getState().log(
|
|
844
|
+
5,
|
|
845
|
+
`Route /fields/show-calculated/${tableName}/${fieldName}/${fieldview} user=${req.user?.id}`
|
|
846
|
+
);
|
|
847
|
+
|
|
843
848
|
const fields = table.getFields();
|
|
844
849
|
let row = { ...req.body };
|
|
845
850
|
if (row && Object.keys(row).length > 0) readState(row, fields);
|
|
@@ -1018,6 +1023,13 @@ router.post(
|
|
|
1018
1023
|
const { tableName, fieldName, fieldview } = req.params;
|
|
1019
1024
|
const table = Table.findOne({ name: tableName });
|
|
1020
1025
|
const fields = table.getFields();
|
|
1026
|
+
const state = getState();
|
|
1027
|
+
|
|
1028
|
+
state.log(
|
|
1029
|
+
5,
|
|
1030
|
+
`Route /fields/preview/${tableName}/${fieldName}/${fieldview} user=${req.user?.id}`
|
|
1031
|
+
);
|
|
1032
|
+
|
|
1021
1033
|
let field, row, value;
|
|
1022
1034
|
if (fieldName.includes(".")) {
|
|
1023
1035
|
const [refNm, targetNm] = fieldName.split(".");
|
|
@@ -1048,9 +1060,9 @@ router.post(
|
|
|
1048
1060
|
}
|
|
1049
1061
|
const fieldviews =
|
|
1050
1062
|
field.type === "Key"
|
|
1051
|
-
?
|
|
1063
|
+
? state.keyFieldviews
|
|
1052
1064
|
: field.type === "File"
|
|
1053
|
-
?
|
|
1065
|
+
? state.fileviews
|
|
1054
1066
|
: field.type.fieldviews;
|
|
1055
1067
|
if (!field.type || !fieldviews) {
|
|
1056
1068
|
res.send("");
|
package/routes/packs.js
CHANGED
|
@@ -6,18 +6,19 @@
|
|
|
6
6
|
|
|
7
7
|
const Router = require("express-promise-router");
|
|
8
8
|
const { isAdmin, error_catcher } = require("./utils.js");
|
|
9
|
-
const {
|
|
10
|
-
const { getState } = require("@saltcorn/data/db/state");
|
|
9
|
+
const { renderForm } = require("@saltcorn/markup");
|
|
11
10
|
const Table = require("@saltcorn/data/models/table");
|
|
12
11
|
const Form = require("@saltcorn/data/models/form");
|
|
13
12
|
const View = require("@saltcorn/data/models/view");
|
|
14
|
-
const Field = require("@saltcorn/data/models/field");
|
|
15
13
|
const Plugin = require("@saltcorn/data/models/plugin");
|
|
16
14
|
const Page = require("@saltcorn/data/models/page");
|
|
15
|
+
const Tag = require("@saltcorn/data/models/tag");
|
|
16
|
+
const EventLog = require("@saltcorn/data/models/eventlog");
|
|
17
|
+
const Model = require("@saltcorn/data/models/model");
|
|
18
|
+
const ModelInstance = require("@saltcorn/data/models/model_instance");
|
|
17
19
|
const load_plugins = require("../load_plugins");
|
|
18
20
|
|
|
19
21
|
const { is_pack } = require("@saltcorn/data/contracts");
|
|
20
|
-
const { contract, is } = require("contractis");
|
|
21
22
|
const {
|
|
22
23
|
table_pack,
|
|
23
24
|
view_pack,
|
|
@@ -26,15 +27,20 @@ const {
|
|
|
26
27
|
role_pack,
|
|
27
28
|
library_pack,
|
|
28
29
|
trigger_pack,
|
|
30
|
+
tag_pack,
|
|
31
|
+
model_pack,
|
|
32
|
+
model_instance_pack,
|
|
29
33
|
install_pack,
|
|
30
34
|
fetch_pack_by_name,
|
|
31
35
|
can_install_pack,
|
|
32
36
|
uninstall_pack,
|
|
37
|
+
event_log_pack,
|
|
33
38
|
} = require("@saltcorn/admin-models/models/pack");
|
|
34
|
-
const {
|
|
39
|
+
const { pre, code, p, text, text_attr } = require("@saltcorn/markup/tags");
|
|
35
40
|
const Library = require("@saltcorn/data/models/library");
|
|
36
41
|
const Trigger = require("@saltcorn/data/models/trigger");
|
|
37
42
|
const Role = require("@saltcorn/data/models/role");
|
|
43
|
+
const fs = require("fs");
|
|
38
44
|
|
|
39
45
|
/**
|
|
40
46
|
* @type {object}
|
|
@@ -98,6 +104,52 @@ router.get(
|
|
|
98
104
|
name: `role.${l.role}`,
|
|
99
105
|
type: "Bool",
|
|
100
106
|
}));
|
|
107
|
+
const tags = await Tag.find({});
|
|
108
|
+
const tagFields = tags.map((t) => ({
|
|
109
|
+
label: `${t.name} tag`,
|
|
110
|
+
name: `tag.${t.name}`,
|
|
111
|
+
type: "Bool",
|
|
112
|
+
}));
|
|
113
|
+
const models = await Model.find({});
|
|
114
|
+
const modelFields = models.map((m) => {
|
|
115
|
+
const modelTbl = Table.findOne({ id: m.table_id });
|
|
116
|
+
return {
|
|
117
|
+
label: `${m.name} model, table: ${
|
|
118
|
+
modelTbl.name || req.__("Table not found")
|
|
119
|
+
}`,
|
|
120
|
+
name: `model.${m.name}.${modelTbl.name}`,
|
|
121
|
+
type: "Bool",
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
const modelInstances = await ModelInstance.find({});
|
|
125
|
+
const modelInstanceFields = (
|
|
126
|
+
await Promise.all(
|
|
127
|
+
modelInstances.map(async (instance) => {
|
|
128
|
+
const model = await Model.findOne({ id: instance.model_id });
|
|
129
|
+
if (!model) {
|
|
130
|
+
req.flash(
|
|
131
|
+
"warning",
|
|
132
|
+
req.__(`Model with '${instance.model_id}' not found`)
|
|
133
|
+
);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const mTable = await Table.findOne({ id: model.table_id });
|
|
137
|
+
if (!mTable) {
|
|
138
|
+
req.flash(
|
|
139
|
+
"warning",
|
|
140
|
+
req.__(`Table of model '${model.name}' not found`)
|
|
141
|
+
);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
label: `${instance.name} model instance, model: ${model.name}, table: ${mTable.name}`,
|
|
146
|
+
name: `model_instance.${instance.name}.${model.name}.${mTable.name}`,
|
|
147
|
+
type: "Bool",
|
|
148
|
+
};
|
|
149
|
+
})
|
|
150
|
+
)
|
|
151
|
+
).filter((f) => f);
|
|
152
|
+
|
|
101
153
|
const form = new Form({
|
|
102
154
|
action: "/packs/create",
|
|
103
155
|
fields: [
|
|
@@ -108,6 +160,14 @@ router.get(
|
|
|
108
160
|
...trigFields,
|
|
109
161
|
...roleFields,
|
|
110
162
|
...libFields,
|
|
163
|
+
...tagFields,
|
|
164
|
+
...modelFields,
|
|
165
|
+
...modelInstanceFields,
|
|
166
|
+
{
|
|
167
|
+
name: "with_event_logs",
|
|
168
|
+
label: req.__("Include Event Logs"),
|
|
169
|
+
type: "Bool",
|
|
170
|
+
},
|
|
111
171
|
],
|
|
112
172
|
});
|
|
113
173
|
res.sendWrap(req.__(`Create Pack`), {
|
|
@@ -140,7 +200,7 @@ router.post(
|
|
|
140
200
|
"/create",
|
|
141
201
|
isAdmin,
|
|
142
202
|
error_catcher(async (req, res) => {
|
|
143
|
-
|
|
203
|
+
const pack = {
|
|
144
204
|
tables: [],
|
|
145
205
|
views: [],
|
|
146
206
|
plugins: [],
|
|
@@ -148,9 +208,13 @@ router.post(
|
|
|
148
208
|
roles: [],
|
|
149
209
|
library: [],
|
|
150
210
|
triggers: [],
|
|
211
|
+
tags: [],
|
|
212
|
+
models: [],
|
|
213
|
+
model_instances: [],
|
|
214
|
+
event_logs: [],
|
|
151
215
|
};
|
|
152
216
|
for (const k of Object.keys(req.body)) {
|
|
153
|
-
const [type, name] = k.split(".");
|
|
217
|
+
const [type, name, ...rest] = k.split(".");
|
|
154
218
|
switch (type) {
|
|
155
219
|
case "table":
|
|
156
220
|
pack.tables.push(await table_pack(name));
|
|
@@ -173,7 +237,32 @@ router.post(
|
|
|
173
237
|
case "trigger":
|
|
174
238
|
pack.triggers.push(await trigger_pack(name));
|
|
175
239
|
break;
|
|
176
|
-
|
|
240
|
+
case "tag":
|
|
241
|
+
pack.tags.push(await tag_pack(name));
|
|
242
|
+
break;
|
|
243
|
+
case "model": {
|
|
244
|
+
const table = rest[0];
|
|
245
|
+
if (!table) throw new Error(`Table for model '${name}' not found`);
|
|
246
|
+
pack.models.push(await model_pack(name, table));
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "model_instance": {
|
|
250
|
+
const model = rest[0];
|
|
251
|
+
if (!model)
|
|
252
|
+
throw new Error(`Model of Model Instance '${name}' not found`);
|
|
253
|
+
const table = rest[1];
|
|
254
|
+
if (!table) throw new Error(`Table of Model '${model}' not found`);
|
|
255
|
+
pack.model_instances.push(
|
|
256
|
+
await model_instance_pack(name, model, table)
|
|
257
|
+
);
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
case "with_event_logs":
|
|
261
|
+
const logs = await EventLog.find({});
|
|
262
|
+
pack.event_logs = await Promise.all(
|
|
263
|
+
logs.map(async (l) => await event_log_pack(l))
|
|
264
|
+
);
|
|
265
|
+
break;
|
|
177
266
|
default:
|
|
178
267
|
break;
|
|
179
268
|
}
|
|
@@ -217,11 +306,33 @@ const install_pack_form = (req) =>
|
|
|
217
306
|
action: "/packs/install",
|
|
218
307
|
submitLabel: req.__("Install"),
|
|
219
308
|
fields: [
|
|
309
|
+
{
|
|
310
|
+
name: "source",
|
|
311
|
+
label: req.__("Source"),
|
|
312
|
+
type: "String",
|
|
313
|
+
attributes: {
|
|
314
|
+
options: [
|
|
315
|
+
{ label: "from text", name: "from_text" },
|
|
316
|
+
{ label: "from file", name: "from_file" },
|
|
317
|
+
],
|
|
318
|
+
},
|
|
319
|
+
default: "from_text",
|
|
320
|
+
required: true,
|
|
321
|
+
},
|
|
220
322
|
{
|
|
221
323
|
name: "pack",
|
|
222
324
|
label: req.__("Pack"),
|
|
223
325
|
type: "String",
|
|
224
326
|
fieldview: "textarea",
|
|
327
|
+
showIf: { source: "from_text" },
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
name: "pack_file",
|
|
331
|
+
label: req.__("Pack file"),
|
|
332
|
+
class: "form-control",
|
|
333
|
+
type: "File",
|
|
334
|
+
sublabel: req.__("Upload a pack file"),
|
|
335
|
+
showIf: { source: "from_file" },
|
|
225
336
|
},
|
|
226
337
|
],
|
|
227
338
|
});
|
|
@@ -267,8 +378,22 @@ router.post(
|
|
|
267
378
|
isAdmin,
|
|
268
379
|
error_catcher(async (req, res) => {
|
|
269
380
|
var pack, error;
|
|
381
|
+
const source = req.body.source || "from_text";
|
|
270
382
|
try {
|
|
271
|
-
|
|
383
|
+
switch (source) {
|
|
384
|
+
case "from_text":
|
|
385
|
+
pack = JSON.parse(req.body.pack);
|
|
386
|
+
break;
|
|
387
|
+
case "from_file":
|
|
388
|
+
if (req.files?.pack_file?.tempFilePath)
|
|
389
|
+
pack = JSON.parse(
|
|
390
|
+
fs.readFileSync(req.files?.pack_file?.tempFilePath)
|
|
391
|
+
);
|
|
392
|
+
else throw new Error(req.__("No file uploaded"));
|
|
393
|
+
break;
|
|
394
|
+
default:
|
|
395
|
+
throw new Error(req.__("Invalid source"));
|
|
396
|
+
}
|
|
272
397
|
} catch (e) {
|
|
273
398
|
error = e.message;
|
|
274
399
|
}
|
package/routes/viewedit.js
CHANGED
|
@@ -632,6 +632,19 @@ router.post(
|
|
|
632
632
|
|
|
633
633
|
const view = await View.findOne({ name });
|
|
634
634
|
const configFlow = await view.get_config_flow(req);
|
|
635
|
+
configFlow.onStepSuccess = async (step, context) => {
|
|
636
|
+
let newcfg;
|
|
637
|
+
if (step.contextField)
|
|
638
|
+
newcfg = {
|
|
639
|
+
...view.configuration,
|
|
640
|
+
[step.contextField]: {
|
|
641
|
+
...view.configuration?.[step.contextField],
|
|
642
|
+
...context,
|
|
643
|
+
},
|
|
644
|
+
};
|
|
645
|
+
else newcfg = { ...view.configuration, ...context };
|
|
646
|
+
await View.update({ configuration: newcfg }, view.id);
|
|
647
|
+
};
|
|
635
648
|
const wfres = await configFlow.run(req.body, req);
|
|
636
649
|
|
|
637
650
|
let table;
|
package/tests/admin.test.js
CHANGED
|
@@ -568,11 +568,11 @@ describe("tags", () => {
|
|
|
568
568
|
.post("/tag")
|
|
569
569
|
.set("Cookie", loginCookie)
|
|
570
570
|
.send("name=MyNewTestTag")
|
|
571
|
-
.expect(toRedirect("/tag/
|
|
571
|
+
.expect(toRedirect("/tag/2?show_list=tables"));
|
|
572
572
|
});
|
|
573
573
|
|
|
574
574
|
itShouldIncludeTextForAdmin("/tag", "MyNewTestTag");
|
|
575
|
-
itShouldIncludeTextForAdmin("/tag/
|
|
575
|
+
itShouldIncludeTextForAdmin("/tag/2", "MyNewTestTag");
|
|
576
576
|
itShouldIncludeTextForAdmin("/tag-entries/add/tables/1", "Add entries");
|
|
577
577
|
itShouldIncludeTextForAdmin("/tag-entries/add/pages/1", "Add entries");
|
|
578
578
|
itShouldIncludeTextForAdmin("/tag-entries/add/views/1", "Add entries");
|