adminizer 4.0.0-commit.f68c68e → 4.0.0
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/assets/{app-B3KHqZ_H.css → app-DiNg6K-6.css} +1 -1
- package/assets/field-renderer-CvC9UdC0.js +1 -1
- package/assets/home-CmIZ3AL2.js +1 -1
- package/assets/manifest.json +1 -1
- package/controllers/add.d.ts +1 -1
- package/controllers/add.js +6 -16
- package/controllers/addGroup.js +0 -3
- package/controllers/addUser.js +0 -3
- package/controllers/dashboard.d.ts +1 -1
- package/controllers/dashboard.js +1 -3
- package/controllers/edit.js +6 -12
- package/controllers/editGroup.js +0 -2
- package/controllers/editUser.js +0 -2
- package/controllers/form.js +0 -1
- package/controllers/login.js +0 -3
- package/controllers/register.js +0 -4
- package/controllers/remove.js +0 -3
- package/controllers/view.js +0 -5
- package/lib/Adminizer.js +1 -5
- package/lib/controls/ControlsHandler.d.ts +1 -1
- package/lib/controls/ControlsHandler.js +1 -1
- package/lib/datatable/NodeTable.js +0 -42
- package/lib/inertia/inertiaAdapter.js +1 -1
- package/package.json +120 -120
- package/system/Router.js +0 -2
- package/system/bindInertia.js +1 -1
- package/controllers/listJson.d.ts +0 -1
- package/controllers/listJson.js +0 -35
- package/helpers/viewsHelper.d.ts +0 -44
- package/helpers/viewsHelper.js +0 -82
- package/system/bindResFunctions.d.ts +0 -2
- package/system/bindResFunctions.js +0 -52
- package/system/bindViewsLocals.d.ts +0 -2
- package/system/bindViewsLocals.js +0 -19
package/helpers/viewsHelper.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
export class ViewsHelper {
|
|
3
|
-
/**
|
|
4
|
-
* Base path for all views.
|
|
5
|
-
*/
|
|
6
|
-
static BASE_VIEWS_PATH = path.join(import.meta.dirname, '../views/');
|
|
7
|
-
/**
|
|
8
|
-
* Will generate path to view file
|
|
9
|
-
*
|
|
10
|
-
* @param {string} view
|
|
11
|
-
* @returns {string}
|
|
12
|
-
*/
|
|
13
|
-
static getViewPath(view) {
|
|
14
|
-
return path.resolve(ViewsHelper.BASE_VIEWS_PATH, view);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {IncomingMessage} req
|
|
19
|
-
* @param {string} key Types: adminError|adminSuccess
|
|
20
|
-
*/
|
|
21
|
-
static hasMessages(req, key) {
|
|
22
|
-
return (req.session.messages && req.session.messages[key]);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Get needed field value from dat provided.
|
|
26
|
-
*
|
|
27
|
-
* @param {string} key
|
|
28
|
-
* @param {object} field
|
|
29
|
-
* @param {Array} data
|
|
30
|
-
*/
|
|
31
|
-
static getFieldValue(key, field, data) {
|
|
32
|
-
let value = data[key];
|
|
33
|
-
if (typeof value === "object" && value !== null) {
|
|
34
|
-
let fieldConfigConfig = field.config;
|
|
35
|
-
if (fieldConfigConfig.type === 'association' && !Array.isArray(value)) {
|
|
36
|
-
// Here we assert that value is an object and has the identifierField
|
|
37
|
-
return value[fieldConfigConfig.identifierField];
|
|
38
|
-
}
|
|
39
|
-
if (Array.isArray(value) && fieldConfigConfig.type === 'association-many') {
|
|
40
|
-
return value.map(val => val[fieldConfigConfig.identifierField]);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Check if given option equals value or is in array
|
|
47
|
-
*
|
|
48
|
-
* @param {string|number} option
|
|
49
|
-
* @param {string|number|Array} value
|
|
50
|
-
* @returns {boolean}
|
|
51
|
-
*/
|
|
52
|
-
static isOptionSelected(option, value) {
|
|
53
|
-
if (Array.isArray(value)) {
|
|
54
|
-
return value.includes(option);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return (option == value);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Gets field value for view screen
|
|
62
|
-
*
|
|
63
|
-
* @param {string|number|boolean|object|Array} value
|
|
64
|
-
* @param {object} field
|
|
65
|
-
*/
|
|
66
|
-
static getAssociationValue(value, field) {
|
|
67
|
-
if (!value) {
|
|
68
|
-
return '-----------';
|
|
69
|
-
}
|
|
70
|
-
let fieldConfigConfig = field.config;
|
|
71
|
-
const displayField = fieldConfigConfig.displayField || 'id';
|
|
72
|
-
if (Array.isArray(value)) {
|
|
73
|
-
return value
|
|
74
|
-
.map(val => val[displayField])
|
|
75
|
-
.join('<br/>');
|
|
76
|
-
}
|
|
77
|
-
if (typeof value === 'object') {
|
|
78
|
-
return value[displayField];
|
|
79
|
-
}
|
|
80
|
-
return String(value);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ViewsHelper } from "../helpers/viewsHelper";
|
|
2
|
-
import { Adminizer } from "../lib/Adminizer";
|
|
3
|
-
export default function bindResFunctions(adminizer) {
|
|
4
|
-
let bindResFunctions = function (req, res, next) {
|
|
5
|
-
/**
|
|
6
|
-
* Guess view name by request
|
|
7
|
-
*
|
|
8
|
-
* @param {ReqType} req
|
|
9
|
-
* @returns {string}
|
|
10
|
-
*/
|
|
11
|
-
let guessViewName = function (req) {
|
|
12
|
-
if (!req || !req.route || !req.route.path || typeof req.route.path !== "string") {
|
|
13
|
-
return '';
|
|
14
|
-
}
|
|
15
|
-
let routeSplit = req.route.path.split('/');
|
|
16
|
-
let viewName = routeSplit.pop();
|
|
17
|
-
// :entity = list
|
|
18
|
-
if (viewName === ':entityName') {
|
|
19
|
-
viewName = 'list';
|
|
20
|
-
}
|
|
21
|
-
// for id we dont need last name
|
|
22
|
-
if (viewName === ':id') {
|
|
23
|
-
viewName = routeSplit.pop();
|
|
24
|
-
}
|
|
25
|
-
return viewName;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Show admin panel view.
|
|
29
|
-
*/
|
|
30
|
-
res.viewAdmin = function (specifiedPath, locals = {}, cb_view) {
|
|
31
|
-
if (!specifiedPath) {
|
|
32
|
-
specifiedPath = guessViewName(req);
|
|
33
|
-
}
|
|
34
|
-
// Set theme for admin panel
|
|
35
|
-
locals.theme = adminizer.config?.theme || 'light';
|
|
36
|
-
locals.scripts = adminizer.config?.scripts || {};
|
|
37
|
-
locals.section = locals.section || 'adminpanel';
|
|
38
|
-
// Add req to views
|
|
39
|
-
locals.req = req;
|
|
40
|
-
if (cb_view) {
|
|
41
|
-
console.warn(`Detected cb_view: ${cb_view}`);
|
|
42
|
-
}
|
|
43
|
-
// Rendering view
|
|
44
|
-
return res.render(ViewsHelper.getViewPath(specifiedPath), locals, cb_view);
|
|
45
|
-
};
|
|
46
|
-
next();
|
|
47
|
-
};
|
|
48
|
-
adminizer.app.use('/', bindResFunctions);
|
|
49
|
-
adminizer.app.use('/*', bindResFunctions);
|
|
50
|
-
Adminizer.log.info("Adminizer view loaded");
|
|
51
|
-
adminizer.emitter.emit("adminizer:viewadmin:loaded");
|
|
52
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ViewsHelper } from "../helpers/viewsHelper";
|
|
2
|
-
import { MenuHelper } from "../helpers/menuHelper";
|
|
3
|
-
import { viteRender } from "../helpers/viteHelper";
|
|
4
|
-
export default function bindViewsLocals(adminizer) {
|
|
5
|
-
/**
|
|
6
|
-
* Bind adminpanel fields to views
|
|
7
|
-
*/
|
|
8
|
-
adminizer.app.locals = {
|
|
9
|
-
viteDev: process.env.VITE_ENV === "dev",
|
|
10
|
-
viteRender: (assetName) => { return viteRender(adminizer.config.routePrefix, assetName); },
|
|
11
|
-
config: adminizer.config,
|
|
12
|
-
viewsHelper: ViewsHelper,
|
|
13
|
-
menuHelper: new MenuHelper(adminizer.config),
|
|
14
|
-
configHelper: adminizer.configHelper,
|
|
15
|
-
hasPermission: adminizer.accessRightsHelper.hasPermission.bind(adminizer.accessRightsHelper), // bind helper itself to keep the context
|
|
16
|
-
enoughPermissions: adminizer.accessRightsHelper.enoughPermissions.bind(adminizer.accessRightsHelper),
|
|
17
|
-
_csrf: "csrf" // TODO a lot of views uses csrf, but nobody sets it
|
|
18
|
-
};
|
|
19
|
-
}
|