@saltcorn/server 0.7.2-beta.0 → 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/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 { ul, li, h3, div, small } = require("@saltcorn/markup/tags");
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
- const menu = [
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
- var links = [];
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