adminizer 4.3.0-build.99 → 4.3.1
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/add-9NSjG6Jx.js +1 -0
- package/assets/add-form-uUiOWEy_.js +1 -0
- package/assets/add-group-Db0HkA1m.js +1 -0
- package/assets/add-group-form-DMz0_Oo9.js +1 -0
- package/assets/add-user-BMklpOqf.js +1 -0
- package/assets/{add-user-form-DrclnTOd.js → add-user-form-izlXhv2-.js} +1 -1
- package/assets/{app-D8oqdt8J.css → app-BJd5vD4i.css} +1 -1
- package/assets/app-layout-DcgYmhNb.js +1 -0
- package/assets/{app-shell-CHEYhVco.js → app-shell-C8Cnr5Hy.js} +1 -1
- package/assets/app-sidebar-HwvXNZzk.js +1 -0
- package/assets/app-sidebar-header-C8TTx8yd.js +1 -0
- package/assets/app.js +5 -5
- package/assets/{breadcrumbs-C439DWrC.js → breadcrumbs-DSMzNYiS.js} +1 -1
- package/assets/catalog-C2INmTwI.js +6 -0
- package/assets/catalog-D4n6dpGl.css +1 -0
- package/assets/{dashboard-Bi5KeZu2.js → dashboard-DwFL6nqn.js} +1 -1
- package/assets/{date-picker-DbJ8nHp5.js → date-picker-kW3wZQr_.js} +1 -1
- package/assets/{del-modal-_b3CSNHb.js → del-modal-DyIWFflP.js} +1 -1
- package/assets/{field-renderer-4obZ_jUo.js → field-renderer-BNQVfOir.js} +3 -3
- package/assets/form-CAIoGuhZ.js +1 -0
- package/assets/form-NUd-JZJN.js +1 -0
- package/assets/{geo-json-CadjdhwW.js → geo-json-YeWQOYnT.js} +1 -1
- package/assets/{home-BUoDaWe0.js → home-CteDT1us.js} +2 -2
- package/assets/{icon-DM49pZW3.js → icon-DpkedrXG.js} +1 -1
- package/assets/{init-user-DNrB8Xt5.js → init-user-DaOvt0vG.js} +1 -1
- package/assets/{input-error--IOnWghB.js → input-error-CmXZF6xy.js} +1 -1
- package/assets/list-CXQmJbH8.js +1 -0
- package/assets/{list-table-BKxxQkCW.js → list-table-BPpHDVPf.js} +4 -4
- package/assets/{login-6Xb8bcPq.js → login-DR6fvKtm.js} +1 -1
- package/assets/manifest.json +82 -82
- package/assets/{material-icon-BedgD2NE.js → material-icon-DwkE6wKL.js} +1 -1
- package/assets/media-manager-DYOfUh8F.js +14 -0
- package/assets/{module-B4-7WkY5.js → module-BIUqcf4-.js} +1 -1
- package/assets/{nav-footer-BwkQkwow.js → nav-footer-B85HLj-j.js} +1 -1
- package/assets/{nav-main-9Eb_A0rf.js → nav-main-BqKm87JZ.js} +1 -1
- package/assets/nav-user-DuCZNsZX.js +1 -0
- package/assets/notification-BQTjxH2H.js +27 -0
- package/assets/pagination-render-io0M2m2O.js +1 -0
- package/assets/{register-BIyjCy8M.js → register-hJD1ETdf.js} +1 -1
- package/assets/{tabs-BK_5wdPA.js → tabs-BhkFoerH.js} +1 -1
- package/assets/{theme-switcher-CKiJbMkh.js → theme-switcher-cgyA7_cO.js} +1 -1
- package/assets/{toast-editor-BZM5RHph.js → toast-editor-DwRk6WqT.js} +1 -1
- package/assets/{user-info-CcYdmjMZ.js → user-info-BGQvqBmO.js} +1 -1
- package/assets/{user-menu-content-DbUk8ZeY.js → user-menu-content-BDm88xaM.js} +1 -1
- package/assets/welcome-ks57d2us.js +1 -0
- package/controllers/add.js +8 -8
- package/controllers/addGroup.js +3 -3
- package/controllers/addUser.js +3 -3
- package/controllers/catalog/Catalog.js +22 -21
- package/controllers/catalog/FrontendCatalogAdapter.d.ts +82 -0
- package/controllers/catalog/FrontendCatalogAdapter.js +228 -0
- package/controllers/catalog/FrontentCatalogAdapter.d.ts +4 -4
- package/controllers/catalog/FrontentCatalogAdapter.js +28 -10
- package/controllers/ckeditorUpload.js +1 -1
- package/controllers/edit.js +21 -12
- package/controllers/editGroup.js +3 -3
- package/controllers/editUser.js +3 -3
- package/controllers/form.js +12 -10
- package/controllers/initUser.js +2 -2
- package/controllers/list.js +5 -5
- package/controllers/login.js +7 -4
- package/controllers/media-manager/ThumbController.js +2 -2
- package/controllers/media-manager/mediaManagerAdapter.js +2 -2
- package/controllers/media-manager/mediaManagerApi.js +2 -3
- package/controllers/navigation/edit.js +2 -2
- package/controllers/notifications/NotificationController.d.ts +1 -1
- package/controllers/notifications/NotificationController.js +6 -5
- package/controllers/register.js +1 -1
- package/controllers/remove.js +4 -4
- package/controllers/view.js +13 -11
- package/helpers/accessRightsHelper.js +1 -1
- package/helpers/controllerHelper.js +1 -1
- package/helpers/fieldsHelper.js +3 -3
- package/helpers/formHelper.js +1 -1
- package/helpers/inertiaAddHelper.js +3 -4
- package/helpers/inertiaFromHelper.js +2 -3
- package/helpers/inertiaListHelper.js +1 -1
- package/helpers/menuHelper.js +1 -1
- package/helpers/translationHelper.js +2 -2
- package/index.d.ts +5 -0
- package/index.js +31 -26
- package/interfaces/adminpanelConfig.d.ts +12 -0
- package/lib/Adminizer.d.ts +4 -3
- package/lib/Adminizer.js +41 -47
- package/lib/DataAccessor.js +3 -3
- package/lib/I18n.js +1 -1
- package/lib/PolicyManager.js +1 -1
- package/lib/catalog/AbstractCatalog.d.ts +6 -4
- package/lib/catalog/AbstractCatalog.js +5 -4
- package/lib/catalog/Navigation.d.ts +9 -7
- package/lib/catalog/Navigation.js +71 -42
- package/lib/controls/codeEditor/MonacoEditor.js +1 -1
- package/lib/controls/geojsoneditor/GeoEditor.js +1 -1
- package/lib/controls/jsoneditor/JsonEditor.js +1 -1
- package/lib/controls/markdown/ToastUiEditor.js +1 -1
- package/lib/controls/table/Handsontable.js +1 -1
- package/lib/controls/wysiwyg/CKeditor.js +1 -1
- package/lib/inertia/inertiaAdapter.js +31 -13
- package/lib/media-manager/AbstractMediaManager.d.ts +5 -3
- package/lib/media-manager/DefaultMediaManager.d.ts +3 -3
- package/lib/media-manager/DefaultMediaManager.js +21 -16
- package/lib/media-manager/Items.js +7 -6
- package/lib/media-manager/MediaManagerHandler.d.ts +3 -3
- package/lib/media-manager/MediaManagerHandler.js +4 -4
- package/lib/media-manager/Thumb.d.ts +2 -1
- package/lib/media-manager/Thumb.js +3 -4
- package/lib/media-manager/helpers/MediaManagerHelper.d.ts +7 -2
- package/lib/media-manager/helpers/MediaManagerHelper.js +12 -8
- package/lib/model/AbstractModel.js +1 -1
- package/lib/model/ModelHandler.js +1 -1
- package/lib/model/adapter/sequelize.js +1 -1
- package/lib/model/adapter/waterline.js +7 -1
- package/lib/notifications/AbstractNotificationService.js +1 -1
- package/lib/notifications/GeneralNotificationService.js +2 -2
- package/lib/notifications/NotificationHandler.js +1 -1
- package/lib/notifications/SystemNotificationService.js +2 -2
- package/lib/requestProcessor.js +2 -2
- package/lib/widgets/abstractAction.js +1 -1
- package/lib/widgets/abstractInfo.js +1 -1
- package/lib/widgets/abstractLink.js +1 -1
- package/lib/widgets/abstractSwitch.js +1 -1
- package/migrations/index.js +1 -1
- package/migrations/umzugExports.js +1 -1
- package/package.json +4 -2
- package/system/Router.js +31 -29
- package/system/bindAccessRights.js +7 -0
- package/system/bindAuthorization.js +4 -4
- package/system/bindControls.js +6 -6
- package/system/bindCors.d.ts +2 -0
- package/system/bindCors.js +41 -0
- package/system/bindDashboardWidgets.js +1 -1
- package/system/bindForms.js +1 -1
- package/system/bindInertia.js +4 -4
- package/system/bindMediaManager.js +2 -3
- package/system/bindModels.js +1 -1
- package/system/bindNavigation.d.ts +1 -1
- package/system/bindNavigation.js +34 -36
- package/system/bindNotifications.js +7 -7
- package/system/bindReqFunctions.js +7 -4
- package/system/bindTranslations.js +2 -2
- package/system/defaults.js +10 -2
- package/translations/ru.json +121 -120
- package/ui/components/handsontable.js +6 -3
- package/ui/lib/utils.d.ts +1 -0
- package/ui/lib/utils.js +16 -0
- package/assets/add-1E1UsMVZ.js +0 -1
- package/assets/add-form-CGa9QbwE.js +0 -1
- package/assets/add-group-7yAK6uFY.js +0 -1
- package/assets/add-group-form-BNmpvW8K.js +0 -1
- package/assets/add-user-NoYkTfZi.js +0 -1
- package/assets/app-layout-i2zN9Rn-.js +0 -1
- package/assets/app-sidebar-DeF8WNmW.js +0 -1
- package/assets/app-sidebar-header-DdM1EOrb.js +0 -1
- package/assets/catalog-B9hdop59.js +0 -6
- package/assets/catalog-C71LuRag.css +0 -1
- package/assets/form-Bte5kzjB.js +0 -1
- package/assets/form-oUlsuu7h.js +0 -1
- package/assets/list-C04Krl_W.js +0 -1
- package/assets/media-manager-UQT6RhI8.js +0 -14
- package/assets/nav-user-CRAfyE-x.js +0 -1
- package/assets/notification-ma2x7vka.js +0 -27
- package/assets/pagination-render-D3UyVAlr.js +0 -1
- package/assets/welcome-cWh1qnl_.js +0 -1
package/controllers/addUser.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ControllerHelper } from "../helpers/controllerHelper";
|
|
2
|
-
import { Adminizer } from "../lib/Adminizer";
|
|
1
|
+
import { ControllerHelper } from "../helpers/controllerHelper.js";
|
|
2
|
+
import { Adminizer } from "../lib/Adminizer.js";
|
|
3
3
|
import { generate } from 'password-hash';
|
|
4
|
-
import { inertiaUserHelper } from "../helpers/inertiaUserHelper";
|
|
4
|
+
import { inertiaUserHelper } from "../helpers/inertiaUserHelper.js";
|
|
5
5
|
export default async function (req, res) {
|
|
6
6
|
let entity = ControllerHelper.findEntityObject(req);
|
|
7
7
|
if (req.adminizer.config.auth.enable) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Adminizer } from "../../lib/Adminizer";
|
|
1
|
+
import { FrontendCatalog, FrontendCatalogUtils } from "./FrontendCatalogAdapter.js";
|
|
2
|
+
import { Adminizer } from "../../lib/Adminizer.js";
|
|
3
3
|
export async function catalogController(req, res) {
|
|
4
4
|
const slug = req.params.slug;
|
|
5
5
|
let id = req.params.id ? req.params.id : '';
|
|
@@ -34,7 +34,7 @@ export async function catalogController(req, res) {
|
|
|
34
34
|
}
|
|
35
35
|
if (method === 'POST' || method === 'PUT' || method === 'DELETE') {
|
|
36
36
|
const data = req.body;
|
|
37
|
-
const frontendCatalog = new
|
|
37
|
+
const frontendCatalog = new FrontendCatalog(_catalog);
|
|
38
38
|
if (!frontendCatalog)
|
|
39
39
|
return res.status(404);
|
|
40
40
|
frontendCatalog.setId(id);
|
|
@@ -46,24 +46,24 @@ export async function catalogController(req, res) {
|
|
|
46
46
|
return res.json(await frontendCatalog.getAddTemplate(item, req));
|
|
47
47
|
case 'getEditTemplate':
|
|
48
48
|
return res.json(await frontendCatalog.getEditTemplate(item, data.id, req, data.modelId));
|
|
49
|
-
case 'getCatalog':
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
49
|
+
case 'getCatalog': {
|
|
50
|
+
const __catalog = await frontendCatalog.getCatalog();
|
|
51
|
+
return res.json({
|
|
52
|
+
items: frontendCatalog.getitemTypes(),
|
|
53
|
+
catalog: {
|
|
54
|
+
nodes: __catalog,
|
|
55
|
+
movingGroupsRootOnly: _catalog.movingGroupsRootOnly ?? false,
|
|
56
|
+
catalogName: _catalog.name,
|
|
57
|
+
catalogId: _catalog.id,
|
|
58
|
+
catalogSlug: _catalog.slug,
|
|
59
|
+
idList: idList
|
|
60
|
+
},
|
|
61
|
+
toolsActions: await frontendCatalog.getActions([], 'tools')
|
|
62
|
+
});
|
|
63
|
+
}
|
|
65
64
|
case 'createItem':
|
|
66
|
-
|
|
65
|
+
const createdItem = await frontendCatalog.createItem(data.data, req);
|
|
66
|
+
return res.json({ 'data': FrontendCatalogUtils.normalizeForFrontend(createdItem) });
|
|
67
67
|
case 'getChilds':
|
|
68
68
|
return res.json({ data: await frontendCatalog.getChilds(data.data, req) });
|
|
69
69
|
case 'getActions':
|
|
@@ -85,7 +85,8 @@ export async function catalogController(req, res) {
|
|
|
85
85
|
case 'getPopUpTemplate':
|
|
86
86
|
return res.json({ data: await frontendCatalog.getPopUpTemplate(data.actionId, req) });
|
|
87
87
|
case 'updateItem':
|
|
88
|
-
|
|
88
|
+
const updatedItem = await frontendCatalog.updateItem(item, data.modelId, data.data, req);
|
|
89
|
+
return res.json({ data: FrontendCatalogUtils.normalizeForFrontend(updatedItem) });
|
|
89
90
|
}
|
|
90
91
|
break;
|
|
91
92
|
case 'DELETE':
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AbstractCatalog, Item } from "../../lib/catalog/AbstractCatalog";
|
|
2
|
+
interface NodeModel<TDataType> {
|
|
3
|
+
text: string;
|
|
4
|
+
droppable: boolean;
|
|
5
|
+
id: string;
|
|
6
|
+
parent: number;
|
|
7
|
+
data?: TDataType;
|
|
8
|
+
children?: NodeModel<TDataType>[];
|
|
9
|
+
isSelected?: boolean;
|
|
10
|
+
isVisible?: boolean;
|
|
11
|
+
isDraggable?: boolean;
|
|
12
|
+
isSelectable?: boolean;
|
|
13
|
+
path?: number[];
|
|
14
|
+
pathStr?: string;
|
|
15
|
+
level?: number;
|
|
16
|
+
isFirstChild?: boolean;
|
|
17
|
+
isLastChild?: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface NodeData extends Item {
|
|
20
|
+
}
|
|
21
|
+
interface RequestData {
|
|
22
|
+
reqNode: NodeModel<NodeData>[];
|
|
23
|
+
reqParent: NodeModel<NodeData>;
|
|
24
|
+
_method: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Now is React
|
|
28
|
+
* // TODO: refactor for react name
|
|
29
|
+
*/
|
|
30
|
+
export declare class FrontendCatalog {
|
|
31
|
+
catalog: AbstractCatalog;
|
|
32
|
+
constructor(_catalog: AbstractCatalog);
|
|
33
|
+
setId(id: string): void;
|
|
34
|
+
getItemType(type: string): import("../../lib/catalog/AbstractCatalog").BaseItem<Item>;
|
|
35
|
+
getAddTemplate(item: any, req: ReqType): Promise<{
|
|
36
|
+
type: "component" | "navigation.group" | "navigation.link" | "model" | "model.link";
|
|
37
|
+
data: any;
|
|
38
|
+
}>;
|
|
39
|
+
getEditTemplate(item: any, id: string | number, req: ReqType, modelId: string | number): Promise<{
|
|
40
|
+
type: "component" | "navigation.group" | "navigation.link" | "model" | "model.link";
|
|
41
|
+
data: any;
|
|
42
|
+
}>;
|
|
43
|
+
getitemTypes(): {
|
|
44
|
+
type: string;
|
|
45
|
+
name: string;
|
|
46
|
+
isGroup: boolean;
|
|
47
|
+
allowedRoot: boolean;
|
|
48
|
+
icon: string;
|
|
49
|
+
actionHandlers: import("../../lib/catalog/AbstractCatalog").ActionHandler[];
|
|
50
|
+
}[];
|
|
51
|
+
getLocales(req: ReqType): {
|
|
52
|
+
[key: string]: string;
|
|
53
|
+
};
|
|
54
|
+
getActions(items: NodeModel<any>[], type: string): Promise<import("../../lib/catalog/AbstractCatalog").ActionHandler[]>;
|
|
55
|
+
handleAction(actionId: string, items: any[], data: any, req: ReqType): Promise<string | void>;
|
|
56
|
+
getPopUpTemplate(actionId: string, req: ReqType): Promise<string>;
|
|
57
|
+
getLink(actionId: string): Promise<string>;
|
|
58
|
+
getCatalog(): Promise<NodeModel<Item>[]>;
|
|
59
|
+
createItem(data: any, req: ReqType): Promise<any>;
|
|
60
|
+
getChilds(data: any, req: ReqType): Promise<NodeModel<Item>[]>;
|
|
61
|
+
search(s: string, req: ReqType): Promise<NodeModel<Item>[]>;
|
|
62
|
+
updateTree(data: RequestData, req: ReqType): Promise<any>;
|
|
63
|
+
updateItem(item: any, modelId: string, data: any, req: ReqType): Promise<any>;
|
|
64
|
+
deleteItem(item: Item, req: ReqType): Promise<{
|
|
65
|
+
ok: boolean;
|
|
66
|
+
}>;
|
|
67
|
+
}
|
|
68
|
+
export declare class FrontendCatalogUtils {
|
|
69
|
+
/**
|
|
70
|
+
* Removes unnecessary data from the front
|
|
71
|
+
*/
|
|
72
|
+
static refinement<T extends NodeModel<any>>(nodeModel: T): any;
|
|
73
|
+
/**
|
|
74
|
+
* Normalizes data for frontend: replaces null parentId with 0
|
|
75
|
+
*/
|
|
76
|
+
static normalizeForFrontend<T extends Item>(item: T): T;
|
|
77
|
+
static arrayToNode<T extends Item>(items: T[], groupTypeName: string): NodeModel<T>[];
|
|
78
|
+
static toNode<T extends NodeData>(data: T, groupTypeName: string): NodeModel<T>;
|
|
79
|
+
static expandTo<T extends NodeData>(frontendCatalogData: NodeModel<T>, theseItemIdsNeedToBeOpened: (string | number)[]): NodeModel<T>;
|
|
80
|
+
static treeToNode(tree: Item[], groupTypeName: string): NodeModel<Item>[];
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Now is React
|
|
3
|
+
* // TODO: refactor for react name
|
|
4
|
+
*/
|
|
5
|
+
export class FrontendCatalog {
|
|
6
|
+
catalog;
|
|
7
|
+
constructor(_catalog) {
|
|
8
|
+
this.catalog = _catalog;
|
|
9
|
+
}
|
|
10
|
+
setId(id) {
|
|
11
|
+
this.catalog.setId(id);
|
|
12
|
+
}
|
|
13
|
+
getItemType(type) {
|
|
14
|
+
return this.catalog.getItemType(type);
|
|
15
|
+
}
|
|
16
|
+
getAddTemplate(item, req) {
|
|
17
|
+
return this.catalog.getAddTemplate(item, req);
|
|
18
|
+
}
|
|
19
|
+
getEditTemplate(item, id, req, modelId) {
|
|
20
|
+
return this.catalog.getEditTemplate(item, id, req, modelId);
|
|
21
|
+
}
|
|
22
|
+
getitemTypes() {
|
|
23
|
+
return this.catalog.getitemTypes();
|
|
24
|
+
}
|
|
25
|
+
getLocales(req) {
|
|
26
|
+
let obj = {
|
|
27
|
+
"Delete": "",
|
|
28
|
+
"Edit": "",
|
|
29
|
+
"create": "",
|
|
30
|
+
"Search": "",
|
|
31
|
+
"Select Item type": "",
|
|
32
|
+
"Select Items": "",
|
|
33
|
+
"Save": "",
|
|
34
|
+
"No": "",
|
|
35
|
+
"Are you sure?": "",
|
|
36
|
+
"Yes": "",
|
|
37
|
+
"Select Ids": "",
|
|
38
|
+
"OR": "",
|
|
39
|
+
"Open in a new window": "",
|
|
40
|
+
"Visible": "",
|
|
41
|
+
"Clean": "",
|
|
42
|
+
"Performing an action...": "",
|
|
43
|
+
"Action completed": "",
|
|
44
|
+
};
|
|
45
|
+
obj[this.catalog.name] = "";
|
|
46
|
+
for (const actionHandler of this.catalog.actionHandlers) {
|
|
47
|
+
obj[actionHandler.name] = "";
|
|
48
|
+
}
|
|
49
|
+
let messages = obj;
|
|
50
|
+
let outMessages = {};
|
|
51
|
+
for (const mess of Object.keys(messages)) {
|
|
52
|
+
outMessages[mess] = req.i18n.__(mess);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
...outMessages,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async getActions(items, type) {
|
|
59
|
+
let arrItems = [];
|
|
60
|
+
for (const item of items) {
|
|
61
|
+
if (item.data.id === 0)
|
|
62
|
+
item.data.id = null;
|
|
63
|
+
arrItems.push(await this.catalog.find(item.data));
|
|
64
|
+
}
|
|
65
|
+
console.log(arrItems);
|
|
66
|
+
if (type === 'tools') {
|
|
67
|
+
return (await this.catalog.getActions(arrItems))?.filter(e => e.displayTool);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return (await this.catalog.getActions(arrItems))?.filter(e => e.displayContext);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async handleAction(actionId, items, data, req) {
|
|
74
|
+
let arrItems = [];
|
|
75
|
+
for (const item of items) {
|
|
76
|
+
if (item.data.id === 0)
|
|
77
|
+
item.data.id = null;
|
|
78
|
+
arrItems.push(await this.catalog.find(item.data));
|
|
79
|
+
}
|
|
80
|
+
console.log(arrItems);
|
|
81
|
+
return this.catalog.handleAction(actionId, arrItems, data, req);
|
|
82
|
+
}
|
|
83
|
+
async getPopUpTemplate(actionId, req) {
|
|
84
|
+
return this.catalog.getPopUpTemplate(actionId, req);
|
|
85
|
+
}
|
|
86
|
+
async getLink(actionId) {
|
|
87
|
+
return this.catalog.getLink(actionId);
|
|
88
|
+
}
|
|
89
|
+
//Below are the methods that require action
|
|
90
|
+
async getCatalog() {
|
|
91
|
+
let rootItems = await this.catalog.getChilds(null);
|
|
92
|
+
return FrontendCatalogUtils.arrayToNode(rootItems, this.catalog.getGroupType().type);
|
|
93
|
+
}
|
|
94
|
+
async createItem(data, req) {
|
|
95
|
+
// TODO It's not clear why it's here.
|
|
96
|
+
//data = VueCatalogUtils.refinement(data);
|
|
97
|
+
// if (this.catalog.slug !== "navigation") {
|
|
98
|
+
// let item = data.record;
|
|
99
|
+
// item.parenId = data.parenId;
|
|
100
|
+
// return await this.catalog.createItem(item, req);
|
|
101
|
+
// } else {
|
|
102
|
+
if (data.parentId === 0)
|
|
103
|
+
data.parentId = null;
|
|
104
|
+
return await this.catalog.createItem(data, req);
|
|
105
|
+
// }
|
|
106
|
+
}
|
|
107
|
+
async getChilds(data, req) {
|
|
108
|
+
data = FrontendCatalogUtils.refinement(data);
|
|
109
|
+
if (!data || data.id === 0 || data.id === undefined) {
|
|
110
|
+
data = { id: null };
|
|
111
|
+
}
|
|
112
|
+
if (data.id === 0)
|
|
113
|
+
data.id = null;
|
|
114
|
+
return FrontendCatalogUtils.arrayToNode(await this.catalog.getChilds(data.id, undefined, req), this.catalog.getGroupType().type);
|
|
115
|
+
}
|
|
116
|
+
// Moved into actions
|
|
117
|
+
// getCreatedItems(data: any) {
|
|
118
|
+
// data = VueCatalogUtils.refinement(data);
|
|
119
|
+
// return this.catalog.getChilds(data.id);
|
|
120
|
+
// }
|
|
121
|
+
async search(s, req) {
|
|
122
|
+
let searchResult = await this.catalog.search(s, undefined, req);
|
|
123
|
+
// let itemsTree = AbstractCatalog.buildTree(searchResult);
|
|
124
|
+
// console.log(itemsTree)
|
|
125
|
+
return FrontendCatalogUtils.treeToNode(searchResult, this.catalog.getGroupType().type);
|
|
126
|
+
}
|
|
127
|
+
async updateTree(data, req) {
|
|
128
|
+
// console.dir(data, {depth: null})
|
|
129
|
+
// return
|
|
130
|
+
let reqParent = data.reqParent;
|
|
131
|
+
if (reqParent.data.id === 0)
|
|
132
|
+
reqParent.data.id = null;
|
|
133
|
+
// Update all items into parent (for two reason: update parent, updare sorting order)
|
|
134
|
+
let sortCount = 0;
|
|
135
|
+
for (const childNode of reqParent.children) {
|
|
136
|
+
childNode.data.sortOrder = sortCount;
|
|
137
|
+
childNode.data.parentId = reqParent.data.id;
|
|
138
|
+
if (childNode.data.id === 0)
|
|
139
|
+
childNode.data.id = null;
|
|
140
|
+
await this.catalog.updateItem(childNode.data.id, childNode.data.type, childNode.data, req);
|
|
141
|
+
sortCount++;
|
|
142
|
+
}
|
|
143
|
+
return Promise.resolve('ok');
|
|
144
|
+
}
|
|
145
|
+
async updateItem(item, modelId, data, req) {
|
|
146
|
+
//TODO It's not clear why it's here.
|
|
147
|
+
//data = VueCatalogUtils.refinement(data);
|
|
148
|
+
// if (this.catalog.slug !== "navigation") {
|
|
149
|
+
// return await this.catalog.updateModelItems(data.modelId, data.type, data.record, req);
|
|
150
|
+
// } else {
|
|
151
|
+
let normalizedModelId = modelId;
|
|
152
|
+
if (normalizedModelId === '0')
|
|
153
|
+
normalizedModelId = null;
|
|
154
|
+
return await this.catalog.updateModelItems(normalizedModelId, item.type, data, req);
|
|
155
|
+
// }
|
|
156
|
+
}
|
|
157
|
+
async deleteItem(item, req) {
|
|
158
|
+
if (item.id === 0)
|
|
159
|
+
item.id = null;
|
|
160
|
+
// Получаем всех непосредственных потомков текущего элемента
|
|
161
|
+
const children = await this.catalog.getChilds(item.id, undefined, req);
|
|
162
|
+
// Рекурсивно удаляем всех потомков
|
|
163
|
+
for (const child of children) {
|
|
164
|
+
await this.deleteItem(child, req);
|
|
165
|
+
}
|
|
166
|
+
// После удаления всех потомков удаляем сам элемент
|
|
167
|
+
await this.catalog.deleteItem(item.type, item.id, req);
|
|
168
|
+
return { ok: true };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export class FrontendCatalogUtils {
|
|
172
|
+
/**
|
|
173
|
+
* Removes unnecessary data from the front
|
|
174
|
+
*/
|
|
175
|
+
static refinement(nodeModel) {
|
|
176
|
+
return nodeModel.data;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Normalizes data for frontend: replaces null parentId with 0
|
|
180
|
+
*/
|
|
181
|
+
static normalizeForFrontend(item) {
|
|
182
|
+
return { ...item, parentId: item.parentId === null ? 0 : item.parentId };
|
|
183
|
+
}
|
|
184
|
+
static arrayToNode(items, groupTypeName) {
|
|
185
|
+
return items.map(node => FrontendCatalogUtils.toNode(node, groupTypeName));
|
|
186
|
+
}
|
|
187
|
+
static toNode(data, groupTypeName) {
|
|
188
|
+
const normalizedData = FrontendCatalogUtils.normalizeForFrontend(data);
|
|
189
|
+
return {
|
|
190
|
+
data: normalizedData,
|
|
191
|
+
droppable: data.type === groupTypeName,
|
|
192
|
+
id: data.id,
|
|
193
|
+
text: data.name,
|
|
194
|
+
parent: (data.parentId === null ? 0 : data.parentId),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
static expandTo(frontendCatalogData, theseItemIdsNeedToBeOpened) {
|
|
198
|
+
function expand(node) {
|
|
199
|
+
if (theseItemIdsNeedToBeOpened.includes(node.data.id)) {
|
|
200
|
+
// node.isExpanded = true;
|
|
201
|
+
}
|
|
202
|
+
if (node.children) {
|
|
203
|
+
for (const child of node.children) {
|
|
204
|
+
expand(child);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
theseItemIdsNeedToBeOpened.forEach(id => {
|
|
209
|
+
expand(frontendCatalogData);
|
|
210
|
+
});
|
|
211
|
+
return frontendCatalogData;
|
|
212
|
+
}
|
|
213
|
+
static treeToNode(tree, groupTypeName) {
|
|
214
|
+
function buildNodes(items) {
|
|
215
|
+
return items.map(item => {
|
|
216
|
+
const node = FrontendCatalogUtils.toNode(item, groupTypeName);
|
|
217
|
+
if (item.childs && item.childs.length > 0) {
|
|
218
|
+
// Sort the children before building their nodes
|
|
219
|
+
item.childs.sort((a, b) => (a.sortOrder || 0) - (b.sortOrder || 0));
|
|
220
|
+
node.children = buildNodes(item.childs);
|
|
221
|
+
// node.isExpanded = !node.droppable;
|
|
222
|
+
}
|
|
223
|
+
return node;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return buildNodes(tree);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -27,17 +27,17 @@ interface RequestData {
|
|
|
27
27
|
* @deprecated Now is React
|
|
28
28
|
* // TODO: refactor for react name
|
|
29
29
|
*/
|
|
30
|
-
export declare class
|
|
30
|
+
export declare class FrontendCatalog {
|
|
31
31
|
catalog: AbstractCatalog;
|
|
32
32
|
constructor(_catalog: AbstractCatalog);
|
|
33
33
|
setId(id: string): void;
|
|
34
34
|
getItemType(type: string): import("../../lib/catalog/AbstractCatalog").BaseItem<Item>;
|
|
35
35
|
getAddTemplate(item: any, req: ReqType): Promise<{
|
|
36
|
-
type: "component" | "navigation.group" | "navigation.link" | "model";
|
|
36
|
+
type: "component" | "navigation.group" | "navigation.link" | "model" | "model.link";
|
|
37
37
|
data: any;
|
|
38
38
|
}>;
|
|
39
39
|
getEditTemplate(item: any, id: string | number, req: ReqType, modelId: string | number): Promise<{
|
|
40
|
-
type: "component" | "navigation.group" | "navigation.link" | "model";
|
|
40
|
+
type: "component" | "navigation.group" | "navigation.link" | "model" | "model.link";
|
|
41
41
|
data: any;
|
|
42
42
|
}>;
|
|
43
43
|
getitemTypes(): {
|
|
@@ -65,7 +65,7 @@ export declare class VueCatalog {
|
|
|
65
65
|
ok: boolean;
|
|
66
66
|
}>;
|
|
67
67
|
}
|
|
68
|
-
export declare class
|
|
68
|
+
export declare class FrontendCatalogUtils {
|
|
69
69
|
/**
|
|
70
70
|
* Removes unnecessary data from the front
|
|
71
71
|
*/
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @deprecated Now is React
|
|
3
3
|
* // TODO: refactor for react name
|
|
4
4
|
*/
|
|
5
|
-
export class
|
|
5
|
+
export class FrontendCatalog {
|
|
6
6
|
catalog;
|
|
7
7
|
constructor(_catalog) {
|
|
8
8
|
this.catalog = _catalog;
|
|
@@ -37,6 +37,7 @@ export class VueCatalog {
|
|
|
37
37
|
"Select Ids": "",
|
|
38
38
|
"OR": "",
|
|
39
39
|
"Open in a new window": "",
|
|
40
|
+
"Visible": "",
|
|
40
41
|
"Clean": "",
|
|
41
42
|
"Performing an action...": "",
|
|
42
43
|
"Action completed": "",
|
|
@@ -57,6 +58,8 @@ export class VueCatalog {
|
|
|
57
58
|
async getActions(items, type) {
|
|
58
59
|
let arrItems = [];
|
|
59
60
|
for (const item of items) {
|
|
61
|
+
if (item.data.id === 0)
|
|
62
|
+
item.data.id = null;
|
|
60
63
|
arrItems.push(await this.catalog.find(item.data));
|
|
61
64
|
}
|
|
62
65
|
console.log(arrItems);
|
|
@@ -70,6 +73,8 @@ export class VueCatalog {
|
|
|
70
73
|
async handleAction(actionId, items, data, req) {
|
|
71
74
|
let arrItems = [];
|
|
72
75
|
for (const item of items) {
|
|
76
|
+
if (item.data.id === 0)
|
|
77
|
+
item.data.id = null;
|
|
73
78
|
arrItems.push(await this.catalog.find(item.data));
|
|
74
79
|
}
|
|
75
80
|
console.log(arrItems);
|
|
@@ -83,8 +88,8 @@ export class VueCatalog {
|
|
|
83
88
|
}
|
|
84
89
|
//Below are the methods that require action
|
|
85
90
|
async getCatalog() {
|
|
86
|
-
let rootItems = await this.catalog.getChilds(
|
|
87
|
-
return
|
|
91
|
+
let rootItems = await this.catalog.getChilds(null);
|
|
92
|
+
return FrontendCatalogUtils.arrayToNode(rootItems, this.catalog.getGroupType().type);
|
|
88
93
|
}
|
|
89
94
|
async createItem(data, req) {
|
|
90
95
|
// TODO It's not clear why it's here.
|
|
@@ -94,12 +99,16 @@ export class VueCatalog {
|
|
|
94
99
|
// item.parenId = data.parenId;
|
|
95
100
|
// return await this.catalog.createItem(item, req);
|
|
96
101
|
// } else {
|
|
102
|
+
if (data.parentId === 0)
|
|
103
|
+
data.parentId = null;
|
|
97
104
|
return await this.catalog.createItem(data, req);
|
|
98
105
|
// }
|
|
99
106
|
}
|
|
100
107
|
async getChilds(data, req) {
|
|
101
|
-
data =
|
|
102
|
-
|
|
108
|
+
data = FrontendCatalogUtils.refinement(data);
|
|
109
|
+
if (data.id === 0)
|
|
110
|
+
data.id = null;
|
|
111
|
+
return FrontendCatalogUtils.arrayToNode(await this.catalog.getChilds(data.id, undefined, req), this.catalog.getGroupType().type);
|
|
103
112
|
}
|
|
104
113
|
// Moved into actions
|
|
105
114
|
// getCreatedItems(data: any) {
|
|
@@ -110,17 +119,21 @@ export class VueCatalog {
|
|
|
110
119
|
let searchResult = await this.catalog.search(s, undefined, req);
|
|
111
120
|
// let itemsTree = AbstractCatalog.buildTree(searchResult);
|
|
112
121
|
// console.log(itemsTree)
|
|
113
|
-
return
|
|
122
|
+
return FrontendCatalogUtils.treeToNode(searchResult, this.catalog.getGroupType().type);
|
|
114
123
|
}
|
|
115
124
|
async updateTree(data, req) {
|
|
116
125
|
// console.dir(data, {depth: null})
|
|
117
126
|
// return
|
|
118
127
|
let reqParent = data.reqParent;
|
|
128
|
+
if (reqParent.data.id === 0)
|
|
129
|
+
reqParent.data.id = null;
|
|
119
130
|
// Update all items into parent (for two reason: update parent, updare sorting order)
|
|
120
131
|
let sortCount = 0;
|
|
121
132
|
for (const childNode of reqParent.children) {
|
|
122
133
|
childNode.data.sortOrder = sortCount;
|
|
123
134
|
childNode.data.parentId = reqParent.data.id;
|
|
135
|
+
if (childNode.data.id === 0)
|
|
136
|
+
childNode.data.id = null;
|
|
124
137
|
await this.catalog.updateItem(childNode.data.id, childNode.data.type, childNode.data, req);
|
|
125
138
|
sortCount++;
|
|
126
139
|
}
|
|
@@ -132,10 +145,15 @@ export class VueCatalog {
|
|
|
132
145
|
// if (this.catalog.slug !== "navigation") {
|
|
133
146
|
// return await this.catalog.updateModelItems(data.modelId, data.type, data.record, req);
|
|
134
147
|
// } else {
|
|
135
|
-
|
|
148
|
+
let normalizedModelId = modelId;
|
|
149
|
+
if (normalizedModelId === '0')
|
|
150
|
+
normalizedModelId = null;
|
|
151
|
+
return await this.catalog.updateModelItems(normalizedModelId, item.type, data, req);
|
|
136
152
|
// }
|
|
137
153
|
}
|
|
138
154
|
async deleteItem(item, req) {
|
|
155
|
+
if (item.id === 0)
|
|
156
|
+
item.id = null;
|
|
139
157
|
// Получаем всех непосредственных потомков текущего элемента
|
|
140
158
|
const children = await this.catalog.getChilds(item.id, undefined, req);
|
|
141
159
|
// Рекурсивно удаляем всех потомков
|
|
@@ -147,7 +165,7 @@ export class VueCatalog {
|
|
|
147
165
|
return { ok: true };
|
|
148
166
|
}
|
|
149
167
|
}
|
|
150
|
-
export class
|
|
168
|
+
export class FrontendCatalogUtils {
|
|
151
169
|
/**
|
|
152
170
|
* Removes unnecessary data from the front
|
|
153
171
|
*/
|
|
@@ -155,7 +173,7 @@ export class VueCatalogUtils {
|
|
|
155
173
|
return nodeModel.data;
|
|
156
174
|
}
|
|
157
175
|
static arrayToNode(items, groupTypeName) {
|
|
158
|
-
return items.map(node =>
|
|
176
|
+
return items.map(node => FrontendCatalogUtils.toNode(node, groupTypeName));
|
|
159
177
|
}
|
|
160
178
|
static toNode(data, groupTypeName) {
|
|
161
179
|
return {
|
|
@@ -185,7 +203,7 @@ export class VueCatalogUtils {
|
|
|
185
203
|
static treeToNode(tree, groupTypeName) {
|
|
186
204
|
function buildNodes(items) {
|
|
187
205
|
return items.map(item => {
|
|
188
|
-
const node =
|
|
206
|
+
const node = FrontendCatalogUtils.toNode(item, groupTypeName);
|
|
189
207
|
if (item.childs && item.childs.length > 0) {
|
|
190
208
|
// Sort the children before building their nodes
|
|
191
209
|
item.childs.sort((a, b) => (a.sortOrder || 0) - (b.sortOrder || 0));
|
package/controllers/edit.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ControllerHelper } from "../helpers/controllerHelper";
|
|
2
|
-
import { RequestProcessor } from "../lib/requestProcessor";
|
|
3
|
-
import { FieldsHelper } from "../helpers/fieldsHelper";
|
|
4
|
-
import { getRelationsMediaManager, saveRelationsMediaManager } from "../lib/media-manager/helpers/MediaManagerHelper";
|
|
5
|
-
import { DataAccessor } from "../lib/DataAccessor";
|
|
6
|
-
import { Adminizer } from "../lib/Adminizer";
|
|
7
|
-
import inertiaAddHelper from "../helpers/inertiaAddHelper";
|
|
1
|
+
import { ControllerHelper } from "../helpers/controllerHelper.js";
|
|
2
|
+
import { RequestProcessor } from "../lib/requestProcessor.js";
|
|
3
|
+
import { FieldsHelper } from "../helpers/fieldsHelper.js";
|
|
4
|
+
import { getRelationsMediaManager, saveRelationsMediaManager } from "../lib/media-manager/helpers/MediaManagerHelper.js";
|
|
5
|
+
import { DataAccessor } from "../lib/DataAccessor.js";
|
|
6
|
+
import { Adminizer } from "../lib/Adminizer.js";
|
|
7
|
+
import inertiaAddHelper from "../helpers/inertiaAddHelper.js";
|
|
8
8
|
export default async function edit(req, res) {
|
|
9
9
|
//Check id
|
|
10
10
|
if (!req.params.id) {
|
|
@@ -44,6 +44,8 @@ export default async function edit(req, res) {
|
|
|
44
44
|
fields = await FieldsHelper.loadAssociations(req, fields, "edit");
|
|
45
45
|
// Save
|
|
46
46
|
if (req.method.toUpperCase() === 'POST') {
|
|
47
|
+
const backUrl = req.body.redirectUrl;
|
|
48
|
+
delete req.body.redirectUrl;
|
|
47
49
|
let reqData = RequestProcessor.processRequest(req, fields);
|
|
48
50
|
let params = {};
|
|
49
51
|
params[entity.config.identifierField || req.adminizer.config.identifierField] = req.params.id;
|
|
@@ -112,7 +114,7 @@ export default async function edit(req, res) {
|
|
|
112
114
|
}
|
|
113
115
|
try {
|
|
114
116
|
let newRecord = await entity.model.update(params, reqData, dataAccessor);
|
|
115
|
-
await saveRelationsMediaManager(fields, rawReqData, entity.model.
|
|
117
|
+
await saveRelationsMediaManager(req.adminizer, fields, rawReqData, entity.model.modelname, newRecord[0].id);
|
|
116
118
|
Adminizer.log.debug(`Record was updated: `, newRecord);
|
|
117
119
|
if (req.body.jsonPopupCatalog) {
|
|
118
120
|
return res.json({ record: newRecord });
|
|
@@ -130,7 +132,12 @@ export default async function edit(req, res) {
|
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
134
|
req.flash.setFlashMessage('success', req.i18n.__('Record was updated'));
|
|
133
|
-
|
|
135
|
+
if (backUrl) {
|
|
136
|
+
return req.Inertia.redirect(backUrl);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return req.Inertia.redirect(`${req.adminizer.config.routePrefix}/model/${entity.name}`);
|
|
140
|
+
}
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
143
|
catch (e) {
|
|
@@ -142,9 +149,11 @@ export default async function edit(req, res) {
|
|
|
142
149
|
for (const field of Object.keys(fields)) {
|
|
143
150
|
let fieldConfigConfig = fields[field].config;
|
|
144
151
|
if (fieldConfigConfig.type === 'mediamanager') {
|
|
145
|
-
record[field] = await getRelationsMediaManager({
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
record[field] = await getRelationsMediaManager(req.adminizer, {
|
|
153
|
+
mediaManagerId: fieldConfigConfig.options?.id ?? "default",
|
|
154
|
+
model: entity.model.modelname,
|
|
155
|
+
widgetName: field,
|
|
156
|
+
modelId: id
|
|
148
157
|
});
|
|
149
158
|
}
|
|
150
159
|
}
|
package/controllers/editGroup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ControllerHelper } from "../helpers/controllerHelper";
|
|
2
|
-
import { Adminizer } from "../lib/Adminizer";
|
|
3
|
-
import { inertiaGroupHelper } from "../helpers/inertiaGroupHelper";
|
|
1
|
+
import { ControllerHelper } from "../helpers/controllerHelper.js";
|
|
2
|
+
import { Adminizer } from "../lib/Adminizer.js";
|
|
3
|
+
import { inertiaGroupHelper } from "../helpers/inertiaGroupHelper.js";
|
|
4
4
|
export default async function editGroup(req, res) {
|
|
5
5
|
let entity = ControllerHelper.findEntityObject(req);
|
|
6
6
|
if (req.adminizer.config.auth.enable) {
|
package/controllers/editUser.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ControllerHelper } from "../helpers/controllerHelper";
|
|
2
|
-
import { Adminizer } from "../lib/Adminizer";
|
|
1
|
+
import { ControllerHelper } from "../helpers/controllerHelper.js";
|
|
2
|
+
import { Adminizer } from "../lib/Adminizer.js";
|
|
3
3
|
import { generate } from "password-hash";
|
|
4
|
-
import { inertiaUserHelper } from "../helpers/inertiaUserHelper";
|
|
4
|
+
import { inertiaUserHelper } from "../helpers/inertiaUserHelper.js";
|
|
5
5
|
export default async function (req, res) {
|
|
6
6
|
let entity = ControllerHelper.findEntityObject(req);
|
|
7
7
|
if (req.adminizer.config.auth.enable) {
|