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.
Files changed (163) hide show
  1. package/assets/add-9NSjG6Jx.js +1 -0
  2. package/assets/add-form-uUiOWEy_.js +1 -0
  3. package/assets/add-group-Db0HkA1m.js +1 -0
  4. package/assets/add-group-form-DMz0_Oo9.js +1 -0
  5. package/assets/add-user-BMklpOqf.js +1 -0
  6. package/assets/{add-user-form-DrclnTOd.js → add-user-form-izlXhv2-.js} +1 -1
  7. package/assets/{app-D8oqdt8J.css → app-BJd5vD4i.css} +1 -1
  8. package/assets/app-layout-DcgYmhNb.js +1 -0
  9. package/assets/{app-shell-CHEYhVco.js → app-shell-C8Cnr5Hy.js} +1 -1
  10. package/assets/app-sidebar-HwvXNZzk.js +1 -0
  11. package/assets/app-sidebar-header-C8TTx8yd.js +1 -0
  12. package/assets/app.js +5 -5
  13. package/assets/{breadcrumbs-C439DWrC.js → breadcrumbs-DSMzNYiS.js} +1 -1
  14. package/assets/catalog-C2INmTwI.js +6 -0
  15. package/assets/catalog-D4n6dpGl.css +1 -0
  16. package/assets/{dashboard-Bi5KeZu2.js → dashboard-DwFL6nqn.js} +1 -1
  17. package/assets/{date-picker-DbJ8nHp5.js → date-picker-kW3wZQr_.js} +1 -1
  18. package/assets/{del-modal-_b3CSNHb.js → del-modal-DyIWFflP.js} +1 -1
  19. package/assets/{field-renderer-4obZ_jUo.js → field-renderer-BNQVfOir.js} +3 -3
  20. package/assets/form-CAIoGuhZ.js +1 -0
  21. package/assets/form-NUd-JZJN.js +1 -0
  22. package/assets/{geo-json-CadjdhwW.js → geo-json-YeWQOYnT.js} +1 -1
  23. package/assets/{home-BUoDaWe0.js → home-CteDT1us.js} +2 -2
  24. package/assets/{icon-DM49pZW3.js → icon-DpkedrXG.js} +1 -1
  25. package/assets/{init-user-DNrB8Xt5.js → init-user-DaOvt0vG.js} +1 -1
  26. package/assets/{input-error--IOnWghB.js → input-error-CmXZF6xy.js} +1 -1
  27. package/assets/list-CXQmJbH8.js +1 -0
  28. package/assets/{list-table-BKxxQkCW.js → list-table-BPpHDVPf.js} +4 -4
  29. package/assets/{login-6Xb8bcPq.js → login-DR6fvKtm.js} +1 -1
  30. package/assets/manifest.json +82 -82
  31. package/assets/{material-icon-BedgD2NE.js → material-icon-DwkE6wKL.js} +1 -1
  32. package/assets/media-manager-DYOfUh8F.js +14 -0
  33. package/assets/{module-B4-7WkY5.js → module-BIUqcf4-.js} +1 -1
  34. package/assets/{nav-footer-BwkQkwow.js → nav-footer-B85HLj-j.js} +1 -1
  35. package/assets/{nav-main-9Eb_A0rf.js → nav-main-BqKm87JZ.js} +1 -1
  36. package/assets/nav-user-DuCZNsZX.js +1 -0
  37. package/assets/notification-BQTjxH2H.js +27 -0
  38. package/assets/pagination-render-io0M2m2O.js +1 -0
  39. package/assets/{register-BIyjCy8M.js → register-hJD1ETdf.js} +1 -1
  40. package/assets/{tabs-BK_5wdPA.js → tabs-BhkFoerH.js} +1 -1
  41. package/assets/{theme-switcher-CKiJbMkh.js → theme-switcher-cgyA7_cO.js} +1 -1
  42. package/assets/{toast-editor-BZM5RHph.js → toast-editor-DwRk6WqT.js} +1 -1
  43. package/assets/{user-info-CcYdmjMZ.js → user-info-BGQvqBmO.js} +1 -1
  44. package/assets/{user-menu-content-DbUk8ZeY.js → user-menu-content-BDm88xaM.js} +1 -1
  45. package/assets/welcome-ks57d2us.js +1 -0
  46. package/controllers/add.js +8 -8
  47. package/controllers/addGroup.js +3 -3
  48. package/controllers/addUser.js +3 -3
  49. package/controllers/catalog/Catalog.js +22 -21
  50. package/controllers/catalog/FrontendCatalogAdapter.d.ts +82 -0
  51. package/controllers/catalog/FrontendCatalogAdapter.js +228 -0
  52. package/controllers/catalog/FrontentCatalogAdapter.d.ts +4 -4
  53. package/controllers/catalog/FrontentCatalogAdapter.js +28 -10
  54. package/controllers/ckeditorUpload.js +1 -1
  55. package/controllers/edit.js +21 -12
  56. package/controllers/editGroup.js +3 -3
  57. package/controllers/editUser.js +3 -3
  58. package/controllers/form.js +12 -10
  59. package/controllers/initUser.js +2 -2
  60. package/controllers/list.js +5 -5
  61. package/controllers/login.js +7 -4
  62. package/controllers/media-manager/ThumbController.js +2 -2
  63. package/controllers/media-manager/mediaManagerAdapter.js +2 -2
  64. package/controllers/media-manager/mediaManagerApi.js +2 -3
  65. package/controllers/navigation/edit.js +2 -2
  66. package/controllers/notifications/NotificationController.d.ts +1 -1
  67. package/controllers/notifications/NotificationController.js +6 -5
  68. package/controllers/register.js +1 -1
  69. package/controllers/remove.js +4 -4
  70. package/controllers/view.js +13 -11
  71. package/helpers/accessRightsHelper.js +1 -1
  72. package/helpers/controllerHelper.js +1 -1
  73. package/helpers/fieldsHelper.js +3 -3
  74. package/helpers/formHelper.js +1 -1
  75. package/helpers/inertiaAddHelper.js +3 -4
  76. package/helpers/inertiaFromHelper.js +2 -3
  77. package/helpers/inertiaListHelper.js +1 -1
  78. package/helpers/menuHelper.js +1 -1
  79. package/helpers/translationHelper.js +2 -2
  80. package/index.d.ts +5 -0
  81. package/index.js +31 -26
  82. package/interfaces/adminpanelConfig.d.ts +12 -0
  83. package/lib/Adminizer.d.ts +4 -3
  84. package/lib/Adminizer.js +41 -47
  85. package/lib/DataAccessor.js +3 -3
  86. package/lib/I18n.js +1 -1
  87. package/lib/PolicyManager.js +1 -1
  88. package/lib/catalog/AbstractCatalog.d.ts +6 -4
  89. package/lib/catalog/AbstractCatalog.js +5 -4
  90. package/lib/catalog/Navigation.d.ts +9 -7
  91. package/lib/catalog/Navigation.js +71 -42
  92. package/lib/controls/codeEditor/MonacoEditor.js +1 -1
  93. package/lib/controls/geojsoneditor/GeoEditor.js +1 -1
  94. package/lib/controls/jsoneditor/JsonEditor.js +1 -1
  95. package/lib/controls/markdown/ToastUiEditor.js +1 -1
  96. package/lib/controls/table/Handsontable.js +1 -1
  97. package/lib/controls/wysiwyg/CKeditor.js +1 -1
  98. package/lib/inertia/inertiaAdapter.js +31 -13
  99. package/lib/media-manager/AbstractMediaManager.d.ts +5 -3
  100. package/lib/media-manager/DefaultMediaManager.d.ts +3 -3
  101. package/lib/media-manager/DefaultMediaManager.js +21 -16
  102. package/lib/media-manager/Items.js +7 -6
  103. package/lib/media-manager/MediaManagerHandler.d.ts +3 -3
  104. package/lib/media-manager/MediaManagerHandler.js +4 -4
  105. package/lib/media-manager/Thumb.d.ts +2 -1
  106. package/lib/media-manager/Thumb.js +3 -4
  107. package/lib/media-manager/helpers/MediaManagerHelper.d.ts +7 -2
  108. package/lib/media-manager/helpers/MediaManagerHelper.js +12 -8
  109. package/lib/model/AbstractModel.js +1 -1
  110. package/lib/model/ModelHandler.js +1 -1
  111. package/lib/model/adapter/sequelize.js +1 -1
  112. package/lib/model/adapter/waterline.js +7 -1
  113. package/lib/notifications/AbstractNotificationService.js +1 -1
  114. package/lib/notifications/GeneralNotificationService.js +2 -2
  115. package/lib/notifications/NotificationHandler.js +1 -1
  116. package/lib/notifications/SystemNotificationService.js +2 -2
  117. package/lib/requestProcessor.js +2 -2
  118. package/lib/widgets/abstractAction.js +1 -1
  119. package/lib/widgets/abstractInfo.js +1 -1
  120. package/lib/widgets/abstractLink.js +1 -1
  121. package/lib/widgets/abstractSwitch.js +1 -1
  122. package/migrations/index.js +1 -1
  123. package/migrations/umzugExports.js +1 -1
  124. package/package.json +4 -2
  125. package/system/Router.js +31 -29
  126. package/system/bindAccessRights.js +7 -0
  127. package/system/bindAuthorization.js +4 -4
  128. package/system/bindControls.js +6 -6
  129. package/system/bindCors.d.ts +2 -0
  130. package/system/bindCors.js +41 -0
  131. package/system/bindDashboardWidgets.js +1 -1
  132. package/system/bindForms.js +1 -1
  133. package/system/bindInertia.js +4 -4
  134. package/system/bindMediaManager.js +2 -3
  135. package/system/bindModels.js +1 -1
  136. package/system/bindNavigation.d.ts +1 -1
  137. package/system/bindNavigation.js +34 -36
  138. package/system/bindNotifications.js +7 -7
  139. package/system/bindReqFunctions.js +7 -4
  140. package/system/bindTranslations.js +2 -2
  141. package/system/defaults.js +10 -2
  142. package/translations/ru.json +121 -120
  143. package/ui/components/handsontable.js +6 -3
  144. package/ui/lib/utils.d.ts +1 -0
  145. package/ui/lib/utils.js +16 -0
  146. package/assets/add-1E1UsMVZ.js +0 -1
  147. package/assets/add-form-CGa9QbwE.js +0 -1
  148. package/assets/add-group-7yAK6uFY.js +0 -1
  149. package/assets/add-group-form-BNmpvW8K.js +0 -1
  150. package/assets/add-user-NoYkTfZi.js +0 -1
  151. package/assets/app-layout-i2zN9Rn-.js +0 -1
  152. package/assets/app-sidebar-DeF8WNmW.js +0 -1
  153. package/assets/app-sidebar-header-DdM1EOrb.js +0 -1
  154. package/assets/catalog-B9hdop59.js +0 -6
  155. package/assets/catalog-C71LuRag.css +0 -1
  156. package/assets/form-Bte5kzjB.js +0 -1
  157. package/assets/form-oUlsuu7h.js +0 -1
  158. package/assets/list-C04Krl_W.js +0 -1
  159. package/assets/media-manager-UQT6RhI8.js +0 -14
  160. package/assets/nav-user-CRAfyE-x.js +0 -1
  161. package/assets/notification-ma2x7vka.js +0 -27
  162. package/assets/pagination-render-D3UyVAlr.js +0 -1
  163. package/assets/welcome-cWh1qnl_.js +0 -1
