adminizer 5.0.0-build.2 → 5.0.0-build.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/abnfDiagram-VCTEODGH-CkmsvdDi.js +1 -0
- package/assets/add-CESPH_aI.js +1 -0
- package/assets/add-group-CQ4Xm8Ru.js +1 -0
- package/assets/add-user-B-QNjR4B.js +1 -0
- package/assets/ai-assistant/agent.es.js +28362 -0
- package/assets/app-C5Ju5Zra.css +1 -0
- package/assets/app-Ca5yUSBv.js +138 -0
- package/assets/arc-B-Dt8YNl.js +1 -0
- package/assets/architectureDiagram-5GKGNRK7-Ca58kq-l.js +36 -0
- package/assets/asmcrypto-DZeQH0LC.js +1 -0
- package/assets/blockDiagram-NRAW4CY4-CuqE52IG.js +129 -0
- package/assets/c4Diagram-UCG6FXSJ-Cx8z-0Bw.js +38 -0
- package/assets/catalog-CkSbxvx0.js +6 -0
- package/assets/channel-C9z6Pi_j.js +1 -0
- package/assets/chunk-2Q5K7J3B-CXISVKTC.js +1 -0
- package/assets/chunk-5VM5RSS4-DYGeeVYe.js +15 -0
- package/assets/chunk-F27PBJKO-BeY-dbKj.js +1 -0
- package/assets/chunk-G27WJ6UU-DeX_eH7C.js +231 -0
- package/assets/chunk-JWPE2WC7-DaxI9q0u.js +1 -0
- package/assets/chunk-LCL6LL3I-B7PkaEz_.js +206 -0
- package/assets/chunk-POPQ4Y6H-lwu6ZpsN.js +1 -0
- package/assets/chunk-SVP7TREG-CVFllgl1.js +88 -0
- package/assets/chunk-XXDRQBXY-DDLN0rcg.js +1 -0
- package/assets/classDiagram-DTDB5LWJ-BKtCIC3B.js +1 -0
- package/assets/classDiagram-v2-JRS7N3AN-BKtCIC3B.js +1 -0
- package/assets/controls/ckeditor.es.js +9370 -9306
- package/assets/controls/handsontable.es.js +11971 -11938
- package/assets/controls/jsoneditor.es.js +13104 -13008
- package/assets/controls/leaflet.es.js +1023 -1004
- package/assets/controls/toast-ui.es.js +1843 -1834
- package/assets/cose-bilkent-JH36ORCC-CWRyUkhQ.js +1 -0
- package/assets/cynefin-OW5HDTMX-B1iLDXCC.js +166 -0
- package/assets/cynefinDiagram-5FMLGOSQ-DaXQHr3l.js +62 -0
- package/assets/cytoscape.esm-yzknjiTM.js +321 -0
- package/assets/dagre-3AP2YEHR-DFORa4Hz.js +4 -0
- package/assets/dashboard-Ssa1_Of3.js +3 -0
- package/assets/debounce-B3mXI_sx.js +1 -0
- package/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/assets/diagram-S7CK7UJ4-CgP6KBo0.js +30 -0
- package/assets/diagram-UQ7AKVKN-oYfQe6w0.js +41 -0
- package/assets/diagram-VSXAHHWV-DfCU5wgt.js +3 -0
- package/assets/diagram-VX7I27RA-BITJVrNY.js +24 -0
- package/assets/diagram-Z3DM3KII-D8J9Ssjy.js +24 -0
- package/assets/docs-DHMt_Rq1.js +1 -0
- package/assets/ebnfDiagram-PWID7BFC-qpNmoYgx.js +1 -0
- package/assets/erDiagram-SSCWMZ5O-DDF-Y0zs.js +99 -0
- package/assets/flowDiagram-A5DVABFB-CjKVkR9T.js +168 -0
- package/assets/ganttDiagram-EL5Y4UJY-BXGQ53w6.js +292 -0
- package/assets/gitGraphDiagram-WWUBYQGX-BLMevdLh.js +106 -0
- package/assets/history-tBOo2gd5.js +1 -0
- package/assets/infoDiagram-RXCK75RN-BAnPdnyw.js +2 -0
- package/assets/init-Gi6I4Gst.js +1 -0
- package/assets/init-user-DrNUHa6r.js +1 -0
- package/assets/isObject-DL-BuaBl.js +1 -0
- package/assets/ishikawaDiagram-5VMMS53U-PnL0Z4Li.js +70 -0
- package/assets/journeyDiagram-EYS64GPL-CLcsCSwF.js +139 -0
- package/assets/kanban-definition-3QL26DDD-C2eU3uBE.js +89 -0
- package/assets/katex-HP8lGamR.js +257 -0
- package/assets/layout-BXoYdHdx.js +1 -0
- package/assets/linear-BSzrP0oP.js +1 -0
- package/assets/list-CLg6xeIK.js +4 -0
- package/assets/login-Ce7o3-o_.js +1 -0
- package/assets/manifest.json +834 -58
- package/assets/{media-manager-BDbpSSjH.js → media-manager-D7G1P3fz.js} +3 -3
- package/assets/mermaid.core-aKMJHeEk.js +310 -0
- package/assets/mindmap-definition-FBJOCRG2-Dzbz5ghA.js +96 -0
- package/assets/module-BsXph_pA.js +1 -0
- package/assets/notification-D-Zz1gF_.js +20 -0
- package/assets/ordinal-Cboi1Yqb.js +1 -0
- package/assets/pegDiagram-XKGWAZYB-BTdWkU0Y.js +1 -0
- package/assets/pieDiagram-E7YTZNPT-Dnw8-TB-.js +39 -0
- package/assets/quadrantDiagram-AXDQQJYC-CALzLlg9.js +7 -0
- package/assets/railroadDiagram-O6MQD6OU-CTA1vzcv.js +1 -0
- package/assets/register-CNnBkzej.js +1 -0
- package/assets/requirementDiagram-EFPCY7ZU-UX2CF5HA.js +84 -0
- package/assets/ru-CoNgAwFK.js +1 -0
- package/assets/sankeyDiagram-P5KCCOFB-4aPp3ATV.js +40 -0
- package/assets/sequenceDiagram-WJ2MYXX4--kltkwJw.js +162 -0
- package/assets/sizeCapture-X5ZJPWSS-Ca9-g5QY.js +1 -0
- package/assets/stateDiagram-HBIQ2CUA-Diaf5Q7I.js +1 -0
- package/assets/stateDiagram-v2-4QOOHH4V-C6FlRp7u.js +1 -0
- package/assets/swimlanes-XN3QIQJK-DhqX_myE.js +1 -0
- package/assets/swimlanesDiagram-VK2B7HYN-i_3LTEBk.js +8 -0
- package/assets/timeline-definition-24CTP7MA-CwkJQbhq.js +120 -0
- package/assets/toNumber-DZb-r9sy.js +1 -0
- package/assets/use-appearance-DC-DESKB.js +1 -0
- package/assets/user-filters-list-W47DTBp2.js +1 -0
- package/assets/vennDiagram-4TSXK5OY-BNM3_cVS.js +34 -0
- package/assets/wardleyDiagram-VM6X3IG4-BODb1NP8.js +78 -0
- package/assets/welcome-BeBm6NIi.js +1 -0
- package/assets/with-app-layout-B90DtzYC.js +31 -0
- package/assets/xychartDiagram-S5SC5T6Z-DthqEh3g.js +7 -0
- package/controllers/access-rights/permissionOptions.d.ts +2 -0
- package/controllers/access-rights/permissionOptions.js +23 -0
- package/controllers/add.js +1 -1
- package/controllers/addGroup.js +15 -6
- package/controllers/ai/AiAgentController.d.ts +66 -0
- package/controllers/ai/AiAgentController.js +435 -0
- package/controllers/ai/AiAssistantController.d.ts +0 -4
- package/controllers/ai/AiAssistantController.js +4 -78
- package/controllers/catalog/FrontendCatalogAdapter.d.ts +1 -1
- package/controllers/catalog/FrontentCatalogAdapter.d.ts +1 -1
- package/controllers/docs/index.d.ts +22 -0
- package/controllers/docs/index.js +126 -0
- package/controllers/edit.js +1 -1
- package/controllers/editGroup.js +15 -6
- package/controllers/feedback/feedbackController.d.ts +1 -1
- package/controllers/filter-fields/savedFilters.js +1 -1
- package/controllers/history-actions/HistoryController.d.ts +1 -1
- package/controllers/history-actions/HistoryController.js +6 -6
- package/controllers/list.js +1 -1
- package/controllers/login.js +1 -1
- package/controllers/media-manager/mediaManagerAdapter.d.ts +1 -1
- package/controllers/notifications/NotificationController.js +14 -8
- package/controllers/view.js +2 -2
- package/controllers/widgets/filterInfo.js +1 -1
- package/helpers/accessRightsHelper.d.ts +11 -4
- package/helpers/accessRightsHelper.js +82 -12
- package/helpers/assetVersionHelper.d.ts +14 -0
- package/helpers/assetVersionHelper.js +42 -0
- package/helpers/configHelper.d.ts +3 -3
- package/helpers/configHelper.js +20 -18
- package/helpers/controllerHelper.d.ts +3 -2
- package/helpers/controllerHelper.js +25 -15
- package/helpers/fieldsHelper.d.ts +2 -2
- package/helpers/fieldsHelper.js +3 -3
- package/helpers/filterDatetimeHelper.d.ts +1 -1
- package/helpers/inertiaActionsHelper.d.ts +3 -3
- package/helpers/inertiaActionsHelper.js +4 -5
- package/helpers/inertiaAddHelper.d.ts +5 -5
- package/helpers/inertiaAddHelper.js +7 -6
- package/helpers/inertiaGroupHelper.d.ts +3 -3
- package/helpers/inertiaGroupHelper.js +10 -2
- package/helpers/inertiaListHelper.d.ts +4 -4
- package/helpers/inertiaListHelper.js +7 -8
- package/helpers/inertiaMenuHelper.d.ts +2 -3
- package/helpers/inertiaMenuHelper.js +3 -26
- package/helpers/inertiaUserHelper.d.ts +3 -3
- package/helpers/menuHelper.d.ts +2 -2
- package/helpers/modelResourceHelper.d.ts +9 -0
- package/helpers/modelResourceHelper.js +43 -0
- package/helpers/navigationAccessHelper.d.ts +13 -0
- package/helpers/navigationAccessHelper.js +40 -0
- package/helpers/translationHelper.d.ts +2 -2
- package/index.d.ts +69 -58
- package/index.js +11 -0
- package/interfaces/adminpanelConfig.d.ts +18 -5
- package/interfaces/global.d.ts +6 -6
- package/interfaces/internalModelAccess.d.ts +1 -1
- package/interfaces/listQueryBuilder.d.ts +1 -1
- package/interfaces/types.d.ts +171 -2
- package/lib/Adminizer.d.ts +46 -26
- package/lib/Adminizer.js +37 -1
- package/lib/DataAccessor.d.ts +7 -6
- package/lib/DataAccessor.js +50 -48
- package/lib/MiddlewareManager.d.ts +1 -1
- package/lib/access-rights/AccessRightsHandler.d.ts +2 -2
- package/lib/admin-links/AdminLinkHandler.d.ts +72 -0
- package/lib/admin-links/AdminLinkHandler.js +175 -0
- package/lib/ai-assistant/AbstractAiConversationHistoryService.d.ts +39 -0
- package/lib/ai-assistant/AbstractAiConversationHistoryService.js +98 -0
- package/lib/ai-assistant/AbstractAiModelService.d.ts +140 -3
- package/lib/ai-assistant/AbstractAiModelService.js +154 -1
- package/lib/ai-assistant/AiAgentRunManager.d.ts +35 -0
- package/lib/ai-assistant/AiAgentRunManager.js +109 -0
- package/lib/ai-assistant/AiAssistantAgentSkillHandler.d.ts +58 -0
- package/lib/ai-assistant/AiAssistantAgentSkillHandler.js +87 -0
- package/lib/ai-assistant/AiAssistantHandler.d.ts +16 -5
- package/lib/ai-assistant/AiAssistantHandler.js +35 -1
- package/lib/ai-assistant/AiAssistantUiMethodHandler.d.ts +60 -0
- package/lib/ai-assistant/AiAssistantUiMethodHandler.js +138 -0
- package/lib/ai-assistant/builtinAgentSkills.d.ts +9 -0
- package/lib/ai-assistant/builtinAgentSkills.js +256 -0
- package/lib/ai-assistant/jsonSafe.d.ts +13 -0
- package/lib/ai-assistant/jsonSafe.js +81 -0
- package/lib/app-manager/AdminizerApp.d.ts +40 -11
- package/lib/app-manager/AppManager.d.ts +2 -2
- package/lib/app-manager/AppManager.js +54 -50
- package/lib/app-manager/AssetHandler.d.ts +2 -2
- package/lib/app-manager/ConfigLayerHandler.d.ts +2 -2
- package/lib/app-manager/ControllerHandler.d.ts +2 -2
- package/lib/catalog/AbstractCatalog.d.ts +1 -1
- package/lib/catalog/CatalogHandler.d.ts +1 -1
- package/lib/controls/ControlsHandler.d.ts +1 -1
- package/lib/controls/codeEditor/MonacoEditor.d.ts +1 -1
- package/lib/controls/geojsoneditor/GeoEditor.d.ts +1 -1
- package/lib/controls/jsoneditor/JsonEditor.d.ts +1 -1
- package/lib/controls/markdown/ToastUiEditor.d.ts +1 -1
- package/lib/controls/table/Handsontable.d.ts +1 -1
- package/lib/controls/wysiwyg/CKeditor.d.ts +1 -1
- package/lib/docs/AbstractDocumentation.d.ts +100 -0
- package/lib/docs/AbstractDocumentation.js +108 -0
- package/lib/docs/DocumentationHandler.d.ts +100 -0
- package/lib/docs/DocumentationHandler.js +198 -0
- package/lib/docs/FileDocumentation.d.ts +47 -0
- package/lib/docs/FileDocumentation.js +189 -0
- package/lib/docs/docsAgentSkills.d.ts +10 -0
- package/lib/docs/docsAgentSkills.js +93 -0
- package/lib/feedback/FeedbackHandler.d.ts +2 -2
- package/lib/filters/ConditionValidator.d.ts +1 -1
- package/lib/filters/FilterCustomFieldHandler.d.ts +2 -2
- package/lib/filters/FilterService.d.ts +4 -4
- package/lib/filters/FilterService.js +4 -3
- package/lib/filters/index.d.ts +6 -6
- package/lib/history-actions/AbstractHistoryAdapter.d.ts +6 -6
- package/lib/history-actions/AbstractHistoryAdapter.js +11 -9
- package/lib/history-actions/DefaultHistoryAdapter.d.ts +4 -4
- package/lib/history-actions/HistoryHandler.d.ts +1 -1
- package/lib/list-query-builder/ListQueryBuilder.d.ts +7 -7
- package/lib/media-manager/AbstractMediaManager.d.ts +2 -2
- package/lib/media-manager/MediaManagerHandler.d.ts +1 -1
- package/lib/media-manager/Thumb.d.ts +1 -1
- package/lib/media-manager/helpers/MediaManagerHelper.d.ts +5 -5
- package/lib/model/AbstractModel.d.ts +11 -4
- package/lib/model/InternalModelAccessFactory.d.ts +2 -2
- package/lib/model/ModelHandler.d.ts +50 -5
- package/lib/model/ModelHandler.js +107 -8
- package/lib/model/adapter/sequelize.d.ts +7 -5
- package/lib/model/adapter/sequelize.js +79 -46
- package/lib/model/adapter/typeorm.d.ts +2 -2
- package/lib/model/adapter/typeorm.js +1 -1
- package/lib/model/internalModelRepository.d.ts +2 -2
- package/lib/notifications/AbstractNotificationService.d.ts +4 -4
- package/lib/notifications/GeneralNotificationService.d.ts +2 -2
- package/lib/notifications/GeneralNotificationService.js +6 -5
- package/lib/notifications/NotificationHandler.d.ts +2 -2
- package/lib/notifications/SystemNotificationService.d.ts +2 -2
- package/lib/notifications/SystemNotificationService.js +1 -1
- package/lib/requestProcessor.d.ts +1 -1
- package/lib/ui-i18n/uiTranslationKeys.d.ts +2 -1
- package/lib/ui-i18n/uiTranslationKeys.js +42 -1
- package/lib/widgets/abstractAction.d.ts +1 -1
- package/lib/widgets/abstractCustom.d.ts +2 -2
- package/lib/widgets/abstractInfo.d.ts +1 -1
- package/lib/widgets/abstractLink.d.ts +2 -2
- package/lib/widgets/abstractSwitch.d.ts +1 -1
- package/lib/widgets/abstractWidgetBase.d.ts +1 -1
- package/lib/widgets/widgetHandler.d.ts +9 -9
- package/lib/widgets/widgetHandler.js +5 -1
- package/models/Filter.d.ts +1 -1
- package/models/FilterColumn.d.ts +1 -1
- package/models/Group.d.ts +3 -2
- package/models/HistoryActions.d.ts +1 -1
- package/models/MediaManagerAP.d.ts +2 -2
- package/models/MediaManagerAssociationsAP.d.ts +1 -1
- package/models/MediaManagerMetaAP.d.ts +1 -1
- package/models/User.d.ts +2 -2
- package/models/UserNotification.d.ts +1 -1
- package/package.json +29 -20
- package/policies/authPolicies.js +6 -6
- package/policies/permissionResolvers.d.ts +1 -0
- package/policies/permissionResolvers.js +3 -0
- package/services/FeedService.d.ts +3 -3
- package/system/Router.d.ts +1 -1
- package/system/Router.js +27 -1
- package/system/bindAccessRights.d.ts +1 -1
- package/system/bindAccessRights.js +2 -3
- package/system/bindAuthorization.d.ts +1 -1
- package/system/bindControls.d.ts +1 -1
- package/system/bindCors.d.ts +1 -1
- package/system/bindCustomFilterHandlers.d.ts +1 -1
- package/system/bindDashboardWidgets.d.ts +1 -1
- package/system/bindDev.d.ts +1 -1
- package/system/bindDocs.d.ts +13 -0
- package/system/bindDocs.js +77 -0
- package/system/bindHistory.d.ts +1 -1
- package/system/bindInertia.d.ts +1 -1
- package/system/bindInertia.js +23 -1
- package/system/bindMediaManager.d.ts +1 -1
- package/system/bindNotifications.d.ts +1 -1
- package/system/bindReqFunctions.d.ts +1 -1
- package/system/bindTranslations.d.ts +1 -1
- package/system/buildInternalModelAccess.d.ts +3 -3
- package/system/buildInternalModelAccess.js +5 -2
- package/system/defaults.d.ts +1 -1
- package/system/routePolicies.d.ts +1 -1
- package/system/systemModelContracts.d.ts +1 -1
- package/system/systemModelContracts.js +11 -7
- package/system/validateSystemModels.d.ts +1 -1
- package/system/validateSystemModels.js +29 -9
- package/assets/add-group-BdHFzKng.js +0 -1
- package/assets/add-p6yGCoZ7.js +0 -1
- package/assets/add-user-CDspCLu4.js +0 -1
- package/assets/app-DNXiApCk.css +0 -1
- package/assets/app-layout-DCr_-JY3.js +0 -1
- package/assets/app.js +0 -138
- package/assets/catalog-XN-_p9TB.js +0 -6
- package/assets/dashboard-CHZO2QFY.js +0 -3
- package/assets/debounce-BMmXVQ06.js +0 -1
- package/assets/history-CQd0FojQ.js +0 -1
- package/assets/init-user-8aUohVDq.js +0 -1
- package/assets/list-PHWgTHsg.js +0 -4
- package/assets/login-CO4laf6m.js +0 -1
- package/assets/module-DVyQtIxm.js +0 -1
- package/assets/notification-B87XG8nQ.js +0 -20
- package/assets/register-DBYIMXGQ.js +0 -1
- package/assets/ru-rYKdQbWF.js +0 -1
- package/assets/use-appearance-_EbbjHTh.js +0 -1
- package/assets/user-filters-list-BRzDbPkx.js +0 -1
- package/assets/welcome-DiXmrTgc.js +0 -1
package/helpers/configHelper.js
CHANGED
|
@@ -34,23 +34,17 @@ export class ConfigHelper {
|
|
|
34
34
|
if (!modelName) {
|
|
35
35
|
throw new Error("Model name is not defined");
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (typeof config.models[modelResourceName] !== "boolean") {
|
|
44
|
-
modelConfig = config.models[modelResourceName];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
});
|
|
37
|
+
const resourceName = this.adminizer.modelHandler.getResourceRecord(modelName)?.name
|
|
38
|
+
?? this.adminizer.modelHandler.resolveResourceByHostModel(modelName);
|
|
39
|
+
const modelConfig = resourceName && typeof this.adminizer.config.models[resourceName] !== "boolean"
|
|
40
|
+
? this.adminizer.config.models[resourceName]
|
|
41
|
+
: undefined;
|
|
42
|
+
const model = resourceName ? this.adminizer.modelHandler.getResource(resourceName) : undefined;
|
|
49
43
|
if (modelConfig && modelConfig.identifierField) {
|
|
50
44
|
return modelConfig.identifierField;
|
|
51
45
|
}
|
|
52
|
-
else if (
|
|
53
|
-
return
|
|
46
|
+
else if (model?.primaryKey) {
|
|
47
|
+
return model.primaryKey;
|
|
54
48
|
}
|
|
55
49
|
else {
|
|
56
50
|
throw new Error("ConfigHelper > Identifier field was not found");
|
|
@@ -87,12 +81,13 @@ export class ConfigHelper {
|
|
|
87
81
|
let displayField;
|
|
88
82
|
try {
|
|
89
83
|
const associatedModelName = config.type === "association"
|
|
90
|
-
? modelField.model
|
|
91
|
-
: modelField.collection
|
|
84
|
+
? modelField.model
|
|
85
|
+
: modelField.collection;
|
|
92
86
|
if (!associatedModelName) {
|
|
93
87
|
throw new Error(`No model/collection defined for association field: ${key}`);
|
|
94
88
|
}
|
|
95
|
-
const
|
|
89
|
+
const resourceName = adminizer.modelHandler.resolveAssociationResource(associatedModelName, modelField.resourceName);
|
|
90
|
+
const associatedModel = resourceName ? adminizer.modelHandler.getResource(resourceName) : undefined;
|
|
96
91
|
if (!associatedModel) {
|
|
97
92
|
throw new Error(`Can not add relations to unloaded models; Config: ${JSON.stringify(config, null, 2)}`);
|
|
98
93
|
}
|
|
@@ -119,6 +114,13 @@ export class ConfigHelper {
|
|
|
119
114
|
*/
|
|
120
115
|
static normalizeConfig(config) {
|
|
121
116
|
const defaultConfig = getDefaultConfig();
|
|
117
|
+
const defaultPrefix = defaultConfig.routePrefix;
|
|
118
|
+
const routePrefix = config.routePrefix ?? defaultPrefix;
|
|
119
|
+
// Built-in navbar links are written against the default prefix, so retarget
|
|
120
|
+
// them whenever the app overrides routePrefix (otherwise they 404).
|
|
121
|
+
const builtinLinks = (defaultConfig.navbar?.additionalLinks || []).map((item) => typeof item.link === 'string' && item.link.startsWith(`${defaultPrefix}/`)
|
|
122
|
+
? { ...item, link: routePrefix + item.link.slice(defaultPrefix.length) }
|
|
123
|
+
: item);
|
|
122
124
|
const mergedConfig = {
|
|
123
125
|
...defaultConfig,
|
|
124
126
|
...config,
|
|
@@ -130,7 +132,7 @@ export class ConfigHelper {
|
|
|
130
132
|
...defaultConfig.navbar,
|
|
131
133
|
...config.navbar,
|
|
132
134
|
additionalLinks: [
|
|
133
|
-
...
|
|
135
|
+
...builtinLinks,
|
|
134
136
|
...(config.navbar?.additionalLinks || [])
|
|
135
137
|
]
|
|
136
138
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ModelResource } from "../interfaces/types";
|
|
2
|
-
import { ActionType, CreateUpdateConfig, ModelConfig } from "../interfaces/adminpanelConfig";
|
|
1
|
+
import { ModelResource } from "../interfaces/types.js";
|
|
2
|
+
import { ActionType, CreateUpdateConfig, ModelConfig } from "../interfaces/adminpanelConfig.js";
|
|
3
3
|
/**
|
|
4
4
|
* @deprecated need refactor actions
|
|
5
5
|
*/
|
|
@@ -51,6 +51,7 @@ export declare class ControllerHelper {
|
|
|
51
51
|
* @returns {?string}
|
|
52
52
|
*/
|
|
53
53
|
static findModelResourceName(req: ReqType): string;
|
|
54
|
+
private static resolveConfiguredResourceName;
|
|
54
55
|
/**
|
|
55
56
|
* Searches for config from admin panel
|
|
56
57
|
*
|
|
@@ -89,19 +89,27 @@ export class ControllerHelper {
|
|
|
89
89
|
* @returns {?string}
|
|
90
90
|
*/
|
|
91
91
|
static findModelResourceName(req) {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
const models = req.adminizer.config.models;
|
|
93
|
+
const requestedName = req.params.modelResourceName
|
|
94
|
+
?? req.params.model
|
|
95
|
+
?? req.originalUrl.split('/')[3];
|
|
96
|
+
return this.resolveConfiguredResourceName(models, requestedName);
|
|
97
|
+
}
|
|
98
|
+
static resolveConfiguredResourceName(models, requestedName) {
|
|
99
|
+
if (!models || !requestedName) {
|
|
100
|
+
throw new Error(`Model "${requestedName}" not found`);
|
|
94
101
|
}
|
|
95
|
-
if (
|
|
96
|
-
return
|
|
102
|
+
if (Object.prototype.hasOwnProperty.call(models, requestedName)) {
|
|
103
|
+
return requestedName;
|
|
97
104
|
}
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
const candidates = Object.keys(models).filter((key) => key.toLowerCase() === requestedName.toLowerCase());
|
|
106
|
+
if (candidates.length === 1) {
|
|
107
|
+
return candidates[0];
|
|
108
|
+
}
|
|
109
|
+
if (candidates.length > 1) {
|
|
110
|
+
throw new Error(`Model resource "${requestedName}" is ambiguous: ${candidates.join(", ")}`);
|
|
103
111
|
}
|
|
104
|
-
|
|
112
|
+
throw new Error(`Model "${requestedName}" not found`);
|
|
105
113
|
}
|
|
106
114
|
/**
|
|
107
115
|
* Searches for config from admin panel
|
|
@@ -116,12 +124,14 @@ export class ControllerHelper {
|
|
|
116
124
|
Adminizer.log.error('No models configuration found');
|
|
117
125
|
return null;
|
|
118
126
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
127
|
+
try {
|
|
128
|
+
const foundKey = this.resolveConfiguredResourceName(models, modelResourceName);
|
|
129
|
+
return this._normalizeModelConfig(foundKey, models[foundKey]);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
Adminizer.log.error(error);
|
|
122
133
|
return null;
|
|
123
134
|
}
|
|
124
|
-
return this._normalizeModelConfig(foundKey, models[foundKey]);
|
|
125
135
|
}
|
|
126
136
|
/**
|
|
127
137
|
* Will get action config from configuration file depending to given action
|
|
@@ -197,7 +207,7 @@ export class ControllerHelper {
|
|
|
197
207
|
modelResource.config = this.findModelConfig(req, modelResourceName);
|
|
198
208
|
// Find and add the model itself to the ModelResource
|
|
199
209
|
if (this._isValidModelConfig(modelResource.config)) {
|
|
200
|
-
modelResource.model = req.adminizer.modelHandler.
|
|
210
|
+
modelResource.model = req.adminizer.modelHandler.getResource(modelResourceName);
|
|
201
211
|
}
|
|
202
212
|
// Return the completed ModelResource object
|
|
203
213
|
return modelResource;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ActionType, BaseFieldConfig, FieldsTypes, ModelConfig } from "../interfaces/adminpanelConfig";
|
|
2
|
-
import { Attribute } from "../lib/model/AbstractModel";
|
|
1
|
+
import { ActionType, BaseFieldConfig, FieldsTypes, ModelConfig } from "../interfaces/adminpanelConfig.js";
|
|
2
|
+
import { Attribute } from "../lib/model/AbstractModel.js";
|
|
3
3
|
export type Field = {
|
|
4
4
|
config: BaseFieldConfig & {
|
|
5
5
|
/** @deprecated record should not be in config anymore */
|
package/helpers/fieldsHelper.js
CHANGED
|
@@ -30,9 +30,9 @@ export class FieldsHelper {
|
|
|
30
30
|
Adminizer.log.error('No model found for field: ', fields[key]);
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
const resolvedModelName = req.adminizer.modelHandler.
|
|
34
|
-
let Model = req.adminizer.modelHandler.
|
|
35
|
-
if (!Model) {
|
|
33
|
+
const resolvedModelName = req.adminizer.modelHandler.resolveAssociationResource(modelName, fields[key].model.resourceName);
|
|
34
|
+
let Model = resolvedModelName ? req.adminizer.modelHandler.getResource(resolvedModelName) : undefined;
|
|
35
|
+
if (!Model || !resolvedModelName) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
let list;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ModelResource } from "../interfaces/types";
|
|
2
|
-
import { ActionType } from "../interfaces/adminpanelConfig";
|
|
1
|
+
import { ModelResource } from "../interfaces/types.js";
|
|
2
|
+
import { ActionType } from "../interfaces/adminpanelConfig.js";
|
|
3
3
|
export interface Actions {
|
|
4
4
|
link: string;
|
|
5
5
|
id: string;
|
|
@@ -7,4 +7,4 @@ export interface Actions {
|
|
|
7
7
|
title: string;
|
|
8
8
|
icon: string;
|
|
9
9
|
}
|
|
10
|
-
export default function inertiaActionsHelper(actionType: ActionType, modelResource: ModelResource, req: ReqType): Actions[]
|
|
10
|
+
export default function inertiaActionsHelper(actionType: ActionType, modelResource: ModelResource, req: ReqType): Promise<Actions[]>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export default function inertiaActionsHelper(actionType, modelResource, req) {
|
|
1
|
+
export default async function inertiaActionsHelper(actionType, modelResource, req) {
|
|
2
2
|
let resActions = [];
|
|
3
3
|
if (req.adminizer.menuHelper.hasGlobalActions(modelResource.config, actionType)) {
|
|
4
4
|
const actions = req.adminizer.menuHelper.getGlobalActions(modelResource.config, actionType);
|
|
5
5
|
if (actions && actions.length > 0) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (req.adminizer.accessRightsHelper.hasPermission(action.accessRightsToken, req.user, context)) {
|
|
6
|
+
for (const action of actions) {
|
|
7
|
+
if (await req.adminizer.accessRightsHelper.hasPermission(action.accessRightsToken, req.user)) {
|
|
9
8
|
resActions.push({
|
|
10
9
|
link: action.link,
|
|
11
10
|
id: action.id,
|
|
@@ -14,7 +13,7 @@ export default function inertiaActionsHelper(actionType, modelResource, req) {
|
|
|
14
13
|
icon: action.icon
|
|
15
14
|
});
|
|
16
15
|
}
|
|
17
|
-
}
|
|
16
|
+
}
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
return resActions;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ModelResource, PropsField } from "../interfaces/types";
|
|
2
|
-
import { Actions } from "./inertiaActionsHelper";
|
|
3
|
-
import { Fields, Field } from "./fieldsHelper";
|
|
4
|
-
import { Control, ControlType } from "../lib/controls/Control";
|
|
1
|
+
import { ModelResource, PropsField } from "../interfaces/types.js";
|
|
2
|
+
import { Actions } from "./inertiaActionsHelper.js";
|
|
3
|
+
import { Fields, Field } from "./fieldsHelper.js";
|
|
4
|
+
import { Control, ControlType } from "../lib/controls/Control.js";
|
|
5
5
|
export type PropsFieldType = 'text' | 'number' | 'range' | 'week' | 'month' | 'email' | 'color' | 'time' | 'date' | 'datetime-local' | 'password' | 'select' | 'select-many' | 'association-many' | 'association' | 'textarea' | 'mediamanager' | 'single-file' | 'checkbox' | ControlType;
|
|
6
6
|
interface FieldProps extends Record<string | number | symbol, unknown> {
|
|
7
7
|
edit: boolean;
|
|
@@ -23,7 +23,7 @@ interface FieldProps extends Record<string | number | symbol, unknown> {
|
|
|
23
23
|
postLink: string;
|
|
24
24
|
model: string;
|
|
25
25
|
}
|
|
26
|
-
export default function inertiaAddHelper(req: ReqType, modelResource: ModelResource, fields: Fields, record?: Record<string, string | boolean | number | string[]>, view?: boolean): FieldProps
|
|
26
|
+
export default function inertiaAddHelper(req: ReqType, modelResource: ModelResource, fields: Fields, record?: Record<string, string | boolean | number | string[]>, view?: boolean): Promise<FieldProps>;
|
|
27
27
|
export declare function getControlsOptions(fieldConfig: Field["config"], req: ReqType, type: ControlType, defaultControlName: string, context?: string): {
|
|
28
28
|
name: string;
|
|
29
29
|
config: any;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import inertiaActionsHelper from "./inertiaActionsHelper.js";
|
|
2
2
|
import { isObject } from "./JsUtils.js";
|
|
3
|
+
import { withAssetVersion } from "./assetVersionHelper.js";
|
|
3
4
|
import { Adminizer } from "../lib/Adminizer.js";
|
|
4
5
|
const missingControlWarnings = new Set();
|
|
5
6
|
/**
|
|
@@ -14,7 +15,7 @@ function getWeekNumber(date) {
|
|
|
14
15
|
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
|
15
16
|
return Math.ceil((((d.getTime() - yearStart.getTime()) / 86400000) + 1) / 7);
|
|
16
17
|
}
|
|
17
|
-
export default function inertiaAddHelper(req, modelResource, fields, record, view = false) {
|
|
18
|
+
export default async function inertiaAddHelper(req, modelResource, fields, record, view = false) {
|
|
18
19
|
const actionType = 'add';
|
|
19
20
|
let props = {
|
|
20
21
|
edit: !!record,
|
|
@@ -36,7 +37,7 @@ export default function inertiaAddHelper(req, modelResource, fields, record, vie
|
|
|
36
37
|
postLink: record ? `${modelResource.uri}/edit/${record.id}` : `${modelResource.uri}/add`,
|
|
37
38
|
model: modelResource.name.toLocaleLowerCase()
|
|
38
39
|
};
|
|
39
|
-
props.actions = inertiaActionsHelper(actionType, modelResource, req);
|
|
40
|
+
props.actions = await inertiaActionsHelper(actionType, modelResource, req);
|
|
40
41
|
const config = req.adminizer.configHelper.getConfig();
|
|
41
42
|
for (const key of Object.keys(fields)) {
|
|
42
43
|
if ((!config.showORMtime) && (key === 'createdAt' || key === 'updatedAt'))
|
|
@@ -62,7 +63,7 @@ export default function inertiaAddHelper(req, modelResource, fields, record, vie
|
|
|
62
63
|
let canCreateRelated = false;
|
|
63
64
|
const controlContext = `${modelResource.name}.${key}`;
|
|
64
65
|
//@ts-ignore TODO: fix field type
|
|
65
|
-
if (
|
|
66
|
+
if (req.adminizer.configHelper.isId(field, modelResource.name)) {
|
|
66
67
|
disabled = true;
|
|
67
68
|
}
|
|
68
69
|
if (['string', 'password', 'date', 'datetime', 'time', 'integer', 'number', 'float', 'email', 'month', 'week', 'range'].includes(type)) {
|
|
@@ -118,7 +119,7 @@ export default function inertiaAddHelper(req, modelResource, fields, record, vie
|
|
|
118
119
|
? req.adminizer.modelHandler.resolveModelName(rawRelatedModel)
|
|
119
120
|
: undefined;
|
|
120
121
|
if (relatedModel && req.user) {
|
|
121
|
-
canCreateRelated = req.adminizer.accessRightsHelper.hasPermission(`create-${relatedModel}-model`, req.user);
|
|
122
|
+
canCreateRelated = await req.adminizer.accessRightsHelper.hasPermission(`create-${relatedModel}-model`, req.user);
|
|
122
123
|
}
|
|
123
124
|
else if (relatedModel && !req.adminizer.config.auth?.enable) {
|
|
124
125
|
canCreateRelated = true;
|
|
@@ -195,8 +196,8 @@ export function getControlsOptions(fieldConfig, req, type, defaultControlName, c
|
|
|
195
196
|
...(control?.getConfig() || {}), // Base config of the editor
|
|
196
197
|
...(shouldUseFieldConfig ? fieldOptions?.config || {} : {}),
|
|
197
198
|
},
|
|
198
|
-
path: control.getJsPath(),
|
|
199
|
-
cssPath: control.getCssPath(),
|
|
199
|
+
path: withAssetVersion(control.getJsPath()),
|
|
200
|
+
cssPath: withAssetVersion(control.getCssPath()),
|
|
200
201
|
};
|
|
201
202
|
// If items are provided, use them instead of the CKEditor defaults.
|
|
202
203
|
if (type === 'wysiwyg'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Group } from "../models/Group";
|
|
2
|
-
import { User } from "../models/User";
|
|
3
|
-
import { AccessRightsToken, ModelResource, PropsField } from "../interfaces/types";
|
|
1
|
+
import { Group } from "../models/Group.js";
|
|
2
|
+
import { User } from "../models/User.js";
|
|
3
|
+
import { AccessRightsToken, ModelResource, PropsField } from "../interfaces/types.js";
|
|
4
4
|
interface groupedTokens {
|
|
5
5
|
header: string;
|
|
6
6
|
fields: PropsField[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseGroupPermissionGrant } from "./accessRightsHelper.js";
|
|
1
2
|
export function inertiaGroupHelper(modelResource, req, users, groupedTokens, group, view = false) {
|
|
2
3
|
let props = {
|
|
3
4
|
edit: !!group,
|
|
@@ -55,8 +56,15 @@ export function inertiaGroupHelper(modelResource, req, users, groupedTokens, gro
|
|
|
55
56
|
label: token.name,
|
|
56
57
|
tooltip: token.description,
|
|
57
58
|
name: `token-checkbox-${token.id}`,
|
|
58
|
-
value: group ? (group.tokens
|
|
59
|
-
type: 'checkbox'
|
|
59
|
+
value: group ? Boolean(group.tokens?.some((value) => value === token.id || parseGroupPermissionGrant(value)?.tokenId === token.id)) : false,
|
|
60
|
+
type: 'checkbox',
|
|
61
|
+
options: token.getOptions ? {
|
|
62
|
+
permissionOptions: {
|
|
63
|
+
rights: group?.tokens
|
|
64
|
+
?.map(parseGroupPermissionGrant)
|
|
65
|
+
.find((value) => value?.tokenId === token.id)?.rights ?? [],
|
|
66
|
+
},
|
|
67
|
+
} : undefined,
|
|
60
68
|
});
|
|
61
69
|
}
|
|
62
70
|
props.groupedTokens.push({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ModelResource } from "../interfaces/types";
|
|
2
|
-
import { Fields } from "./fieldsHelper";
|
|
3
|
-
import { Actions } from "./inertiaActionsHelper";
|
|
1
|
+
import { ModelResource } from "../interfaces/types.js";
|
|
2
|
+
import { Fields } from "./fieldsHelper.js";
|
|
3
|
+
import { Actions } from "./inertiaActionsHelper.js";
|
|
4
4
|
interface listProps extends Record<string | number | symbol, unknown> {
|
|
5
5
|
actions: Actions[];
|
|
6
6
|
thActionsTitle: string;
|
|
@@ -28,5 +28,5 @@ interface listProps extends Record<string | number | symbol, unknown> {
|
|
|
28
28
|
defaultPageSize: number;
|
|
29
29
|
pageSizeOptions: number[];
|
|
30
30
|
}
|
|
31
|
-
export declare function inertiaListHelper(modelResource: ModelResource, req: ReqType, fields: Fields, activeFilterName?: string): listProps
|
|
31
|
+
export declare function inertiaListHelper(modelResource: ModelResource, req: ReqType, fields: Fields, activeFilterName?: string): Promise<listProps>;
|
|
32
32
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import inertiaActionsHelper from "./inertiaActionsHelper.js";
|
|
2
|
-
export function inertiaListHelper(modelResource, req, fields, activeFilterName) {
|
|
2
|
+
export async function inertiaListHelper(modelResource, req, fields, activeFilterName) {
|
|
3
3
|
const actionType = 'list';
|
|
4
4
|
// Check if filters are enabled for this model
|
|
5
5
|
// Preferred: model-level `models.<Model>.filters`; fallback: legacy top-level `modelFilters.<Model>`
|
|
@@ -31,23 +31,22 @@ export function inertiaListHelper(modelResource, req, fields, activeFilterName)
|
|
|
31
31
|
defaultPageSize: req.adminizer.config.list?.defaultPageSize ?? 50,
|
|
32
32
|
pageSizeOptions: [5, 20, 50],
|
|
33
33
|
};
|
|
34
|
-
if (modelResource.config.add && req.adminizer.accessRightsHelper.hasPermission(`create-${modelResource.name}-model`, req.user
|
|
34
|
+
if (modelResource.config.add && await req.adminizer.accessRightsHelper.hasPermission(`create-${modelResource.name}-model`, req.user)) {
|
|
35
35
|
props.crudActions.createTitle = req.i18n.__('create');
|
|
36
36
|
}
|
|
37
|
-
if (modelResource.config.edit && req.adminizer.accessRightsHelper.hasPermission(`update-${modelResource.name}-model`, req.user
|
|
37
|
+
if (modelResource.config.edit && await req.adminizer.accessRightsHelper.hasPermission(`update-${modelResource.name}-model`, req.user)) {
|
|
38
38
|
props.crudActions.editTitle = req.i18n.__('Edit');
|
|
39
39
|
}
|
|
40
|
-
if (modelResource.config.view && req.adminizer.accessRightsHelper.hasPermission(`read-${modelResource.name}-model`, req.user
|
|
40
|
+
if (modelResource.config.view && await req.adminizer.accessRightsHelper.hasPermission(`read-${modelResource.name}-model`, req.user)) {
|
|
41
41
|
props.crudActions.viewsTitle = req.i18n.__('View');
|
|
42
42
|
}
|
|
43
|
-
if (modelResource.config.remove && req.adminizer.accessRightsHelper.hasPermission(`delete-${modelResource.name}-model`, req.user
|
|
43
|
+
if (modelResource.config.remove && await req.adminizer.accessRightsHelper.hasPermission(`delete-${modelResource.name}-model`, req.user)) {
|
|
44
44
|
props.crudActions.deleteTitle = req.i18n.__('Delete');
|
|
45
45
|
}
|
|
46
|
-
props.actions = inertiaActionsHelper(actionType, modelResource, req);
|
|
46
|
+
props.actions = await inertiaActionsHelper(actionType, modelResource, req);
|
|
47
47
|
if (req.adminizer.menuHelper.hasInlineActions(modelResource.config, 'list')) {
|
|
48
48
|
for (const inlineAction of req.adminizer.menuHelper.getInlineActions(modelResource.config, 'list')) {
|
|
49
|
-
|
|
50
|
-
if (req.adminizer.accessRightsHelper.hasPermission(inlineAction.accessRightsToken, req.user, context)) {
|
|
49
|
+
if (await req.adminizer.accessRightsHelper.hasPermission(inlineAction.accessRightsToken, req.user)) {
|
|
51
50
|
props.inlineActions.push({
|
|
52
51
|
icon: inlineAction.icon,
|
|
53
52
|
id: inlineAction.id,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Adminizer } from "../lib/Adminizer";
|
|
2
|
-
import { MenuItem } from "./menuHelper";
|
|
1
|
+
import { Adminizer } from "../lib/Adminizer.js";
|
|
2
|
+
import { MenuItem } from "./menuHelper.js";
|
|
3
3
|
export declare class InertiaMenuHelper {
|
|
4
4
|
private adminizer;
|
|
5
5
|
constructor(adminizer: Adminizer);
|
|
6
6
|
getMenuItems(req: ReqType): MenuItem[];
|
|
7
|
-
private filterAccessibleItems;
|
|
8
7
|
private translateMenuItem;
|
|
9
8
|
private translateHrefItem;
|
|
10
9
|
getBrandTitle(): string;
|
|
@@ -1,35 +1,12 @@
|
|
|
1
|
+
import { listAccessibleMenuItems } from "./navigationAccessHelper.js";
|
|
1
2
|
export class InertiaMenuHelper {
|
|
2
3
|
adminizer;
|
|
3
4
|
constructor(adminizer) {
|
|
4
5
|
this.adminizer = adminizer;
|
|
5
6
|
}
|
|
6
7
|
getMenuItems(req) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const filteredActions = this.filterAccessibleItems(menuItem.actions ?? [], req);
|
|
10
|
-
const menuItemTokens = filteredActions.map(item => {
|
|
11
|
-
return item.accessRightsToken;
|
|
12
|
-
}).filter(item => {
|
|
13
|
-
return item;
|
|
14
|
-
});
|
|
15
|
-
if (menuItem.accessRightsToken)
|
|
16
|
-
menuItemTokens.push(menuItem.accessRightsToken);
|
|
17
|
-
if (this.adminizer.accessRightsHelper.enoughPermissions(menuItemTokens, req.user)) {
|
|
18
|
-
menu.push(this.translateMenuItem(req, {
|
|
19
|
-
...menuItem,
|
|
20
|
-
actions: filteredActions
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return menu;
|
|
25
|
-
}
|
|
26
|
-
filterAccessibleItems(items, req) {
|
|
27
|
-
return items
|
|
28
|
-
.filter((item) => !item.accessRightsToken || this.adminizer.accessRightsHelper.hasPermission(item.accessRightsToken, req.user))
|
|
29
|
-
.map((item) => ({
|
|
30
|
-
...item,
|
|
31
|
-
subItems: item.subItems ? this.filterAccessibleItems(item.subItems, req) : item.subItems
|
|
32
|
-
}));
|
|
8
|
+
return listAccessibleMenuItems(this.adminizer, req.user)
|
|
9
|
+
.map((menuItem) => this.translateMenuItem(req, menuItem));
|
|
33
10
|
}
|
|
34
11
|
translateMenuItem(req, menuItem) {
|
|
35
12
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Group } from "../models/Group";
|
|
2
|
-
import { User } from "../models/User";
|
|
3
|
-
import { ModelResource, PropsField } from "../interfaces/types";
|
|
1
|
+
import { Group } from "../models/Group.js";
|
|
2
|
+
import { User } from "../models/User.js";
|
|
3
|
+
import { ModelResource, PropsField } from "../interfaces/types.js";
|
|
4
4
|
interface listProps extends Record<string | number | symbol, unknown> {
|
|
5
5
|
edit: boolean;
|
|
6
6
|
view: boolean;
|
package/helpers/menuHelper.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @constructor
|
|
5
5
|
*/
|
|
6
|
-
import { User } from "../models/User";
|
|
7
|
-
import { ActionType, AdminpanelConfig, HrefConfig, ModelConfig } from "../interfaces/adminpanelConfig";
|
|
6
|
+
import { User } from "../models/User.js";
|
|
7
|
+
import { ActionType, AdminpanelConfig, HrefConfig, ModelConfig } from "../interfaces/adminpanelConfig.js";
|
|
8
8
|
export type MenuItem = {
|
|
9
9
|
link: string;
|
|
10
10
|
title: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ModelConfig } from '../interfaces/adminpanelConfig.js';
|
|
2
|
+
import type { ModelResource } from '../interfaces/types.js';
|
|
3
|
+
import type { Adminizer } from '../lib/Adminizer.js';
|
|
4
|
+
/** Config defaults of a model resource declared as `true` in the panel config. */
|
|
5
|
+
export declare function normalizeModelConfig(name: string, config: ModelConfig | boolean): ModelConfig;
|
|
6
|
+
/** Every configured model resource whose model is actually registered. */
|
|
7
|
+
export declare function listModelResources(adminizer: Adminizer): ModelResource[];
|
|
8
|
+
/** Resolves a resource by its Adminizer name, then by a uniquely registered host model name. */
|
|
9
|
+
export declare function resolveModelResource(adminizer: Adminizer, modelName: string): ModelResource | undefined;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Config defaults of a model resource declared as `true` in the panel config. */
|
|
2
|
+
export function normalizeModelConfig(name, config) {
|
|
3
|
+
const baseConfig = {
|
|
4
|
+
model: name,
|
|
5
|
+
icon: "description",
|
|
6
|
+
title: name,
|
|
7
|
+
list: true,
|
|
8
|
+
add: true,
|
|
9
|
+
edit: true,
|
|
10
|
+
remove: true,
|
|
11
|
+
view: true,
|
|
12
|
+
};
|
|
13
|
+
if (typeof config === "boolean") {
|
|
14
|
+
return config ? baseConfig : { ...baseConfig, list: false, add: false, edit: false, remove: false, view: false };
|
|
15
|
+
}
|
|
16
|
+
return { ...baseConfig, ...config };
|
|
17
|
+
}
|
|
18
|
+
/** Every configured model resource whose model is actually registered. */
|
|
19
|
+
export function listModelResources(adminizer) {
|
|
20
|
+
const resources = [];
|
|
21
|
+
for (const [configName, configValue] of Object.entries(adminizer.config.models ?? {})) {
|
|
22
|
+
const config = normalizeModelConfig(configName, configValue);
|
|
23
|
+
const model = adminizer.modelHandler.getResource(configName);
|
|
24
|
+
if (!model)
|
|
25
|
+
continue;
|
|
26
|
+
resources.push({
|
|
27
|
+
name: configName,
|
|
28
|
+
uri: `${adminizer.config.routePrefix}/model/${configName}`,
|
|
29
|
+
config,
|
|
30
|
+
model,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return resources;
|
|
34
|
+
}
|
|
35
|
+
/** Resolves a resource by its Adminizer name, then by a uniquely registered host model name. */
|
|
36
|
+
export function resolveModelResource(adminizer, modelName) {
|
|
37
|
+
const requestedName = modelName.trim();
|
|
38
|
+
const resourceName = adminizer.modelHandler.getResourceRecord(requestedName)?.name
|
|
39
|
+
?? adminizer.modelHandler.resolveResourceByHostModel(requestedName);
|
|
40
|
+
return resourceName
|
|
41
|
+
? listModelResources(adminizer).find((resource) => resource.name === resourceName)
|
|
42
|
+
: undefined;
|
|
43
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HrefConfig } from '../interfaces/adminpanelConfig.js';
|
|
2
|
+
import type { Adminizer } from '../lib/Adminizer.js';
|
|
3
|
+
import type { User } from '../models/User.js';
|
|
4
|
+
import type { MenuItem } from './menuHelper.js';
|
|
5
|
+
/** Drops the sub-items this user may not open, recursively. */
|
|
6
|
+
export declare function filterAccessibleHrefItems(adminizer: Adminizer, user: User, items: HrefConfig[]): HrefConfig[];
|
|
7
|
+
/**
|
|
8
|
+
* The navigation menu a user may actually open: configured models, additional
|
|
9
|
+
* links and app-contributed pages, filtered with the very same rules the
|
|
10
|
+
* sidebar uses. Titles are left untranslated, so callers that need i18n (the
|
|
11
|
+
* Inertia page props) translate on top of this.
|
|
12
|
+
*/
|
|
13
|
+
export declare function listAccessibleMenuItems(adminizer: Adminizer, user: User): MenuItem[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Drops the sub-items this user may not open, recursively. */
|
|
2
|
+
export function filterAccessibleHrefItems(adminizer, user, items) {
|
|
3
|
+
return items
|
|
4
|
+
.filter((item) => !item.accessRightsToken || adminizer.accessRightsHelper.hasPermission(item.accessRightsToken, user))
|
|
5
|
+
.map((item) => ({
|
|
6
|
+
...item,
|
|
7
|
+
subItems: item.subItems ? filterAccessibleHrefItems(adminizer, user, item.subItems) : item.subItems,
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The navigation menu a user may actually open: configured models, additional
|
|
12
|
+
* links and app-contributed pages, filtered with the very same rules the
|
|
13
|
+
* sidebar uses. Titles are left untranslated, so callers that need i18n (the
|
|
14
|
+
* Inertia page props) translate on top of this.
|
|
15
|
+
*/
|
|
16
|
+
export function listAccessibleMenuItems(adminizer, user) {
|
|
17
|
+
const menu = [];
|
|
18
|
+
for (const menuItem of adminizer.menuHelper.getMenuItems(user)) {
|
|
19
|
+
const actions = filterAccessibleHrefItems(adminizer, user, menuItem.actions ?? []);
|
|
20
|
+
const tokens = actions.map((item) => item.accessRightsToken).filter(Boolean);
|
|
21
|
+
if (menuItem.accessRightsToken)
|
|
22
|
+
tokens.push(menuItem.accessRightsToken);
|
|
23
|
+
if (adminizer.accessRightsHelper.enoughPermissions(tokens, user)) {
|
|
24
|
+
menu.push({ ...menuItem, actions });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const link of adminizer.adminLinkHandler.list(user)) {
|
|
28
|
+
menu.push({
|
|
29
|
+
id: link.id,
|
|
30
|
+
link: link.link,
|
|
31
|
+
title: link.title,
|
|
32
|
+
type: link.type === 'blank' ? 'blank' : 'self',
|
|
33
|
+
actions: null,
|
|
34
|
+
icon: null,
|
|
35
|
+
accessRightsToken: link.accessRightsToken ?? null,
|
|
36
|
+
section: link.section || 'Platform',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return menu;
|
|
40
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Adminizer } from "../lib/Adminizer";
|
|
2
|
-
import { I18n } from "../lib/I18n";
|
|
1
|
+
import { Adminizer } from "../lib/Adminizer.js";
|
|
2
|
+
import { I18n } from "../lib/I18n.js";
|
|
3
3
|
export declare class TranslationHelper {
|
|
4
4
|
static loadTranslations(adminizer: Adminizer, translationsPath: string): void;
|
|
5
5
|
static translateProperties(i18n: I18n, object: any, fields: string[]): any;
|