strapi-plugin-navigation 2.2.14 → 2.2.16
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 +68 -1
- package/admin/src/pages/View/components/NavigationHeader/index.js +8 -1
- package/admin/src/pages/View/components/NavigationItemForm/utils/form.d.ts +6 -6
- package/admin/src/translations/ca.json +1 -0
- package/admin/src/translations/en.json +1 -0
- package/admin/src/translations/fr.json +1 -0
- package/package.json +7 -2
- package/server/controllers/client.js +15 -0
- package/server/i18n/navigationSetupStrategy.js +59 -39
- package/server/routes/client.js +8 -0
- package/server/services/admin.js +113 -56
- package/server/services/client.js +16 -0
- package/server/services/common.js +6 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/types/controllers.d.ts +1 -0
- package/types/services.d.ts +5 -1
package/server/services/admin.js
CHANGED
|
@@ -5,19 +5,21 @@ const lodash_1 = require("lodash");
|
|
|
5
5
|
const utils_2 = require("../utils");
|
|
6
6
|
const i18n_1 = require("../i18n");
|
|
7
7
|
const NavigationError_1 = require("../../utils/NavigationError");
|
|
8
|
-
const adminService = ({ strapi }) => ({
|
|
8
|
+
const adminService = ({ strapi, }) => ({
|
|
9
9
|
async config(viaSettingsPage = false) {
|
|
10
|
-
const commonService = (0, utils_2.getPluginService)(
|
|
10
|
+
const commonService = (0, utils_2.getPluginService)("common");
|
|
11
11
|
const { audienceModel } = (0, utils_2.getPluginModels)();
|
|
12
12
|
const pluginStore = await commonService.getPluginStore();
|
|
13
|
-
const config = await pluginStore.get({
|
|
13
|
+
const config = await pluginStore.get({
|
|
14
|
+
key: "config",
|
|
15
|
+
});
|
|
14
16
|
const additionalFields = config.additionalFields;
|
|
15
17
|
const cascadeMenuAttached = config.cascadeMenuAttached;
|
|
16
18
|
const contentTypesNameFields = config.contentTypesNameFields;
|
|
17
19
|
const contentTypesPopulate = config.contentTypesPopulate;
|
|
18
20
|
const pathDefaultFields = config.pathDefaultFields;
|
|
19
21
|
const allowedLevels = config.allowedLevels;
|
|
20
|
-
const isGQLPluginEnabled = !(0, lodash_1.isNil)(strapi.plugin(
|
|
22
|
+
const isGQLPluginEnabled = !(0, lodash_1.isNil)(strapi.plugin("graphql"));
|
|
21
23
|
let extendedResult = {
|
|
22
24
|
allowedContentTypes: utils_2.ALLOWED_CONTENT_TYPES,
|
|
23
25
|
restrictedContentTypes: utils_2.RESTRICTED_CONTENT_TYPES,
|
|
@@ -29,20 +31,26 @@ const adminService = ({ strapi }) => ({
|
|
|
29
31
|
default: utils_2.CONTENT_TYPES_NAME_FIELDS_DEFAULTS,
|
|
30
32
|
...((0, lodash_1.isObject)(contentTypesNameFields) ? contentTypesNameFields : {}),
|
|
31
33
|
},
|
|
32
|
-
contentTypesPopulate: (0, lodash_1.isObject)(contentTypesPopulate)
|
|
34
|
+
contentTypesPopulate: (0, lodash_1.isObject)(contentTypesPopulate)
|
|
35
|
+
? contentTypesPopulate
|
|
36
|
+
: {},
|
|
33
37
|
pathDefaultFields: (0, lodash_1.isObject)(pathDefaultFields) ? pathDefaultFields : {},
|
|
34
38
|
allowedLevels,
|
|
35
39
|
additionalFields: viaSettingsPage
|
|
36
40
|
? additionalFields
|
|
37
|
-
: additionalFields.filter(field => typeof field ===
|
|
41
|
+
: additionalFields.filter((field) => typeof field === "string" || (0, lodash_1.get)(field, "enabled", false)),
|
|
38
42
|
gql: {
|
|
39
|
-
navigationItemRelated: configContentTypes.map(({ labelSingular }) => labelSingular.replace(/\s+/g,
|
|
43
|
+
navigationItemRelated: configContentTypes.map(({ labelSingular }) => labelSingular.replace(/\s+/g, "")),
|
|
40
44
|
},
|
|
41
45
|
isGQLPluginEnabled: viaSettingsPage ? isGQLPluginEnabled : undefined,
|
|
42
46
|
cascadeMenuAttached,
|
|
43
47
|
};
|
|
44
|
-
const i18nConfig = await (0, i18n_1.addI18NConfigFields)({
|
|
45
|
-
|
|
48
|
+
const i18nConfig = await (0, i18n_1.addI18NConfigFields)({
|
|
49
|
+
strapi,
|
|
50
|
+
viaSettingsPage,
|
|
51
|
+
previousConfig: {},
|
|
52
|
+
});
|
|
53
|
+
if (additionalFields.includes("audience")) {
|
|
46
54
|
const audienceItems = await strapi
|
|
47
55
|
.query(audienceModel.uid)
|
|
48
56
|
.findMany({
|
|
@@ -59,18 +67,23 @@ const adminService = ({ strapi }) => ({
|
|
|
59
67
|
...i18nConfig,
|
|
60
68
|
};
|
|
61
69
|
},
|
|
62
|
-
async get() {
|
|
70
|
+
async get(ids) {
|
|
63
71
|
const { masterModel } = (0, utils_2.getPluginModels)();
|
|
64
|
-
const entities = await strapi
|
|
65
|
-
.query(masterModel.uid)
|
|
66
|
-
.findMany({
|
|
72
|
+
const entities = await strapi.query(masterModel.uid).findMany({
|
|
67
73
|
limit: Number.MAX_SAFE_INTEGER,
|
|
68
74
|
populate: utils_2.DEFAULT_POPULATE,
|
|
75
|
+
where: ids
|
|
76
|
+
? {
|
|
77
|
+
id: {
|
|
78
|
+
$in: ids,
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
: undefined,
|
|
69
82
|
});
|
|
70
83
|
return entities;
|
|
71
84
|
},
|
|
72
85
|
async getById(id) {
|
|
73
|
-
const commonService = (0, utils_2.getPluginService)(
|
|
86
|
+
const commonService = (0, utils_2.getPluginService)("common");
|
|
74
87
|
const { masterModel, itemModel } = (0, utils_2.getPluginModels)();
|
|
75
88
|
const entity = await strapi
|
|
76
89
|
.query(masterModel.uid)
|
|
@@ -82,8 +95,8 @@ const adminService = ({ strapi }) => ({
|
|
|
82
95
|
master: id,
|
|
83
96
|
},
|
|
84
97
|
limit: Number.MAX_SAFE_INTEGER,
|
|
85
|
-
orderBy: [{ order:
|
|
86
|
-
populate: [
|
|
98
|
+
orderBy: [{ order: "asc" }],
|
|
99
|
+
populate: ["related", "parent", "audience"],
|
|
87
100
|
});
|
|
88
101
|
const entities = await commonService.getRelatedItems(entityItems);
|
|
89
102
|
return {
|
|
@@ -92,9 +105,11 @@ const adminService = ({ strapi }) => ({
|
|
|
92
105
|
};
|
|
93
106
|
},
|
|
94
107
|
async post(payload, auditLog) {
|
|
95
|
-
const commonService = (0, utils_2.getPluginService)(
|
|
96
|
-
const adminService = (0, utils_2.getPluginService)(
|
|
97
|
-
const { enabled: i18nEnabled, defaultLocale } = await (0, i18n_1.getI18nStatus)({
|
|
108
|
+
const commonService = (0, utils_2.getPluginService)("common");
|
|
109
|
+
const adminService = (0, utils_2.getPluginService)("admin");
|
|
110
|
+
const { enabled: i18nEnabled, defaultLocale } = await (0, i18n_1.getI18nStatus)({
|
|
111
|
+
strapi,
|
|
112
|
+
});
|
|
98
113
|
const { masterModel } = (0, utils_2.getPluginModels)();
|
|
99
114
|
const { name, visible } = payload;
|
|
100
115
|
const data = {
|
|
@@ -109,18 +124,22 @@ const adminService = ({ strapi }) => ({
|
|
|
109
124
|
.createBranch(payload.items, existingEntity, null, {})
|
|
110
125
|
.then(() => adminService.getById(existingEntity.id))
|
|
111
126
|
.then((newEntity) => {
|
|
112
|
-
(0, utils_2.sendAuditLog)(auditLog,
|
|
127
|
+
(0, utils_2.sendAuditLog)(auditLog, "onChangeNavigation", {
|
|
128
|
+
actionType: "CREATE",
|
|
129
|
+
oldEntity: existingEntity,
|
|
130
|
+
newEntity,
|
|
131
|
+
});
|
|
113
132
|
return newEntity;
|
|
114
133
|
});
|
|
115
|
-
await commonService.emitEvent(masterModel.uid,
|
|
134
|
+
await commonService.emitEvent(masterModel.uid, "entry.create", existingEntity);
|
|
116
135
|
if (i18nEnabled && defaultLocale) {
|
|
117
136
|
await (0, i18n_1.i18nNavigationSetupStrategy)({ strapi });
|
|
118
137
|
}
|
|
119
138
|
return result;
|
|
120
139
|
},
|
|
121
140
|
async put(id, payload, auditLog) {
|
|
122
|
-
const adminService = (0, utils_2.getPluginService)(
|
|
123
|
-
const commonService = (0, utils_2.getPluginService)(
|
|
141
|
+
const adminService = (0, utils_2.getPluginService)("admin");
|
|
142
|
+
const commonService = (0, utils_2.getPluginService)("common");
|
|
124
143
|
const { enabled: i18nEnabled } = await (0, i18n_1.getI18nStatus)({ strapi });
|
|
125
144
|
const { masterModel } = (0, utils_2.getPluginModels)();
|
|
126
145
|
const { name, visible } = payload;
|
|
@@ -128,7 +147,9 @@ const adminService = ({ strapi }) => ({
|
|
|
128
147
|
const detailsHaveChanged = existingEntity.name !== name || existingEntity.visible !== visible;
|
|
129
148
|
if (detailsHaveChanged) {
|
|
130
149
|
const newName = detailsHaveChanged ? name : existingEntity.name;
|
|
131
|
-
const newSlug = detailsHaveChanged
|
|
150
|
+
const newSlug = detailsHaveChanged
|
|
151
|
+
? await commonService.getSlug(name)
|
|
152
|
+
: existingEntity.slug;
|
|
132
153
|
await strapi.query(masterModel.uid).update({
|
|
133
154
|
where: { id },
|
|
134
155
|
data: {
|
|
@@ -138,67 +159,99 @@ const adminService = ({ strapi }) => ({
|
|
|
138
159
|
},
|
|
139
160
|
});
|
|
140
161
|
if (i18nEnabled && existingEntity.localizations) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
162
|
+
for (const locale of existingEntity.localizations) {
|
|
163
|
+
await strapi.query(masterModel.uid).update({
|
|
164
|
+
where: {
|
|
165
|
+
id: locale.id,
|
|
166
|
+
},
|
|
167
|
+
data: {
|
|
168
|
+
name: newName,
|
|
169
|
+
slug: `${newSlug}-${locale.localeCode}`,
|
|
170
|
+
visible,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
151
174
|
}
|
|
152
175
|
}
|
|
153
176
|
const result = await commonService
|
|
154
177
|
.analyzeBranch(payload.items, existingEntity)
|
|
155
178
|
.then((auditLogsOperations) => Promise.all([
|
|
156
|
-
auditLog
|
|
157
|
-
|
|
179
|
+
auditLog
|
|
180
|
+
? (0, utils_2.prepareAuditLog)((auditLogsOperations || []).flat(Number.MAX_SAFE_INTEGER))
|
|
181
|
+
: [],
|
|
182
|
+
adminService.getById(existingEntity.id),
|
|
158
183
|
]))
|
|
159
184
|
.then(([actionType, newEntity]) => {
|
|
160
|
-
(0, utils_2.sendAuditLog)(auditLog,
|
|
185
|
+
(0, utils_2.sendAuditLog)(auditLog, "onChangeNavigation", {
|
|
186
|
+
actionType,
|
|
187
|
+
oldEntity: existingEntity,
|
|
188
|
+
newEntity,
|
|
189
|
+
});
|
|
161
190
|
return newEntity;
|
|
162
191
|
});
|
|
163
|
-
const navigationEntity = await strapi
|
|
164
|
-
|
|
192
|
+
const navigationEntity = await strapi
|
|
193
|
+
.query(masterModel.uid)
|
|
194
|
+
.findOne({ where: { id } });
|
|
195
|
+
await commonService.emitEvent(masterModel.uid, "entry.update", navigationEntity);
|
|
165
196
|
return result;
|
|
166
197
|
},
|
|
167
198
|
async delete(id, auditLog) {
|
|
168
|
-
const { masterModel } = (0, utils_2.getPluginModels)();
|
|
169
|
-
const adminService = (0, utils_2.getPluginService)(
|
|
199
|
+
const { masterModel, itemModel } = (0, utils_2.getPluginModels)();
|
|
200
|
+
const adminService = (0, utils_2.getPluginService)("admin");
|
|
170
201
|
const entity = await adminService.getById(id);
|
|
171
202
|
const { enabled: i18nEnabled } = await (0, i18n_1.getI18nStatus)({ strapi });
|
|
203
|
+
const cleanNavigationItems = async (masterIds) => {
|
|
204
|
+
const navigationItems = await strapi.query(itemModel.uid).findMany({
|
|
205
|
+
where: {
|
|
206
|
+
$or: masterIds.map((id) => ({ master: id }))
|
|
207
|
+
},
|
|
208
|
+
limit: Number.MAX_SAFE_INTEGER,
|
|
209
|
+
});
|
|
210
|
+
await strapi.query(itemModel.uid).deleteMany({
|
|
211
|
+
where: {
|
|
212
|
+
$or: navigationItems.map(({ id }) => ({ id }))
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
await cleanNavigationItems([id]);
|
|
172
217
|
await strapi.query(masterModel.uid).delete({
|
|
173
218
|
where: {
|
|
174
219
|
id,
|
|
175
|
-
}
|
|
220
|
+
},
|
|
176
221
|
});
|
|
177
222
|
if (i18nEnabled && entity.localizations) {
|
|
178
|
-
await
|
|
223
|
+
await cleanNavigationItems(entity.localizations.map(_ => _.id));
|
|
224
|
+
await strapi.query(masterModel.uid).deleteMany({
|
|
179
225
|
where: {
|
|
180
|
-
id:
|
|
181
|
-
|
|
182
|
-
|
|
226
|
+
id: {
|
|
227
|
+
$in: entity.localizations.map((_) => _.id),
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
});
|
|
183
231
|
}
|
|
184
|
-
(0, utils_2.sendAuditLog)(auditLog,
|
|
232
|
+
(0, utils_2.sendAuditLog)(auditLog, "onNavigationDeletion", {
|
|
233
|
+
entity,
|
|
234
|
+
actionType: "DELETE",
|
|
235
|
+
});
|
|
185
236
|
},
|
|
186
237
|
async restart() {
|
|
187
238
|
setImmediate(() => strapi.reload());
|
|
188
239
|
},
|
|
189
240
|
async restoreConfig() {
|
|
190
|
-
const commonService = (0, utils_2.getPluginService)(
|
|
241
|
+
const commonService = (0, utils_2.getPluginService)("common");
|
|
191
242
|
const pluginStore = await commonService.getPluginStore();
|
|
192
|
-
await pluginStore.delete({ key:
|
|
243
|
+
await pluginStore.delete({ key: "config" });
|
|
193
244
|
await commonService.setDefaultConfig();
|
|
194
245
|
},
|
|
195
246
|
async updateConfig(newConfig) {
|
|
196
|
-
const commonService = (0, utils_2.getPluginService)(
|
|
247
|
+
const commonService = (0, utils_2.getPluginService)("common");
|
|
197
248
|
const pluginStore = await commonService.getPluginStore();
|
|
198
|
-
const config = await pluginStore.get({
|
|
249
|
+
const config = await pluginStore.get({
|
|
250
|
+
key: "config",
|
|
251
|
+
});
|
|
199
252
|
(0, utils_2.validateAdditionalFields)(newConfig.additionalFields);
|
|
200
|
-
await pluginStore.set({ key:
|
|
201
|
-
const removedFields = (0, lodash_1.differenceBy)(config.additionalFields, newConfig.additionalFields,
|
|
253
|
+
await pluginStore.set({ key: "config", value: newConfig });
|
|
254
|
+
const removedFields = (0, lodash_1.differenceBy)(config.additionalFields, newConfig.additionalFields, "name").filter((i) => i !== "audience");
|
|
202
255
|
if (!(0, lodash_1.isEmpty)(removedFields)) {
|
|
203
256
|
await commonService.pruneCustomFields(removedFields);
|
|
204
257
|
}
|
|
@@ -208,8 +261,8 @@ const adminService = ({ strapi }) => ({
|
|
|
208
261
|
if (!enabled) {
|
|
209
262
|
throw new NavigationError_1.NavigationError("Not yet implemented.");
|
|
210
263
|
}
|
|
211
|
-
const adminService = (0, utils_2.getPluginService)(
|
|
212
|
-
const commonService = (0, utils_2.getPluginService)(
|
|
264
|
+
const adminService = (0, utils_2.getPluginService)("admin");
|
|
265
|
+
const commonService = (0, utils_2.getPluginService)("common");
|
|
213
266
|
const targetEntity = await adminService.getById(target);
|
|
214
267
|
return await (0, i18n_1.i18nNavigationContentsCopy)({
|
|
215
268
|
source: await adminService.getById(source),
|
|
@@ -219,7 +272,11 @@ const adminService = ({ strapi }) => ({
|
|
|
219
272
|
})
|
|
220
273
|
.then(() => adminService.getById(target))
|
|
221
274
|
.then((updated) => {
|
|
222
|
-
(0, utils_2.sendAuditLog)(auditLog,
|
|
275
|
+
(0, utils_2.sendAuditLog)(auditLog, "onChangeNavigation", {
|
|
276
|
+
actionType: "UPDATE",
|
|
277
|
+
oldEntity: targetEntity,
|
|
278
|
+
newEntity: updated,
|
|
279
|
+
});
|
|
223
280
|
return updated;
|
|
224
281
|
});
|
|
225
282
|
},
|
|
@@ -8,6 +8,22 @@ const utils_2 = require("@strapi/utils");
|
|
|
8
8
|
const i18n_1 = require("../i18n");
|
|
9
9
|
const NavigationError_1 = require("../../utils/NavigationError");
|
|
10
10
|
const clientService = ({ strapi }) => ({
|
|
11
|
+
async readAll({ locale, orderBy = 'createdAt', orderDirection = "DESC" }) {
|
|
12
|
+
const { masterModel } = (0, utils_1.getPluginModels)();
|
|
13
|
+
const navigations = await strapi
|
|
14
|
+
.query(masterModel.uid)
|
|
15
|
+
.findMany({
|
|
16
|
+
where: locale
|
|
17
|
+
? {
|
|
18
|
+
localeCode: locale,
|
|
19
|
+
}
|
|
20
|
+
: undefined,
|
|
21
|
+
orderBy: { [orderBy]: orderDirection },
|
|
22
|
+
limit: Number.MAX_SAFE_INTEGER,
|
|
23
|
+
populate: false
|
|
24
|
+
});
|
|
25
|
+
return navigations;
|
|
26
|
+
},
|
|
11
27
|
async render({ idOrSlug, type = utils_1.RENDER_TYPES.FLAT, menuOnly = false, rootPath = null, wrapRelated = false, locale, populate, }) {
|
|
12
28
|
const clientService = (0, utils_1.getPluginService)('client');
|
|
13
29
|
const findById = !isNaN((0, lodash_1.toNumber)(idOrSlug)) || (0, uuid_1.validate)(idOrSlug);
|
|
@@ -336,10 +336,12 @@ const commonService = ({ strapi }) => ({
|
|
|
336
336
|
const navigationItemsToUpdate = removedFields.reduce((acc, curr) => {
|
|
337
337
|
return acc.map((item) => (0, lodash_1.omit)(item, [`additionalFields.${curr.name}`]));
|
|
338
338
|
}, navigationItems);
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
339
|
+
for (const item of navigationItemsToUpdate) {
|
|
340
|
+
await databaseModel.update({
|
|
341
|
+
where: { id: item.id },
|
|
342
|
+
data: { additionalFields: item.additionalFields },
|
|
343
|
+
});
|
|
344
|
+
}
|
|
343
345
|
},
|
|
344
346
|
async getSlug(query) {
|
|
345
347
|
let slug = (0, slugify_1.default)(query);
|