adminizer 4.7.0-build.222 → 5.0.0-build.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/Readme.md +2 -1
- package/assets/add-a4odXvQk.js +1 -0
- package/assets/add-group-D-NleXth.js +1 -0
- package/assets/add-user-B4SVJT5P.js +1 -0
- package/assets/app-CtWuWD5N.css +1 -0
- package/assets/app-layout-eaSzcROf.js +1 -0
- package/assets/app.js +35 -39
- package/assets/catalog-ByUICd5z.js +6 -0
- package/assets/controls/chunks/_commonjsHelpers-C6fGbg64.js +6 -0
- package/assets/controls/chunks/index-CjiZ2FIa.js +93 -0
- package/assets/controls/chunks/jsx-runtime-jIxVPx5o.js +31 -0
- package/assets/controls/chunks/use-appearance-CFLOwiSX.js +38 -0
- package/assets/controls/chunks/use-window-size-BXgBKW65.js +19 -0
- package/assets/controls/chunks/vanilla-picker-Dg97NL4h.js +529 -0
- package/assets/{RelationDialogStack-CnHFOYyR.css → controls/ckeditor.css} +1 -1
- package/assets/controls/ckeditor.es.js +83663 -0
- package/assets/controls/handsontable.css +1 -0
- package/assets/controls/handsontable.es.js +70550 -0
- package/assets/controls/jsoneditor.css +1 -0
- package/assets/controls/jsoneditor.es.js +42009 -0
- package/assets/controls/leaflet.css +1 -0
- package/assets/controls/leaflet.es.js +10299 -0
- package/assets/controls/monaco.es.js +618 -0
- package/assets/controls/toast-ui.css +1 -0
- package/assets/controls/toast-ui.es.js +41768 -0
- package/assets/dashboard-BYd8G2cW.js +3 -0
- package/assets/debounce-BMmXVQ06.js +1 -0
- package/assets/history-B8KIDy44.js +1 -0
- package/assets/init-user-8aUohVDq.js +1 -0
- package/assets/list-ChmtBGjG.js +4 -0
- package/assets/login-CO4laf6m.js +1 -0
- package/assets/manifest.json +60 -615
- package/assets/{media-manager-WcKe1EvD.js → media-manager-BDbpSSjH.js} +3 -3
- package/assets/module-D59aE9uv.js +1 -0
- package/assets/notification-DNoyfNmT.js +20 -0
- package/assets/register-DBYIMXGQ.js +1 -0
- package/assets/{ru-eW0WKkga.js → ru-rYKdQbWF.js} +1 -1
- package/assets/use-appearance-_EbbjHTh.js +1 -0
- package/assets/user-filters-list-BMFRwkYF.js +1 -0
- package/assets/welcome-37rNVUHt.js +1 -0
- package/controllers/add.d.ts +1 -1
- package/controllers/addGroup.js +3 -3
- package/controllers/addUser.js +3 -3
- package/controllers/catalog/Catalog.d.ts +1 -1
- package/controllers/catalog/Catalog.js +2 -1
- package/controllers/catalog/FrontendCatalogAdapter.d.ts +2 -12
- package/controllers/catalog/FrontendCatalogAdapter.js +3 -16
- package/controllers/catalog/FrontentCatalogAdapter.d.ts +2 -12
- package/controllers/catalog/FrontentCatalogAdapter.js +0 -16
- package/controllers/edit.js +6 -11
- package/controllers/editGroup.d.ts +1 -1
- package/controllers/editGroup.js +3 -3
- package/controllers/editUser.d.ts +1 -1
- package/controllers/editUser.js +3 -3
- package/controllers/feed.js +1 -1
- package/controllers/filter-fields/columns.js +1 -1
- package/controllers/filter-fields/getAllUserFilters.js +2 -2
- package/controllers/filter-fields/groups.js +2 -2
- package/controllers/filter-fields/savedFilters.js +1 -1
- package/controllers/history-actions/HistoryController.js +1 -1
- package/controllers/initUser.js +2 -2
- package/controllers/list.d.ts +1 -1
- package/controllers/login.d.ts +1 -1
- package/controllers/login.js +3 -3
- package/controllers/media-manager/ThumbController.js +2 -2
- package/controllers/media-manager/mediaManagerApi.js +13 -15
- package/controllers/register.d.ts +1 -1
- package/controllers/register.js +5 -5
- package/controllers/remove.d.ts +1 -1
- package/controllers/userApiKey.js +2 -2
- package/controllers/view.d.ts +1 -1
- package/controllers/view.js +5 -5
- package/controllers/widgets/Action.js +5 -2
- package/controllers/widgets/Info.js +1 -1
- package/controllers/widgets/filterInfo.js +1 -1
- package/files/favicon.png +0 -0
- package/helpers/accessRightsHelper.d.ts +6 -4
- package/helpers/accessRightsHelper.js +13 -0
- package/helpers/diffHelpers.js +1 -1
- package/helpers/fieldsHelper.d.ts +1 -1
- package/helpers/fieldsHelper.js +8 -4
- package/helpers/filterDatetimeHelper.d.ts +1 -1
- package/helpers/inertiaAddHelper.d.ts +6 -5
- package/helpers/inertiaAddHelper.js +45 -37
- package/helpers/inertiaAutHelper.js +5 -5
- package/helpers/inertiaGroupHelper.d.ts +4 -4
- package/helpers/inertiaMenuHelper.js +1 -1
- package/helpers/inertiaUserHelper.d.ts +3 -3
- package/helpers/inertiaUserHelper.js +1 -1
- package/helpers/menuHelper.d.ts +2 -2
- package/index.d.ts +18 -6
- package/index.js +18 -6
- package/interfaces/adminpanelConfig.d.ts +10 -33
- package/interfaces/global.d.ts +10 -15
- package/interfaces/listQueryBuilder.d.ts +1 -1
- package/lib/Adminizer.d.ts +25 -2
- package/lib/Adminizer.js +124 -50
- package/lib/DataAccessor.d.ts +9 -5
- package/lib/DataAccessor.js +89 -42
- package/lib/access-rights/AccessRightsHandler.d.ts +17 -0
- package/lib/access-rights/AccessRightsHandler.js +63 -0
- package/lib/ai-assistant/AbstractAiModelService.d.ts +5 -8
- package/lib/ai-assistant/AbstractAiModelService.js +3 -14
- package/lib/ai-assistant/AiAssistantHandler.d.ts +2 -2
- package/lib/app-manager/AdminizerApp.d.ts +228 -0
- package/lib/app-manager/AdminizerApp.js +17 -0
- package/lib/app-manager/AppManager.d.ts +18 -0
- package/lib/app-manager/AppManager.js +537 -0
- package/lib/app-manager/AssetHandler.d.ts +17 -0
- package/lib/app-manager/AssetHandler.js +67 -0
- package/lib/app-manager/ConfigLayerHandler.d.ts +18 -0
- package/lib/app-manager/ConfigLayerHandler.js +119 -0
- package/lib/app-manager/ControllerHandler.d.ts +25 -0
- package/lib/app-manager/ControllerHandler.js +140 -0
- package/lib/catalog/AbstractCatalog.d.ts +28 -19
- package/lib/catalog/AbstractCatalog.js +41 -10
- package/lib/catalog/CatalogHandler.d.ts +13 -0
- package/lib/catalog/CatalogHandler.js +48 -2
- package/lib/catalog/CatalogTemplateComponentHandler.d.ts +23 -0
- package/lib/catalog/CatalogTemplateComponentHandler.js +59 -0
- package/lib/controls/Control.d.ts +17 -0
- package/lib/controls/Control.js +1 -0
- package/lib/controls/ControlsHandler.d.ts +5 -6
- package/lib/controls/ControlsHandler.js +0 -13
- package/lib/controls/codeEditor/MonacoEditor.d.ts +3 -4
- package/lib/controls/codeEditor/MonacoEditor.js +13 -8
- package/lib/controls/geojsoneditor/GeoEditor.d.ts +3 -4
- package/lib/controls/geojsoneditor/GeoEditor.js +14 -9
- package/lib/controls/jsoneditor/JsonEditor.d.ts +5 -6
- package/lib/controls/jsoneditor/JsonEditor.js +14 -13
- package/lib/controls/markdown/ToastUiEditor.d.ts +5 -6
- package/lib/controls/markdown/ToastUiEditor.js +14 -13
- package/lib/controls/table/Handsontable.d.ts +5 -6
- package/lib/controls/table/Handsontable.js +14 -13
- package/lib/controls/wysiwyg/CKeditor.d.ts +5 -6
- package/lib/controls/wysiwyg/CKeditor.js +14 -13
- package/lib/filters/ConditionValidator.d.ts +1 -1
- package/lib/filters/FilterService.d.ts +18 -18
- package/lib/filters/FilterService.js +11 -11
- package/lib/history-actions/AbstractHistoryAdapter.d.ts +14 -14
- package/lib/history-actions/AbstractHistoryAdapter.js +5 -6
- package/lib/history-actions/DefaultHistoryAdapter.d.ts +7 -7
- package/lib/history-actions/DefaultHistoryAdapter.js +2 -2
- package/lib/list-query-builder/ListQueryBuilder.d.ts +1 -1
- package/lib/media-manager/AbstractMediaManager.d.ts +14 -3
- package/lib/media-manager/AbstractMediaManager.js +16 -5
- package/lib/media-manager/MediaManagerHandler.d.ts +3 -0
- package/lib/media-manager/MediaManagerHandler.js +30 -5
- package/lib/media-manager/Thumb.js +7 -13
- package/lib/media-manager/helpers/MediaManagerHelper.d.ts +6 -4
- package/lib/media-manager/helpers/MediaManagerHelper.js +18 -18
- package/lib/model/AbstractModel.d.ts +9 -5
- package/lib/model/AbstractModel.js +9 -13
- package/lib/model/InternalModelAccessFactory.js +9 -10
- package/lib/model/ModelHandler.d.ts +45 -7
- package/lib/model/ModelHandler.js +168 -11
- package/lib/model/adapter/sequelize.d.ts +2 -4
- package/lib/model/adapter/sequelize.js +16 -193
- package/lib/model/adapter/typeorm.d.ts +2 -4
- package/lib/model/adapter/typeorm.js +2 -35
- package/lib/notifications/AbstractNotificationService.d.ts +9 -9
- package/lib/notifications/AbstractNotificationService.js +8 -8
- package/lib/notifications/GeneralNotificationService.js +1 -1
- package/lib/notifications/SystemNotificationService.js +1 -1
- package/lib/ui-i18n/uiTranslationKeys.d.ts +1 -1
- package/lib/ui-i18n/uiTranslationKeys.js +1 -0
- package/lib/widgets/abstractCustom.d.ts +7 -2
- package/lib/widgets/abstractCustom.js +6 -0
- package/lib/widgets/abstractInfo.d.ts +4 -1
- package/lib/widgets/abstractWidgetBase.d.ts +2 -0
- package/lib/widgets/abstractWidgetBase.js +2 -0
- package/lib/widgets/widgetHandler.d.ts +6 -2
- package/lib/widgets/widgetHandler.js +70 -19
- package/models/{FilterAP.d.ts → Filter.d.ts} +4 -70
- package/models/Filter.js +1 -0
- package/models/FilterColumn.d.ts +10 -0
- package/models/FilterColumn.js +1 -0
- package/models/Group.d.ts +8 -0
- package/models/Group.js +1 -0
- package/models/HistoryActions.d.ts +14 -0
- package/models/HistoryActions.js +1 -0
- package/models/MediaManagerAP.d.ts +2 -54
- package/models/MediaManagerAP.js +1 -51
- package/models/MediaManagerAssociationsAP.d.ts +1 -35
- package/models/MediaManagerAssociationsAP.js +1 -33
- package/models/MediaManagerMetaAP.d.ts +2 -30
- package/models/MediaManagerMetaAP.js +1 -27
- package/models/Notification.d.ts +13 -0
- package/models/Notification.js +1 -0
- package/models/User.d.ts +23 -0
- package/models/User.js +1 -0
- package/models/UserNotification.d.ts +7 -0
- package/models/UserNotification.js +1 -0
- package/package.json +25 -30
- package/services/FeedService.d.ts +5 -5
- package/services/FeedService.js +1 -1
- package/system/Router.js +2 -10
- package/system/bindAccessRights.js +1 -1
- package/system/bindAuthorization.js +2 -2
- package/system/bindControls.js +7 -6
- package/system/bindDashboardWidgets.js +3 -2
- package/system/bindDev.js +1 -1
- package/system/bindHistory.d.ts +1 -1
- package/system/bindHistory.js +1 -1
- package/system/bindInertia.js +0 -6
- package/system/bindMediaManager.js +4 -17
- package/system/bindNotifications.d.ts +1 -1
- package/system/bindNotifications.js +1 -1
- package/system/bindReqFunctions.d.ts +1 -0
- package/system/bindReqFunctions.js +20 -3
- package/system/buildInternalModelAccess.js +2 -15
- package/system/defaults.js +5 -10
- package/system/systemModelContracts.d.ts +22 -0
- package/system/systemModelContracts.js +155 -0
- package/system/validateSystemModels.d.ts +2 -0
- package/system/validateSystemModels.js +101 -0
- package/translations/ar.json +2 -1
- package/translations/cn.json +2 -1
- package/translations/de.json +2 -1
- package/translations/en.json +1 -0
- package/translations/es.json +2 -1
- package/translations/fr.json +2 -1
- package/translations/hi.json +2 -1
- package/translations/jp.json +2 -1
- package/translations/ko.json +2 -1
- package/translations/pt.json +2 -1
- package/translations/ru.json +2 -1
- package/translations/ua.json +2 -1
- package/translations/uz.json +2 -1
- package/translations/vi.json +2 -1
- package/ui/components/VanillaJSONEditor.d.ts +1 -1
- package/ui/components/handsontable.d.ts +1 -1
- package/ui/components/ui/avatar.d.ts +3 -3
- package/ui/components/ui/badge.d.ts +1 -1
- package/ui/components/ui/breadcrumb.d.ts +7 -7
- package/ui/components/ui/button.d.ts +1 -1
- package/ui/components/ui/calendar.d.ts +1 -1
- package/ui/components/ui/card.d.ts +7 -7
- package/ui/components/ui/checkbox.d.ts +1 -1
- package/ui/components/ui/collapsible.d.ts +3 -3
- package/ui/components/ui/command.d.ts +9 -9
- package/ui/components/ui/context-menu.d.ts +15 -15
- package/ui/components/ui/dialog-stack.d.ts +10 -10
- package/ui/components/ui/dialog.d.ts +10 -10
- package/ui/components/ui/dropdown-menu.d.ts +15 -15
- package/ui/components/ui/input.d.ts +1 -1
- package/ui/components/ui/label.d.ts +1 -1
- package/ui/components/ui/menubar.d.ts +16 -16
- package/ui/components/ui/pagination.d.ts +7 -7
- package/ui/components/ui/popover.d.ts +4 -4
- package/ui/components/ui/select.d.ts +10 -10
- package/ui/components/ui/separator.d.ts +1 -1
- package/ui/components/ui/sheet.d.ts +8 -8
- package/ui/components/ui/sidebar.d.ts +23 -23
- package/ui/components/ui/skeleton.d.ts +1 -1
- package/ui/components/ui/slider.d.ts +1 -1
- package/ui/components/ui/sonner.d.ts +1 -1
- package/ui/components/ui/switch.d.ts +1 -1
- package/ui/components/ui/table.d.ts +8 -8
- package/ui/components/ui/tabs.d.ts +4 -4
- package/ui/components/ui/textarea.d.ts +1 -1
- package/ui/components/ui/tooltip.d.ts +4 -4
- package/assets/RelationDialogStack-DI2bZxQX.js +0 -20
- package/assets/add-DCQ7ZW4B.js +0 -1
- package/assets/add-group-DCVPryBo.js +0 -1
- package/assets/add-group-form-DKRXC2n-.js +0 -1
- package/assets/add-user-B7OOiYxv.js +0 -1
- package/assets/add-user-form-UXAToWQd.js +0 -1
- package/assets/app-AKbNCggP.css +0 -1
- package/assets/app-layout-6EwNBvnR.js +0 -1
- package/assets/app-shell-D8wtkECO.js +0 -1
- package/assets/app-sidebar-DfGjL-2K.js +0 -1
- package/assets/app-sidebar-header-BZbIBQjq.js +0 -1
- package/assets/breadcrumbs-CODaqVkB.js +0 -1
- package/assets/catalog-DVvFGa2X.js +0 -6
- package/assets/dashboard-BadoiH_a.js +0 -3
- package/assets/date-picker-DSOkNiNo.js +0 -1
- package/assets/del-modal-Cd4M7af8.js +0 -1
- package/assets/dynamic-controls-BsrJhPDY.js +0 -1
- package/assets/geo-json-CzR5JBXL.js +0 -1
- package/assets/handsontable-BI98OF5R.js +0 -336
- package/assets/history-D1iLA6rs.js +0 -1
- package/assets/home-DbWj-W_k.js +0 -2
- package/assets/icon-C2JNaLxH.js +0 -1
- package/assets/init-user-D2HSyXup.js +0 -1
- package/assets/input-error-CH2caTtO.js +0 -1
- package/assets/jsoneditor-DVNQmA6G.js +0 -3869
- package/assets/list-CVoljVUw.js +0 -4
- package/assets/login-DFSLEO17.js +0 -1
- package/assets/material-icon-Bx9pGQiQ.js +0 -1
- package/assets/module-DJsC37CM.js +0 -1
- package/assets/monaco-Bl4zdWCn.js +0 -11
- package/assets/nav-footer-BiSQkPt4.js +0 -1
- package/assets/nav-main-rTH0PfDw.js +0 -1
- package/assets/nav-user-Bj6cWs0a.js +0 -1
- package/assets/notification-DKrNfaAB.js +0 -20
- package/assets/pagination-render-AKJvTIRA.js +0 -1
- package/assets/register-BTP4uxsK.js +0 -1
- package/assets/theme-switcher-Dm8EOGzx.js +0 -1
- package/assets/toast-editor-DOg_gvSp.js +0 -668
- package/assets/user-filters-list-C9R9J6Om.js +0 -1
- package/assets/user-info-BgSbT02v.js +0 -1
- package/assets/user-menu-content-TQTXHIv6.js +0 -1
- package/assets/vanilla-picker-B3LgXoKV.js +0 -2
- package/assets/vendor-l0sNRNKZ.js +0 -1
- package/assets/welcome-BwDlAOGh.js +0 -1
- package/controllers/navigation/edit.d.ts +0 -1
- package/controllers/navigation/edit.js +0 -8
- package/lib/ai-assistant/DummyAiModelService.d.ts +0 -8
- package/lib/ai-assistant/DummyAiModelService.js +0 -14
- package/lib/ai-assistant/OpenAiModelService.d.ts +0 -24
- package/lib/ai-assistant/OpenAiModelService.js +0 -184
- package/lib/catalog/Navigation.d.ts +0 -49
- package/lib/catalog/Navigation.js +0 -492
- package/lib/controls/AbstractControls.d.ts +0 -30
- package/lib/controls/AbstractControls.js +0 -14
- package/lib/media-manager/DefaultMediaManager.d.ts +0 -20
- package/lib/media-manager/DefaultMediaManager.js +0 -127
- package/lib/media-manager/Items.d.ts +0 -50
- package/lib/media-manager/Items.js +0 -296
- package/models/FilterAP.js +0 -68
- package/models/FilterColumnAP.d.ts +0 -32
- package/models/FilterColumnAP.js +0 -21
- package/models/GroupAP.d.ts +0 -31
- package/models/GroupAP.js +0 -22
- package/models/HistoryActionsAP.d.ts +0 -56
- package/models/HistoryActionsAP.js +0 -42
- package/models/NavigationAP.d.ts +0 -22
- package/models/NavigationAP.js +0 -16
- package/models/NotificationAP.d.ts +0 -44
- package/models/NotificationAP.js +0 -30
- package/models/UserAP.d.ts +0 -81
- package/models/UserAP.js +0 -57
- package/models/UserNotificationAP.d.ts +0 -26
- package/models/UserNotificationAP.js +0 -18
- package/system/bindAiAssistant.d.ts +0 -2
- package/system/bindAiAssistant.js +0 -30
- package/system/bindModels.d.ts +0 -2
- package/system/bindModels.js +0 -48
- package/system/bindNavigation.d.ts +0 -2
- package/system/bindNavigation.js +0 -38
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
import { AbstractCatalog, AbstractGroup, AbstractItem } from "./AbstractCatalog.js";
|
|
2
|
-
import { v4 as uuid } from "uuid";
|
|
3
|
-
import { Adminizer } from "../Adminizer.js";
|
|
4
|
-
export class StorageService {
|
|
5
|
-
storageMap = new Map();
|
|
6
|
-
id;
|
|
7
|
-
model;
|
|
8
|
-
adminizer;
|
|
9
|
-
ready;
|
|
10
|
-
constructor(adminizer, id, model) {
|
|
11
|
-
this.adminizer = adminizer;
|
|
12
|
-
this.id = id;
|
|
13
|
-
this.model = model.toLowerCase();
|
|
14
|
-
this.ready = this.initModel();
|
|
15
|
-
}
|
|
16
|
-
navigationModel() {
|
|
17
|
-
return this.adminizer.modelHandler.internal("navigation").get(this.model);
|
|
18
|
-
}
|
|
19
|
-
async initModel() {
|
|
20
|
-
const navigation = await this.navigationModel().findOne({ where: { label: this.id } });
|
|
21
|
-
if (navigation) {
|
|
22
|
-
Adminizer.log.info(`Found existing navigation: ${this.id}`);
|
|
23
|
-
await this.populateFromTree(navigation.tree);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const newNavigation = { label: this.id, tree: [] };
|
|
27
|
-
await this.navigationModel().create(newNavigation);
|
|
28
|
-
Adminizer.log.info(`Created a new navigation: ${this.id}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
getId() {
|
|
32
|
-
return this.id;
|
|
33
|
-
}
|
|
34
|
-
async buildTree() {
|
|
35
|
-
const rootElements = await this.findElementsByParentId(null, null);
|
|
36
|
-
const buildSubTree = async (elements) => {
|
|
37
|
-
const tree = [];
|
|
38
|
-
for (const element of elements) {
|
|
39
|
-
const children = await this.findElementsByParentId(element.id, null);
|
|
40
|
-
tree.push({
|
|
41
|
-
...element,
|
|
42
|
-
children: await buildSubTree(children)
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return tree;
|
|
46
|
-
};
|
|
47
|
-
let tree = await buildSubTree(rootElements);
|
|
48
|
-
function sortTree(items) {
|
|
49
|
-
items.sort((a, b) => a.sortOrder - b.sortOrder);
|
|
50
|
-
for (let i = 0; i < items.length; i++) {
|
|
51
|
-
const item = items[i];
|
|
52
|
-
if (item.children) {
|
|
53
|
-
sortTree(item.children);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
sortTree(tree);
|
|
58
|
-
return tree;
|
|
59
|
-
}
|
|
60
|
-
async populateFromTree(tree) {
|
|
61
|
-
const traverseTree = async (node, parentId = null) => {
|
|
62
|
-
const { children, ...itemData } = node;
|
|
63
|
-
const item = { ...itemData, parentId: itemData.parentId === 0 ? null : itemData.parentId };
|
|
64
|
-
await this.setElement(item.id, item, true);
|
|
65
|
-
if (children && children.length > 0) {
|
|
66
|
-
for (const child of children) {
|
|
67
|
-
await traverseTree(child, item.id);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
for (const node of tree) {
|
|
72
|
-
await traverseTree(node);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
async setElement(id, item, init = false) {
|
|
76
|
-
this.storageMap.set(item.id, item);
|
|
77
|
-
if (!init)
|
|
78
|
-
await this.saveToDB();
|
|
79
|
-
// This like fetch in DB
|
|
80
|
-
return this.findElementById(item.id);
|
|
81
|
-
}
|
|
82
|
-
async removeElementById(id) {
|
|
83
|
-
this.storageMap.delete(id);
|
|
84
|
-
setTimeout(async () => {
|
|
85
|
-
await this.saveToDB();
|
|
86
|
-
}, 500);
|
|
87
|
-
}
|
|
88
|
-
async findElementById(id) {
|
|
89
|
-
return this.storageMap.get(id);
|
|
90
|
-
}
|
|
91
|
-
async findElementByModelId(modelId) {
|
|
92
|
-
const elements = [];
|
|
93
|
-
for (const item of this.storageMap.values()) {
|
|
94
|
-
if (item.modelId === modelId) {
|
|
95
|
-
elements.push(item);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return elements;
|
|
99
|
-
}
|
|
100
|
-
async saveToDB() {
|
|
101
|
-
let tree = await this.buildTree();
|
|
102
|
-
try {
|
|
103
|
-
await this.navigationModel().update({ where: { label: this.id } }, { tree: tree });
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
console.log(e);
|
|
107
|
-
throw 'navigation model update error';
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
async findElementsByParentId(parentId, type) {
|
|
111
|
-
const elements = [];
|
|
112
|
-
for (const item of this.storageMap.values()) {
|
|
113
|
-
if (parentId === 0)
|
|
114
|
-
parentId = null;
|
|
115
|
-
if (type === null && item.parentId === parentId) {
|
|
116
|
-
elements.push(item);
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
if (item.parentId === parentId && item.type === type) {
|
|
120
|
-
elements.push(item);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return elements;
|
|
124
|
-
}
|
|
125
|
-
async getAllElements() {
|
|
126
|
-
return Array.from(this.storageMap.values());
|
|
127
|
-
}
|
|
128
|
-
async search(s, type) {
|
|
129
|
-
const lowerCaseQuery = s.toLowerCase(); // Convert query to lowercase for case-insensitive search
|
|
130
|
-
const matchedElements = [];
|
|
131
|
-
for (const item of this.storageMap.values()) {
|
|
132
|
-
// Check if item type matches the specified type
|
|
133
|
-
if (item.type === type) {
|
|
134
|
-
// Search by name
|
|
135
|
-
if (item.name.toLowerCase().includes(lowerCaseQuery)) {
|
|
136
|
-
matchedElements.push(item);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return matchedElements;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
export class StorageServices {
|
|
144
|
-
storages = [];
|
|
145
|
-
constructor() {
|
|
146
|
-
}
|
|
147
|
-
add(storage) {
|
|
148
|
-
this.storages.push(storage);
|
|
149
|
-
}
|
|
150
|
-
get(id) {
|
|
151
|
-
return this.storages.find(storage => storage.getId() === id);
|
|
152
|
-
}
|
|
153
|
-
getAll() {
|
|
154
|
-
return this.storages;
|
|
155
|
-
}
|
|
156
|
-
/** Resolves when all sections have finished loading from the database */
|
|
157
|
-
async ready() {
|
|
158
|
-
await Promise.all(this.storages.map(s => s.ready));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
export class Navigation extends AbstractCatalog {
|
|
162
|
-
name = 'Navigation';
|
|
163
|
-
slug = 'navigation';
|
|
164
|
-
icon = "box";
|
|
165
|
-
actionHandlers = [];
|
|
166
|
-
idList = [];
|
|
167
|
-
storageServices;
|
|
168
|
-
constructor(adminizer, config) {
|
|
169
|
-
let items = [];
|
|
170
|
-
const storageServices = new StorageServices();
|
|
171
|
-
for (const configElement of config.items) {
|
|
172
|
-
items.push(new NavigationItem(adminizer, configElement.title, configElement.model, config.model, configElement.urlPath, storageServices));
|
|
173
|
-
}
|
|
174
|
-
items.push(new NavigationGroup(adminizer, config.groupField, storageServices));
|
|
175
|
-
items.push(new LinkItem(adminizer, storageServices));
|
|
176
|
-
super(adminizer, items);
|
|
177
|
-
this.storageServices = storageServices;
|
|
178
|
-
adminizer.storageServices = storageServices;
|
|
179
|
-
for (const section of config.sections) {
|
|
180
|
-
this.storageServices.add(new StorageService(adminizer, section, config.model));
|
|
181
|
-
}
|
|
182
|
-
this.movingGroupsRootOnly = config.movingGroupsRootOnly;
|
|
183
|
-
this.idList = config.sections ?? [];
|
|
184
|
-
}
|
|
185
|
-
async getIdList() {
|
|
186
|
-
return this.idList;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
class NavigationItem extends AbstractItem {
|
|
190
|
-
allowedRoot = true;
|
|
191
|
-
icon;
|
|
192
|
-
name;
|
|
193
|
-
type;
|
|
194
|
-
model;
|
|
195
|
-
navigationModel;
|
|
196
|
-
actionHandlers = [];
|
|
197
|
-
urlPath;
|
|
198
|
-
adminizer;
|
|
199
|
-
constructor(adminizer, name, model, navigationModel, urlPath, storageServices) {
|
|
200
|
-
super();
|
|
201
|
-
this.name = name;
|
|
202
|
-
this.navigationModel = navigationModel;
|
|
203
|
-
this.model = model;
|
|
204
|
-
this.type = model.toLowerCase();
|
|
205
|
-
this.urlPath = urlPath;
|
|
206
|
-
let configModel = adminizer.config.models[this.model];
|
|
207
|
-
this.icon = configModel?.icon ?? 'file_present';
|
|
208
|
-
this.adminizer = adminizer;
|
|
209
|
-
this.storageServices = storageServices;
|
|
210
|
-
}
|
|
211
|
-
contentModel() {
|
|
212
|
-
return this.adminizer.modelHandler.internal("navigation").get(this.model);
|
|
213
|
-
}
|
|
214
|
-
async create(data, catalogId) {
|
|
215
|
-
let storage = this.storageServices.get(catalogId);
|
|
216
|
-
let storageData = null;
|
|
217
|
-
if (data._method === 'select') {
|
|
218
|
-
let record = await this.contentModel().findOne({ where: { id: data.record } });
|
|
219
|
-
storageData = await this.dataPreparation({
|
|
220
|
-
record: record,
|
|
221
|
-
parentId: data.parentId,
|
|
222
|
-
targetBlank: data.targetBlank,
|
|
223
|
-
visible: data.visible
|
|
224
|
-
}, catalogId);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
storageData = await this.dataPreparation(data, catalogId);
|
|
228
|
-
}
|
|
229
|
-
return await storage.setElement(data.id, storageData);
|
|
230
|
-
}
|
|
231
|
-
async dataPreparation(data, catalogId, sortOrder) {
|
|
232
|
-
let storage = this.storageServices.get(catalogId);
|
|
233
|
-
let urlPath = eval('`' + this.urlPath + '`');
|
|
234
|
-
let parentId = data.parentId ? data.parentId : null; // changed from 0 to null
|
|
235
|
-
if (parentId === 0)
|
|
236
|
-
parentId = null;
|
|
237
|
-
return {
|
|
238
|
-
id: uuid(),
|
|
239
|
-
modelId: data.record.id,
|
|
240
|
-
targetBlank: data.targetBlank ?? data.record.targetBlank,
|
|
241
|
-
visible: data.visible ?? data.record.visible,
|
|
242
|
-
isNavigation: true,
|
|
243
|
-
name: data.record.name ?? data.record.title ?? data.record.id,
|
|
244
|
-
parentId: parentId,
|
|
245
|
-
sortOrder: sortOrder ?? (await storage.findElementsByParentId(parentId, null)).length,
|
|
246
|
-
icon: this.icon,
|
|
247
|
-
type: this.type,
|
|
248
|
-
urlPath: urlPath
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
async updateModelItems(modelId, data, catalogId) {
|
|
252
|
-
let storage = this.storageServices.get(catalogId);
|
|
253
|
-
let items = await storage.findElementByModelId(modelId);
|
|
254
|
-
let urlPath = eval('`' + this.urlPath + '`');
|
|
255
|
-
let response = [];
|
|
256
|
-
for (const item of items) {
|
|
257
|
-
item.name = data.record.name ?? data.record.title ?? data.record.id;
|
|
258
|
-
item.urlPath = urlPath;
|
|
259
|
-
if (item.id === data.record.treeId) {
|
|
260
|
-
item.targetBlank = data.record.targetBlank;
|
|
261
|
-
item.visible = data.record.visible;
|
|
262
|
-
}
|
|
263
|
-
response.push(await storage.setElement(item.id, item));
|
|
264
|
-
}
|
|
265
|
-
return response[0];
|
|
266
|
-
}
|
|
267
|
-
async update(itemId, data, catalogId) {
|
|
268
|
-
let storage = this.storageServices.get(catalogId);
|
|
269
|
-
return await storage.setElement(itemId, data);
|
|
270
|
-
}
|
|
271
|
-
async deleteItem(itemId, catalogId) {
|
|
272
|
-
let storage = this.storageServices.get(catalogId);
|
|
273
|
-
return await storage.removeElementById(itemId);
|
|
274
|
-
}
|
|
275
|
-
async find(itemId, catalogId) {
|
|
276
|
-
let storage = this.storageServices.get(catalogId);
|
|
277
|
-
return await storage.findElementById(itemId);
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* @deprecated reason: transition to Inertia
|
|
281
|
-
* // TODO: need passing custom React module
|
|
282
|
-
*/
|
|
283
|
-
async getAddTemplate(req) {
|
|
284
|
-
let type = 'model.link';
|
|
285
|
-
let itemsDB = await this.contentModel().find({});
|
|
286
|
-
let items = itemsDB.map((item) => {
|
|
287
|
-
return {
|
|
288
|
-
id: item.id,
|
|
289
|
-
name: item.name ?? item.title ?? item.id
|
|
290
|
-
};
|
|
291
|
-
});
|
|
292
|
-
return {
|
|
293
|
-
type: type,
|
|
294
|
-
data: {
|
|
295
|
-
items: items,
|
|
296
|
-
model: this.model,
|
|
297
|
-
labels: {
|
|
298
|
-
selectTitle: `${req.i18n.__('Select')} ${req.i18n.__(this.name + 's')}`,
|
|
299
|
-
createTitle: `${req.i18n.__('create new')} ${req.i18n.__(this.name + 's')}`,
|
|
300
|
-
OR: req.i18n.__('OR'),
|
|
301
|
-
openInNewWindow: req.i18n.__('Open in a new window'),
|
|
302
|
-
visible: req.i18n.__('Visible')
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
async getChilds(parentId, catalogId) {
|
|
308
|
-
let storage = this.storageServices.get(catalogId);
|
|
309
|
-
return await storage.findElementsByParentId(parentId, this.type);
|
|
310
|
-
}
|
|
311
|
-
async getEditTemplate(id, catalogId, req, modelId) {
|
|
312
|
-
return Promise.resolve({
|
|
313
|
-
type: 'model.link',
|
|
314
|
-
data: {
|
|
315
|
-
item: await this.find(id, catalogId)
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
async search(s, catalogId) {
|
|
320
|
-
let storage = this.storageServices.get(catalogId);
|
|
321
|
-
return await storage.search(s, this.type);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
class NavigationGroup extends AbstractGroup {
|
|
325
|
-
allowedRoot = true;
|
|
326
|
-
name = "Group";
|
|
327
|
-
groupField;
|
|
328
|
-
adminizer;
|
|
329
|
-
constructor(adminizer, groupField, storageServices) {
|
|
330
|
-
super();
|
|
331
|
-
this.groupField = groupField;
|
|
332
|
-
this.adminizer = adminizer;
|
|
333
|
-
this.storageServices = storageServices;
|
|
334
|
-
}
|
|
335
|
-
async create(data, catalogId) {
|
|
336
|
-
let storage = this.storageServices.get(catalogId);
|
|
337
|
-
let storageData = await this.dataPreparation(data, catalogId);
|
|
338
|
-
delete data.name;
|
|
339
|
-
delete data.parentId;
|
|
340
|
-
storageData = { ...storageData, ...data };
|
|
341
|
-
return await storage.setElement(storageData.id, storageData);
|
|
342
|
-
}
|
|
343
|
-
async dataPreparation(data, catalogId, sortOrder) {
|
|
344
|
-
let storage = this.storageServices.get(catalogId);
|
|
345
|
-
let parentId = data.parentId ? data.parentId : null; // changed from 0 to null
|
|
346
|
-
if (parentId === 0)
|
|
347
|
-
parentId = null;
|
|
348
|
-
return {
|
|
349
|
-
id: uuid(),
|
|
350
|
-
name: data.name,
|
|
351
|
-
targetBlank: data.targetBlank,
|
|
352
|
-
visible: data.visible,
|
|
353
|
-
isNavigation: true,
|
|
354
|
-
parentId: parentId,
|
|
355
|
-
sortOrder: sortOrder ?? (await storage.findElementsByParentId(parentId, null)).length,
|
|
356
|
-
icon: this.icon,
|
|
357
|
-
type: this.type
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
async deleteItem(itemId, catalogId) {
|
|
361
|
-
let storage = this.storageServices.get(catalogId);
|
|
362
|
-
return await storage.removeElementById(itemId);
|
|
363
|
-
}
|
|
364
|
-
async find(itemId, catalogId) {
|
|
365
|
-
let storage = this.storageServices.get(catalogId);
|
|
366
|
-
return await storage.findElementById(itemId);
|
|
367
|
-
}
|
|
368
|
-
async update(itemId, data, catalogId) {
|
|
369
|
-
let storage = this.storageServices.get(catalogId);
|
|
370
|
-
return await storage.setElement(itemId, data);
|
|
371
|
-
}
|
|
372
|
-
async updateModelItems(modelId, data, catalogId) {
|
|
373
|
-
let storage = this.storageServices.get(catalogId);
|
|
374
|
-
return await storage.setElement(modelId, data);
|
|
375
|
-
}
|
|
376
|
-
getAddTemplate(req) {
|
|
377
|
-
let type = 'navigation.group';
|
|
378
|
-
let resItems = [];
|
|
379
|
-
if (this.groupField.length) {
|
|
380
|
-
resItems = this.groupField.map((field) => {
|
|
381
|
-
return {
|
|
382
|
-
name: field.name,
|
|
383
|
-
label: field.label,
|
|
384
|
-
required: field.required
|
|
385
|
-
};
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
return Promise.resolve({
|
|
389
|
-
type: type,
|
|
390
|
-
data: {
|
|
391
|
-
items: resItems,
|
|
392
|
-
labels: {
|
|
393
|
-
openInNewWindow: req.i18n.__('Open in a new window'),
|
|
394
|
-
visible: req.i18n.__('Visible'),
|
|
395
|
-
title: req.i18n.__('Title'),
|
|
396
|
-
save: req.i18n.__('Save')
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
async getEditTemplate(id, catalogId, req, modelId) {
|
|
402
|
-
let item = await this.find(id, catalogId);
|
|
403
|
-
let type = 'navigation.group';
|
|
404
|
-
let resItems = [];
|
|
405
|
-
if (this.groupField.length) {
|
|
406
|
-
resItems = this.groupField.map((field) => {
|
|
407
|
-
return {
|
|
408
|
-
name: field.name,
|
|
409
|
-
label: field.label,
|
|
410
|
-
required: field.required
|
|
411
|
-
};
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
return Promise.resolve({
|
|
415
|
-
type: type,
|
|
416
|
-
data: {
|
|
417
|
-
items: resItems,
|
|
418
|
-
item: item,
|
|
419
|
-
labels: {
|
|
420
|
-
openInNewWindow: req.i18n.__('Open in a new window'),
|
|
421
|
-
visible: req.i18n.__('Visible'),
|
|
422
|
-
title: req.i18n.__('Title'),
|
|
423
|
-
save: req.i18n.__('Save')
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
async getChilds(parentId, catalogId) {
|
|
429
|
-
let storage = this.storageServices.get(catalogId);
|
|
430
|
-
return await storage.findElementsByParentId(parentId, this.type);
|
|
431
|
-
}
|
|
432
|
-
async search(s, catalogId) {
|
|
433
|
-
let storage = this.storageServices.get(catalogId);
|
|
434
|
-
return await storage.search(s, this.type);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
class LinkItem extends NavigationGroup {
|
|
438
|
-
allowedRoot = true;
|
|
439
|
-
icon = 'insert_link';
|
|
440
|
-
name = 'Link';
|
|
441
|
-
type = 'link';
|
|
442
|
-
isGroup = false;
|
|
443
|
-
constructor(adminizer, storageServices) {
|
|
444
|
-
super(adminizer, [], storageServices);
|
|
445
|
-
}
|
|
446
|
-
getAddTemplate(req) {
|
|
447
|
-
let type = 'navigation.link';
|
|
448
|
-
let resItems = [
|
|
449
|
-
{
|
|
450
|
-
label: req.i18n.__('Link'),
|
|
451
|
-
name: "link",
|
|
452
|
-
required: true
|
|
453
|
-
}
|
|
454
|
-
];
|
|
455
|
-
return Promise.resolve({
|
|
456
|
-
type: type,
|
|
457
|
-
data: {
|
|
458
|
-
items: resItems,
|
|
459
|
-
labels: {
|
|
460
|
-
title: req.i18n.__('Title'),
|
|
461
|
-
openInNewWindow: req.i18n.__('Open in a new window'),
|
|
462
|
-
visible: req.i18n.__('Visible'),
|
|
463
|
-
save: req.i18n.__('Save')
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
async getEditTemplate(id, catalogId, req) {
|
|
469
|
-
let item = await this.find(id, catalogId);
|
|
470
|
-
let type = 'navigation.group';
|
|
471
|
-
let resItems = [
|
|
472
|
-
{
|
|
473
|
-
label: req.i18n.__('Link'),
|
|
474
|
-
name: 'link',
|
|
475
|
-
required: true
|
|
476
|
-
}
|
|
477
|
-
];
|
|
478
|
-
return Promise.resolve({
|
|
479
|
-
type: type,
|
|
480
|
-
data: {
|
|
481
|
-
items: resItems,
|
|
482
|
-
item: item,
|
|
483
|
-
labels: {
|
|
484
|
-
openInNewWindow: req.i18n.__('Open in a new window'),
|
|
485
|
-
visible: req.i18n.__('Visible'),
|
|
486
|
-
title: req.i18n.__('Title'),
|
|
487
|
-
save: req.i18n.__('Save')
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Adminizer } from "../Adminizer";
|
|
2
|
-
export type ControlType = 'wysiwyg' | 'jsonEditor' | 'geoJson' | 'markdown' | 'table' | 'codeEditor';
|
|
3
|
-
export interface Path {
|
|
4
|
-
jsPath: {
|
|
5
|
-
dev: string;
|
|
6
|
-
production: string;
|
|
7
|
-
};
|
|
8
|
-
cssPath: string;
|
|
9
|
-
}
|
|
10
|
-
export type Config = Record<string, string | string[] | object | number | boolean>;
|
|
11
|
-
/**
|
|
12
|
-
* AbstractControls
|
|
13
|
-
*/
|
|
14
|
-
export declare abstract class AbstractControls {
|
|
15
|
-
abstract readonly name: string;
|
|
16
|
-
abstract readonly type: ControlType;
|
|
17
|
-
abstract readonly path: Path;
|
|
18
|
-
abstract readonly config: Config;
|
|
19
|
-
readonly routPrefix: string;
|
|
20
|
-
/**
|
|
21
|
-
* @requires
|
|
22
|
-
* @param adminizer
|
|
23
|
-
* @protected
|
|
24
|
-
*/
|
|
25
|
-
protected constructor(adminizer: Adminizer);
|
|
26
|
-
abstract getConfig(): Config | undefined;
|
|
27
|
-
abstract getJsPath(): string | undefined;
|
|
28
|
-
abstract getCssPath(): string | undefined;
|
|
29
|
-
abstract getName(): string;
|
|
30
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { AbstractMediaManager, MediaManagerItem, File, MediaManagerWidgetData, MediaManagerWidgetClientItem, SortCriteria } from "./AbstractMediaManager";
|
|
2
|
-
import { Adminizer } from "../Adminizer";
|
|
3
|
-
export declare class DefaultMediaManager extends AbstractMediaManager {
|
|
4
|
-
readonly itemTypes: File<MediaManagerItem>[];
|
|
5
|
-
model: string;
|
|
6
|
-
modelAssoc: string;
|
|
7
|
-
id: string;
|
|
8
|
-
protected readonly adminizer: Adminizer;
|
|
9
|
-
constructor(adminizer: Adminizer, id: string, urlPathPrefix: string, fileStoragePath: string);
|
|
10
|
-
private mediaModel;
|
|
11
|
-
private associationModel;
|
|
12
|
-
getAll(limit: number, skip: number, sort: SortCriteria, group: string): Promise<{
|
|
13
|
-
data: MediaManagerItem[];
|
|
14
|
-
next: boolean;
|
|
15
|
-
}>;
|
|
16
|
-
searchAll(s: string, group: string): Promise<MediaManagerItem[]>;
|
|
17
|
-
setRelations(data: MediaManagerWidgetData[], model: string, modelId: string | number, //Updated
|
|
18
|
-
widgetName: string): Promise<void>;
|
|
19
|
-
getRelations(model: string, widgetName: string, modelId: string | number): Promise<MediaManagerWidgetClientItem[]>;
|
|
20
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { AbstractMediaManager, } from "./AbstractMediaManager.js";
|
|
2
|
-
import { populateVariants } from "./helpers/MediaManagerHelper.js";
|
|
3
|
-
import { ApplicationItem, ImageItem, TextItem, VideoItem } from "./Items.js";
|
|
4
|
-
export class DefaultMediaManager extends AbstractMediaManager {
|
|
5
|
-
itemTypes = [];
|
|
6
|
-
model = "mediamanagerap";
|
|
7
|
-
modelAssoc = "mediamanagerassociationsap";
|
|
8
|
-
id;
|
|
9
|
-
adminizer;
|
|
10
|
-
constructor(adminizer, id, urlPathPrefix, fileStoragePath) {
|
|
11
|
-
super(adminizer);
|
|
12
|
-
this.id = id;
|
|
13
|
-
this.urlPathPrefix = urlPathPrefix;
|
|
14
|
-
this.fileStoragePath = fileStoragePath;
|
|
15
|
-
this.itemTypes.push(new ImageItem(adminizer, urlPathPrefix, fileStoragePath));
|
|
16
|
-
this.itemTypes.push(new TextItem(adminizer, urlPathPrefix, fileStoragePath));
|
|
17
|
-
this.itemTypes.push(new ApplicationItem(adminizer, urlPathPrefix, fileStoragePath));
|
|
18
|
-
this.itemTypes.push(new VideoItem(adminizer, urlPathPrefix, fileStoragePath));
|
|
19
|
-
this.adminizer = adminizer;
|
|
20
|
-
}
|
|
21
|
-
mediaModel() {
|
|
22
|
-
return this.adminizer.modelHandler.internal("media-manager").get(this.model);
|
|
23
|
-
}
|
|
24
|
-
associationModel() {
|
|
25
|
-
return this.adminizer.modelHandler.internal("media-manager").get(this.modelAssoc);
|
|
26
|
-
}
|
|
27
|
-
async getAll(limit, skip, sort, group) {
|
|
28
|
-
let data = await this.mediaModel().find({
|
|
29
|
-
where: { parent: null, group: group },
|
|
30
|
-
limit: limit,
|
|
31
|
-
skip: skip,
|
|
32
|
-
sort: sort,
|
|
33
|
-
populate: {
|
|
34
|
-
variants: { sort: sort },
|
|
35
|
-
meta: true
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
let next = await this.mediaModel().find({
|
|
39
|
-
where: { parent: null, group: group },
|
|
40
|
-
limit: limit,
|
|
41
|
-
skip: skip === 0 ? limit : skip + limit,
|
|
42
|
-
sort: sort,
|
|
43
|
-
});
|
|
44
|
-
for (let elem of data) {
|
|
45
|
-
elem.variants = await populateVariants(this.adminizer, elem.variants, this.model);
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
data: data,
|
|
49
|
-
next: !!next.length,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
async searchAll(s, group) {
|
|
53
|
-
let data = await this.mediaModel().find({
|
|
54
|
-
where: { filename: { contains: s }, parent: null, group: group },
|
|
55
|
-
sort: "createdAt DESC",
|
|
56
|
-
// This limitation is made strictly, if your code solves this please make a PR
|
|
57
|
-
limit: 1000,
|
|
58
|
-
populate: {
|
|
59
|
-
variants: { sort: "createdAt DESC" },
|
|
60
|
-
meta: true
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
for (let elem of data) {
|
|
64
|
-
elem.variants = await populateVariants(this.adminizer, elem.variants, this.model);
|
|
65
|
-
}
|
|
66
|
-
return data;
|
|
67
|
-
}
|
|
68
|
-
async setRelations(data, model, modelId, //Updated
|
|
69
|
-
widgetName) {
|
|
70
|
-
if (modelId == null) {
|
|
71
|
-
throw new Error("modelId must be a string or number");
|
|
72
|
-
}
|
|
73
|
-
const modelIdStr = String(modelId); //Normalize to string
|
|
74
|
-
const associationModel = this.associationModel();
|
|
75
|
-
let modelAssociations = await associationModel.find({
|
|
76
|
-
where: {
|
|
77
|
-
modelId: modelIdStr,
|
|
78
|
-
model: model.toLowerCase(),
|
|
79
|
-
widgetName: widgetName,
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
for (const modelAssociation of modelAssociations) {
|
|
83
|
-
const q = {};
|
|
84
|
-
const pk = this.adminizer.modelHandler.model.get(this.modelAssoc).primaryKey;
|
|
85
|
-
q[pk] = modelAssociation.id;
|
|
86
|
-
await associationModel.destroy({ where: q });
|
|
87
|
-
}
|
|
88
|
-
const fieldName = this.adminizer.ormAdapters[0].ormType === 'sequelize' ? 'fileId' : 'file';
|
|
89
|
-
for (const [key, widgetItem] of data.entries()) {
|
|
90
|
-
await associationModel.create({
|
|
91
|
-
mediaManagerId: this.id,
|
|
92
|
-
model: model.toLowerCase(),
|
|
93
|
-
modelId: modelIdStr, //Save as a string
|
|
94
|
-
[fieldName]: widgetItem.id,
|
|
95
|
-
widgetName: widgetName,
|
|
96
|
-
sortOrder: key + 1,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async getRelations(model, widgetName, modelId) {
|
|
101
|
-
if (modelId == null) {
|
|
102
|
-
throw new Error("modelId must be a string or number");
|
|
103
|
-
}
|
|
104
|
-
const modelIdStr = String(modelId); //Normalize to string
|
|
105
|
-
let widgetItems = [];
|
|
106
|
-
const fieldName = this.adminizer.ormAdapters[0].ormType === 'sequelize' ? 'fileRef' : 'file';
|
|
107
|
-
let files = await this.associationModel().find({
|
|
108
|
-
where: {
|
|
109
|
-
model: model.toLowerCase(),
|
|
110
|
-
widgetName: widgetName,
|
|
111
|
-
modelId: modelIdStr, //Search by string
|
|
112
|
-
},
|
|
113
|
-
sort: "sortOrder ASC",
|
|
114
|
-
populate: { [fieldName]: true }
|
|
115
|
-
});
|
|
116
|
-
for (const file of files) {
|
|
117
|
-
widgetItems.push({
|
|
118
|
-
id: file[fieldName].id,
|
|
119
|
-
mimeType: file[fieldName].mimeType,
|
|
120
|
-
filename: file[fieldName].filename,
|
|
121
|
-
url: file[fieldName].url,
|
|
122
|
-
variants: []
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return widgetItems;
|
|
126
|
-
}
|
|
127
|
-
}
|