@saltcorn/data 1.6.0-alpha.7 → 1.6.0-alpha.9
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/dist/base-plugin/actions.d.ts +1850 -1656
- package/dist/base-plugin/actions.d.ts.map +1 -1
- package/dist/base-plugin/actions.js +122 -104
- package/dist/base-plugin/actions.js.map +1 -1
- package/dist/base-plugin/fieldviews.d.ts +284 -114
- package/dist/base-plugin/fieldviews.d.ts.map +1 -1
- package/dist/base-plugin/fieldviews.js +23 -69
- package/dist/base-plugin/fieldviews.js.map +1 -1
- package/dist/base-plugin/fileviews.d.ts +15 -14
- package/dist/base-plugin/fileviews.d.ts.map +1 -1
- package/dist/base-plugin/fileviews.js +22 -18
- package/dist/base-plugin/fileviews.js.map +1 -1
- package/dist/base-plugin/index.d.ts +3369 -1293
- package/dist/base-plugin/index.d.ts.map +1 -1
- package/dist/base-plugin/index.js +39 -25
- package/dist/base-plugin/index.js.map +1 -1
- package/dist/base-plugin/types.d.ts +1438 -1029
- package/dist/base-plugin/types.d.ts.map +1 -1
- package/dist/base-plugin/types.js +3 -2
- package/dist/base-plugin/types.js.map +1 -1
- package/dist/base-plugin/viewtemplates/edit.d.ts +133 -257
- package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/edit.js +292 -349
- package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
- package/dist/base-plugin/viewtemplates/feed.d.ts +30 -81
- package/dist/base-plugin/viewtemplates/feed.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/feed.js +37 -30
- package/dist/base-plugin/viewtemplates/feed.js.map +1 -1
- package/dist/base-plugin/viewtemplates/filter.d.ts +42 -64
- package/dist/base-plugin/viewtemplates/filter.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/filter.js +86 -82
- package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
- package/dist/base-plugin/viewtemplates/list.d.ts +40 -115
- package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/list.js +154 -168
- package/dist/base-plugin/viewtemplates/list.js.map +1 -1
- package/dist/base-plugin/viewtemplates/listshowlist.d.ts +65 -49
- package/dist/base-plugin/viewtemplates/listshowlist.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/listshowlist.js +33 -58
- package/dist/base-plugin/viewtemplates/listshowlist.js.map +1 -1
- package/dist/base-plugin/viewtemplates/room.d.ts +102 -109
- package/dist/base-plugin/viewtemplates/room.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/room.js +53 -50
- package/dist/base-plugin/viewtemplates/room.js.map +1 -1
- package/dist/base-plugin/viewtemplates/show.d.ts +72 -133
- package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/show.js +72 -182
- package/dist/base-plugin/viewtemplates/show.js.map +1 -1
- package/dist/base-plugin/viewtemplates/viewable_fields.d.ts +2 -2
- package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/viewable_fields.js +2 -1
- package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
- package/dist/base-plugin/viewtemplates/workflow-room.d.ts +37 -61
- package/dist/base-plugin/viewtemplates/workflow-room.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/workflow-room.js +42 -65
- package/dist/base-plugin/viewtemplates/workflow-room.js.map +1 -1
- package/dist/contracts.d.ts +4 -48
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +18 -2
- package/dist/contracts.js.map +1 -1
- package/dist/db/connect.d.ts.map +1 -1
- package/dist/db/connect.js +1 -0
- package/dist/db/connect.js.map +1 -1
- package/dist/db/state.d.ts +31 -28
- package/dist/db/state.d.ts.map +1 -1
- package/dist/db/state.js +5 -2
- package/dist/db/state.js.map +1 -1
- package/dist/model-helper.d.ts +4 -16
- package/dist/model-helper.d.ts.map +1 -1
- package/dist/model-helper.js +3 -3
- package/dist/model-helper.js.map +1 -1
- package/dist/models/config.d.ts +5 -0
- package/dist/models/config.d.ts.map +1 -1
- package/dist/models/config.js +5 -0
- package/dist/models/config.js.map +1 -1
- package/dist/models/field.d.ts +1 -1
- package/dist/models/field.d.ts.map +1 -1
- package/dist/models/field.js +3 -2
- package/dist/models/field.js.map +1 -1
- package/dist/models/file.d.ts +1 -1
- package/dist/models/file.d.ts.map +1 -1
- package/dist/models/file.js.map +1 -1
- package/dist/models/form.js +1 -1
- package/dist/models/form.js.map +1 -1
- package/dist/models/index.d.ts +5 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/layout.d.ts +1 -1
- package/dist/models/layout.d.ts.map +1 -1
- package/dist/models/layout.js +12 -0
- package/dist/models/layout.js.map +1 -1
- package/dist/models/plugin.d.ts +3 -2
- package/dist/models/plugin.d.ts.map +1 -1
- package/dist/models/plugin.js +7 -0
- package/dist/models/plugin.js.map +1 -1
- package/dist/models/table.d.ts.map +1 -1
- package/dist/models/table.js +6 -1
- package/dist/models/table.js.map +1 -1
- package/dist/plugin-helper.d.ts.map +1 -1
- package/dist/plugin-helper.js +4 -0
- package/dist/plugin-helper.js.map +1 -1
- package/dist/plugin-testing.d.ts +3 -63
- package/dist/plugin-testing.d.ts.map +1 -1
- package/dist/plugin-testing.js +34 -15
- package/dist/plugin-testing.js.map +1 -1
- package/dist/standard-menu.d.ts.map +1 -1
- package/dist/standard-menu.js +15 -0
- package/dist/standard-menu.js.map +1 -1
- package/dist/tests/actions.test.d.ts +2 -0
- package/dist/tests/actions.test.d.ts.map +1 -0
- package/dist/tests/actions.test.js +936 -0
- package/dist/tests/actions.test.js.map +1 -0
- package/dist/tests/auth.test.d.ts +2 -0
- package/dist/tests/auth.test.d.ts.map +1 -0
- package/dist/tests/auth.test.js +824 -0
- package/dist/tests/auth.test.js.map +1 -0
- package/dist/tests/auxtest.test.d.ts +2 -0
- package/dist/tests/auxtest.test.d.ts.map +1 -0
- package/dist/tests/auxtest.test.js +562 -0
- package/dist/tests/auxtest.test.js.map +1 -0
- package/dist/tests/base.test.d.ts +2 -0
- package/dist/tests/base.test.d.ts.map +1 -0
- package/dist/tests/base.test.js +30 -0
- package/dist/tests/base.test.js.map +1 -0
- package/dist/tests/calc.test.d.ts +2 -0
- package/dist/tests/calc.test.d.ts.map +1 -0
- package/dist/tests/calc.test.js +1081 -0
- package/dist/tests/calc.test.js.map +1 -0
- package/dist/tests/composite_pk.test.d.ts +2 -0
- package/dist/tests/composite_pk.test.d.ts.map +1 -0
- package/dist/tests/composite_pk.test.js +98 -0
- package/dist/tests/composite_pk.test.js.map +1 -0
- package/dist/tests/config.test.d.ts +2 -0
- package/dist/tests/config.test.d.ts.map +1 -0
- package/dist/tests/config.test.js +86 -0
- package/dist/tests/config.test.js.map +1 -0
- package/dist/tests/db.test.d.ts +2 -0
- package/dist/tests/db.test.d.ts.map +1 -0
- package/dist/tests/db.test.js +178 -0
- package/dist/tests/db.test.js.map +1 -0
- package/dist/tests/discover.test.d.ts +2 -0
- package/dist/tests/discover.test.d.ts.map +1 -0
- package/dist/tests/discover.test.js +245 -0
- package/dist/tests/discover.test.js.map +1 -0
- package/dist/tests/edit.test.d.ts +2 -0
- package/dist/tests/edit.test.d.ts.map +1 -0
- package/dist/tests/edit.test.js +1161 -0
- package/dist/tests/edit.test.js.map +1 -0
- package/dist/tests/email.test.d.ts +2 -0
- package/dist/tests/email.test.d.ts.map +1 -0
- package/dist/tests/email.test.js +255 -0
- package/dist/tests/email.test.js.map +1 -0
- package/dist/tests/exact_views.test.d.ts +2 -0
- package/dist/tests/exact_views.test.d.ts.map +1 -0
- package/dist/tests/exact_views.test.js +1363 -0
- package/dist/tests/exact_views.test.js.map +1 -0
- package/dist/tests/field.test.d.ts +2 -0
- package/dist/tests/field.test.d.ts.map +1 -0
- package/dist/tests/field.test.js +588 -0
- package/dist/tests/field.test.js.map +1 -0
- package/dist/tests/fieldviews.test.d.ts +2 -0
- package/dist/tests/fieldviews.test.d.ts.map +1 -0
- package/dist/tests/fieldviews.test.js +74 -0
- package/dist/tests/fieldviews.test.js.map +1 -0
- package/dist/tests/file.test.d.ts +2 -0
- package/dist/tests/file.test.d.ts.map +1 -0
- package/dist/tests/file.test.js +148 -0
- package/dist/tests/file.test.js.map +1 -0
- package/dist/tests/filter.test.d.ts +2 -0
- package/dist/tests/filter.test.d.ts.map +1 -0
- package/dist/tests/filter.test.js +496 -0
- package/dist/tests/filter.test.js.map +1 -0
- package/dist/tests/form.test.d.ts +2 -0
- package/dist/tests/form.test.d.ts.map +1 -0
- package/dist/tests/form.test.js +264 -0
- package/dist/tests/form.test.js.map +1 -0
- package/dist/tests/list.test.d.ts +2 -0
- package/dist/tests/list.test.d.ts.map +1 -0
- package/dist/tests/list.test.js +1037 -0
- package/dist/tests/list.test.js.map +1 -0
- package/dist/tests/models.test.d.ts +2 -0
- package/dist/tests/models.test.d.ts.map +1 -0
- package/dist/tests/models.test.js +417 -0
- package/dist/tests/models.test.js.map +1 -0
- package/dist/tests/page.test.d.ts +2 -0
- package/dist/tests/page.test.d.ts.map +1 -0
- package/dist/tests/page.test.js +26 -0
- package/dist/tests/page.test.js.map +1 -0
- package/dist/tests/page_group.test.d.ts +2 -0
- package/dist/tests/page_group.test.d.ts.map +1 -0
- package/dist/tests/page_group.test.js +51 -0
- package/dist/tests/page_group.test.js.map +1 -0
- package/dist/tests/plugin.test.d.ts +2 -0
- package/dist/tests/plugin.test.d.ts.map +1 -0
- package/dist/tests/plugin.test.js +60 -0
- package/dist/tests/plugin.test.js.map +1 -0
- package/dist/tests/show.test.d.ts +2 -0
- package/dist/tests/show.test.d.ts.map +1 -0
- package/dist/tests/show.test.js +561 -0
- package/dist/tests/show.test.js.map +1 -0
- package/dist/tests/state.test.d.ts +2 -0
- package/dist/tests/state.test.d.ts.map +1 -0
- package/dist/tests/state.test.js +82 -0
- package/dist/tests/state.test.js.map +1 -0
- package/dist/tests/table.test.d.ts +2 -0
- package/dist/tests/table.test.d.ts.map +1 -0
- package/dist/tests/table.test.js +2717 -0
- package/dist/tests/table.test.js.map +1 -0
- package/dist/tests/table_history.test.d.ts +2 -0
- package/dist/tests/table_history.test.d.ts.map +1 -0
- package/dist/tests/table_history.test.js +413 -0
- package/dist/tests/table_history.test.js.map +1 -0
- package/dist/tests/tag.test.d.ts +2 -0
- package/dist/tests/tag.test.d.ts.map +1 -0
- package/dist/tests/tag.test.js +97 -0
- package/dist/tests/tag.test.js.map +1 -0
- package/dist/tests/user.test.d.ts +2 -0
- package/dist/tests/user.test.d.ts.map +1 -0
- package/dist/tests/user.test.js +441 -0
- package/dist/tests/user.test.js.map +1 -0
- package/dist/tests/view.test.d.ts +2 -0
- package/dist/tests/view.test.d.ts.map +1 -0
- package/dist/tests/view.test.js +699 -0
- package/dist/tests/view.test.js.map +1 -0
- package/dist/tests/workflow.test.d.ts +2 -0
- package/dist/tests/workflow.test.d.ts.map +1 -0
- package/dist/tests/workflow.test.js +303 -0
- package/dist/tests/workflow.test.js.map +1 -0
- package/dist/tests/workflow_run.test.d.ts +2 -0
- package/dist/tests/workflow_run.test.d.ts.map +1 -0
- package/dist/tests/workflow_run.test.js +922 -0
- package/dist/tests/workflow_run.test.js.map +1 -0
- package/dist/viewable_fields.d.ts +5 -4
- package/dist/viewable_fields.d.ts.map +1 -1
- package/dist/viewable_fields.js +12 -6
- package/dist/viewable_fields.js.map +1 -1
- package/dist/web-mobile-commons.d.ts.map +1 -1
- package/dist/web-mobile-commons.js +1 -0
- package/dist/web-mobile-commons.js.map +1 -1
- package/package.json +8 -8
|
@@ -1,73 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
/**
|
|
3
6
|
* @category saltcorn-data
|
|
4
7
|
* @module base-plugin/viewtemplates/edit
|
|
5
8
|
* @subcategory base-plugin
|
|
6
9
|
*/
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
10
|
+
const field_1 = __importDefault(require("../../models/field"));
|
|
11
|
+
const table_1 = __importDefault(require("../../models/table"));
|
|
12
|
+
const user_1 = __importDefault(require("../../models/user"));
|
|
13
|
+
const crash_1 = __importDefault(require("../../models/crash"));
|
|
14
|
+
const form_1 = __importDefault(require("../../models/form"));
|
|
15
|
+
const page_1 = __importDefault(require("../../models/page"));
|
|
16
|
+
const view_1 = __importDefault(require("../../models/view"));
|
|
17
|
+
const workflow_1 = __importDefault(require("../../models/workflow"));
|
|
18
|
+
const trigger_1 = __importDefault(require("../../models/trigger"));
|
|
19
|
+
const file_1 = __importDefault(require("../../models/file"));
|
|
14
20
|
const PageGroup = require("../../models/page_group");
|
|
15
|
-
const View = require("../../models/view");
|
|
16
|
-
const Workflow = require("../../models/workflow");
|
|
17
|
-
const Trigger = require("../../models/trigger");
|
|
18
|
-
const { getState } = require("../../db/state");
|
|
19
|
-
const { text, text_attr, script, domReady, div, button, i, pre, } = require("@saltcorn/markup/tags");
|
|
20
|
-
const { renderForm } = require("@saltcorn/markup");
|
|
21
21
|
const FieldRepeat = require("../../models/fieldrepeat");
|
|
22
|
-
const { get_expression_function, expressionChecker, eval_expression, freeVariables, freeVariablesInInterpolation, add_free_variables_to_aggregations, } = require("../../models/expression");
|
|
23
|
-
const { InvalidConfiguration, isNode, isWeb, isTest, mergeIntoWhere, dollarizeObject, getSessionId, interpolate, asyncMap, removeEmptyStrings, renderServerSide, } = require("../../utils");
|
|
24
22
|
const Library = require("../../models/library");
|
|
25
|
-
const {
|
|
26
|
-
const
|
|
27
|
-
const {
|
|
28
|
-
const
|
|
29
|
-
const {
|
|
30
|
-
const
|
|
31
|
-
const {
|
|
32
|
-
const
|
|
23
|
+
const { getState } = require("../../db/state");
|
|
24
|
+
const tags_1 = require("@saltcorn/markup/tags");
|
|
25
|
+
const { renderForm } = require("@saltcorn/markup");
|
|
26
|
+
const expression_1 = __importDefault(require("../../models/expression"));
|
|
27
|
+
const { get_expression_function, expressionChecker, eval_expression, freeVariables, freeVariablesInInterpolation, add_free_variables_to_aggregations, } = expression_1.default;
|
|
28
|
+
const utils_1 = __importDefault(require("../../utils"));
|
|
29
|
+
const { InvalidConfiguration, isNode, isWeb, isTest, mergeIntoWhere, interpolate, asyncMap, removeEmptyStrings, structuredClone, } = utils_1.default;
|
|
30
|
+
const plugin_testing_1 = require("../../plugin-testing");
|
|
31
|
+
const plugin_helper_1 = require("../../plugin-helper");
|
|
32
|
+
const viewable_fields_1 = require("../../viewable_fields");
|
|
33
|
+
const layout_1 = __importDefault(require("../../models/layout"));
|
|
34
|
+
const { traverse, getStringsForI18n, traverseSync, splitLayoutContainerFields, findLayoutBranchWith, } = layout_1.default;
|
|
35
|
+
const node_extract_utils_1 = require("../../diagram/node_extract_utils");
|
|
36
|
+
const db_1 = __importDefault(require("../../db"));
|
|
33
37
|
const { Relation, RelationType } = require("@saltcorn/common-code");
|
|
34
38
|
/**
|
|
35
|
-
* @param
|
|
36
|
-
* @returns
|
|
39
|
+
* @param req
|
|
40
|
+
* @returns
|
|
37
41
|
*/
|
|
38
|
-
const configuration_workflow = (req) => new
|
|
42
|
+
const configuration_workflow = (req) => new workflow_1.default({
|
|
39
43
|
steps: [
|
|
40
44
|
{
|
|
41
45
|
name: req.__("Layout"),
|
|
42
46
|
builder: async (context) => {
|
|
43
|
-
const table =
|
|
47
|
+
const table = table_1.default.findOne({ id: context.table_id });
|
|
44
48
|
const fields = table
|
|
45
49
|
.getFields()
|
|
46
50
|
.filter((f) => !f.primary_key || f.attributes?.NonSerial);
|
|
47
51
|
for (const field of fields) {
|
|
48
52
|
if (field.type === "Key") {
|
|
49
|
-
field.reftable =
|
|
53
|
+
field.reftable = table_1.default.findOne({
|
|
50
54
|
name: field.reftable_name,
|
|
51
55
|
});
|
|
52
56
|
if (field.reftable)
|
|
53
57
|
await field.reftable.getFields();
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
|
-
const { field_view_options, handlesTextStyle, blockDisplay } = calcfldViewOptions(fields, "edit");
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const images = await File.find({ mime_super: "image" });
|
|
60
|
+
const { field_view_options, handlesTextStyle, blockDisplay } = (0, plugin_helper_1.calcfldViewOptions)(fields, "edit");
|
|
61
|
+
const roles = await user_1.default.get_roles();
|
|
62
|
+
const images = await file_1.default.find({ mime_super: "image" });
|
|
60
63
|
const stateActions = Object.entries(getState().actions).filter(([k, v]) => !v.disableInBuilder && !v.disableIf?.());
|
|
61
|
-
const triggerActions =
|
|
64
|
+
const triggerActions = trigger_1.default.trigger_actions({
|
|
62
65
|
tableTriggers: table.id,
|
|
63
66
|
apiNeverTriggers: true,
|
|
64
67
|
});
|
|
65
|
-
const actions =
|
|
68
|
+
const actions = trigger_1.default.action_options({
|
|
66
69
|
tableTriggers: table.id,
|
|
67
70
|
apiNeverTriggers: true,
|
|
68
71
|
forBuilder: true,
|
|
69
72
|
builtInLabel: "Edit Actions",
|
|
70
|
-
builtIns: edit_build_in_actions,
|
|
73
|
+
builtIns: viewable_fields_1.edit_build_in_actions,
|
|
71
74
|
});
|
|
72
75
|
const actionConfigForms = {
|
|
73
76
|
Delete: [
|
|
@@ -98,10 +101,10 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
98
101
|
};
|
|
99
102
|
for (const [name, action] of stateActions) {
|
|
100
103
|
if (action.configFields) {
|
|
101
|
-
actionConfigForms[name] = await getActionConfigFields(action, table, { mode: "edit", req });
|
|
104
|
+
actionConfigForms[name] = await (0, plugin_helper_1.getActionConfigFields)(action, table, { mode: "edit", req });
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
|
-
const workflowActions =
|
|
107
|
+
const workflowActions = trigger_1.default.trigger_actions({
|
|
105
108
|
tableTriggers: table.id,
|
|
106
109
|
apiNeverTriggers: true,
|
|
107
110
|
onlyWorkflows: true,
|
|
@@ -122,29 +125,29 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
122
125
|
Object.entries(getState().auth_methods).forEach(([k, v]) => {
|
|
123
126
|
actions.push(`Login with ${k}`);
|
|
124
127
|
});
|
|
125
|
-
fields.push({
|
|
128
|
+
fields.push(new field_1.default({
|
|
126
129
|
name: "password",
|
|
127
130
|
label: req.__("Password"),
|
|
128
131
|
type: "String",
|
|
129
|
-
});
|
|
130
|
-
fields.push({
|
|
132
|
+
}));
|
|
133
|
+
fields.push(new field_1.default({
|
|
131
134
|
name: "passwordRepeat",
|
|
132
135
|
label: req.__("Password Repeat"),
|
|
133
136
|
type: "String",
|
|
134
|
-
});
|
|
135
|
-
fields.push({
|
|
137
|
+
}));
|
|
138
|
+
fields.push(new field_1.default({
|
|
136
139
|
name: "remember",
|
|
137
140
|
label: req.__("Remember me"),
|
|
138
141
|
type: "Bool",
|
|
139
|
-
});
|
|
142
|
+
}));
|
|
140
143
|
field_view_options.password = ["password"];
|
|
141
144
|
field_view_options.passwordRepeat = ["password"];
|
|
142
145
|
field_view_options.remember = ["edit"];
|
|
143
146
|
}
|
|
144
147
|
const library = (await Library.find({})).filter((l) => l.suitableFor("edit"));
|
|
145
|
-
const myviewrow =
|
|
148
|
+
const myviewrow = view_1.default.findOne({ name: context.viewname });
|
|
146
149
|
const { parent_field_list } = await table.get_parent_relations(true, true);
|
|
147
|
-
const pages = await
|
|
150
|
+
const pages = await page_1.default.find();
|
|
148
151
|
const groups = (await PageGroup.find()).map((g) => ({
|
|
149
152
|
name: g.name,
|
|
150
153
|
}));
|
|
@@ -158,8 +161,7 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
158
161
|
roles,
|
|
159
162
|
actions,
|
|
160
163
|
triggerActions,
|
|
161
|
-
builtInActions: edit_build_in_actions,
|
|
162
|
-
//fieldViewConfigForms,
|
|
164
|
+
builtInActions: viewable_fields_1.edit_build_in_actions,
|
|
163
165
|
actionConfigForms,
|
|
164
166
|
images,
|
|
165
167
|
allowMultiStepAction: true,
|
|
@@ -179,7 +181,7 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
179
181
|
name: req.__("Fixed and blocked fields"),
|
|
180
182
|
contextField: "fixed",
|
|
181
183
|
onlyWhen: async (context) => {
|
|
182
|
-
const table =
|
|
184
|
+
const table = table_1.default.findOne({ id: context.table_id });
|
|
183
185
|
const fields = table.getFields();
|
|
184
186
|
const in_form_fields = context.columns.map((f) => f.field_name);
|
|
185
187
|
return fields.some((f) => !in_form_fields.includes(f.name) &&
|
|
@@ -187,7 +189,7 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
187
189
|
!f.primary_key);
|
|
188
190
|
},
|
|
189
191
|
form: async (context) => {
|
|
190
|
-
const table =
|
|
192
|
+
const table = table_1.default.findOne({ id: context.table_id });
|
|
191
193
|
const fields = table.getFields();
|
|
192
194
|
const in_form_fields = context.columns.map((f) => f.field_name);
|
|
193
195
|
const omitted_fields = fields.filter((f) => !in_form_fields.includes(f.name) &&
|
|
@@ -202,7 +204,7 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
202
204
|
}
|
|
203
205
|
formFields.push(f);
|
|
204
206
|
if (f.presets) {
|
|
205
|
-
formFields.push(new
|
|
207
|
+
formFields.push(new field_1.default({
|
|
206
208
|
name: "preset_" + f.name,
|
|
207
209
|
label: req.__("Preset %s", f.label),
|
|
208
210
|
type: "String",
|
|
@@ -215,7 +217,7 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
215
217
|
label: f.label,
|
|
216
218
|
});
|
|
217
219
|
});
|
|
218
|
-
const form = new
|
|
220
|
+
const form = new form_1.default({
|
|
219
221
|
fields: [
|
|
220
222
|
{
|
|
221
223
|
input_type: "section_header",
|
|
@@ -236,26 +238,26 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
236
238
|
{
|
|
237
239
|
name: req.__("Edit options"),
|
|
238
240
|
form: async (context) => {
|
|
239
|
-
const own_views = await
|
|
241
|
+
const own_views = await view_1.default.find_all_views_where(({ state_fields, viewrow }) => viewrow.table_id === context.table_id ||
|
|
240
242
|
state_fields.every((sf) => !sf.required));
|
|
241
|
-
const table =
|
|
243
|
+
const table = table_1.default.findOne({ id: context.table_id });
|
|
242
244
|
own_views.forEach((v) => {
|
|
243
245
|
if (!v.table && v.table_id === table.id)
|
|
244
246
|
v.table = table;
|
|
245
247
|
else if (!v.table && v.table_id) {
|
|
246
|
-
const vtable =
|
|
248
|
+
const vtable = table_1.default.findOne({ id: v.table_id });
|
|
247
249
|
v.table = vtable;
|
|
248
250
|
}
|
|
249
251
|
});
|
|
250
|
-
const parent_views = await get_parent_views(table, context.viewname);
|
|
252
|
+
const parent_views = await (0, plugin_helper_1.get_parent_views)(table, context.viewname);
|
|
251
253
|
const done_view_opts = own_views.map((v) => v.select_option);
|
|
252
254
|
parent_views.forEach(({ relation, related_table, views }) => views.forEach((v) => {
|
|
253
255
|
done_view_opts.push(`${v.name}.${relation.name}`);
|
|
254
256
|
}));
|
|
255
|
-
const pages = await
|
|
257
|
+
const pages = await page_1.default.find();
|
|
256
258
|
const groups = await PageGroup.find();
|
|
257
|
-
const triggers =
|
|
258
|
-
return new
|
|
259
|
+
const triggers = trigger_1.default.find();
|
|
260
|
+
return new form_1.default({
|
|
259
261
|
fields: [
|
|
260
262
|
{
|
|
261
263
|
name: "auto_save",
|
|
@@ -317,7 +319,6 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
317
319
|
type: "String",
|
|
318
320
|
required: true,
|
|
319
321
|
sublabel: req.__("This is the view to which the user will be sent when the form is submitted. The view you specify here can be ignored depending on the context of the form, for instance if it appears in a pop-up the redirect will not take place."),
|
|
320
|
-
//fieldview: "radio_group",
|
|
321
322
|
attributes: {
|
|
322
323
|
options: [
|
|
323
324
|
"Back to referer",
|
|
@@ -396,11 +397,10 @@ const configuration_workflow = (req) => new Workflow({
|
|
|
396
397
|
],
|
|
397
398
|
});
|
|
398
399
|
/**
|
|
399
|
-
* @param
|
|
400
|
-
* @param
|
|
401
|
-
* @param
|
|
402
|
-
* @
|
|
403
|
-
* @returns {Promise<object[]>}
|
|
400
|
+
* @param table_id
|
|
401
|
+
* @param viewname
|
|
402
|
+
* @param param2
|
|
403
|
+
* @returns
|
|
404
404
|
*/
|
|
405
405
|
const get_state_fields = async (table_id, viewname, { columns }) => [
|
|
406
406
|
{
|
|
@@ -409,37 +409,28 @@ const get_state_fields = async (table_id, viewname, { columns }) => [
|
|
|
409
409
|
primary_key: true,
|
|
410
410
|
},
|
|
411
411
|
];
|
|
412
|
+
const initial_config = (0, plugin_helper_1.initial_config_all_fields)(true);
|
|
412
413
|
/**
|
|
413
|
-
* @param
|
|
414
|
-
* @param
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
* @
|
|
420
|
-
* @param {string} viewname
|
|
421
|
-
* @param {object} optsOne
|
|
422
|
-
* @param {*} optsOne.columns
|
|
423
|
-
* @param {*} optsOne.layout
|
|
424
|
-
* @param {string} state
|
|
425
|
-
* @param {object} optsTwo
|
|
426
|
-
* @param {object} optsTwo.req
|
|
427
|
-
* @param {object} optsTwo.res
|
|
428
|
-
* @returns {Promise<Form>}
|
|
414
|
+
* @param table_id
|
|
415
|
+
* @param viewname
|
|
416
|
+
* @param cfg
|
|
417
|
+
* @param state
|
|
418
|
+
* @param param4
|
|
419
|
+
* @param param5
|
|
420
|
+
* @returns
|
|
429
421
|
*/
|
|
430
|
-
const run = async (table_id, viewname, cfg, state, { res, req, isPreview, hiddenLoginDest }, { editQuery }) => {
|
|
422
|
+
const run = async (table_id, viewname, cfg, state, { res, req, isPreview, hiddenLoginDest, }, { editQuery }) => {
|
|
431
423
|
const mobileReferrer = isWeb(req) ? undefined : req?.headers?.referer;
|
|
432
424
|
return await editQuery(state, mobileReferrer, isPreview, hiddenLoginDest);
|
|
433
425
|
};
|
|
434
426
|
/**
|
|
435
|
-
* @param
|
|
436
|
-
* @param
|
|
437
|
-
* @param
|
|
438
|
-
* @param
|
|
439
|
-
* @param
|
|
440
|
-
* @param
|
|
441
|
-
* @
|
|
442
|
-
* @returns {Promise<Form[]>}
|
|
427
|
+
* @param table_id
|
|
428
|
+
* @param viewname
|
|
429
|
+
* @param param2
|
|
430
|
+
* @param state
|
|
431
|
+
* @param extra
|
|
432
|
+
* @param param5
|
|
433
|
+
* @returns
|
|
443
434
|
*/
|
|
444
435
|
const runMany = async (table_id, viewname, { columns, layout, auto_save, split_paste, confirm_leave, enable_realtime, update_events, }, state, extra, { editManyQuery, getRowQuery, optionsQuery }) => {
|
|
445
436
|
let { table, fields, rows } = await editManyQuery(state, {
|
|
@@ -450,7 +441,7 @@ const runMany = async (table_id, viewname, { columns, layout, auto_save, split_p
|
|
|
450
441
|
where: extra.where,
|
|
451
442
|
});
|
|
452
443
|
if (!isNode()) {
|
|
453
|
-
table =
|
|
444
|
+
table = table_1.default.findOne({ id: table.id });
|
|
454
445
|
fields = table.getFields();
|
|
455
446
|
}
|
|
456
447
|
const isRemote = !isWeb(extra.req);
|
|
@@ -477,19 +468,9 @@ const runMany = async (table_id, viewname, { columns, layout, auto_save, split_p
|
|
|
477
468
|
return { html, row };
|
|
478
469
|
});
|
|
479
470
|
};
|
|
480
|
-
/**
|
|
481
|
-
* @param {object} opts
|
|
482
|
-
* @param {Form} opts.form
|
|
483
|
-
* @param {Table} opts.table
|
|
484
|
-
* @param {object} opts.req
|
|
485
|
-
* @param {object} opts.row
|
|
486
|
-
* @param {object} opts.res
|
|
487
|
-
* @throws {InvalidConfiguration}
|
|
488
|
-
* @returns {Promise<void>}
|
|
489
|
-
*/
|
|
490
471
|
const realTimeScript = (viewname, table_id, row, scriptId) => {
|
|
491
|
-
const view =
|
|
492
|
-
const table =
|
|
472
|
+
const view = view_1.default.findOne({ name: viewname });
|
|
473
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
493
474
|
const rowId = row[table.pk_name];
|
|
494
475
|
return `
|
|
495
476
|
const collabCfg = {
|
|
@@ -515,21 +496,8 @@ const realTimeScript = (viewname, table_id, row, scriptId) => {
|
|
|
515
496
|
};
|
|
516
497
|
init_collab_room('${viewname}', collabCfg);`.trim();
|
|
517
498
|
};
|
|
518
|
-
/**
|
|
519
|
-
* @param {object} opts
|
|
520
|
-
* @param {Table} opts.table
|
|
521
|
-
* @param {Fields[]} opts.fields
|
|
522
|
-
* @param {string} opts.viewname
|
|
523
|
-
* @param {object[]} opts.columns
|
|
524
|
-
* @param {Layout} opts.layout
|
|
525
|
-
* @param {object} opts.row
|
|
526
|
-
* @param {object} opts.req
|
|
527
|
-
* @param {object} opts.state
|
|
528
|
-
* @param {object} opts.res
|
|
529
|
-
* @returns {Promise<Form>}
|
|
530
|
-
*/
|
|
531
499
|
const render = async ({ table, fields, viewname, columns, layout, row, req, state, res, auto_save, destination_type, isRemote, getRowQuery, optionsQuery, split_paste, mobileReferrer, confirm_leave, delete_unchanged_auto_create, isPreview, auto_created_row, hiddenLoginDest, enable_realtime, }) => {
|
|
532
|
-
const form = await getForm(table, viewname, columns, layout, state[table.pk_name], req, isRemote);
|
|
500
|
+
const form = await (0, viewable_fields_1.getForm)(table, viewname, columns, layout, state[table.pk_name], req, isRemote);
|
|
533
501
|
if (split_paste)
|
|
534
502
|
form.splitPaste = true;
|
|
535
503
|
if (row) {
|
|
@@ -538,12 +506,12 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
|
|
|
538
506
|
if (isWeb(req)) {
|
|
539
507
|
for (const field of file_fields) {
|
|
540
508
|
if (field.fieldviewObj?.valueIsFilename && row[field.name]) {
|
|
541
|
-
const file = await
|
|
509
|
+
const file = await file_1.default.findOne({ id: row[field.name] });
|
|
542
510
|
if (file?.id)
|
|
543
511
|
form.values[field.name] = file.filename;
|
|
544
512
|
}
|
|
545
513
|
if (field.fieldviewObj?.editContent && row[field.name]) {
|
|
546
|
-
const file = await
|
|
514
|
+
const file = await file_1.default.findOne(row[field.name]);
|
|
547
515
|
if (file && file.min_role_read >= (req.user?.role_id || 100))
|
|
548
516
|
form.values[`_content_${field.name}`] = await file.get_contents();
|
|
549
517
|
}
|
|
@@ -554,10 +522,9 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
|
|
|
554
522
|
const owner_field = await table.owner_fieldname();
|
|
555
523
|
if (table.ownership_formula && user_id) {
|
|
556
524
|
const freeVars = freeVariables(table.ownership_formula);
|
|
557
|
-
//need to fetch with joinfields
|
|
558
525
|
if (freeVars.size > 0) {
|
|
559
526
|
const joinFields = {};
|
|
560
|
-
add_free_variables_to_joinfields(freeVars, joinFields, fields);
|
|
527
|
+
(0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, fields);
|
|
561
528
|
const row_joined = await table.getJoinedRow({
|
|
562
529
|
where: { [table.pk_name]: row[table.pk_name] },
|
|
563
530
|
forPublic: !req.user,
|
|
@@ -596,7 +563,7 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
|
|
|
596
563
|
else {
|
|
597
564
|
const tbl_field = fields.find((f) => f.name === k);
|
|
598
565
|
if (tbl_field && !field) {
|
|
599
|
-
form.fields.push(new
|
|
566
|
+
form.fields.push(new field_1.default({ name: k, input_type: "hidden" }));
|
|
600
567
|
form.values[k] = tbl_field.type.read
|
|
601
568
|
? tbl_field.type.read(v, tbl_field.attributes)
|
|
602
569
|
: v;
|
|
@@ -608,18 +575,19 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
|
|
|
608
575
|
const need_join_fields = new Set(columns
|
|
609
576
|
.filter((c) => c.type === "JoinField")
|
|
610
577
|
.map((c) => c.join_field.split(".")[0]));
|
|
611
|
-
const colFields = new Set(columns
|
|
578
|
+
const colFields = new Set(columns
|
|
579
|
+
.filter((c) => c.type === "Field")
|
|
580
|
+
.map((c) => c.field_name));
|
|
612
581
|
const formFields = new Set(form.fields.map((f) => f.name));
|
|
613
582
|
fields.forEach((f) => {
|
|
614
583
|
if (!colFields.has(f.name) &&
|
|
615
584
|
!formFields.has(f.name) &&
|
|
616
585
|
typeof row[f.name] !== "undefined" &&
|
|
617
586
|
need_join_fields.has(f.name))
|
|
618
|
-
form.fields.push(new
|
|
587
|
+
form.fields.push(new field_1.default({ name: f.name, input_type: "hidden" }));
|
|
619
588
|
});
|
|
620
589
|
}
|
|
621
590
|
// no autosave if new and save button exists
|
|
622
|
-
// !row && hasSave
|
|
623
591
|
let hasSave = false;
|
|
624
592
|
traverseSync(layout, {
|
|
625
593
|
action({ action_name }) {
|
|
@@ -632,7 +600,7 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
|
|
|
632
600
|
if (actually_auto_save)
|
|
633
601
|
form.onChange = `saveAndContinueDelayed(this, ${!isWeb(req) ? `'${form.action}'` : undefined}, event);`;
|
|
634
602
|
let reloadAfterCloseInModalScript = actually_auto_save && req.xhr
|
|
635
|
-
? script(domReady(`
|
|
603
|
+
? (0, tags_1.script)((0, tags_1.domReady)(`
|
|
636
604
|
$("#scmodal").on("hidden.bs.modal", function (e) {
|
|
637
605
|
const on_close_reload_view = $("#scmodal").attr(
|
|
638
606
|
"data-on-close-reload-view"
|
|
@@ -645,15 +613,13 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
|
|
|
645
613
|
: "";
|
|
646
614
|
let confirmLeaveScript = "";
|
|
647
615
|
if (confirm_leave) {
|
|
648
|
-
//add to onchange
|
|
649
616
|
if (!form.onChange)
|
|
650
617
|
form.onChange = "";
|
|
651
618
|
form.onChange += "this.setAttribute('data-unsaved-changes','true');";
|
|
652
619
|
if (!form.onSubmit)
|
|
653
620
|
form.onSubmit = "";
|
|
654
621
|
form.onSubmit += "this.removeAttribute('data-unsaved-changes')";
|
|
655
|
-
|
|
656
|
-
confirmLeaveScript = script(`((curScript)=>{window.addEventListener("beforeunload", (e) => check_unsaved_form(e, curScript));})(document.currentScript)`);
|
|
622
|
+
confirmLeaveScript = (0, tags_1.script)(`((curScript)=>{window.addEventListener("beforeunload", (e) => check_unsaved_form(e, curScript));})(document.currentScript)`);
|
|
657
623
|
}
|
|
658
624
|
let deleteUnchangedScript = "";
|
|
659
625
|
if (auto_created_row && delete_unchanged_auto_create && !isPreview) {
|
|
@@ -667,23 +633,23 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
|
|
|
667
633
|
form.onChange = "";
|
|
668
634
|
form.onChange += "this.setAttribute('data-form-changed','true');";
|
|
669
635
|
}
|
|
670
|
-
deleteUnchangedScript = script(`((curScript)=>{window.addEventListener("beforeunload", () => check_delete_unsaved("${table.name}", curScript));})(document.currentScript)`);
|
|
636
|
+
deleteUnchangedScript = (0, tags_1.script)(`((curScript)=>{window.addEventListener("beforeunload", () => check_delete_unsaved("${table.name}", curScript));})(document.currentScript)`);
|
|
671
637
|
}
|
|
672
638
|
const formId = isTest()
|
|
673
639
|
? "test-form-id"
|
|
674
640
|
: `form${Math.floor(Math.random() * 16777215).toString(16)}`;
|
|
675
|
-
const identicalFieldsScript = script(domReady(`const editForm = document.getElementById('${formId}'); if (editForm) editForm.addEventListener("change", handle_identical_fields, true);`));
|
|
641
|
+
const identicalFieldsScript = (0, tags_1.script)((0, tags_1.domReady)(`const editForm = document.getElementById('${formId}'); if (editForm) editForm.addEventListener("change", handle_identical_fields, true);`));
|
|
676
642
|
const dynamic_updates_enabled = getState().getConfig("enable_dynamic_updates", true);
|
|
677
643
|
const rndid = isTest()
|
|
678
644
|
? "test-script-id"
|
|
679
645
|
: Math.floor(Math.random() * 16777215).toString(16);
|
|
680
646
|
const realTimeCollabScript = enable_realtime && row && !(req.headers?.pjaxpageload === "true")
|
|
681
647
|
? (!dynamic_updates_enabled
|
|
682
|
-
? script({
|
|
683
|
-
src: `/static_assets/${
|
|
648
|
+
? (0, tags_1.script)({
|
|
649
|
+
src: `/static_assets/${db_1.default.connectObj.version_tag}/socket.io.min.js`,
|
|
684
650
|
})
|
|
685
651
|
: "") +
|
|
686
|
-
script({ id: rndid }, domReady(realTimeScript(viewname, table.id, row, rndid)))
|
|
652
|
+
(0, tags_1.script)({ id: rndid }, (0, tags_1.domReady)(realTimeScript(viewname, table.id, row, rndid)))
|
|
687
653
|
: "";
|
|
688
654
|
if (actually_auto_save) {
|
|
689
655
|
for (const field of form.fields) {
|
|
@@ -691,11 +657,11 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
|
|
|
691
657
|
}
|
|
692
658
|
}
|
|
693
659
|
await form.fill_fkey_options(false, optionsQuery, req.user);
|
|
694
|
-
await transformForm({
|
|
660
|
+
await (0, viewable_fields_1.transformForm)({
|
|
695
661
|
form,
|
|
696
662
|
table,
|
|
697
663
|
req,
|
|
698
|
-
row,
|
|
664
|
+
row: row,
|
|
699
665
|
res,
|
|
700
666
|
getRowQuery,
|
|
701
667
|
viewname,
|
|
@@ -724,40 +690,32 @@ const identicalFieldNames = (columns) => {
|
|
|
724
690
|
return result;
|
|
725
691
|
};
|
|
726
692
|
const prepSafeBody = (body, columns) => {
|
|
727
|
-
const safeBody = { ...body };
|
|
693
|
+
const safeBody = { ...body };
|
|
728
694
|
const identicalFields = identicalFieldNames(columns);
|
|
729
695
|
for (const field of identicalFields) {
|
|
730
696
|
if (body && body[field] && Array.isArray(body[field])) {
|
|
731
|
-
// should all be the same (see saltcorn.js handle_identical_fields())
|
|
732
|
-
// or at least the submit still works (e.g. different plugin fieldviews)
|
|
733
697
|
safeBody[field] = body[field][0];
|
|
734
698
|
}
|
|
735
699
|
}
|
|
736
700
|
return safeBody;
|
|
737
701
|
};
|
|
738
702
|
/**
|
|
739
|
-
* @param
|
|
740
|
-
* @param
|
|
741
|
-
* @param
|
|
742
|
-
* @param
|
|
743
|
-
* @param
|
|
744
|
-
* @param
|
|
745
|
-
* @param
|
|
746
|
-
* @param
|
|
747
|
-
* @
|
|
748
|
-
* @param {*} body
|
|
749
|
-
* @param {object} optsTwo
|
|
750
|
-
* @param {object} optsTwo.res
|
|
751
|
-
* @param {object} optsTwo.req
|
|
752
|
-
* @param {string} optsTwo.redirect
|
|
753
|
-
* @returns {Promise<void>}
|
|
703
|
+
* @param table_id
|
|
704
|
+
* @param viewname
|
|
705
|
+
* @param param2
|
|
706
|
+
* @param state
|
|
707
|
+
* @param body
|
|
708
|
+
* @param param5
|
|
709
|
+
* @param param6
|
|
710
|
+
* @param remote
|
|
711
|
+
* @returns
|
|
754
712
|
*/
|
|
755
713
|
const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_done, formula_destinations, auto_save, destination_type, dest_url_formula, page_when_done, page_group_when_done, }, state, body, { res, req, redirect }, { tryInsertQuery, tryUpdateQuery, getRowQuery, saveFileQuery, saveFileFromContentsQuery, optionsQuery, getRowByIdQuery, }, remote) => {
|
|
756
714
|
const safeBody = prepSafeBody(body, columns);
|
|
757
|
-
const table =
|
|
715
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
758
716
|
const fields = table.getFields();
|
|
759
|
-
if (safeBody?.password && table_id ===
|
|
760
|
-
safeBody.password = await
|
|
717
|
+
if (safeBody?.password && table_id === user_1.default.table.id) {
|
|
718
|
+
safeBody.password = await user_1.default.hashPassword(safeBody.password);
|
|
761
719
|
}
|
|
762
720
|
const prepResult = await prepare(viewname, table, fields, {
|
|
763
721
|
columns,
|
|
@@ -771,7 +729,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
771
729
|
optionsQuery,
|
|
772
730
|
getRowByIdQuery,
|
|
773
731
|
}, remote);
|
|
774
|
-
const view =
|
|
732
|
+
const view = view_1.default.findOne({ name: viewname });
|
|
775
733
|
const pagetitle = { title: viewname, no_menu: view?.attributes?.no_menu };
|
|
776
734
|
if (prepResult) {
|
|
777
735
|
let { form, row, pk, id } = prepResult;
|
|
@@ -781,7 +739,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
781
739
|
let ins_upd_error;
|
|
782
740
|
if (!cancel) {
|
|
783
741
|
getState().log(6, `Edit POST ready to insert/update into ${table.name} Row=${JSON.stringify(row)} ID=${id} Ajax=${!!req.xhr}`);
|
|
784
|
-
const doReturn = await
|
|
742
|
+
const doReturn = await db_1.default.withTransaction(async (rollback) => {
|
|
785
743
|
if (typeof id === "undefined") {
|
|
786
744
|
const ins_res = await tryInsertQuery(row);
|
|
787
745
|
if (ins_res.success) {
|
|
@@ -796,7 +754,6 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
796
754
|
else {
|
|
797
755
|
if (table.composite_pk_names ||
|
|
798
756
|
table.getField(table.pk_name).attributes.NonSerial) {
|
|
799
|
-
//console.log("edit", { id });
|
|
800
757
|
const upd_res = await tryInsertOrUpdateImpl(row, id, table, req);
|
|
801
758
|
if (upd_res.error) {
|
|
802
759
|
ins_upd_error = upd_res.error;
|
|
@@ -820,7 +777,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
820
777
|
}
|
|
821
778
|
else {
|
|
822
779
|
await form.fill_fkey_options(false, optionsQuery, req.user);
|
|
823
|
-
req.flash("error", text_attr(ins_upd_error));
|
|
780
|
+
req.flash("error", (0, tags_1.text_attr)(ins_upd_error));
|
|
824
781
|
for (const file_field of fields.filter((f) => f.type === "File")) {
|
|
825
782
|
if (!form.values[file_field.name])
|
|
826
783
|
continue;
|
|
@@ -833,19 +790,19 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
833
790
|
return true;
|
|
834
791
|
}
|
|
835
792
|
for (const field of form.fields.filter((f) => f.isRepeat)) {
|
|
836
|
-
const view_select = parse_view_select(field.metadata.view, field.metadata.relation_path);
|
|
793
|
+
const view_select = (0, viewable_fields_1.parse_view_select)(field.metadata.view, field.metadata.relation_path);
|
|
837
794
|
const order_field = field.metadata.order_field;
|
|
838
|
-
const childView =
|
|
795
|
+
const childView = view_1.default.findOne({ name: view_select.viewname });
|
|
839
796
|
if (!childView)
|
|
840
797
|
throw new InvalidConfiguration(`Cannot find embedded view: ${view_select.viewname}`);
|
|
841
798
|
if (field.metadata.relation_path &&
|
|
842
799
|
view_select.type === "RelationPath") {
|
|
843
|
-
const targetTbl =
|
|
844
|
-
const relation = new Relation(field.metadata.relation_path, targetTbl.name, displayType(await childView.get_state_fields()));
|
|
800
|
+
const targetTbl = table_1.default.findOne({ id: childView.table_id });
|
|
801
|
+
const relation = new Relation(field.metadata.relation_path, targetTbl.name, (0, plugin_helper_1.displayType)(await childView.get_state_fields()));
|
|
845
802
|
if (relation.type === RelationType.CHILD_LIST)
|
|
846
|
-
updateViewSelect(view_select);
|
|
803
|
+
(0, viewable_fields_1.updateViewSelect)(view_select);
|
|
847
804
|
}
|
|
848
|
-
const childTable =
|
|
805
|
+
const childTable = table_1.default.findOne({ id: field.metadata?.table_id });
|
|
849
806
|
const submitted_row_ids = new Set((form.values[field.name] || []).map((srow) => `${srow[childTable.pk_name]}`));
|
|
850
807
|
const childFields = new Set(childTable.fields.map((f) => f.name));
|
|
851
808
|
let repeatIx = 0;
|
|
@@ -856,8 +813,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
856
813
|
if (typeof childRow[k] === "undefined" &&
|
|
857
814
|
!k.startsWith("_block_") &&
|
|
858
815
|
childFields.has(k) &&
|
|
859
|
-
(v || v === 0)
|
|
860
|
-
)
|
|
816
|
+
(v || v === 0))
|
|
861
817
|
childRow[k] = v;
|
|
862
818
|
}
|
|
863
819
|
if (order_field && !childRow[order_field])
|
|
@@ -866,7 +822,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
866
822
|
const key = `${file_field.name}_${repeatIx}`;
|
|
867
823
|
if (req.files?.[key] &&
|
|
868
824
|
(!file_field.fieldviewObj || file_field.fieldviewObj.isEdit)) {
|
|
869
|
-
const file = await
|
|
825
|
+
const file = await file_1.default.from_req_files(req.files[key], req.user ? req.user.id : undefined, (file_field.attributes &&
|
|
870
826
|
+file_field.attributes.min_role_read) ||
|
|
871
827
|
1, file_field?.attributes?.folder);
|
|
872
828
|
childRow[file_field.name] = file.field_value;
|
|
@@ -878,7 +834,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
878
834
|
if (upd_res.error) {
|
|
879
835
|
await rollback();
|
|
880
836
|
getState().log(6, `Update child row failure ${JSON.stringify(upd_res)}`);
|
|
881
|
-
req.flash("error", text_attr(upd_res.error));
|
|
837
|
+
req.flash("error", (0, tags_1.text_attr)(upd_res.error));
|
|
882
838
|
res.sendWrap(pagetitle, renderForm(form, req.csrfToken()));
|
|
883
839
|
return true;
|
|
884
840
|
}
|
|
@@ -888,7 +844,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
888
844
|
if (ins_res.error) {
|
|
889
845
|
await rollback();
|
|
890
846
|
getState().log(6, `Insert child row failure ${JSON.stringify(ins_res)}`);
|
|
891
|
-
req.flash("error", text_attr(ins_res.error));
|
|
847
|
+
req.flash("error", (0, tags_1.text_attr)(ins_res.error));
|
|
892
848
|
res.sendWrap(pagetitle, renderForm(form, req.csrfToken()));
|
|
893
849
|
return true;
|
|
894
850
|
}
|
|
@@ -921,14 +877,14 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
921
877
|
}
|
|
922
878
|
trigger_return = trigger_return || {};
|
|
923
879
|
if (trigger_return.notify && trigger_return.details)
|
|
924
|
-
req.flash("success", div({ class: "d-inline" }, trigger_return.notify, button({
|
|
880
|
+
req.flash("success", (0, tags_1.div)({ class: "d-inline" }, trigger_return.notify, (0, tags_1.button)({
|
|
925
881
|
class: "btn btn-sm btn-outline-secondary btn-xs",
|
|
926
882
|
type: "button",
|
|
927
883
|
"data-bs-toggle": "collapse",
|
|
928
884
|
"data-bs-target": "#notifyDetails",
|
|
929
885
|
"aria-expanded": "false",
|
|
930
886
|
"aria-controls": "notifyDetails",
|
|
931
|
-
}, i({ class: "fas fa-plus" })), div({ class: "collapse", id: "notifyDetails" }, pre(trigger_return.details))));
|
|
887
|
+
}, (0, tags_1.i)({ class: "fas fa-plus" })), (0, tags_1.div)({ class: "collapse", id: "notifyDetails" }, (0, tags_1.pre)(trigger_return.details))));
|
|
932
888
|
else if (trigger_return.notify)
|
|
933
889
|
req.flash("success", trigger_return.notify);
|
|
934
890
|
if (trigger_return.error)
|
|
@@ -937,13 +893,6 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
937
893
|
res.redirect(trigger_return.goto);
|
|
938
894
|
return;
|
|
939
895
|
}
|
|
940
|
-
/*if (req.xhr && !originalID && !req.smr) {
|
|
941
|
-
res.json({ id, view_when_done, ...trigger_return });
|
|
942
|
-
return;
|
|
943
|
-
} else if (req.xhr && !req.smr) {
|
|
944
|
-
res.json({ view_when_done, ...trigger_return });
|
|
945
|
-
return;
|
|
946
|
-
}*/
|
|
947
896
|
await whenDone(viewname, table_id, fields, pk, {
|
|
948
897
|
view_when_done,
|
|
949
898
|
formula_destinations,
|
|
@@ -955,20 +904,22 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
|
|
|
955
904
|
}, req, res, safeBody, row, !originalID ? { id, ...trigger_return } : trigger_return, true, originalID, table);
|
|
956
905
|
}
|
|
957
906
|
};
|
|
958
|
-
const doAuthPost = async ({ body, table_id, req }) => {
|
|
959
|
-
const table =
|
|
907
|
+
const doAuthPost = async ({ body, table_id, req, }) => {
|
|
908
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
960
909
|
const user_id = req.user ? req.user.id : null;
|
|
961
910
|
if (table.ownership_field_id && user_id) {
|
|
962
911
|
const field_name = await table.owner_fieldname();
|
|
963
|
-
if (typeof body[field_name] === "undefined") {
|
|
912
|
+
if (typeof body[field_name || ""] === "undefined") {
|
|
964
913
|
const fields = table.getFields();
|
|
965
|
-
const { uniques } = splitUniques(fields, body);
|
|
914
|
+
const { uniques } = (0, viewable_fields_1.splitUniques)(fields, body);
|
|
966
915
|
if (Object.keys(uniques).length > 0) {
|
|
967
|
-
|
|
916
|
+
const dbrow = await table.getRow(uniques, {
|
|
968
917
|
forUser: req.user,
|
|
969
918
|
forPublic: !req.user,
|
|
970
919
|
});
|
|
971
|
-
|
|
920
|
+
if (!dbrow)
|
|
921
|
+
return false;
|
|
922
|
+
return table.is_owner(req.user, dbrow);
|
|
972
923
|
}
|
|
973
924
|
}
|
|
974
925
|
else
|
|
@@ -981,7 +932,7 @@ const doAuthPost = async ({ body, table_id, req }) => {
|
|
|
981
932
|
if (table.ownership_formula) {
|
|
982
933
|
const fields = table.getFields();
|
|
983
934
|
const freeVars = freeVariables(table.ownership_formula);
|
|
984
|
-
add_free_variables_to_joinfields(freeVars, joinFields, fields);
|
|
935
|
+
(0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, fields);
|
|
985
936
|
}
|
|
986
937
|
const dbrow = await table.getJoinedRows({
|
|
987
938
|
where: {
|
|
@@ -993,21 +944,19 @@ const doAuthPost = async ({ body, table_id, req }) => {
|
|
|
993
944
|
row = { ...body, ...dbrow[0] };
|
|
994
945
|
}
|
|
995
946
|
else {
|
|
996
|
-
// need to check new row conforms to ownership fml
|
|
997
947
|
const freeVars = freeVariables(table.ownership_formula);
|
|
998
948
|
const fields = table.getFields();
|
|
999
949
|
const field_names = new Set(fields.map((f) => f.name));
|
|
1000
|
-
// loop free vars, substitute in row
|
|
1001
950
|
for (const fv of freeVars) {
|
|
1002
951
|
const kpath = fv.split(".");
|
|
1003
952
|
if (field_names.has(kpath[0]) && kpath.length > 1) {
|
|
1004
953
|
const field = fields.find((f) => f.name === kpath[0]);
|
|
1005
954
|
if (!field)
|
|
1006
955
|
throw new Error("Invalid formula:" + table.ownership_formula);
|
|
1007
|
-
const reftable =
|
|
956
|
+
const reftable = table_1.default.findOne({ name: field.reftable_name });
|
|
1008
957
|
const joinFields = {};
|
|
1009
958
|
const [kpath0, ...kpathrest] = kpath;
|
|
1010
|
-
add_free_variables_to_joinfields(new Set([kpathrest.join(".")]), joinFields, fields);
|
|
959
|
+
(0, plugin_helper_1.add_free_variables_to_joinfields)(new Set([kpathrest.join(".")]), joinFields, fields);
|
|
1011
960
|
const rows = await reftable.getJoinedRows({
|
|
1012
961
|
where: {
|
|
1013
962
|
[reftable.pk_name]: body[kpath0],
|
|
@@ -1026,17 +975,26 @@ const doAuthPost = async ({ body, table_id, req }) => {
|
|
|
1026
975
|
return false;
|
|
1027
976
|
};
|
|
1028
977
|
/**
|
|
1029
|
-
* @param
|
|
1030
|
-
* @param
|
|
1031
|
-
* @
|
|
1032
|
-
* @param {object} opts.req
|
|
1033
|
-
* @returns {Promise<boolean>}
|
|
978
|
+
* @param param0
|
|
979
|
+
* @param param1
|
|
980
|
+
* @returns
|
|
1034
981
|
*/
|
|
1035
|
-
const authorise_post = async ({ body, table_id, req }, { authorizePostQuery }) => {
|
|
982
|
+
const authorise_post = async ({ body, table_id, req, }, { authorizePostQuery }) => {
|
|
1036
983
|
return await authorizePostQuery(body, table_id);
|
|
1037
984
|
};
|
|
985
|
+
/**
|
|
986
|
+
* @param tableId
|
|
987
|
+
* @param viewName
|
|
988
|
+
* @param id
|
|
989
|
+
* @param fieldName
|
|
990
|
+
* @param fieldView
|
|
991
|
+
* @param user
|
|
992
|
+
* @param configuration
|
|
993
|
+
* @param targetOpts
|
|
994
|
+
* @returns
|
|
995
|
+
*/
|
|
1038
996
|
const openDataStream = async (tableId, viewName, id, fieldName, fieldView, user, configuration, targetOpts) => {
|
|
1039
|
-
const table =
|
|
997
|
+
const table = table_1.default.findOne({ id: tableId });
|
|
1040
998
|
const field = table.getField(fieldName);
|
|
1041
999
|
if (!field)
|
|
1042
1000
|
throw new InvalidConfiguration(`Field ${fieldName} not found`);
|
|
@@ -1048,64 +1006,55 @@ const openDataStream = async (tableId, viewName, id, fieldName, fieldView, user,
|
|
|
1048
1006
|
return await fileView.openDataStream(tableId, id, fieldName, user, cfgCol.configuration, targetOpts);
|
|
1049
1007
|
}
|
|
1050
1008
|
};
|
|
1051
|
-
|
|
1009
|
+
/**
|
|
1010
|
+
* @param view
|
|
1011
|
+
* @param id
|
|
1012
|
+
* @param fieldName
|
|
1013
|
+
* @param user
|
|
1014
|
+
* @param targetOpts
|
|
1015
|
+
* @returns
|
|
1016
|
+
*/
|
|
1052
1017
|
const authorizeDataStream = async (view, id, fieldName, user, targetOpts) => {
|
|
1053
1018
|
if (!user || user.role_id > view.min_role)
|
|
1054
1019
|
return false;
|
|
1055
1020
|
else {
|
|
1056
|
-
const table =
|
|
1021
|
+
const table = table_1.default.findOne({ id: view.table_id });
|
|
1057
1022
|
if (!table || user.role_id > table.min_role_write)
|
|
1058
1023
|
return false;
|
|
1059
1024
|
else {
|
|
1060
1025
|
const field = table.getField(fieldName);
|
|
1061
1026
|
if (field.type === "File") {
|
|
1062
1027
|
if (targetOpts?.oldTarget) {
|
|
1063
|
-
|
|
1064
|
-
const file = await File.findOne(targetOpts.oldTarget);
|
|
1028
|
+
const file = await file_1.default.findOne(targetOpts.oldTarget);
|
|
1065
1029
|
if (file)
|
|
1066
1030
|
return file.min_role_read >= user.role_id;
|
|
1067
1031
|
}
|
|
1068
1032
|
else if (id) {
|
|
1069
|
-
// continue file of existing row ?
|
|
1070
1033
|
const row = await table.getRow({ [table.pk_name]: id });
|
|
1071
1034
|
const fileCol = row[fieldName];
|
|
1072
1035
|
if (fileCol) {
|
|
1073
|
-
const file = await
|
|
1036
|
+
const file = await file_1.default.findOne(row[fieldName]);
|
|
1074
1037
|
if (file)
|
|
1075
1038
|
return file.min_role_read >= user.role_id;
|
|
1076
1039
|
}
|
|
1077
1040
|
}
|
|
1078
|
-
// stream is new or the file does not exist
|
|
1079
1041
|
return true;
|
|
1080
1042
|
}
|
|
1081
1043
|
else {
|
|
1082
|
-
// only files for now
|
|
1083
1044
|
return false;
|
|
1084
1045
|
}
|
|
1085
1046
|
}
|
|
1086
1047
|
}
|
|
1087
1048
|
};
|
|
1088
|
-
/**
|
|
1089
|
-
* @param {number} table_id
|
|
1090
|
-
* @param {*} viewname
|
|
1091
|
-
* @param {object} opts
|
|
1092
|
-
* @param {object[]} opts.columns
|
|
1093
|
-
* @param {*} opts.layout
|
|
1094
|
-
* @param {*} body
|
|
1095
|
-
* @param {object} optsTwo
|
|
1096
|
-
* @param {object} optsTwo.req
|
|
1097
|
-
* @param {*} optsTwo.res
|
|
1098
|
-
* @returns {Promise<object>}
|
|
1099
|
-
*/
|
|
1100
1049
|
const run_action = async (table_id, viewname, { columns, layout }, body, { req, res }, { actionQuery }) => {
|
|
1101
1050
|
const result = await actionQuery();
|
|
1102
1051
|
if (result.json.error) {
|
|
1103
|
-
|
|
1052
|
+
crash_1.default.create({ message: result.json.error, stack: "" }, req);
|
|
1104
1053
|
}
|
|
1105
1054
|
return result;
|
|
1106
1055
|
};
|
|
1107
1056
|
const update_matching_rows = async (table_id, viewname, { columns, layout, fixed, view_when_done, formula_destinations, auto_save, destination_type, dest_url_formula, page_when_done, page_group_when_done, }, body, { req, res, redirect }, { updateMatchingQuery, getRowQuery, saveFileQuery, saveFileFromContentsQuery, optionsQuery, getRowByIdQuery, }) => {
|
|
1108
|
-
const table =
|
|
1057
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
1109
1058
|
const fields = table.getFields();
|
|
1110
1059
|
const prepResult = await prepare(viewname, table, fields, {
|
|
1111
1060
|
columns,
|
|
@@ -1122,9 +1071,9 @@ const update_matching_rows = async (table_id, viewname, { columns, layout, fixed
|
|
|
1122
1071
|
if (prepResult) {
|
|
1123
1072
|
let { form, row, pk } = prepResult;
|
|
1124
1073
|
const state = req?.query
|
|
1125
|
-
? readState(removeEmptyStrings(req.query), fields, req)
|
|
1074
|
+
? (0, plugin_helper_1.readState)(removeEmptyStrings(req.query), fields, req)
|
|
1126
1075
|
: {};
|
|
1127
|
-
const where = stateFieldsToWhere({ fields, state, table });
|
|
1076
|
+
const where = (0, plugin_helper_1.stateFieldsToWhere)({ fields, state, table });
|
|
1128
1077
|
const repeatFields = form.fields.filter((f) => f.isRepeat);
|
|
1129
1078
|
const childRows = {};
|
|
1130
1079
|
for (const field of repeatFields)
|
|
@@ -1133,7 +1082,7 @@ const update_matching_rows = async (table_id, viewname, { columns, layout, fixed
|
|
|
1133
1082
|
const uptResults = await updateMatchingQuery(where, rest, repeatFields, childRows);
|
|
1134
1083
|
if (uptResults.error || uptResults.rowError || uptResults.inEditError) {
|
|
1135
1084
|
res.status(422);
|
|
1136
|
-
req.flash("error", text_attr(uptResults.error || uptResults.rowError || uptResults.inEditError));
|
|
1085
|
+
req.flash("error", (0, tags_1.text_attr)(uptResults.error || uptResults.rowError || uptResults.inEditError));
|
|
1137
1086
|
res.sendWrap(viewname, renderForm(form, req.csrfToken()));
|
|
1138
1087
|
return;
|
|
1139
1088
|
}
|
|
@@ -1159,38 +1108,25 @@ const update_matching_rows = async (table_id, viewname, { columns, layout, fixed
|
|
|
1159
1108
|
}, req, res, body, row);
|
|
1160
1109
|
}
|
|
1161
1110
|
};
|
|
1162
|
-
/**
|
|
1163
|
-
* preparations for the form and the data row
|
|
1164
|
-
* @param {*} viewname
|
|
1165
|
-
* @param {*} table table of the view
|
|
1166
|
-
* @param {*} fields all fields in table
|
|
1167
|
-
* @param {*} param3 columns, layout, fixed, auto_save
|
|
1168
|
-
* @param {*} param4 req, res
|
|
1169
|
-
* @param {*} body request body
|
|
1170
|
-
* @param {*} param6 getRowQuery, saveFileQuery, saveFileFromContentsQuery, optionsQuery, getRowByIdQuery
|
|
1171
|
-
* @param {*} remote
|
|
1172
|
-
* @returns null on error, { form, row, pk, id } on success
|
|
1173
|
-
*/
|
|
1174
1111
|
const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_save }, { req, res }, body, { getRowQuery, saveFileQuery, saveFileFromContentsQuery, optionsQuery, getRowByIdQuery, }, remote) => {
|
|
1175
1112
|
const isRemote = !isWeb(req);
|
|
1176
|
-
const form = await getForm(table, viewname, columns, layout, body.id, req, isRemote);
|
|
1113
|
+
const form = await (0, viewable_fields_1.getForm)(table, viewname, columns, layout, body.id, req, isRemote);
|
|
1177
1114
|
if (auto_save)
|
|
1178
1115
|
form.onChange = `saveAndContinueDelayed(this, ${!isWeb(req) ? `'${form.action}'` : undefined}, event);`;
|
|
1179
1116
|
Object.entries(body).forEach(([k, v]) => {
|
|
1180
1117
|
const form_field = form.fields.find((f) => f.name === k);
|
|
1181
1118
|
const tbl_field = fields.find((f) => f.name === k);
|
|
1182
1119
|
if (tbl_field && !form_field && !fixed?.[`_block_${k}`]) {
|
|
1183
|
-
form.fields.push(new
|
|
1120
|
+
form.fields.push(new field_1.default({ name: k, input_type: "hidden" }));
|
|
1184
1121
|
}
|
|
1185
1122
|
});
|
|
1186
|
-
setDateLocales(form, req.getLocale());
|
|
1187
|
-
await transformForm({
|
|
1123
|
+
(0, viewable_fields_1.setDateLocales)(form, req.getLocale());
|
|
1124
|
+
await (0, viewable_fields_1.transformForm)({
|
|
1188
1125
|
form,
|
|
1189
1126
|
table,
|
|
1190
1127
|
req,
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
: undefined,
|
|
1128
|
+
res,
|
|
1129
|
+
row: body[table.pk_name] ? { [table.pk_name]: body[table.pk_name] } : null,
|
|
1194
1130
|
getRowQuery,
|
|
1195
1131
|
viewname,
|
|
1196
1132
|
optionsQuery,
|
|
@@ -1204,7 +1140,7 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
|
|
|
1204
1140
|
if (req.xhr)
|
|
1205
1141
|
res.status(422);
|
|
1206
1142
|
await form.fill_fkey_options(false, optionsQuery, req.user);
|
|
1207
|
-
const view =
|
|
1143
|
+
const view = view_1.default.findOne({ name: viewname });
|
|
1208
1144
|
res.sendWrap({ title: viewname, no_menu: view?.attributes?.no_menu }, renderForm(form, req.csrfToken ? req.csrfToken() : false));
|
|
1209
1145
|
return null;
|
|
1210
1146
|
}
|
|
@@ -1223,7 +1159,7 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
|
|
|
1223
1159
|
id = pk.type.read(body[pk.name]);
|
|
1224
1160
|
}
|
|
1225
1161
|
if (typeof id === "undefined") {
|
|
1226
|
-
const use_fixed = await fill_presets(table, req, fixed);
|
|
1162
|
+
const use_fixed = await (0, viewable_fields_1.fill_presets)(table, req, fixed);
|
|
1227
1163
|
row = { ...use_fixed, ...form.values };
|
|
1228
1164
|
}
|
|
1229
1165
|
else if (cancel) {
|
|
@@ -1248,7 +1184,7 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
|
|
|
1248
1184
|
if (body[field.name]) {
|
|
1249
1185
|
if (body[field.name].startsWith("data:")) {
|
|
1250
1186
|
const path_to_serve = await saveFileQuery(body[field.name], field.id, field.fieldview, row);
|
|
1251
|
-
const storedValue =
|
|
1187
|
+
const storedValue = file_1.default.fieldValueFromRelative(path_to_serve);
|
|
1252
1188
|
row[field.name] = storedValue;
|
|
1253
1189
|
form.values[field.name] = storedValue;
|
|
1254
1190
|
}
|
|
@@ -1257,7 +1193,7 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
|
|
|
1257
1193
|
else if (field.fieldviewObj?.editContent) {
|
|
1258
1194
|
if (body[field.name]) {
|
|
1259
1195
|
const path_to_serve = await saveFileFromContentsQuery(body[`_content_${field.name}`], field.id, field.fieldview, row, body[field.name], "utf8");
|
|
1260
|
-
const storedValue =
|
|
1196
|
+
const storedValue = file_1.default.fieldValueFromRelative(path_to_serve);
|
|
1261
1197
|
row[field.name] = storedValue;
|
|
1262
1198
|
form.values[field.name] = storedValue;
|
|
1263
1199
|
}
|
|
@@ -1267,21 +1203,21 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
|
|
|
1267
1203
|
throw new Error("The mobile-app supports no local files, please use a remote table.");
|
|
1268
1204
|
}
|
|
1269
1205
|
if (isWeb(req)) {
|
|
1270
|
-
const file = await
|
|
1206
|
+
const file = await file_1.default.from_req_files(req.files[field.name], req.user ? req.user.id : undefined, (field.attributes && +field.attributes.min_role_read) || 1, field?.attributes?.folder);
|
|
1271
1207
|
row[field.name] = file.field_value;
|
|
1272
1208
|
form.values[field.name] = file.field_value;
|
|
1273
1209
|
}
|
|
1274
1210
|
else {
|
|
1275
1211
|
const file = req.files[field.name];
|
|
1276
1212
|
if (file) {
|
|
1277
|
-
const serverResp = await
|
|
1213
|
+
const serverResp = await file_1.default.upload(req.files[field.name]);
|
|
1278
1214
|
if (serverResp?.location)
|
|
1279
|
-
row[field.name] =
|
|
1215
|
+
row[field.name] = file_1.default.normalizeFieldValueInput(serverResp.location);
|
|
1280
1216
|
}
|
|
1281
1217
|
}
|
|
1282
1218
|
}
|
|
1283
1219
|
else if (typeof body[`__exisiting_file_${field.name}`] === "string") {
|
|
1284
|
-
row[field.name] =
|
|
1220
|
+
row[field.name] = file_1.default.normalizeFieldValueInput(body[`__exisiting_file_${field.name}`]);
|
|
1285
1221
|
form.values[field.name] = row[field.name];
|
|
1286
1222
|
}
|
|
1287
1223
|
else {
|
|
@@ -1290,19 +1226,6 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
|
|
|
1290
1226
|
}
|
|
1291
1227
|
return { form, row, pk, id };
|
|
1292
1228
|
};
|
|
1293
|
-
/**
|
|
1294
|
-
* take care of final redirect
|
|
1295
|
-
* @param {*} viewname
|
|
1296
|
-
* @param {*} table_id id of the table of the view
|
|
1297
|
-
* @param {*} fields all fields in table
|
|
1298
|
-
* @param {*} pk private key field
|
|
1299
|
-
* @param {*} param4 view_when_done, formula_destinations, destination_type, dest_url_formula, page_when_done, page_group_when_done, redirect
|
|
1300
|
-
* @param {*} req
|
|
1301
|
-
* @param {*} res
|
|
1302
|
-
* @param {*} body reuqest body
|
|
1303
|
-
* @param {*} row row of the form
|
|
1304
|
-
* @returns
|
|
1305
|
-
*/
|
|
1306
1229
|
const whenDone = async (viewname, table_id, fields, pk, { view_when_done, formula_destinations, destination_type, dest_url_formula, page_when_done, page_group_when_done, redirect, }, req, res, body, row0, trigger_return, check_ajax, originalID, table) => {
|
|
1307
1230
|
const res_redirect = (url) => {
|
|
1308
1231
|
if (check_ajax && req.xhr && !req.smr)
|
|
@@ -1330,7 +1253,6 @@ const whenDone = async (viewname, table_id, fields, pk, { view_when_done, formul
|
|
|
1330
1253
|
if (table &&
|
|
1331
1254
|
((originalID && destination_type === "URL formula") ||
|
|
1332
1255
|
(use_view_when_done || "").includes("."))) {
|
|
1333
|
-
// Refetch row as there can be fields not included in form
|
|
1334
1256
|
const db_row = await table.getRow({ [table.pk_name]: originalID });
|
|
1335
1257
|
row = { ...db_row, ...row0 };
|
|
1336
1258
|
}
|
|
@@ -1368,20 +1290,20 @@ const whenDone = async (viewname, table_id, fields, pk, { view_when_done, formul
|
|
|
1368
1290
|
return;
|
|
1369
1291
|
}
|
|
1370
1292
|
const [viewname_when_done, relation] = use_view_when_done.split(".");
|
|
1371
|
-
const nxview =
|
|
1293
|
+
const nxview = view_1.default.findOne({ name: viewname_when_done });
|
|
1372
1294
|
if (!nxview) {
|
|
1373
1295
|
req.flash("warning", `View "${use_view_when_done}" not found - change "View when done" in "${viewname}" view`);
|
|
1374
1296
|
res_redirect(`/`);
|
|
1375
1297
|
}
|
|
1376
1298
|
else {
|
|
1377
1299
|
const state_fields = await nxview.get_state_fields();
|
|
1378
|
-
let target = `/view/${text(viewname_when_done)}`;
|
|
1300
|
+
let target = `/view/${(0, tags_1.text)(viewname_when_done)}`;
|
|
1379
1301
|
let query = "";
|
|
1380
1302
|
if ((nxview.table_id === table_id || relation) &&
|
|
1381
1303
|
state_fields.some((sf) => sf.name === pk.name) &&
|
|
1382
1304
|
viewname_when_done !== viewname) {
|
|
1383
|
-
const get_query = get_view_link_query(fields, nxview);
|
|
1384
|
-
query = relation ? `?${pk.name}=${text(row[relation])}` : get_query(row);
|
|
1305
|
+
const get_query = (0, viewable_fields_1.get_view_link_query)(fields, nxview);
|
|
1306
|
+
query = relation ? `?${pk.name}=${(0, tags_1.text)(row[relation])}` : get_query(row);
|
|
1385
1307
|
}
|
|
1386
1308
|
const redirectPath = `${target}${query}`;
|
|
1387
1309
|
if (!isWeb(req)) {
|
|
@@ -1392,29 +1314,25 @@ const whenDone = async (viewname, table_id, fields, pk, { view_when_done, formul
|
|
|
1392
1314
|
}
|
|
1393
1315
|
}
|
|
1394
1316
|
};
|
|
1395
|
-
/**
|
|
1396
|
-
* @param {*} results results from updateMatchingQuery
|
|
1397
|
-
* @returns success, danger, goto
|
|
1398
|
-
*/
|
|
1399
1317
|
const combineResults = (results) => {
|
|
1400
1318
|
const combined = { success: [], danger: [] };
|
|
1401
1319
|
for (const uptResult of results) {
|
|
1402
1320
|
const trigger_return = uptResult.trigger_return || {};
|
|
1403
1321
|
if (trigger_return.notify && trigger_return.details)
|
|
1404
|
-
combined.success.push(div({ class: "d-inline" }, trigger_return.notify, button({
|
|
1322
|
+
combined.success.push((0, tags_1.div)({ class: "d-inline" }, trigger_return.notify, (0, tags_1.button)({
|
|
1405
1323
|
class: "btn btn-sm btn-outline-secondary btn-xs",
|
|
1406
1324
|
type: "button",
|
|
1407
1325
|
"data-bs-toggle": "collapse",
|
|
1408
1326
|
"data-bs-target": "#notifyDetails",
|
|
1409
1327
|
"aria-expanded": "false",
|
|
1410
1328
|
"aria-controls": "notifyDetails",
|
|
1411
|
-
}, i({ class: "fas fa-plus" })), div({ class: "collapse", id: "notifyDetails" }, pre(trigger_return.details))));
|
|
1329
|
+
}, (0, tags_1.i)({ class: "fas fa-plus" })), (0, tags_1.div)({ class: "collapse", id: "notifyDetails" }, (0, tags_1.pre)(trigger_return.details))));
|
|
1412
1330
|
else if (trigger_return.notify)
|
|
1413
1331
|
combined.success.push(trigger_return.notify);
|
|
1414
1332
|
if (trigger_return.error)
|
|
1415
1333
|
combined.danger.push(trigger_return.error);
|
|
1416
1334
|
if (trigger_return.goto && !combined.goto)
|
|
1417
|
-
combined.trigger_return.goto;
|
|
1335
|
+
combined.goto = trigger_return.goto;
|
|
1418
1336
|
}
|
|
1419
1337
|
return combined;
|
|
1420
1338
|
};
|
|
@@ -1439,9 +1357,13 @@ const tryInsertOrUpdateImpl = async (row, id, table, req) => {
|
|
|
1439
1357
|
return ins_res;
|
|
1440
1358
|
}
|
|
1441
1359
|
};
|
|
1360
|
+
/**
|
|
1361
|
+
* @param param0
|
|
1362
|
+
* @returns
|
|
1363
|
+
*/
|
|
1442
1364
|
const createBasicView = async ({ table, viewname, template_view, template_table, all_views_created, }) => {
|
|
1443
1365
|
if (!template_view) {
|
|
1444
|
-
const configuration = await initial_config_all_fields(true)({
|
|
1366
|
+
const configuration = await (0, plugin_helper_1.initial_config_all_fields)(true)({
|
|
1445
1367
|
table_id: table.id,
|
|
1446
1368
|
});
|
|
1447
1369
|
if (all_views_created.List) {
|
|
@@ -1456,9 +1378,11 @@ const createBasicView = async ({ table, viewname, template_view, template_table,
|
|
|
1456
1378
|
templateFieldTypes[field.name] = field.type_name;
|
|
1457
1379
|
templateFieldLabels[field.name] = field.label;
|
|
1458
1380
|
}
|
|
1459
|
-
const defaultBranch =
|
|
1460
|
-
|
|
1461
|
-
|
|
1381
|
+
const defaultBranch = inner
|
|
1382
|
+
? findLayoutBranchWith(inner.above || inner.contents.above, (s) => {
|
|
1383
|
+
return s.type === "field";
|
|
1384
|
+
})
|
|
1385
|
+
: null;
|
|
1462
1386
|
const inners = [], columns = [];
|
|
1463
1387
|
for (const field of table.fields) {
|
|
1464
1388
|
if (field.primary_key)
|
|
@@ -1468,11 +1392,12 @@ const createBasicView = async ({ table, viewname, template_view, template_table,
|
|
|
1468
1392
|
templateFieldTypes[s.field_name] === field.type_name);
|
|
1469
1393
|
}) || defaultBranch;
|
|
1470
1394
|
let oldField;
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1395
|
+
if (branch)
|
|
1396
|
+
traverseSync(branch, {
|
|
1397
|
+
field(s) {
|
|
1398
|
+
oldField = template_table.getField(s.field_name);
|
|
1399
|
+
},
|
|
1400
|
+
});
|
|
1476
1401
|
const newBranch = structuredClone(branch);
|
|
1477
1402
|
let newCol = {};
|
|
1478
1403
|
traverseSync(newBranch, {
|
|
@@ -1497,7 +1422,7 @@ const createBasicView = async ({ table, viewname, template_view, template_table,
|
|
|
1497
1422
|
//clone any actions in inner
|
|
1498
1423
|
for (const tmpl_inner of inner.above || inner.contents.above) {
|
|
1499
1424
|
let hasField = false;
|
|
1500
|
-
let hasAction =
|
|
1425
|
+
let hasAction = false;
|
|
1501
1426
|
const theActions = [];
|
|
1502
1427
|
traverseSync(tmpl_inner, {
|
|
1503
1428
|
field() {
|
|
@@ -1528,22 +1453,27 @@ const createBasicView = async ({ table, viewname, template_view, template_table,
|
|
|
1528
1453
|
cfg.split_paste = template_view.configuration.split_paste;
|
|
1529
1454
|
return cfg;
|
|
1530
1455
|
};
|
|
1456
|
+
/**
|
|
1457
|
+
* @param table_id
|
|
1458
|
+
* @param viewname
|
|
1459
|
+
* @param param2
|
|
1460
|
+
* @returns
|
|
1461
|
+
*/
|
|
1531
1462
|
const virtual_triggers = (table_id, viewname, { enable_realtime, update_events }) => {
|
|
1532
1463
|
if (!enable_realtime)
|
|
1533
1464
|
return [];
|
|
1534
|
-
const table =
|
|
1535
|
-
const view =
|
|
1465
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
1466
|
+
const view = view_1.default.findOne({ name: viewname });
|
|
1536
1467
|
return [
|
|
1537
1468
|
{
|
|
1538
1469
|
when_trigger: "Update",
|
|
1539
1470
|
table_id: table_id,
|
|
1540
1471
|
run: async (row, { old_row, user }) => {
|
|
1541
1472
|
getState().log(6, `Virtual trigger Update for ${viewname} on table ${table.name}`);
|
|
1542
|
-
// find changed columns within the layout
|
|
1543
1473
|
const fields = table.getFields();
|
|
1544
1474
|
const changedFields = fields.filter((f) => {
|
|
1545
1475
|
if (f.name === table.pk_name)
|
|
1546
|
-
return false;
|
|
1476
|
+
return false;
|
|
1547
1477
|
const a = row[f.name];
|
|
1548
1478
|
const b = old_row[f.name];
|
|
1549
1479
|
if (f.type?.equals)
|
|
@@ -1563,14 +1493,13 @@ const virtual_triggers = (table_id, viewname, { enable_realtime, update_events }
|
|
|
1563
1493
|
getState().log(6, "No layout fields changed, skipping real-time update");
|
|
1564
1494
|
}
|
|
1565
1495
|
else {
|
|
1566
|
-
// build and emit updates
|
|
1567
1496
|
const updates = {};
|
|
1568
1497
|
for (const fieldName of changedLayoutFields) {
|
|
1569
1498
|
const newVal = row[fieldName];
|
|
1570
1499
|
updates[fieldName] = newVal;
|
|
1571
1500
|
}
|
|
1572
1501
|
const rowId = row[table.pk_name];
|
|
1573
|
-
const actionResults = await runCollabEvents(update_events, user, {
|
|
1502
|
+
const actionResults = await (0, plugin_helper_1.runCollabEvents)(update_events, user, {
|
|
1574
1503
|
new_row: row,
|
|
1575
1504
|
old_row: old_row,
|
|
1576
1505
|
updates: updates,
|
|
@@ -1602,34 +1531,35 @@ module.exports = {
|
|
|
1602
1531
|
authorise_post,
|
|
1603
1532
|
virtual_triggers,
|
|
1604
1533
|
/**
|
|
1605
|
-
* @param
|
|
1606
|
-
* @param
|
|
1607
|
-
* @
|
|
1608
|
-
* @returns {Promise<boolean>}
|
|
1534
|
+
* @param param0
|
|
1535
|
+
* @param param1
|
|
1536
|
+
* @returns
|
|
1609
1537
|
*/
|
|
1610
|
-
authorise_get: async ({ query, table_id, req }, { authorizeGetQuery }) => {
|
|
1538
|
+
authorise_get: async ({ query, table_id, req, }, { authorizeGetQuery }) => {
|
|
1611
1539
|
return await authorizeGetQuery(query, table_id);
|
|
1612
1540
|
},
|
|
1613
1541
|
/**
|
|
1614
|
-
* @param
|
|
1615
|
-
* @
|
|
1616
|
-
* @returns {string[]}
|
|
1542
|
+
* @param param0
|
|
1543
|
+
* @returns
|
|
1617
1544
|
*/
|
|
1618
1545
|
getStringsForI18n({ layout }) {
|
|
1619
1546
|
return getStringsForI18n(layout);
|
|
1620
1547
|
},
|
|
1548
|
+
/**
|
|
1549
|
+
* @param param0
|
|
1550
|
+
* @returns
|
|
1551
|
+
*/
|
|
1621
1552
|
queries: ({ table_id, name, configuration: { columns, default_state, layout, auto_save, split_paste, destination_type, fixed, confirm_leave, auto_create, delete_unchanged_auto_create, enable_realtime, update_events, }, req, res, }) => ({
|
|
1622
1553
|
async editQuery(state, mobileReferrer, isPreview, hiddenLoginDest) {
|
|
1623
|
-
const table =
|
|
1554
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
1624
1555
|
const fields = table.getFields();
|
|
1625
|
-
const { uniques } = splitUniques(fields, state);
|
|
1556
|
+
const { uniques } = (0, viewable_fields_1.splitUniques)(fields, state);
|
|
1626
1557
|
let row = null;
|
|
1627
1558
|
let auto_created_row = false;
|
|
1628
1559
|
const unique_constraints = table.constraints.filter((tc) => tc.type === "Unique");
|
|
1629
1560
|
const getRow = async (where) => {
|
|
1630
|
-
// add joinfields from certain locations if they are not fields in columns
|
|
1631
1561
|
const joinFields = {};
|
|
1632
|
-
const picked = picked_fields_to_query([], fields, layout, req, table);
|
|
1562
|
+
const picked = (0, plugin_helper_1.picked_fields_to_query)([], fields, layout, req, table);
|
|
1633
1563
|
const colFields = new Set(columns.map((c) => c.join_field ? c.join_field.split(".")[0] : c.field_name));
|
|
1634
1564
|
Object.entries(picked.joinFields).forEach(([nm, jfv]) => {
|
|
1635
1565
|
if (!colFields.has(jfv.ref))
|
|
@@ -1673,7 +1603,7 @@ module.exports = {
|
|
|
1673
1603
|
else if (f.type.sql_name === "text")
|
|
1674
1604
|
row[f.name] = "";
|
|
1675
1605
|
});
|
|
1676
|
-
const use_fixed = await fill_presets(table, req, fixed);
|
|
1606
|
+
const use_fixed = await (0, viewable_fields_1.fill_presets)(table, req, fixed);
|
|
1677
1607
|
row = { ...row, ...use_fixed };
|
|
1678
1608
|
row.id = await table.insertRow(row, req.user);
|
|
1679
1609
|
auto_created_row = true;
|
|
@@ -1704,16 +1634,16 @@ module.exports = {
|
|
|
1704
1634
|
});
|
|
1705
1635
|
},
|
|
1706
1636
|
async editManyQuery(state, { limit, offset, orderBy, orderDesc, where }) {
|
|
1707
|
-
const table =
|
|
1637
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
1708
1638
|
const fields = table.getFields();
|
|
1709
|
-
const { joinFields, aggregations } = picked_fields_to_query(columns, fields, undefined, req, table);
|
|
1710
|
-
const qstate = stateFieldsToWhere({
|
|
1639
|
+
const { joinFields, aggregations } = (0, plugin_helper_1.picked_fields_to_query)(columns, fields, undefined, req, table);
|
|
1640
|
+
const qstate = (0, plugin_helper_1.stateFieldsToWhere)({
|
|
1711
1641
|
fields,
|
|
1712
1642
|
state,
|
|
1713
1643
|
table,
|
|
1714
1644
|
prefix: "a.",
|
|
1715
1645
|
});
|
|
1716
|
-
const q = stateFieldsToQuery({ state, fields });
|
|
1646
|
+
const q = (0, plugin_helper_1.stateFieldsToQuery)({ state, fields });
|
|
1717
1647
|
if (where)
|
|
1718
1648
|
mergeIntoWhere(qstate, where);
|
|
1719
1649
|
const rows = await table.getJoinedRows({
|
|
@@ -1735,18 +1665,18 @@ module.exports = {
|
|
|
1735
1665
|
};
|
|
1736
1666
|
},
|
|
1737
1667
|
async tryInsertQuery(row) {
|
|
1738
|
-
const table =
|
|
1668
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
1739
1669
|
const result = {};
|
|
1740
1670
|
const ins_res = await table.tryInsertRow(row, req.user || { role_id: 100 }, result);
|
|
1741
1671
|
ins_res.trigger_return = result;
|
|
1742
1672
|
return ins_res;
|
|
1743
1673
|
},
|
|
1744
1674
|
async tryUpdateQuery(row, id) {
|
|
1745
|
-
const table =
|
|
1675
|
+
const table = table_1.default.findOne(table_id);
|
|
1746
1676
|
return await tryUpdateImpl(row, id, table, req);
|
|
1747
1677
|
},
|
|
1748
1678
|
async saveFileQuery(fieldVal, fieldId, fieldView, row) {
|
|
1749
|
-
const field = await
|
|
1679
|
+
const field = await field_1.default.findOne({ id: fieldId });
|
|
1750
1680
|
const column = columns.find((c) => c.type === "Field" && c.field_name === field.name);
|
|
1751
1681
|
field.fieldviewObj = getState().fileviews[fieldView];
|
|
1752
1682
|
const [pre, allData] = fieldVal.split(",");
|
|
@@ -1761,11 +1691,11 @@ module.exports = {
|
|
|
1761
1691
|
...field.attributes,
|
|
1762
1692
|
...(column?.configuration || {}),
|
|
1763
1693
|
});
|
|
1764
|
-
const file = await
|
|
1765
|
-
return
|
|
1694
|
+
const file = await file_1.default.from_contents(filename, mimetype, buffer, req.user?.id, field.attributes.min_role_read || 1, folder);
|
|
1695
|
+
return file_1.default.fieldValueFromRelative(file.path_to_serve);
|
|
1766
1696
|
},
|
|
1767
1697
|
async saveFileFromContentsQuery(fieldVal, fieldId, fieldView, row, filename, encoding = "base64") {
|
|
1768
|
-
const field = await
|
|
1698
|
+
const field = await field_1.default.findOne({ id: fieldId });
|
|
1769
1699
|
const column = columns.find((c) => c.type === "Field" && c.field_name === field.name);
|
|
1770
1700
|
field.fieldviewObj = getState().fileviews[fieldView];
|
|
1771
1701
|
let mimetype, allData;
|
|
@@ -1777,38 +1707,38 @@ module.exports = {
|
|
|
1777
1707
|
else {
|
|
1778
1708
|
allData = fieldVal;
|
|
1779
1709
|
mimetype =
|
|
1780
|
-
(filename &&
|
|
1710
|
+
(filename && file_1.default.nameToMimeType(filename)) ||
|
|
1781
1711
|
"application/octet-stream";
|
|
1782
1712
|
}
|
|
1783
1713
|
const buffer = require("buffer/").Buffer.from(allData, encoding);
|
|
1784
1714
|
const filename1 = filename || "file";
|
|
1785
|
-
const existing_file = await
|
|
1715
|
+
const existing_file = await file_1.default.findOne(filename1);
|
|
1786
1716
|
if (existing_file) {
|
|
1787
1717
|
if (existing_file.min_role_read >= (req.user?.role_id || 100)) {
|
|
1788
1718
|
await existing_file.overwrite_contents(buffer);
|
|
1789
|
-
return
|
|
1719
|
+
return file_1.default.fieldValueFromRelative(existing_file.path_to_serve);
|
|
1790
1720
|
}
|
|
1791
1721
|
else
|
|
1792
1722
|
throw new Error("Not authorized to write file");
|
|
1793
1723
|
}
|
|
1794
|
-
const file = await
|
|
1795
|
-
return
|
|
1724
|
+
const file = await file_1.default.from_contents(filename1, mimetype, buffer, req.user?.id, field.attributes.min_role_read || 1);
|
|
1725
|
+
return file_1.default.fieldValueFromRelative(file.path_to_serve);
|
|
1796
1726
|
},
|
|
1797
|
-
async authorizePostQuery(body, table_id
|
|
1727
|
+
async authorizePostQuery(body, table_id) {
|
|
1798
1728
|
return await doAuthPost({ body, table_id, req });
|
|
1799
1729
|
},
|
|
1800
1730
|
async authorizeGetQuery(query, table_id) {
|
|
1801
1731
|
let body = query || {};
|
|
1802
|
-
const table =
|
|
1732
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
1803
1733
|
if (Object.keys(body).length == 1) {
|
|
1804
1734
|
if (table.ownership_field_id || table.ownership_formula) {
|
|
1805
1735
|
const fields = table.getFields();
|
|
1806
|
-
const { uniques } = splitUniques(fields, body);
|
|
1736
|
+
const { uniques } = (0, viewable_fields_1.splitUniques)(fields, body);
|
|
1807
1737
|
if (Object.keys(uniques).length > 0) {
|
|
1808
1738
|
const joinFields = {};
|
|
1809
1739
|
if (table.ownership_formula) {
|
|
1810
1740
|
const freeVars = freeVariables(table.ownership_formula);
|
|
1811
|
-
add_free_variables_to_joinfields(freeVars, joinFields, fields);
|
|
1741
|
+
(0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, fields);
|
|
1812
1742
|
}
|
|
1813
1743
|
const row = await table.getJoinedRows({
|
|
1814
1744
|
where: uniques,
|
|
@@ -1817,7 +1747,7 @@ module.exports = {
|
|
|
1817
1747
|
if (row.length > 0)
|
|
1818
1748
|
return table.is_owner(req.user, row[0]);
|
|
1819
1749
|
else
|
|
1820
|
-
return true;
|
|
1750
|
+
return true;
|
|
1821
1751
|
}
|
|
1822
1752
|
else {
|
|
1823
1753
|
return true;
|
|
@@ -1830,7 +1760,7 @@ module.exports = {
|
|
|
1830
1760
|
return doAuthPost({ body, table_id, req });
|
|
1831
1761
|
},
|
|
1832
1762
|
async getRowQuery(table_id, view_select, row_id, order_field) {
|
|
1833
|
-
const childTable =
|
|
1763
|
+
const childTable = table_1.default.findOne({ id: table_id });
|
|
1834
1764
|
return await childTable.getRows({
|
|
1835
1765
|
[view_select.field_name]: row_id,
|
|
1836
1766
|
}, {
|
|
@@ -1840,7 +1770,7 @@ module.exports = {
|
|
|
1840
1770
|
});
|
|
1841
1771
|
},
|
|
1842
1772
|
async getRowByIdQuery(id) {
|
|
1843
|
-
const table =
|
|
1773
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
1844
1774
|
return await table.getRow(typeof id === "object" ? id : { id }, {
|
|
1845
1775
|
forUser: req.user,
|
|
1846
1776
|
forPublic: !req.user,
|
|
@@ -1848,7 +1778,7 @@ module.exports = {
|
|
|
1848
1778
|
},
|
|
1849
1779
|
async actionQuery() {
|
|
1850
1780
|
const { rndid, _csrf, onchange_action, onchange_field, click_action, ...body } = req.body || {};
|
|
1851
|
-
const table =
|
|
1781
|
+
const table = table_1.default.findOne({ id: table_id });
|
|
1852
1782
|
const pk_name = table.pk_name;
|
|
1853
1783
|
let row = body[pk_name]
|
|
1854
1784
|
? (await table.getRow({ [pk_name]: body[pk_name] }, {
|
|
@@ -1864,14 +1794,14 @@ module.exports = {
|
|
|
1864
1794
|
row[f.name] = valres.success;
|
|
1865
1795
|
});
|
|
1866
1796
|
if (fixed) {
|
|
1867
|
-
const use_fixed = await fill_presets(table, req, fixed);
|
|
1797
|
+
const use_fixed = await (0, viewable_fields_1.fill_presets)(table, req, fixed);
|
|
1868
1798
|
Object.keys(use_fixed).forEach((k) => {
|
|
1869
1799
|
if (row[k] === null || typeof row[k] === "undefined")
|
|
1870
1800
|
row[k] = use_fixed[k];
|
|
1871
1801
|
});
|
|
1872
1802
|
}
|
|
1873
1803
|
try {
|
|
1874
|
-
return await
|
|
1804
|
+
return await db_1.default.withTransaction(async () => {
|
|
1875
1805
|
if (click_action) {
|
|
1876
1806
|
let container;
|
|
1877
1807
|
traverseSync(layout, {
|
|
@@ -1882,12 +1812,12 @@ module.exports = {
|
|
|
1882
1812
|
});
|
|
1883
1813
|
if (!container)
|
|
1884
1814
|
return { json: { error: "Action not found" } };
|
|
1885
|
-
const trigger =
|
|
1815
|
+
const trigger = trigger_1.default.findOne({ name: click_action });
|
|
1886
1816
|
if (!trigger)
|
|
1887
1817
|
throw new Error(`View ${name}: Container click action ${click_action} not found`);
|
|
1888
1818
|
const result = await trigger.runWithoutRow({
|
|
1889
1819
|
table,
|
|
1890
|
-
Table,
|
|
1820
|
+
Table: table_1.default,
|
|
1891
1821
|
req,
|
|
1892
1822
|
row,
|
|
1893
1823
|
referrer: req?.get?.("Referrer"),
|
|
@@ -1900,12 +1830,12 @@ module.exports = {
|
|
|
1900
1830
|
c.onchange_action === onchange_action);
|
|
1901
1831
|
if (!fldCol)
|
|
1902
1832
|
return { json: { error: "Field not found" } };
|
|
1903
|
-
const trigger =
|
|
1833
|
+
const trigger = trigger_1.default.findOne({ name: onchange_action });
|
|
1904
1834
|
if (!trigger)
|
|
1905
1835
|
throw new Error(`View ${name}: On change action ${onchange_action} for field ${onchange_field} not found`);
|
|
1906
1836
|
const result = await trigger.runWithoutRow({
|
|
1907
1837
|
table,
|
|
1908
|
-
Table,
|
|
1838
|
+
Table: table_1.default,
|
|
1909
1839
|
req,
|
|
1910
1840
|
row,
|
|
1911
1841
|
referrer: req?.get?.("Referrer"),
|
|
@@ -1915,7 +1845,7 @@ module.exports = {
|
|
|
1915
1845
|
}
|
|
1916
1846
|
else {
|
|
1917
1847
|
const col = columns.find((c) => c.type === "Action" && c.rndid === rndid && rndid);
|
|
1918
|
-
const result = await run_action_column({
|
|
1848
|
+
const result = await (0, plugin_helper_1.run_action_column)({
|
|
1919
1849
|
col,
|
|
1920
1850
|
req,
|
|
1921
1851
|
table,
|
|
@@ -1925,7 +1855,6 @@ module.exports = {
|
|
|
1925
1855
|
columns,
|
|
1926
1856
|
viewname: name,
|
|
1927
1857
|
});
|
|
1928
|
-
//console.log("result", result);
|
|
1929
1858
|
return { json: { success: "ok", ...(result || {}) } };
|
|
1930
1859
|
}
|
|
1931
1860
|
});
|
|
@@ -1936,7 +1865,7 @@ module.exports = {
|
|
|
1936
1865
|
}
|
|
1937
1866
|
},
|
|
1938
1867
|
async optionsQuery(reftable_name, type, attributes, where) {
|
|
1939
|
-
const refTable =
|
|
1868
|
+
const refTable = table_1.default.findOne({ name: reftable_name });
|
|
1940
1869
|
const rows = await refTable.getRows(where, {
|
|
1941
1870
|
forUser: req.user,
|
|
1942
1871
|
forPublic: !req.user,
|
|
@@ -1944,7 +1873,7 @@ module.exports = {
|
|
|
1944
1873
|
return rows;
|
|
1945
1874
|
},
|
|
1946
1875
|
async updateMatchingQuery(where, updateVals, repeatFields, childRows) {
|
|
1947
|
-
const table =
|
|
1876
|
+
const table = table_1.default.findOne(table_id);
|
|
1948
1877
|
const rows = await table.getRows(where, {
|
|
1949
1878
|
forUser: req.user,
|
|
1950
1879
|
forPublic: !req.user,
|
|
@@ -1954,18 +1883,18 @@ module.exports = {
|
|
|
1954
1883
|
try {
|
|
1955
1884
|
if (rows.length === 0)
|
|
1956
1885
|
return results;
|
|
1957
|
-
await
|
|
1886
|
+
await db_1.default.begin();
|
|
1958
1887
|
inTransaction = true;
|
|
1959
1888
|
for (const row of rows) {
|
|
1960
1889
|
const uptRes = await tryUpdateImpl(updateVals, row.id, table, req);
|
|
1961
1890
|
if (uptRes.error) {
|
|
1962
1891
|
inTransaction = false;
|
|
1963
|
-
await
|
|
1892
|
+
await db_1.default.rollback();
|
|
1964
1893
|
return { rowError: uptRes.error };
|
|
1965
1894
|
}
|
|
1966
1895
|
results.push(uptRes);
|
|
1967
1896
|
for (const field of repeatFields) {
|
|
1968
|
-
const childTable =
|
|
1897
|
+
const childTable = table_1.default.findOne({ id: field.metadata?.table_id });
|
|
1969
1898
|
await childTable.deleteRows({ [field.metadata?.relation]: row.id }, req.user || { role_id: 100 });
|
|
1970
1899
|
for (const childRow of childRows[field.name]) {
|
|
1971
1900
|
childRow[field.metadata?.relation] = row.id;
|
|
@@ -1974,31 +1903,37 @@ module.exports = {
|
|
|
1974
1903
|
const insRes = await childTable.tryInsertRow(insRow, req.user || { role_id: 100 });
|
|
1975
1904
|
if (insRes.error) {
|
|
1976
1905
|
inTransaction = false;
|
|
1977
|
-
await
|
|
1906
|
+
await db_1.default.rollback();
|
|
1978
1907
|
return { inEditError: insRes.error };
|
|
1979
1908
|
}
|
|
1980
1909
|
}
|
|
1981
1910
|
}
|
|
1982
1911
|
}
|
|
1983
1912
|
if (inTransaction)
|
|
1984
|
-
await
|
|
1913
|
+
await db_1.default.commit();
|
|
1985
1914
|
}
|
|
1986
1915
|
catch (error) {
|
|
1987
1916
|
if (inTransaction)
|
|
1988
|
-
await
|
|
1917
|
+
await db_1.default.rollback();
|
|
1989
1918
|
return { error: error.message };
|
|
1990
1919
|
}
|
|
1991
1920
|
return results;
|
|
1992
1921
|
},
|
|
1993
1922
|
}),
|
|
1994
1923
|
routes: { run_action, update_matching_rows },
|
|
1924
|
+
/**
|
|
1925
|
+
* @param table_id
|
|
1926
|
+
* @param title
|
|
1927
|
+
* @param state
|
|
1928
|
+
* @returns
|
|
1929
|
+
*/
|
|
1995
1930
|
async interpolate_title_string(table_id, title, state) {
|
|
1996
|
-
const tbl =
|
|
1931
|
+
const tbl = table_1.default.findOne(table_id);
|
|
1997
1932
|
if (state?.[tbl.pk_name]) {
|
|
1998
1933
|
const freeVars = freeVariablesInInterpolation(title);
|
|
1999
1934
|
const joinFields = {};
|
|
2000
1935
|
const aggregations = {};
|
|
2001
|
-
add_free_variables_to_joinfields(freeVars, joinFields, tbl.fields);
|
|
1936
|
+
(0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, tbl.fields);
|
|
2002
1937
|
add_free_variables_to_aggregations(freeVars, aggregations, tbl);
|
|
2003
1938
|
const row = await tbl.getJoinedRow({
|
|
2004
1939
|
where: { [tbl.pk_name]: state[tbl.pk_name] },
|
|
@@ -2011,19 +1946,23 @@ module.exports = {
|
|
|
2011
1946
|
return interpolate(title, null, null, "Edit view title string");
|
|
2012
1947
|
}
|
|
2013
1948
|
},
|
|
1949
|
+
/**
|
|
1950
|
+
* @param view
|
|
1951
|
+
* @returns
|
|
1952
|
+
*/
|
|
2014
1953
|
configCheck: async (view) => {
|
|
2015
1954
|
const { name, configuration: { view_when_done, destination_type, dest_url_formula, formula_destinations, page_when_done, page_group_when_done, }, } = view;
|
|
2016
1955
|
const errs = [];
|
|
2017
1956
|
const warnings = [];
|
|
2018
1957
|
if (!destination_type || destination_type === "View") {
|
|
2019
|
-
const vwd =
|
|
1958
|
+
const vwd = view_1.default.findOne({
|
|
2020
1959
|
name: (view_when_done || "").split(".")[0],
|
|
2021
1960
|
});
|
|
2022
1961
|
if (!vwd)
|
|
2023
1962
|
warnings.push(`In View ${name}, view when done ${view_when_done} not found`);
|
|
2024
1963
|
}
|
|
2025
1964
|
if (destination_type === "Page") {
|
|
2026
|
-
const page =
|
|
1965
|
+
const page = page_1.default.findOne({ name: page_when_done });
|
|
2027
1966
|
if (!page)
|
|
2028
1967
|
errs.push(`In View ${name}, page when done ${page_when_done} not found`);
|
|
2029
1968
|
}
|
|
@@ -2041,13 +1980,17 @@ module.exports = {
|
|
|
2041
1980
|
if (destination_type === "URL Formula") {
|
|
2042
1981
|
expressionChecker(dest_url_formula, `In View ${name}, URL formula ${dest_url_formula} error: `, errs);
|
|
2043
1982
|
}
|
|
2044
|
-
const colcheck = await check_view_columns(view, view.configuration.columns);
|
|
1983
|
+
const colcheck = await (0, plugin_testing_1.check_view_columns)(view, view.configuration.columns);
|
|
2045
1984
|
errs.push(...colcheck.errors);
|
|
2046
1985
|
warnings.push(...colcheck.warnings);
|
|
2047
1986
|
return { errors: errs, warnings };
|
|
2048
1987
|
},
|
|
1988
|
+
/**
|
|
1989
|
+
* @param configuration
|
|
1990
|
+
* @returns
|
|
1991
|
+
*/
|
|
2049
1992
|
connectedObjects: async (configuration) => {
|
|
2050
|
-
return extractFromLayout(configuration.layout);
|
|
1993
|
+
return (0, node_extract_utils_1.extractFromLayout)(configuration.layout);
|
|
2051
1994
|
},
|
|
2052
1995
|
};
|
|
2053
1996
|
//# sourceMappingURL=edit.js.map
|