@@ -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 { VueCatalog } from "./FrontentCatalogAdapter";
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 VueCatalog(_catalog);
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
- const __catalog = await frontendCatalog.getCatalog();
52
- return res.json({
53
- items: frontendCatalog.getitemTypes(),
54
- catalog: {
55
- nodes: __catalog,
56
- movingGroupsRootOnly: _catalog.movingGroupsRootOnly ?? false,
57
- catalogName: _catalog.name,
58
- catalogId: _catalog.id,
59
- catalogSlug: _catalog.slug,
60
- idList: idList
61
- },
62
- toolsActions: await frontendCatalog.getActions([], 'tools')
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
- return res.json({ 'data': await frontendCatalog.createItem(data.data, req) });
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
- return res.json({ data: await frontendCatalog.updateItem(item, data.modelId, data.data, req) });
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 VueCatalog {
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 VueCatalogUtils {
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 VueCatalog {
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(0);
87
- return VueCatalogUtils.arrayToNode(rootItems, this.catalog.getGroupType().type);
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 = VueCatalogUtils.refinement(data);
102
- return VueCatalogUtils.arrayToNode(await this.catalog.getChilds(data.id, undefined, req), this.catalog.getGroupType().type);
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 VueCatalogUtils.treeToNode(searchResult, this.catalog.getGroupType().type);
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
- return await this.catalog.updateModelItems(modelId, item.type, data, req);
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 VueCatalogUtils {
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 => VueCatalogUtils.toNode(node, groupTypeName));
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 = VueCatalogUtils.toNode(item, groupTypeName);
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));
@@ -1,4 +1,4 @@
1
- import { ControllerHelper } from "../helpers/controllerHelper";
1
+ import { ControllerHelper } from "../helpers/controllerHelper.js";
2
2
  import * as fs from "fs";
3
3
  import multer from "multer";
4
4
  export async function ckEditorUpload(req, res) {
@@ -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.identity, newRecord[0].id);
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
- return req.Inertia.redirect(`${req.adminizer.config.routePrefix}/model/${entity.name}`);
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
- list: record[field],
147
- mediaManagerId: fieldConfigConfig.options?.id ?? "default"
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
  }
@@ -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) {
@@ -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) {