adminizer 4.6.0 → 4.7.0-build.222
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 +12 -0
- package/assets/RelationDialogStack-CnHFOYyR.css +1 -0
- package/assets/RelationDialogStack-DI2bZxQX.js +20 -0
- package/assets/add-DCQ7ZW4B.js +1 -0
- package/assets/add-group-DCVPryBo.js +1 -0
- package/assets/add-group-form-DKRXC2n-.js +1 -0
- package/assets/add-user-B7OOiYxv.js +1 -0
- package/assets/add-user-form-UXAToWQd.js +1 -0
- package/assets/app-AKbNCggP.css +1 -0
- package/assets/app-layout-6EwNBvnR.js +1 -0
- package/assets/app-shell-D8wtkECO.js +1 -0
- package/assets/app-sidebar-DfGjL-2K.js +1 -0
- package/assets/app-sidebar-header-BZbIBQjq.js +1 -0
- package/assets/app.js +59 -7990
- package/assets/breadcrumbs-CODaqVkB.js +1 -0
- package/assets/catalog-DVvFGa2X.js +6 -0
- package/assets/dashboard-BadoiH_a.js +3 -0
- package/assets/date-picker-DSOkNiNo.js +1 -0
- package/assets/del-modal-Cd4M7af8.js +1 -0
- package/assets/dynamic-controls-BsrJhPDY.js +1 -0
- package/assets/geo-json-CzR5JBXL.js +1 -0
- package/assets/handsontable-BI98OF5R.js +336 -0
- package/assets/history-D1iLA6rs.js +1 -0
- package/assets/home-DbWj-W_k.js +2 -0
- package/assets/icon-C2JNaLxH.js +1 -0
- package/assets/init-user-D2HSyXup.js +1 -0
- package/assets/input-error-CH2caTtO.js +1 -0
- package/assets/jsoneditor-DVNQmA6G.js +3869 -0
- package/assets/list-CVoljVUw.js +4 -0
- package/assets/login-DFSLEO17.js +1 -0
- package/assets/manifest.json +246 -273
- package/assets/material-icon-Bx9pGQiQ.js +1 -0
- package/assets/media-manager-WcKe1EvD.js +6 -0
- package/assets/module-DJsC37CM.js +1 -0
- package/assets/monaco-Bl4zdWCn.js +11 -0
- package/assets/nav-footer-BiSQkPt4.js +1 -0
- package/assets/nav-main-rTH0PfDw.js +1 -0
- package/assets/nav-user-Bj6cWs0a.js +1 -0
- package/assets/notification-DKrNfaAB.js +20 -0
- package/assets/pagination-render-AKJvTIRA.js +1 -0
- package/assets/register-BTP4uxsK.js +1 -0
- package/assets/ru-eW0WKkga.js +1 -0
- package/assets/theme-switcher-Dm8EOGzx.js +1 -0
- package/assets/toast-editor-DOg_gvSp.js +668 -0
- package/assets/user-filters-list-C9R9J6Om.js +1 -0
- package/assets/user-info-BgSbT02v.js +1 -0
- package/assets/user-menu-content-TQTXHIv6.js +1 -0
- package/assets/{vanilla-picker-l5rcX3cq.js → vanilla-picker-B3LgXoKV.js} +1 -7
- package/assets/welcome-BwDlAOGh.js +1 -0
- package/controllers/add.d.ts +1 -1
- package/controllers/add.js +20 -26
- package/controllers/addGroup.d.ts +1 -1
- package/controllers/addGroup.js +7 -15
- package/controllers/addUser.d.ts +1 -1
- package/controllers/addUser.js +10 -16
- package/controllers/catalog/Catalog.d.ts +1 -1
- package/controllers/catalog/Catalog.js +1 -10
- package/controllers/catalog/FrontendCatalogAdapter.d.ts +3 -3
- package/controllers/catalog/FrontendCatalogAdapter.js +0 -6
- package/controllers/catalog/FrontentCatalogAdapter.d.ts +3 -3
- package/controllers/catalog/FrontentCatalogAdapter.js +0 -4
- package/controllers/ckeditorUpload.js +2 -18
- package/controllers/dashboard.d.ts +1 -1
- package/controllers/dashboard.js +2 -5
- package/controllers/edit.js +24 -37
- package/controllers/editGroup.d.ts +1 -1
- package/controllers/editGroup.js +10 -21
- package/controllers/editUser.d.ts +1 -1
- package/controllers/editUser.js +11 -23
- package/controllers/exportData.d.ts +6 -0
- package/controllers/exportData.js +315 -0
- package/controllers/feed.d.ts +6 -0
- package/controllers/feed.js +73 -0
- package/controllers/feedback/feedbackController.d.ts +1 -1
- package/controllers/feedback/feedbackController.js +5 -7
- package/controllers/filter-fields/columns.d.ts +11 -0
- package/controllers/filter-fields/columns.js +106 -0
- package/controllers/filter-fields/filterFields.d.ts +10 -0
- package/controllers/filter-fields/filterFields.js +141 -0
- package/controllers/filter-fields/getAllUserFilters.d.ts +6 -0
- package/controllers/filter-fields/getAllUserFilters.js +115 -0
- package/controllers/filter-fields/groups.d.ts +5 -0
- package/controllers/filter-fields/groups.js +26 -0
- package/controllers/filter-fields/savedFilters.d.ts +25 -0
- package/controllers/filter-fields/savedFilters.js +317 -0
- package/controllers/getAllWidgets.d.ts +1 -1
- package/controllers/getAllWidgets.js +1 -9
- package/controllers/history-actions/HistoryController.js +6 -31
- package/controllers/initUser.js +6 -5
- package/controllers/inlineUpdate.d.ts +7 -0
- package/controllers/inlineUpdate.js +148 -0
- package/controllers/list.d.ts +1 -1
- package/controllers/list.js +383 -70
- package/controllers/listUserFilters.d.ts +5 -0
- package/controllers/listUserFilters.js +26 -0
- package/controllers/login.js +2 -2
- package/controllers/media-manager/mediaManagerApi.js +0 -9
- package/controllers/navigation/edit.js +3 -9
- package/controllers/notifications/NotificationController.d.ts +1 -1
- package/controllers/notifications/NotificationController.js +12 -36
- package/controllers/register.js +10 -9
- package/controllers/remove.js +10 -19
- package/controllers/timezones.d.ts +1 -1
- package/controllers/timezones.js +0 -6
- package/controllers/userApiKey.d.ts +7 -0
- package/controllers/userApiKey.js +36 -0
- package/controllers/view.js +14 -26
- package/controllers/welcome.d.ts +1 -1
- package/controllers/welcome.js +0 -4
- package/controllers/widgets/Action.d.ts +1 -1
- package/controllers/widgets/Action.js +1 -9
- package/controllers/widgets/Custom.d.ts +1 -1
- package/controllers/widgets/Custom.js +1 -9
- package/controllers/widgets/Info.d.ts +1 -1
- package/controllers/widgets/Info.js +1 -9
- package/controllers/widgets/filterInfo.d.ts +1 -0
- package/controllers/widgets/filterInfo.js +44 -0
- package/controllers/widgets/switch.d.ts +1 -1
- package/controllers/widgets/switch.js +1 -9
- package/controllers/widgetsDB.d.ts +1 -1
- package/controllers/widgetsDB.js +2 -8
- package/helpers/accessRightsHelper.d.ts +1 -1
- package/helpers/accessRightsHelper.js +5 -4
- package/helpers/apiKeyHelper.d.ts +5 -0
- package/helpers/apiKeyHelper.js +8 -0
- package/helpers/configHelper.js +12 -15
- package/helpers/controllerHelper.d.ts +14 -21
- package/helpers/controllerHelper.js +50 -83
- package/helpers/fieldsHelper.js +3 -3
- package/helpers/filterDatetimeHelper.d.ts +5 -0
- package/helpers/filterDatetimeHelper.js +84 -0
- package/helpers/inertiaActionsHelper.d.ts +2 -2
- package/helpers/inertiaActionsHelper.js +5 -4
- package/helpers/inertiaAddHelper.d.ts +3 -414
- package/helpers/inertiaAddHelper.js +39 -15
- package/helpers/inertiaGroupHelper.d.ts +2 -2
- package/helpers/inertiaGroupHelper.js +3 -3
- package/helpers/inertiaListHelper.d.ts +7 -3
- package/helpers/inertiaListHelper.js +26 -12
- package/helpers/inertiaMenuHelper.d.ts +1 -0
- package/helpers/inertiaMenuHelper.js +15 -3
- package/helpers/inertiaUserHelper.d.ts +3 -2
- package/helpers/inertiaUserHelper.js +7 -3
- package/helpers/menuHelper.d.ts +5 -2
- package/helpers/menuHelper.js +64 -12
- package/helpers/viteHelper.js +1 -2
- package/index.d.ts +6 -2
- package/index.js +6 -2
- package/interfaces/adminpanelConfig.d.ts +126 -39
- package/interfaces/internalModelAccess.d.ts +37 -0
- package/interfaces/internalModelAccess.js +1 -0
- package/interfaces/listQueryBuilder.d.ts +22 -0
- package/interfaces/listQueryBuilder.js +1 -0
- package/interfaces/queryCriteria.d.ts +54 -0
- package/interfaces/queryCriteria.js +1 -0
- package/interfaces/types.d.ts +1 -13
- package/lib/Adminizer.d.ts +4 -2
- package/lib/Adminizer.js +29 -10
- package/lib/DataAccessor.d.ts +8 -5
- package/lib/DataAccessor.js +89 -42
- package/lib/I18n.d.ts +5 -1
- package/lib/I18n.js +45 -19
- package/lib/MiddlewareManager.d.ts +8 -0
- package/lib/MiddlewareManager.js +53 -0
- package/lib/ai-assistant/OpenAiModelService.d.ts +3 -3
- package/lib/ai-assistant/OpenAiModelService.js +23 -24
- package/lib/catalog/Navigation.d.ts +1 -0
- package/lib/catalog/Navigation.js +12 -11
- package/lib/controls/jsoneditor/JsonEditor.d.ts +1 -2
- package/lib/controls/markdown/ToastUiEditor.d.ts +1 -2
- package/lib/feedback/FeedbackHandler.js +2 -2
- package/lib/filters/ConditionValidator.d.ts +107 -0
- package/lib/filters/ConditionValidator.js +483 -0
- package/lib/filters/CustomFilterHandler.d.ts +122 -0
- package/lib/filters/CustomFilterHandler.js +131 -0
- package/lib/filters/FilterCustomFieldHandler.d.ts +2 -0
- package/lib/filters/FilterCustomFieldHandler.js +2 -0
- package/lib/filters/FilterService.d.ts +82 -0
- package/lib/filters/FilterService.js +323 -0
- package/lib/filters/index.d.ts +6 -0
- package/lib/filters/index.js +4 -0
- package/lib/history-actions/AbstractHistoryAdapter.d.ts +5 -4
- package/lib/history-actions/AbstractHistoryAdapter.js +45 -30
- package/lib/history-actions/DefaultHistoryAdapter.d.ts +2 -0
- package/lib/history-actions/DefaultHistoryAdapter.js +12 -6
- package/lib/history-actions/HistoryHandler.js +1 -1
- package/lib/list-query-builder/ListQueryBuilder.d.ts +117 -0
- package/lib/list-query-builder/ListQueryBuilder.js +707 -0
- package/lib/media-manager/AbstractMediaManager.d.ts +9 -8
- package/lib/media-manager/DefaultMediaManager.d.ts +2 -0
- package/lib/media-manager/DefaultMediaManager.js +27 -15
- package/lib/media-manager/Items.d.ts +4 -1
- package/lib/media-manager/Items.js +62 -59
- package/lib/media-manager/MediaManagerHandler.js +1 -1
- package/lib/media-manager/helpers/MediaManagerHelper.d.ts +5 -1
- package/lib/media-manager/helpers/MediaManagerHelper.js +38 -4
- package/lib/model/AbstractModel.d.ts +33 -25
- package/lib/model/AbstractModel.js +54 -2
- package/lib/model/InternalModelAccessFactory.d.ts +18 -0
- package/lib/model/InternalModelAccessFactory.js +82 -0
- package/lib/model/ModelHandler.d.ts +6 -0
- package/lib/model/ModelHandler.js +14 -0
- package/lib/model/adapter/sequelize.d.ts +32 -10
- package/lib/model/adapter/sequelize.js +409 -62
- package/lib/model/adapter/typeorm.d.ts +62 -0
- package/lib/model/adapter/typeorm.js +777 -0
- package/lib/model/internalModelAccessToken.d.ts +1 -0
- package/lib/model/internalModelAccessToken.js +1 -0
- package/lib/model/internalModelRepository.d.ts +3 -0
- package/lib/model/internalModelRepository.js +4 -0
- package/lib/notifications/AbstractNotificationService.d.ts +3 -0
- package/lib/notifications/AbstractNotificationService.js +42 -36
- package/lib/notifications/GeneralNotificationService.js +37 -40
- package/lib/notifications/SystemNotificationService.js +33 -36
- package/lib/requestProcessor.js +0 -3
- package/lib/ui-i18n/getUiTranslations.d.ts +1 -0
- package/lib/ui-i18n/getUiTranslations.js +3 -0
- package/lib/ui-i18n/uiTranslationKeys.d.ts +6 -0
- package/lib/ui-i18n/uiTranslationKeys.js +268 -0
- package/lib/widgets/widgetHandler.d.ts +7 -2
- package/lib/widgets/widgetHandler.js +98 -18
- package/models/FilterAP.d.ts +116 -0
- package/models/FilterAP.js +68 -0
- package/models/FilterColumnAP.d.ts +32 -0
- package/models/FilterColumnAP.js +21 -0
- package/models/GroupAP.d.ts +1 -1
- package/models/HistoryActionsAP.d.ts +3 -3
- package/models/MediaManagerMetaAP.d.ts +1 -1
- package/models/NavigationAP.d.ts +1 -1
- package/models/UserAP.d.ts +6 -1
- package/models/UserAP.js +4 -0
- package/package.json +39 -32
- package/policies/authPolicies.d.ts +12 -0
- package/policies/authPolicies.js +104 -0
- package/policies/permissionResolvers.d.ts +12 -0
- package/policies/permissionResolvers.js +52 -0
- package/services/FeedService.d.ts +70 -0
- package/services/FeedService.js +334 -0
- package/system/Router.d.ts +1 -0
- package/system/Router.js +136 -59
- package/system/bindAccessRights.js +11 -30
- package/system/bindAuthorization.js +18 -18
- package/system/bindCors.js +16 -1
- package/system/bindCustomFilterHandlers.d.ts +2 -0
- package/system/bindCustomFilterHandlers.js +4 -0
- package/system/bindInertia.js +18 -61
- package/system/bindReqFunctions.js +10 -2
- package/system/bindTranslations.js +7 -3
- package/system/buildInternalModelAccess.d.ts +4 -0
- package/system/buildInternalModelAccess.js +59 -0
- package/system/defaults.js +18 -14
- package/system/routePolicies.d.ts +2 -0
- package/system/routePolicies.js +29 -0
- package/translations/en.json +151 -39
- package/translations/ru.json +211 -64
- package/ui/components/handsontable.js +13 -27
- package/ui/components/ui/dialog-stack.js +1 -3
- package/ui/components/ui/popover.js +1 -1
- package/ui/components/ui/sidebar.js +1 -1
- package/assets/RelationDialogStack-D9UVEF9s.js +0 -407
- package/assets/RelationDialogStack-DV8OITPR.css +0 -4
- package/assets/add-BlvzWQKF.js +0 -1
- package/assets/add-group-1Uoq9NWe.js +0 -1
- package/assets/add-group-form-B01gwDGu.js +0 -1
- package/assets/add-user-BQCAsaRy.js +0 -1
- package/assets/add-user-form-Cgwc9JkI.js +0 -1
- package/assets/app-DaOMy1nl.css +0 -72
- package/assets/app-layout-CAm60qoE.js +0 -1
- package/assets/app-shell-QWCtn9ye.js +0 -1
- package/assets/app-sidebar-CfaYbnSy.js +0 -1
- package/assets/app-sidebar-header-BsPFDhZ8.js +0 -1
- package/assets/breadcrumbs-CZZirDj8.js +0 -1
- package/assets/catalog-k5myk7fk.js +0 -6
- package/assets/dashboard-BkL9ybBw.js +0 -3
- package/assets/date-picker-B5AZ_7Q9.js +0 -1
- package/assets/del-modal-BoyXZloG.js +0 -1
- package/assets/dynamic-controls-k61T9W2P.js +0 -1
- package/assets/form-1WGY0YgG.js +0 -1
- package/assets/form-DJapG3qF.js +0 -1
- package/assets/geo-json-DsMUHo0l.js +0 -4
- package/assets/handsontable-PxYdjN8c.js +0 -298
- package/assets/history-CluyR-yJ.js +0 -1
- package/assets/home-Dug9zBzM.js +0 -2
- package/assets/icon-DfDLMG5f.js +0 -1
- package/assets/init-user-CF80MEnT.js +0 -1
- package/assets/input-error-DuuqFgZa.js +0 -1
- package/assets/jsoneditor-De1FvcYu.js +0 -3882
- package/assets/list-CuexshNt.js +0 -1
- package/assets/list-table-BsEWjTKY.js +0 -22
- package/assets/login-eDemYzN-.js +0 -1
- package/assets/material-icon-DMT8KdmE.js +0 -1
- package/assets/media-manager-DfYa_mT_.js +0 -14
- package/assets/module-Cd4Tm6uq.js +0 -1
- package/assets/monaco-BhBYtg3d.js +0 -11
- package/assets/nav-footer-D3olYxtz.js +0 -1
- package/assets/nav-main-BctqyzeV.js +0 -1
- package/assets/nav-user-Bn1Lt-BZ.js +0 -1
- package/assets/notification-D64qvni-.js +0 -27
- package/assets/pagination-render-DxD78ahJ.js +0 -1
- package/assets/register-349PwYbe.js +0 -1
- package/assets/theme-switcher-DfExsHW2.js +0 -1
- package/assets/toast-editor-ESK5iWPx.js +0 -845
- package/assets/user-info-DtBK5Kh8.js +0 -1
- package/assets/user-menu-content-0XYOCMaA.js +0 -1
- package/assets/welcome-PDp-gUei.js +0 -1
- package/controllers/form.d.ts +0 -1
- package/controllers/form.js +0 -86
- package/helpers/formHelper.d.ts +0 -6
- package/helpers/formHelper.js +0 -38
- package/helpers/inertiaFromHelper.d.ts +0 -11
- package/helpers/inertiaFromHelper.js +0 -98
- package/helpers/runtimeMode.d.ts +0 -1
- package/helpers/runtimeMode.js +0 -3
- package/lib/PolicyManager.d.ts +0 -8
- package/lib/PolicyManager.js +0 -53
- package/lib/datatable/NodeTable.d.ts +0 -49
- package/lib/datatable/NodeTable.js +0 -207
- package/lib/model/adapter/waterline.d.ts +0 -32
- package/lib/model/adapter/waterline.js +0 -180
- package/migrations/index.d.ts +0 -3
- package/migrations/index.js +0 -4
- package/migrations/knex/20250106000001_adminizer_init.d.ts +0 -8
- package/migrations/knex/20250106000001_adminizer_init.js +0 -164
- package/migrations/umzug/0001.d.ts +0 -7
- package/migrations/umzug/0001.js +0 -121
- package/migrations/umzugExports.d.ts +0 -2
- package/migrations/umzugExports.js +0 -9
- package/system/bindForms.d.ts +0 -2
- package/system/bindForms.js +0 -20
- /package/{policies → middlewares}/addMessages.d.ts +0 -0
- /package/{policies → middlewares}/addMessages.js +0 -0
- /package/{policies → middlewares}/checkAuth.d.ts +0 -0
- /package/{policies → middlewares}/checkAuth.js +0 -0
- /package/{policies → middlewares}/setLocale.d.ts +0 -0
- /package/{policies → middlewares}/setLocale.js +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Adminizer } from "../Adminizer";
|
|
2
|
+
import { MediaManagerMetaAP } from "../../models/MediaManagerMetaAP";
|
|
2
3
|
export interface MediaManagerItem {
|
|
3
|
-
id
|
|
4
|
-
parent: string;
|
|
5
|
-
variants
|
|
4
|
+
id?: string;
|
|
5
|
+
parent: string | null;
|
|
6
|
+
variants?: MediaManagerItem[];
|
|
6
7
|
mimeType: string;
|
|
7
8
|
path: string;
|
|
8
9
|
size: number;
|
|
@@ -13,9 +14,9 @@ export interface MediaManagerItem {
|
|
|
13
14
|
group?: string;
|
|
14
15
|
url: string;
|
|
15
16
|
filename: string;
|
|
16
|
-
meta
|
|
17
|
-
createdAt
|
|
18
|
-
updatedAt
|
|
17
|
+
meta?: MediaManagerMetaAP[];
|
|
18
|
+
createdAt?: number;
|
|
19
|
+
updatedAt?: number;
|
|
19
20
|
}
|
|
20
21
|
type NumericKeys<T> = {
|
|
21
22
|
[K in keyof T]: T[K] extends number ? K : never;
|
|
@@ -121,7 +122,7 @@ export declare abstract class File<T extends MediaManagerItem> {
|
|
|
121
122
|
}>;
|
|
122
123
|
abstract search(s: string, group?: string): Promise<MediaManagerItem[]>;
|
|
123
124
|
abstract getOrigin(id: string): Promise<string>;
|
|
124
|
-
abstract getFile(id: number): Promise<MediaManagerItem>;
|
|
125
|
+
abstract getFile(id: number | string): Promise<MediaManagerItem>;
|
|
125
126
|
}
|
|
126
127
|
/**
|
|
127
128
|
*
|
|
@@ -250,7 +251,7 @@ export declare abstract class AbstractMediaManager {
|
|
|
250
251
|
value: string;
|
|
251
252
|
}[]>;
|
|
252
253
|
getOrigin(id: string): Promise<string>;
|
|
253
|
-
getFile(mimeType: string, id: number): Promise<MediaManagerItem>;
|
|
254
|
+
getFile(mimeType: string, id: number | string): Promise<MediaManagerItem>;
|
|
254
255
|
/**
|
|
255
256
|
* Set metadata of an item.
|
|
256
257
|
* @param item
|
|
@@ -7,6 +7,8 @@ export declare class DefaultMediaManager extends AbstractMediaManager {
|
|
|
7
7
|
id: string;
|
|
8
8
|
protected readonly adminizer: Adminizer;
|
|
9
9
|
constructor(adminizer: Adminizer, id: string, urlPathPrefix: string, fileStoragePath: string);
|
|
10
|
+
private mediaModel;
|
|
11
|
+
private associationModel;
|
|
10
12
|
getAll(limit: number, skip: number, sort: SortCriteria, group: string): Promise<{
|
|
11
13
|
data: MediaManagerItem[];
|
|
12
14
|
next: boolean;
|
|
@@ -18,15 +18,24 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
18
18
|
this.itemTypes.push(new VideoItem(adminizer, urlPathPrefix, fileStoragePath));
|
|
19
19
|
this.adminizer = adminizer;
|
|
20
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
|
+
}
|
|
21
27
|
async getAll(limit, skip, sort, group) {
|
|
22
|
-
|
|
23
|
-
let data = await this.adminizer.modelHandler.model.get(this.model)["_find"]({
|
|
28
|
+
let data = await this.mediaModel().find({
|
|
24
29
|
where: { parent: null, group: group },
|
|
25
30
|
limit: limit,
|
|
26
31
|
skip: skip,
|
|
27
32
|
sort: sort,
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
populate: {
|
|
34
|
+
variants: { sort: sort },
|
|
35
|
+
meta: true
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
let next = await this.mediaModel().find({
|
|
30
39
|
where: { parent: null, group: group },
|
|
31
40
|
limit: limit,
|
|
32
41
|
skip: skip === 0 ? limit : skip + limit,
|
|
@@ -41,14 +50,15 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
41
50
|
};
|
|
42
51
|
}
|
|
43
52
|
async searchAll(s, group) {
|
|
44
|
-
|
|
45
|
-
let data = await this.adminizer.modelHandler.model.get(this.model)["_find"]({
|
|
53
|
+
let data = await this.mediaModel().find({
|
|
46
54
|
where: { filename: { contains: s }, parent: null, group: group },
|
|
47
55
|
sort: "createdAt DESC",
|
|
48
|
-
}, {
|
|
49
|
-
populate: [["variants", { sort: "createdAt DESC" }], ["meta", {}]],
|
|
50
56
|
// This limitation is made strictly, if your code solves this please make a PR
|
|
51
|
-
limit: 1000
|
|
57
|
+
limit: 1000,
|
|
58
|
+
populate: {
|
|
59
|
+
variants: { sort: "createdAt DESC" },
|
|
60
|
+
meta: true
|
|
61
|
+
}
|
|
52
62
|
});
|
|
53
63
|
for (let elem of data) {
|
|
54
64
|
elem.variants = await populateVariants(this.adminizer, elem.variants, this.model);
|
|
@@ -61,7 +71,8 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
61
71
|
throw new Error("modelId must be a string or number");
|
|
62
72
|
}
|
|
63
73
|
const modelIdStr = String(modelId); //Normalize to string
|
|
64
|
-
|
|
74
|
+
const associationModel = this.associationModel();
|
|
75
|
+
let modelAssociations = await associationModel.find({
|
|
65
76
|
where: {
|
|
66
77
|
modelId: modelIdStr,
|
|
67
78
|
model: model.toLowerCase(),
|
|
@@ -72,11 +83,11 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
72
83
|
const q = {};
|
|
73
84
|
const pk = this.adminizer.modelHandler.model.get(this.modelAssoc).primaryKey;
|
|
74
85
|
q[pk] = modelAssociation.id;
|
|
75
|
-
await
|
|
86
|
+
await associationModel.destroy({ where: q });
|
|
76
87
|
}
|
|
77
88
|
const fieldName = this.adminizer.ormAdapters[0].ormType === 'sequelize' ? 'fileId' : 'file';
|
|
78
89
|
for (const [key, widgetItem] of data.entries()) {
|
|
79
|
-
await
|
|
90
|
+
await associationModel.create({
|
|
80
91
|
mediaManagerId: this.id,
|
|
81
92
|
model: model.toLowerCase(),
|
|
82
93
|
modelId: modelIdStr, //Save as a string
|
|
@@ -93,14 +104,15 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
93
104
|
const modelIdStr = String(modelId); //Normalize to string
|
|
94
105
|
let widgetItems = [];
|
|
95
106
|
const fieldName = this.adminizer.ormAdapters[0].ormType === 'sequelize' ? 'fileRef' : 'file';
|
|
96
|
-
let files = await this.
|
|
107
|
+
let files = await this.associationModel().find({
|
|
97
108
|
where: {
|
|
98
109
|
model: model.toLowerCase(),
|
|
99
110
|
widgetName: widgetName,
|
|
100
111
|
modelId: modelIdStr, //Search by string
|
|
101
112
|
},
|
|
102
|
-
sort: "sortOrder ASC"
|
|
103
|
-
|
|
113
|
+
sort: "sortOrder ASC",
|
|
114
|
+
populate: { [fieldName]: true }
|
|
115
|
+
});
|
|
104
116
|
for (const file of files) {
|
|
105
117
|
widgetItems.push({
|
|
106
118
|
id: file[fieldName].id,
|
|
@@ -9,6 +9,9 @@ export declare class ImageItem extends File<MediaManagerItem> {
|
|
|
9
9
|
imageSizes: any;
|
|
10
10
|
protected readonly adminizer: Adminizer;
|
|
11
11
|
constructor(adminizer: Adminizer, urlPathPrefix: string, fileStoragePath: string);
|
|
12
|
+
protected mediaModel(): import("../..").InternalModelRepository<MediaManagerItem>;
|
|
13
|
+
protected metaRepository(): import("../..").InternalModelRepository<any>;
|
|
14
|
+
protected associationModel(): import("../..").InternalModelRepository<any>;
|
|
12
15
|
getItems(limit: number, skip: number, sort: SortCriteria, group: string): Promise<{
|
|
13
16
|
data: MediaManagerItem[];
|
|
14
17
|
next: boolean;
|
|
@@ -18,7 +21,7 @@ export declare class ImageItem extends File<MediaManagerItem> {
|
|
|
18
21
|
getVariants(id: string): Promise<MediaManagerItem[]>;
|
|
19
22
|
protected createVariants(file: UploaderFile, parent: MediaManagerItem, filename: string, group: string): Promise<void>;
|
|
20
23
|
getOrigin(id: string): Promise<string>;
|
|
21
|
-
getFile(id: number): Promise<MediaManagerItem>;
|
|
24
|
+
getFile(id: number | string): Promise<MediaManagerItem>;
|
|
22
25
|
protected createMeta(id: string): Promise<void>;
|
|
23
26
|
protected addFileMeta(file: string, id: string): Promise<void>;
|
|
24
27
|
getMeta(id: string): Promise<{
|
|
@@ -17,15 +17,27 @@ export class ImageItem extends File {
|
|
|
17
17
|
this.imageSizes = adminizer.config.mediamanager.imageSizes || {};
|
|
18
18
|
this.adminizer = adminizer;
|
|
19
19
|
}
|
|
20
|
+
mediaModel() {
|
|
21
|
+
return this.adminizer.modelHandler.internal("media-manager").get(this.model);
|
|
22
|
+
}
|
|
23
|
+
metaRepository() {
|
|
24
|
+
return this.adminizer.modelHandler.internal("media-manager").get(this.metaModel);
|
|
25
|
+
}
|
|
26
|
+
associationModel() {
|
|
27
|
+
return this.adminizer.modelHandler.internal("media-manager").get(this.modelAssoc);
|
|
28
|
+
}
|
|
20
29
|
async getItems(limit, skip, sort, group) {
|
|
21
|
-
|
|
22
|
-
let data = await this.adminizer.modelHandler.model.get(this.model)["_find"]({
|
|
30
|
+
let data = await this.mediaModel().find({
|
|
23
31
|
where: { parent: null, mimeType: { contains: this.type }, group: group },
|
|
24
32
|
limit: limit,
|
|
25
33
|
skip: skip,
|
|
26
34
|
sort: sort,
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
populate: {
|
|
36
|
+
variants: { sort: sort },
|
|
37
|
+
meta: true
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
let next = await this.mediaModel().find({
|
|
29
41
|
where: { parent: null, mimeType: { contains: this.type }, group: group },
|
|
30
42
|
limit: limit,
|
|
31
43
|
skip: skip === 0 ? limit : skip + limit,
|
|
@@ -40,19 +52,20 @@ export class ImageItem extends File {
|
|
|
40
52
|
};
|
|
41
53
|
}
|
|
42
54
|
async search(s, group) {
|
|
43
|
-
|
|
44
|
-
let data = await this.adminizer.modelHandler.model.get(this.model)["_find"]({
|
|
55
|
+
let data = await this.mediaModel().find({
|
|
45
56
|
where: { filename: { contains: s }, mimeType: { contains: this.type }, parent: null, group: group },
|
|
46
57
|
sort: "createdAt DESC",
|
|
47
|
-
|
|
58
|
+
populate: {
|
|
59
|
+
variants: { sort: "createdAt DESC" }
|
|
60
|
+
}
|
|
61
|
+
});
|
|
48
62
|
for (let elem of data) {
|
|
49
63
|
elem.variants = await populateVariants(this.adminizer, elem.variants, this.model);
|
|
50
64
|
}
|
|
51
65
|
return data;
|
|
52
66
|
}
|
|
53
67
|
async upload(file, filename, origFileName, group) {
|
|
54
|
-
|
|
55
|
-
let parent = await this.adminizer.modelHandler.model.get(this.model)["_create"]({
|
|
68
|
+
let parent = await this.mediaModel().create({
|
|
56
69
|
parent: null,
|
|
57
70
|
mimeType: file.mimetype,
|
|
58
71
|
size: file.size,
|
|
@@ -68,16 +81,17 @@ export class ImageItem extends File {
|
|
|
68
81
|
if (Object.keys(this.imageSizes).length && file.mimetype !== 'image/svg+xml') {
|
|
69
82
|
await this.createVariants(file, parent, filename, group);
|
|
70
83
|
}
|
|
71
|
-
|
|
72
|
-
const item = await this.adminizer.modelHandler.model.get(this.model)["_findOne"]({ where: { id: parent.id } });
|
|
84
|
+
const item = await this.mediaModel().findOne({ where: { id: parent.id } });
|
|
73
85
|
item.variants = await populateVariants(this.adminizer, item.variants, this.model);
|
|
74
86
|
return [item];
|
|
75
87
|
}
|
|
76
88
|
async getVariants(id) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
let items = ((await this.mediaModel().find({
|
|
90
|
+
where: { id: id },
|
|
91
|
+
populate: {
|
|
92
|
+
variants: { sort: "createdAt DESC" }
|
|
93
|
+
}
|
|
94
|
+
}))[0]).variants;
|
|
81
95
|
return (await populateVariants(this.adminizer, items, this.model));
|
|
82
96
|
}
|
|
83
97
|
async createVariants(file, parent, filename, group) {
|
|
@@ -90,8 +104,7 @@ export class ImageItem extends File {
|
|
|
90
104
|
continue;
|
|
91
105
|
const output = `${this.fileStoragePath}/${this.urlPathPrefix}/${sizeName}`;
|
|
92
106
|
let newFile = await this.resizeImage(file.path, output, width, height);
|
|
93
|
-
|
|
94
|
-
let newSize = await this.adminizer.modelHandler.model.get(this.model)["_create"]({
|
|
107
|
+
let newSize = await this.mediaModel().create({
|
|
95
108
|
parent: parent.id,
|
|
96
109
|
mimeType: parent.mimeType,
|
|
97
110
|
size: newFile.size,
|
|
@@ -105,11 +118,10 @@ export class ImageItem extends File {
|
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
120
|
async getOrigin(id) {
|
|
108
|
-
|
|
109
|
-
return (await this.adminizer.modelHandler.model.get(this.model)["_findOne"]({ where: { id: id } })).path;
|
|
121
|
+
return (await this.mediaModel().findOne({ where: { id: id } })).path;
|
|
110
122
|
}
|
|
111
123
|
async getFile(id) {
|
|
112
|
-
let item = await this.
|
|
124
|
+
let item = await this.mediaModel().findOne({ where: { id: String(id) } });
|
|
113
125
|
item.variants = await populateVariants(this.adminizer, item.variants, this.model);
|
|
114
126
|
return item;
|
|
115
127
|
}
|
|
@@ -121,8 +133,7 @@ export class ImageItem extends File {
|
|
|
121
133
|
title: "",
|
|
122
134
|
};
|
|
123
135
|
for (const key of Object.keys(metaData)) {
|
|
124
|
-
|
|
125
|
-
await this.adminizer.modelHandler.model.get(this.metaModel)["_create"]({
|
|
136
|
+
await this.metaRepository().create({
|
|
126
137
|
key: key,
|
|
127
138
|
value: metaData[key],
|
|
128
139
|
parent: id,
|
|
@@ -131,9 +142,8 @@ export class ImageItem extends File {
|
|
|
131
142
|
}
|
|
132
143
|
}
|
|
133
144
|
async addFileMeta(file, id) {
|
|
134
|
-
// TODO refactor CRUD functions for DataAccessor usage
|
|
135
145
|
const metaBuffer = fs.readFileSync(file);
|
|
136
|
-
await this.
|
|
146
|
+
await this.metaRepository().create({
|
|
137
147
|
key: 'imageSizes',
|
|
138
148
|
value: sizeOf(metaBuffer),
|
|
139
149
|
parent: id,
|
|
@@ -142,15 +152,16 @@ export class ImageItem extends File {
|
|
|
142
152
|
}
|
|
143
153
|
// TODO {where: {isPublic: true}, sort: "id ASC"} ???
|
|
144
154
|
async getMeta(id) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
155
|
+
return ((await this.mediaModel().find({
|
|
156
|
+
where: { id: id },
|
|
157
|
+
populate: {
|
|
158
|
+
meta: { where: { isPublic: true } }
|
|
159
|
+
}
|
|
160
|
+
}))[0]).meta;
|
|
149
161
|
}
|
|
150
162
|
async setMeta(id, data) {
|
|
151
163
|
for (const key of Object.keys(data)) {
|
|
152
|
-
|
|
153
|
-
await this.adminizer.modelHandler.model.get(this.metaModel)["_update"]({ parent: id, key: key }, { value: data[key] });
|
|
164
|
+
await this.metaRepository().update({ where: { parent: id, key: key } }, { value: data[key] });
|
|
154
165
|
}
|
|
155
166
|
}
|
|
156
167
|
async resizeImage(input, output, width, height) {
|
|
@@ -168,8 +179,7 @@ export class ImageItem extends File {
|
|
|
168
179
|
async uploadVariant(parent, file, filename, group, localeId) {
|
|
169
180
|
const variantBuffer = fs.readFileSync(file.path);
|
|
170
181
|
const { width, height } = sizeOf(variantBuffer);
|
|
171
|
-
|
|
172
|
-
let item = await this.adminizer.modelHandler.model.get(this.model)["_create"]({
|
|
182
|
+
let item = await this.mediaModel().create({
|
|
173
183
|
parent: parent.id,
|
|
174
184
|
mimeType: file.mimetype,
|
|
175
185
|
size: file.size,
|
|
@@ -180,21 +190,18 @@ export class ImageItem extends File {
|
|
|
180
190
|
url: `/${this.urlPathPrefix}/${filename}`,
|
|
181
191
|
});
|
|
182
192
|
await this.addFileMeta(file.path, item.id);
|
|
183
|
-
|
|
184
|
-
return (await this.adminizer.modelHandler.model.get(this.model)["_findOne"]({ where: { id: item.id } }));
|
|
193
|
+
return (await this.mediaModel().findOne({ where: { id: item.id } }));
|
|
185
194
|
}
|
|
186
195
|
async delete(id) {
|
|
187
196
|
const fieldName = this.adminizer.ormAdapters[0].ormType === 'sequelize' ? 'fileId' : 'file';
|
|
188
|
-
const assoc = await this.
|
|
197
|
+
const assoc = await this.associationModel().find({ where: { [fieldName]: id } });
|
|
189
198
|
if (assoc.length) {
|
|
190
199
|
return Promise.resolve(false);
|
|
191
200
|
}
|
|
192
201
|
const criteria = { where: { id: id } };
|
|
193
|
-
|
|
194
|
-
let record = await this.adminizer.modelHandler.model.get(this.model)["_findOne"](criteria);
|
|
202
|
+
let record = await this.mediaModel().findOne(criteria);
|
|
195
203
|
await beforeDestroy(this.adminizer, criteria);
|
|
196
|
-
|
|
197
|
-
await this.adminizer.modelHandler.model.get(this.model)["_destroy"]({ id: id });
|
|
204
|
+
await this.mediaModel().destroy({ where: { id: id } });
|
|
198
205
|
await deleteFile(record.path);
|
|
199
206
|
// Delete all variants
|
|
200
207
|
if (record.variants.length) {
|
|
@@ -211,8 +218,7 @@ export class ImageItem extends File {
|
|
|
211
218
|
export class TextItem extends ImageItem {
|
|
212
219
|
type = "text";
|
|
213
220
|
async upload(file, filename, origFileName, group) {
|
|
214
|
-
|
|
215
|
-
let parent = await this.adminizer.modelHandler.model.get(this.model)["_create"]({
|
|
221
|
+
let parent = await this.mediaModel().create({
|
|
216
222
|
parent: null,
|
|
217
223
|
mimeType: file.mimetype,
|
|
218
224
|
size: file.size,
|
|
@@ -223,8 +229,7 @@ export class TextItem extends ImageItem {
|
|
|
223
229
|
url: `/${this.urlPathPrefix}/${filename}`,
|
|
224
230
|
});
|
|
225
231
|
await this.createMeta(parent.id);
|
|
226
|
-
|
|
227
|
-
const item = await this.adminizer.modelHandler.model.get(this.model)["_findOne"]({ where: { id: parent.id } });
|
|
232
|
+
const item = await this.mediaModel().findOne({ where: { id: parent.id } });
|
|
228
233
|
item.variants = await populateVariants(this.adminizer, item.variants, this.model);
|
|
229
234
|
return [item];
|
|
230
235
|
}
|
|
@@ -233,8 +238,7 @@ export class TextItem extends ImageItem {
|
|
|
233
238
|
}
|
|
234
239
|
async uploadVariant(parent, file, filename, group, localeId) {
|
|
235
240
|
let variants = parent.variants.filter(e => /^loc:/.test(e.tag) === false);
|
|
236
|
-
|
|
237
|
-
let item = await this.adminizer.modelHandler.model.get(this.model)["_create"]({
|
|
241
|
+
let item = await this.mediaModel().create({
|
|
238
242
|
parent: parent.id,
|
|
239
243
|
mimeType: file.mimetype,
|
|
240
244
|
size: file.size,
|
|
@@ -244,14 +248,15 @@ export class TextItem extends ImageItem {
|
|
|
244
248
|
filename: parent.filename,
|
|
245
249
|
url: `/${this.urlPathPrefix}/${filename}`,
|
|
246
250
|
});
|
|
247
|
-
|
|
248
|
-
return (await this.adminizer.modelHandler.model.get(this.model)["_findOne"]({ where: { id: item.id } }));
|
|
251
|
+
return (await this.mediaModel().findOne({ where: { id: item.id } }));
|
|
249
252
|
}
|
|
250
253
|
async getVariants(id) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
254
|
+
let items = ((await this.mediaModel().find({
|
|
255
|
+
where: { id: id },
|
|
256
|
+
populate: {
|
|
257
|
+
variants: { sort: "createdAt DESC" }
|
|
258
|
+
}
|
|
259
|
+
}))[0]).variants;
|
|
255
260
|
return (await populateVariants(this.adminizer, items, this.model));
|
|
256
261
|
}
|
|
257
262
|
}
|
|
@@ -262,18 +267,16 @@ export class VideoItem extends TextItem {
|
|
|
262
267
|
type = "video";
|
|
263
268
|
}
|
|
264
269
|
async function beforeDestroy(adminizer, criteria) {
|
|
265
|
-
|
|
266
|
-
|
|
270
|
+
const mediaModel = adminizer.modelHandler.internal("media-manager").get("MediaManagerAP");
|
|
271
|
+
const metaModel = adminizer.modelHandler.internal("media-manager").get("MediaManagerMetaAP");
|
|
272
|
+
let parent = (await mediaModel.find(criteria))[0];
|
|
267
273
|
let meta = parent.meta;
|
|
268
274
|
for (const metaElement of meta) {
|
|
269
|
-
|
|
270
|
-
await adminizer.modelHandler.model.get("MediaManagerMetaAP")?.["_destroy"]({ id: metaElement.id });
|
|
275
|
+
await metaModel.destroy({ where: { id: metaElement.id } });
|
|
271
276
|
}
|
|
272
|
-
|
|
273
|
-
let variants = (await adminizer.modelHandler.model.get("MediaManagerAP")?.["_find"](criteria))[0].variants;
|
|
277
|
+
let variants = (await mediaModel.find(criteria))[0].variants;
|
|
274
278
|
for (const child of variants) {
|
|
275
|
-
|
|
276
|
-
await adminizer.modelHandler.model.get("MediaManagerAP")?.["_destroy"]({ id: child.id });
|
|
279
|
+
await mediaModel.destroy({ where: { id: child.id } });
|
|
277
280
|
}
|
|
278
281
|
}
|
|
279
282
|
async function deleteFile(file) {
|
|
@@ -15,7 +15,7 @@ export class MediaManagerHandler {
|
|
|
15
15
|
if (!instance) {
|
|
16
16
|
Adminizer.log.debug(`MediaManager with id ${id} not found`);
|
|
17
17
|
}
|
|
18
|
-
Adminizer.log.debug(`ins`, instance)
|
|
18
|
+
// Adminizer.log.debug(`ins`, instance) // DEBUG: removed to reduce console noise
|
|
19
19
|
return instance;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Fields } from "../../../helpers/fieldsHelper";
|
|
2
2
|
import { MediaManagerWidgetData, MediaManagerItem, MediaManagerWidgetItem, MediaManagerWidgetJSON } from "../AbstractMediaManager";
|
|
3
|
+
import { BaseFieldConfig } from "../../../interfaces/adminpanelConfig";
|
|
3
4
|
import { Adminizer } from "../../Adminizer";
|
|
4
5
|
type PostParams = Record<string, string | number | boolean | object | string[] | number[] | null>;
|
|
6
|
+
export declare function isMediaManagerFieldConfig(fieldConfig: BaseFieldConfig): boolean;
|
|
5
7
|
export declare function normalizeMediaManagerWidgetData(value: PostParams[string] | undefined, prop: string): MediaManagerWidgetData[];
|
|
6
8
|
export declare function detachMediaManagerField(reqData: PostParams, rawReqData: PostParams, prop: string): void;
|
|
7
9
|
/**
|
|
@@ -19,7 +21,9 @@ export declare function randomFileName(filenameOrig: string, type: string, prefi
|
|
|
19
21
|
* @param model
|
|
20
22
|
* @param recordId
|
|
21
23
|
*/
|
|
22
|
-
export declare function saveRelationsMediaManager(adminizer: Adminizer, fields: Fields, reqData: PostParams, model: string, recordId: number): Promise<void>;
|
|
24
|
+
export declare function saveRelationsMediaManager(adminizer: Adminizer, fields: Fields, reqData: PostParams, model: string, recordId: string | number): Promise<void>;
|
|
25
|
+
export declare function collectMediaManagerHistoryData(fields: Fields, reqData: PostParams): Record<string, MediaManagerWidgetData[]>;
|
|
26
|
+
export declare function updateCurrentHistoryMediaManagerData(adminizer: Adminizer, fields: Fields, reqData: PostParams, model: string, recordId: string | number): Promise<void>;
|
|
23
27
|
/**
|
|
24
28
|
* Get realtions
|
|
25
29
|
* @param adminizer
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export function isMediaManagerFieldConfig(fieldConfig) {
|
|
2
|
+
return fieldConfig.type === 'mediamanager' || fieldConfig.type === 'single-file';
|
|
3
|
+
}
|
|
1
4
|
export function normalizeMediaManagerWidgetData(value, prop) {
|
|
2
5
|
if (value === undefined || value === null || value === "") {
|
|
3
6
|
return [];
|
|
@@ -51,13 +54,44 @@ export async function saveRelationsMediaManager(adminizer, fields, reqData, mode
|
|
|
51
54
|
for (let prop in reqData) {
|
|
52
55
|
let fieldConfigConfig = fields[prop].config;
|
|
53
56
|
let options = fieldConfigConfig.options;
|
|
54
|
-
if (fieldConfigConfig
|
|
57
|
+
if (isMediaManagerFieldConfig(fieldConfigConfig)) {
|
|
55
58
|
const data = normalizeMediaManagerWidgetData(reqData[prop], prop);
|
|
56
59
|
let mediaManager = adminizer.mediaManagerHandler.get(options?.id ?? 'default');
|
|
57
60
|
await mediaManager.setRelations(data, model, recordId, prop);
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
}
|
|
64
|
+
export function collectMediaManagerHistoryData(fields, reqData) {
|
|
65
|
+
const data = {};
|
|
66
|
+
for (let prop in reqData) {
|
|
67
|
+
const field = fields[prop];
|
|
68
|
+
if (!field)
|
|
69
|
+
continue;
|
|
70
|
+
const fieldConfigConfig = field.config;
|
|
71
|
+
if (!isMediaManagerFieldConfig(fieldConfigConfig))
|
|
72
|
+
continue;
|
|
73
|
+
data[prop] = normalizeMediaManagerWidgetData(reqData[prop], prop);
|
|
74
|
+
}
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
export async function updateCurrentHistoryMediaManagerData(adminizer, fields, reqData, model, recordId) {
|
|
78
|
+
if (!adminizer.config.history?.enabled)
|
|
79
|
+
return;
|
|
80
|
+
const mediaData = collectMediaManagerHistoryData(fields, reqData);
|
|
81
|
+
if (!Object.keys(mediaData).length)
|
|
82
|
+
return;
|
|
83
|
+
const historyModel = adminizer.modelHandler.internal("history").get("HistoryActionsAP");
|
|
84
|
+
const currentHistory = await historyModel.findOne({
|
|
85
|
+
where: {
|
|
86
|
+
modelId: String(recordId),
|
|
87
|
+
modelName: model.toLowerCase(),
|
|
88
|
+
isCurrent: true
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
if (!currentHistory)
|
|
92
|
+
return;
|
|
93
|
+
await historyModel.update({ where: { id: currentHistory.id } }, { data: { ...(currentHistory.data ?? {}), ...mediaData } });
|
|
94
|
+
}
|
|
61
95
|
/**
|
|
62
96
|
* Get realtions
|
|
63
97
|
* @param adminizer
|
|
@@ -79,7 +113,7 @@ export async function deleteRelationsMediaManager(adminizer, model, record) {
|
|
|
79
113
|
let config = adminizer.config.models[model];
|
|
80
114
|
for (const key of Object.keys(record[0])) {
|
|
81
115
|
let field = config.fields[key];
|
|
82
|
-
if (field && field
|
|
116
|
+
if (field && isMediaManagerFieldConfig(field)) {
|
|
83
117
|
const option = field.options;
|
|
84
118
|
let mediaManager = adminizer.mediaManagerHandler.get(option?.id ?? 'default');
|
|
85
119
|
let emptyData = [];
|
|
@@ -94,9 +128,9 @@ export async function deleteRelationsMediaManager(adminizer, model, record) {
|
|
|
94
128
|
*/
|
|
95
129
|
export async function populateVariants(adminizer, variants, model) {
|
|
96
130
|
let items = [];
|
|
131
|
+
const mediaModel = adminizer.modelHandler.internal("media-manager").get(model);
|
|
97
132
|
for (let variant of variants) {
|
|
98
|
-
|
|
99
|
-
variant = await adminizer.modelHandler.model.get(model)["_findOne"]({ where: { id: variant.id } });
|
|
133
|
+
variant = await mediaModel.findOne({ where: { id: variant.id } });
|
|
100
134
|
items.push(variant);
|
|
101
135
|
}
|
|
102
136
|
return items;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataAccessor } from "../DataAccessor";
|
|
2
|
-
import
|
|
2
|
+
import { QueryCriteria } from "../../interfaces/queryCriteria";
|
|
3
|
+
import { InternalModelRepository } from "../../interfaces/internalModelAccess";
|
|
3
4
|
export interface Attribute {
|
|
4
5
|
type: 'association' | 'association-many' | 'number' | 'json' | 'string' | 'boolean' | 'ref';
|
|
5
6
|
required?: boolean;
|
|
@@ -24,14 +25,6 @@ export type ModelAnyField = number | string | boolean | Date | Array<number | st
|
|
|
24
25
|
export type ModelAnyInstance = {
|
|
25
26
|
[key: string]: ModelAnyField;
|
|
26
27
|
};
|
|
27
|
-
type PopulateOption = [string, {
|
|
28
|
-
sort?: string;
|
|
29
|
-
where?: any;
|
|
30
|
-
}];
|
|
31
|
-
export interface FindOptions {
|
|
32
|
-
populate?: PopulateOption[];
|
|
33
|
-
limit?: number;
|
|
34
|
-
}
|
|
35
28
|
export declare abstract class AbstractModel<T> {
|
|
36
29
|
readonly modelname: string;
|
|
37
30
|
readonly attributes: ModelAttributes;
|
|
@@ -39,13 +32,14 @@ export declare abstract class AbstractModel<T> {
|
|
|
39
32
|
readonly identity: string;
|
|
40
33
|
protected constructor(modelname: string, attributes: ModelAttributes, primaryKey: string, identity: string);
|
|
41
34
|
protected abstract _create(data: Partial<T>): Promise<T>;
|
|
42
|
-
protected abstract _findOne(criteria:
|
|
43
|
-
protected abstract _find(criteria:
|
|
44
|
-
protected abstract _updateOne(criteria:
|
|
45
|
-
protected abstract _update(criteria:
|
|
46
|
-
protected abstract _destroyOne(criteria:
|
|
47
|
-
protected abstract _destroy(criteria:
|
|
48
|
-
protected abstract _count(criteria:
|
|
35
|
+
protected abstract _findOne(criteria: QueryCriteria<T>): Promise<T | null>;
|
|
36
|
+
protected abstract _find(criteria: QueryCriteria<T>): Promise<T[]>;
|
|
37
|
+
protected abstract _updateOne(criteria: QueryCriteria<T>, data: Partial<T>): Promise<T | null>;
|
|
38
|
+
protected abstract _update(criteria: QueryCriteria<T>, data: Partial<T>): Promise<T[]>;
|
|
39
|
+
protected abstract _destroyOne(criteria: QueryCriteria<T>): Promise<T | null>;
|
|
40
|
+
protected abstract _destroy(criteria: QueryCriteria<T>): Promise<T[]>;
|
|
41
|
+
protected abstract _count(criteria: QueryCriteria<T>): Promise<number>;
|
|
42
|
+
protected createInternalRepository(accessToken: symbol, modelName?: string): InternalModelRepository<T>;
|
|
49
43
|
/**
|
|
50
44
|
* Generate diff between old and new records
|
|
51
45
|
*/
|
|
@@ -60,13 +54,28 @@ export declare abstract class AbstractModel<T> {
|
|
|
60
54
|
*/
|
|
61
55
|
private logSystemEvent;
|
|
62
56
|
create(data: T, dataAccessor: DataAccessor): Promise<Partial<T>>;
|
|
63
|
-
findOne(criteria:
|
|
64
|
-
find(criteria:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
findOne(criteria: QueryCriteria<T>, dataAccessor: DataAccessor): Promise<Partial<T> | null>;
|
|
58
|
+
find(criteria: QueryCriteria<T>, dataAccessor: DataAccessor): Promise<Partial<T>[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Find with raw SQL where clause (Sequelize.literal support)
|
|
61
|
+
* Only available in Sequelize adapter
|
|
62
|
+
*/
|
|
63
|
+
findWithRawWhere(where: any, options?: {
|
|
64
|
+
limit?: number;
|
|
65
|
+
offset?: number;
|
|
66
|
+
order?: any;
|
|
67
|
+
populate?: boolean;
|
|
68
|
+
}): Promise<any[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Count with raw SQL where clause (Sequelize.literal support)
|
|
71
|
+
* Only available in Sequelize adapter
|
|
72
|
+
*/
|
|
73
|
+
countWithRawWhere(where: any): Promise<number>;
|
|
74
|
+
updateOne(criteria: QueryCriteria<T>, data: Partial<T>, dataAccessor: DataAccessor): Promise<Partial<T> | null>;
|
|
75
|
+
update(criteria: QueryCriteria<T>, data: Partial<T>, dataAccessor: DataAccessor): Promise<Partial<T>[]>;
|
|
76
|
+
destroyOne(criteria: QueryCriteria<T>, dataAccessor: DataAccessor): Promise<Partial<T> | null>;
|
|
77
|
+
destroy(criteria: QueryCriteria<T>, dataAccessor: DataAccessor): Promise<Partial<T>[]>;
|
|
78
|
+
count(criteria: QueryCriteria<T>, dataAccessor: DataAccessor): Promise<number>;
|
|
70
79
|
}
|
|
71
80
|
export declare abstract class AbstractAdapter {
|
|
72
81
|
abstract Model: any;
|
|
@@ -75,7 +84,7 @@ export declare abstract class AbstractAdapter {
|
|
|
75
84
|
protected constructor(type: string, orm: any);
|
|
76
85
|
abstract get models(): Record<string, any>;
|
|
77
86
|
/** This function should return constant type from any adapter (for adminizer proper work) */
|
|
78
|
-
abstract getAttributes(modelName: string):
|
|
87
|
+
abstract getAttributes(modelName: string): ModelAttributes | undefined;
|
|
79
88
|
/** Return full model object */
|
|
80
89
|
abstract getModel(modelName: string): any;
|
|
81
90
|
/**
|
|
@@ -83,4 +92,3 @@ export declare abstract class AbstractAdapter {
|
|
|
83
92
|
*/
|
|
84
93
|
static registerSystemModels(orm: any): void;
|
|
85
94
|
}
|
|
86
|
-
export {};
|