@saltcorn/server 0.7.1-beta.3 → 0.7.2-beta.10
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 +64 -9
- package/auth/routes.js +37 -13
- package/load_plugins.js +39 -27
- package/locales/da.json +1 -1
- package/locales/de.json +155 -155
- package/locales/en.json +29 -4
- package/locales/it.json +3 -2
- package/locales/ru.json +73 -28
- package/locales/zh.json +3 -3
- package/markup/admin.js +25 -9
- package/package.json +14 -9
- package/public/jquery-menu-editor.min.js +5 -0
- package/public/saltcorn-common.js +544 -0
- package/public/saltcorn.css +70 -0
- package/public/saltcorn.js +40 -456
- package/restart_watcher.js +1 -1
- package/routes/admin.js +159 -38
- package/routes/api.js +36 -1
- package/routes/edit.js +2 -1
- package/routes/eventlog.js +30 -30
- package/routes/fields.js +18 -0
- package/routes/files.js +57 -19
- package/routes/homepage.js +35 -7
- package/routes/menu.js +11 -7
- package/routes/plugins.js +4 -4
- package/routes/tables.js +1 -1
- package/routes/tenant.js +13 -10
- package/routes/viewedit.js +55 -1
- package/serve.js +15 -1
- package/tests/admin.test.js +72 -1
- package/tests/clientjs.test.js +1 -0
- package/tests/plugins.test.js +2 -2
- package/tests/view.test.js +1 -1
- package/tests/viewedit.test.js +94 -0
- package/wrapper.js +56 -12
package/tests/viewedit.test.js
CHANGED
|
@@ -8,6 +8,7 @@ const {
|
|
|
8
8
|
toInclude,
|
|
9
9
|
toNotInclude,
|
|
10
10
|
resetToFixtures,
|
|
11
|
+
succeedJsonWith,
|
|
11
12
|
} = require("../auth/testhelp");
|
|
12
13
|
const db = require("@saltcorn/data/db");
|
|
13
14
|
const View = require("@saltcorn/data/models/view");
|
|
@@ -371,3 +372,96 @@ describe("viewedit new Show", () => {
|
|
|
371
372
|
.expect(toRedirect("/viewedit"));
|
|
372
373
|
});
|
|
373
374
|
});
|
|
375
|
+
describe("Library", () => {
|
|
376
|
+
it("should save new from builder", async () => {
|
|
377
|
+
const loginCookie = await getAdminLoginCookie();
|
|
378
|
+
const app = await getApp({ disableCsrf: true });
|
|
379
|
+
await request(app)
|
|
380
|
+
.post("/library/savefrombuilder/")
|
|
381
|
+
.set("Cookie", loginCookie)
|
|
382
|
+
.send({
|
|
383
|
+
layout: {
|
|
384
|
+
columns: [],
|
|
385
|
+
layout: {
|
|
386
|
+
type: "card",
|
|
387
|
+
contents: {
|
|
388
|
+
above: [
|
|
389
|
+
null,
|
|
390
|
+
{
|
|
391
|
+
besides: [
|
|
392
|
+
{
|
|
393
|
+
above: [
|
|
394
|
+
null,
|
|
395
|
+
{
|
|
396
|
+
type: "blank",
|
|
397
|
+
contents: "Hello world",
|
|
398
|
+
block: false,
|
|
399
|
+
inline: false,
|
|
400
|
+
textStyle: "",
|
|
401
|
+
isFormula: {},
|
|
402
|
+
labelFor: "",
|
|
403
|
+
style: {},
|
|
404
|
+
font: "",
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
above: [
|
|
410
|
+
null,
|
|
411
|
+
{
|
|
412
|
+
type: "blank",
|
|
413
|
+
contents: "Bye bye",
|
|
414
|
+
block: false,
|
|
415
|
+
inline: false,
|
|
416
|
+
textStyle: "",
|
|
417
|
+
isFormula: {},
|
|
418
|
+
labelFor: "",
|
|
419
|
+
style: {},
|
|
420
|
+
font: "",
|
|
421
|
+
},
|
|
422
|
+
],
|
|
423
|
+
},
|
|
424
|
+
],
|
|
425
|
+
breakpoints: ["", ""],
|
|
426
|
+
style: {},
|
|
427
|
+
widths: [6, 6],
|
|
428
|
+
},
|
|
429
|
+
],
|
|
430
|
+
},
|
|
431
|
+
title: "header",
|
|
432
|
+
style: {},
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
icon: "far fa-angry",
|
|
436
|
+
name: "ShinyCard",
|
|
437
|
+
})
|
|
438
|
+
.set("Content-Type", "application/json")
|
|
439
|
+
.set("Accept", "application/json")
|
|
440
|
+
.expect(succeedJsonWith(() => true));
|
|
441
|
+
});
|
|
442
|
+
it("shows library with item", async () => {
|
|
443
|
+
const app = await getApp({ disableCsrf: true });
|
|
444
|
+
const loginCookie = await getAdminLoginCookie();
|
|
445
|
+
await request(app)
|
|
446
|
+
.get("/library/list")
|
|
447
|
+
.set("Cookie", loginCookie)
|
|
448
|
+
.expect(toInclude("ShinyCard"));
|
|
449
|
+
});
|
|
450
|
+
it("deletes in library", async () => {
|
|
451
|
+
const app = await getApp({ disableCsrf: true });
|
|
452
|
+
const loginCookie = await getAdminLoginCookie();
|
|
453
|
+
await request(app)
|
|
454
|
+
.post("/library/delete/1")
|
|
455
|
+
.set("Cookie", loginCookie)
|
|
456
|
+
.expect(toRedirect("/library/list"));
|
|
457
|
+
});
|
|
458
|
+
it("shows empty library", async () => {
|
|
459
|
+
const app = await getApp({ disableCsrf: true });
|
|
460
|
+
const loginCookie = await getAdminLoginCookie();
|
|
461
|
+
await request(app)
|
|
462
|
+
.get("/library/list")
|
|
463
|
+
.set("Cookie", loginCookie)
|
|
464
|
+
.expect(toInclude("Library"))
|
|
465
|
+
.expect(toNotInclude("ShinyCard"))
|
|
466
|
+
});
|
|
467
|
+
});
|
package/wrapper.js
CHANGED
|
@@ -3,18 +3,28 @@
|
|
|
3
3
|
* @module wrapper
|
|
4
4
|
*/
|
|
5
5
|
const { getState } = require("@saltcorn/data/db/state");
|
|
6
|
-
const db = require("@saltcorn/data/db");
|
|
7
|
-
const {
|
|
6
|
+
//const db = require("@saltcorn/data/db");
|
|
7
|
+
const { h3, div, small } = require("@saltcorn/markup/tags");
|
|
8
8
|
const { renderForm, link } = require("@saltcorn/markup");
|
|
9
9
|
const renderLayout = require("@saltcorn/markup/layout");
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* get flashes
|
|
12
|
+
* @param req
|
|
13
|
+
* @returns {T[]}
|
|
14
|
+
*/
|
|
11
15
|
const getFlashes = (req) =>
|
|
12
|
-
["error", "success", "danger", "warning"]
|
|
16
|
+
["error", "success", "danger", "warning","information"]
|
|
13
17
|
.map((type) => {
|
|
14
18
|
return { type, msg: req.flash(type) };
|
|
15
19
|
})
|
|
16
20
|
.filter((a) => a.msg && a.msg.length && a.msg.length > 0);
|
|
17
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Get extra menu
|
|
23
|
+
* @param role
|
|
24
|
+
* @param state
|
|
25
|
+
* @param req
|
|
26
|
+
* @returns {*}
|
|
27
|
+
*/
|
|
18
28
|
const get_extra_menu = (role, state, req) => {
|
|
19
29
|
let cfg = getState().getConfig("unrolled_menu_items", []);
|
|
20
30
|
if (!cfg || cfg.length === 0) {
|
|
@@ -43,7 +53,11 @@ const get_extra_menu = (role, state, req) => {
|
|
|
43
53
|
}));
|
|
44
54
|
return transform(cfg);
|
|
45
55
|
};
|
|
46
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Get menu
|
|
58
|
+
* @param req
|
|
59
|
+
* @returns {(false|{section: *, items}|{section: *, items: [{link: string, icon: string, label: *},{link: string, icon: string, label: *},{link: string, icon: string, label: *},{icon: string, subitems: [{link: string, icon: string, label: *},{link: string, icon: string, label: *},{link: string, icon: string, altlinks: string[], label: *},{link: string, altlinks: string[], icon: string, label: *},{link: string, icon: string, label: *},null], label: *}]}|{section: *, isUser: boolean, items: ([{icon: string, subitems: [{label: *},{icon: string, link: string, label: *},{link: string, icon: string, label: *}], label: *, isUser: boolean}]|*[])})[]}
|
|
60
|
+
*/
|
|
47
61
|
const get_menu = (req) => {
|
|
48
62
|
const isAuth = req.user && req.user.id;
|
|
49
63
|
const state = getState();
|
|
@@ -82,8 +96,13 @@ const get_menu = (req) => {
|
|
|
82
96
|
? [{ link: "/auth/login", label: req.__("Login") }]
|
|
83
97
|
: []),
|
|
84
98
|
];
|
|
85
|
-
const schema = db.getTenantSchema();
|
|
99
|
+
// const schema = db.getTenantSchema();
|
|
100
|
+
// Admin role id (todo move to common constants)
|
|
86
101
|
const isAdmin = role === 1;
|
|
102
|
+
/*
|
|
103
|
+
* Admin Menu items
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
87
106
|
const adminItems = [
|
|
88
107
|
{ link: "/table", icon: "fas fa-table", label: req.__("Tables") },
|
|
89
108
|
{ link: "/viewedit", icon: "far fa-eye", label: req.__("Views") },
|
|
@@ -126,7 +145,8 @@ const get_menu = (req) => {
|
|
|
126
145
|
},
|
|
127
146
|
];
|
|
128
147
|
|
|
129
|
-
|
|
148
|
+
// return menu
|
|
149
|
+
return [
|
|
130
150
|
extra_menu.length > 0 && {
|
|
131
151
|
section: req.__("Menu"),
|
|
132
152
|
items: extra_menu,
|
|
@@ -141,9 +161,16 @@ const get_menu = (req) => {
|
|
|
141
161
|
items: authItems,
|
|
142
162
|
},
|
|
143
163
|
].filter((s) => s);
|
|
144
|
-
return menu;
|
|
145
|
-
};
|
|
146
164
|
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Get Headers
|
|
168
|
+
* @param req
|
|
169
|
+
* @param version_tag
|
|
170
|
+
* @param description
|
|
171
|
+
* @param extras
|
|
172
|
+
* @returns {*[]}
|
|
173
|
+
*/
|
|
147
174
|
const get_headers = (req, version_tag, description, extras = []) => {
|
|
148
175
|
const state = getState();
|
|
149
176
|
const favicon = state.getConfig("favicon_id", null);
|
|
@@ -167,6 +194,7 @@ const get_headers = (req, version_tag, description, extras = []) => {
|
|
|
167
194
|
headerTag: `<script>var _sc_globalCsrf = "${req.csrfToken()}"; var _sc_version_tag = "${version_tag}";</script>`,
|
|
168
195
|
},
|
|
169
196
|
{ css: `/static_assets/${version_tag}/saltcorn.css` },
|
|
197
|
+
{ script: `/static_assets/${version_tag}/saltcorn-common.js` },
|
|
170
198
|
{ script: `/static_assets/${version_tag}/saltcorn.js` },
|
|
171
199
|
];
|
|
172
200
|
let from_cfg = [];
|
|
@@ -187,6 +215,11 @@ const get_headers = (req, version_tag, description, extras = []) => {
|
|
|
187
215
|
...from_cfg,
|
|
188
216
|
];
|
|
189
217
|
};
|
|
218
|
+
/**
|
|
219
|
+
* Get brand
|
|
220
|
+
* @param state
|
|
221
|
+
* @returns {{name: *, logo: (string|undefined)}}
|
|
222
|
+
*/
|
|
190
223
|
const get_brand = (state) => {
|
|
191
224
|
const logo_id = state.getConfig("site_logo_id", "");
|
|
192
225
|
return {
|
|
@@ -195,6 +228,12 @@ const get_brand = (state) => {
|
|
|
195
228
|
};
|
|
196
229
|
};
|
|
197
230
|
module.exports = (version_tag) =>
|
|
231
|
+
/**
|
|
232
|
+
*
|
|
233
|
+
* @param req
|
|
234
|
+
* @param res
|
|
235
|
+
* @param next
|
|
236
|
+
*/
|
|
198
237
|
function (req, res, next) {
|
|
199
238
|
const role = (req.user || {}).role_id || 10;
|
|
200
239
|
|
|
@@ -219,7 +258,7 @@ module.exports = (version_tag) =>
|
|
|
219
258
|
})
|
|
220
259
|
);
|
|
221
260
|
} else {
|
|
222
|
-
|
|
261
|
+
let links = [];
|
|
223
262
|
if (authLinks.login)
|
|
224
263
|
links.push(
|
|
225
264
|
link(authLinks.login, req.__("Already have an account? Login"))
|
|
@@ -300,7 +339,12 @@ module.exports = (version_tag) =>
|
|
|
300
339
|
};
|
|
301
340
|
next();
|
|
302
341
|
};
|
|
303
|
-
|
|
342
|
+
/**
|
|
343
|
+
* Default render to HTML
|
|
344
|
+
* @param s
|
|
345
|
+
* @param role
|
|
346
|
+
* @returns {string|string|*}
|
|
347
|
+
*/
|
|
304
348
|
const defaultRenderToHtml = (s, role) =>
|
|
305
349
|
typeof s === "string"
|
|
306
350
|
? s
|