adminizer 4.3.0-build.117 → 4.3.0-build.119

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.
@@ -46,22 +46,21 @@ export async function catalogController(req, res) {
46
46
  return res.json(await frontendCatalog.getAddTemplate(item, req));
47
47
  case 'getEditTemplate':
48
48
  return res.json(await frontendCatalog.getEditTemplate(item, data.id, req, data.modelId));
49
- case 'getCatalog':
50
- {
51
- const __catalog = await frontendCatalog.getCatalog();
52
- return res.json({
53
- items: frontendCatalog.getitemTypes(),
54
- catalog: {
55
- nodes: __catalog,
56
- movingGroupsRootOnly: _catalog.movingGroupsRootOnly ?? false,
57
- catalogName: _catalog.name,
58
- catalogId: _catalog.id,
59
- catalogSlug: _catalog.slug,
60
- idList: idList
61
- },
62
- toolsActions: await frontendCatalog.getActions([], 'tools')
63
- });
64
- }
49
+ case 'getCatalog': {
50
+ const __catalog = await frontendCatalog.getCatalog();
51
+ return res.json({
52
+ items: frontendCatalog.getitemTypes(),
53
+ catalog: {
54
+ nodes: __catalog,
55
+ movingGroupsRootOnly: _catalog.movingGroupsRootOnly ?? false,
56
+ catalogName: _catalog.name,
57
+ catalogId: _catalog.id,
58
+ catalogSlug: _catalog.slug,
59
+ idList: idList
60
+ },
61
+ toolsActions: await frontendCatalog.getActions([], 'tools')
62
+ });
63
+ }
65
64
  case 'createItem':
66
65
  return res.json({ 'data': await frontendCatalog.createItem(data.data, req) });
67
66
  case 'getChilds':
@@ -457,7 +457,6 @@ export interface NavigationConfig {
457
457
  allowContentInGroup?: boolean;
458
458
  items: NavigationItemTypeConfig[];
459
459
  movingGroupsRootOnly?: boolean;
460
- bindAfter: boolean;
461
460
  }
462
461
  export interface MediaManagerConfig {
463
462
  fileStoragePath: string;
@@ -15,6 +15,7 @@ import { CatalogHandler } from "./catalog/CatalogHandler";
15
15
  import { NotificationHandler } from './notifications/NotificationHandler';
16
16
  import { INotification } from "../interfaces/types";
17
17
  import { MediaManagerHandler } from "./media-manager/MediaManagerHandler";
18
+ import { StorageServices } from "./catalog/Navigation";
18
19
  export declare class Adminizer {
19
20
  /**
20
21
  * If you convey this default Middleware, it will add it to the very top of the router,
@@ -36,6 +37,7 @@ export declare class Adminizer {
36
37
  controlsHandler: ControlsHandler;
37
38
  catalogHandler: CatalogHandler;
38
39
  mediaManagerHandler: MediaManagerHandler;
40
+ storageServices: StorageServices;
39
41
  jwtSecret: string;
40
42
  static logger: winston.Logger;
41
43
  constructor(ormAdapters: AbstractAdapter[]);
package/lib/Adminizer.js CHANGED
@@ -54,6 +54,7 @@ export class Adminizer {
54
54
  controlsHandler;
55
55
  catalogHandler;
56
56
  mediaManagerHandler;
57
+ storageServices;
57
58
  // Constants
58
59
  jwtSecret = process.env.JWT_SECRET ?? uuid();
59
60
  static logger = winston.createLogger({
@@ -208,8 +209,7 @@ export class Adminizer {
208
209
  }
209
210
  }
210
211
  await bindDashboardWidgets(this);
211
- if (!this.config.navigation?.bindAfter)
212
- bindNavigation(this);
212
+ await bindNavigation(this);
213
213
  bindMediaManager(this);
214
214
  await bindAccessRights(this);
215
215
  if (I18n.appendLocale) {
@@ -1,4 +1,5 @@
1
1
  import { Adminizer } from "../Adminizer";
2
+ import { StorageServices } from "./Navigation";
2
3
  /**
3
4
  * Interface `Item` describes the data that the UI will operate on
4
5
  * This is a common interface for all data that is linked to the catalog
@@ -24,6 +25,7 @@ export type _Item_ = {
24
25
  * General Item structure that will be available for all elements, including groups
25
26
  */
26
27
  export declare abstract class BaseItem<T extends Item> {
28
+ storageServices?: StorageServices;
27
29
  abstract readonly type: string;
28
30
  /**
29
31
  * Used for infer T
@@ -2,6 +2,7 @@
2
2
  * General Item structure that will be available for all elements, including groups
3
3
  */
4
4
  export class BaseItem {
5
+ storageServices;
5
6
  /**
6
7
  * Array of all global contexts, which will appear for all elements
7
8
  */
@@ -253,7 +254,7 @@ export class AbstractCatalog {
253
254
  * Method for getting group elements
254
255
  */
255
256
  getitemTypes() {
256
- return this.itemTypes.map(({ adminizer, ...rest }) => rest);
257
+ return this.itemTypes.map(({ adminizer, storageServices, ...rest }) => rest);
257
258
  }
258
259
  ;
259
260
  async search(s, hasExtras = true, req) {
@@ -27,10 +27,11 @@ export declare class StorageService {
27
27
  search(s: string, type: string): Promise<NavItem[]>;
28
28
  }
29
29
  export declare class StorageServices {
30
- protected static storages: StorageService[];
31
- static add(storage: StorageService): void;
32
- static get(id: string): StorageService;
33
- static getAll(): StorageService[];
30
+ protected storages: StorageService[];
31
+ constructor();
32
+ add(storage: StorageService): void;
33
+ get(id: string): StorageService;
34
+ getAll(): StorageService[];
34
35
  }
35
36
  export declare class Navigation extends AbstractCatalog {
36
37
  readonly name: string;
@@ -38,6 +39,7 @@ export declare class Navigation extends AbstractCatalog {
38
39
  readonly icon: string;
39
40
  readonly actionHandlers: ActionHandler[];
40
41
  idList: string[];
42
+ storageServices: StorageServices;
41
43
  constructor(adminizer: Adminizer, config: NavigationConfig);
42
44
  getIdList(): Promise<string[]>;
43
45
  }
@@ -138,14 +138,16 @@ export class StorageService {
138
138
  }
139
139
  }
140
140
  export class StorageServices {
141
- static storages = [];
142
- static add(storage) {
141
+ storages = [];
142
+ constructor() {
143
+ }
144
+ add(storage) {
143
145
  this.storages.push(storage);
144
146
  }
145
- static get(id) {
147
+ get(id) {
146
148
  return this.storages.find(storage => storage.getId() === id);
147
149
  }
148
- static getAll() {
150
+ getAll() {
149
151
  return this.storages;
150
152
  }
151
153
  }
@@ -155,17 +157,21 @@ export class Navigation extends AbstractCatalog {
155
157
  icon = "box";
156
158
  actionHandlers = [];
157
159
  idList = [];
160
+ storageServices;
158
161
  constructor(adminizer, config) {
159
162
  let items = [];
163
+ const storageServices = new StorageServices();
160
164
  for (const configElement of config.items) {
161
- items.push(new NavigationItem(adminizer, configElement.title, configElement.model, config.model, configElement.urlPath));
165
+ items.push(new NavigationItem(adminizer, configElement.title, configElement.model, config.model, configElement.urlPath, storageServices));
162
166
  }
163
- items.push(new NavigationGroup(adminizer, config.groupField));
164
- items.push(new LinkItem(adminizer));
167
+ items.push(new NavigationGroup(adminizer, config.groupField, storageServices));
168
+ items.push(new LinkItem(adminizer, storageServices));
169
+ super(adminizer, items);
170
+ this.storageServices = storageServices;
171
+ adminizer.storageServices = storageServices;
165
172
  for (const section of config.sections) {
166
- StorageServices.add(new StorageService(adminizer, section, config.model));
173
+ this.storageServices.add(new StorageService(adminizer, section, config.model));
167
174
  }
168
- super(adminizer, items);
169
175
  this.movingGroupsRootOnly = config.movingGroupsRootOnly;
170
176
  this.idList = config.sections ?? [];
171
177
  }
@@ -183,7 +189,7 @@ class NavigationItem extends AbstractItem {
183
189
  actionHandlers = [];
184
190
  urlPath;
185
191
  adminizer;
186
- constructor(adminizer, name, model, navigationModel, urlPath) {
192
+ constructor(adminizer, name, model, navigationModel, urlPath, storageServices) {
187
193
  super();
188
194
  this.name = name;
189
195
  this.navigationModel = navigationModel;
@@ -193,9 +199,10 @@ class NavigationItem extends AbstractItem {
193
199
  let configModel = adminizer.config.models[this.model];
194
200
  this.icon = configModel?.icon ?? 'file_present';
195
201
  this.adminizer = adminizer;
202
+ this.storageServices = storageServices;
196
203
  }
197
204
  async create(data, catalogId) {
198
- let storage = StorageServices.get(catalogId);
205
+ let storage = this.storageServices.get(catalogId);
199
206
  let storageData = null;
200
207
  if (data._method === 'select') {
201
208
  // Direct call by model adapter
@@ -213,7 +220,7 @@ class NavigationItem extends AbstractItem {
213
220
  return await storage.setElement(data.id, storageData);
214
221
  }
215
222
  async dataPreparation(data, catalogId, sortOrder) {
216
- let storage = StorageServices.get(catalogId);
223
+ let storage = this.storageServices.get(catalogId);
217
224
  let urlPath = eval('`' + this.urlPath + '`');
218
225
  let parentId = data.parentId ? data.parentId : 0; // changed from null to 0
219
226
  return {
@@ -231,7 +238,7 @@ class NavigationItem extends AbstractItem {
231
238
  };
232
239
  }
233
240
  async updateModelItems(modelId, data, catalogId) {
234
- let storage = StorageServices.get(catalogId);
241
+ let storage = this.storageServices.get(catalogId);
235
242
  let items = await storage.findElementByModelId(modelId);
236
243
  let urlPath = eval('`' + this.urlPath + '`');
237
244
  let response = [];
@@ -247,15 +254,15 @@ class NavigationItem extends AbstractItem {
247
254
  return response[0];
248
255
  }
249
256
  async update(itemId, data, catalogId) {
250
- let storage = StorageServices.get(catalogId);
257
+ let storage = this.storageServices.get(catalogId);
251
258
  return await storage.setElement(itemId, data);
252
259
  }
253
260
  async deleteItem(itemId, catalogId) {
254
- let storage = StorageServices.get(catalogId);
261
+ let storage = this.storageServices.get(catalogId);
255
262
  return await storage.removeElementById(itemId);
256
263
  }
257
264
  async find(itemId, catalogId) {
258
- let storage = StorageServices.get(catalogId);
265
+ let storage = this.storageServices.get(catalogId);
259
266
  return await storage.findElementById(itemId);
260
267
  }
261
268
  /**
@@ -288,7 +295,7 @@ class NavigationItem extends AbstractItem {
288
295
  };
289
296
  }
290
297
  async getChilds(parentId, catalogId) {
291
- let storage = StorageServices.get(catalogId);
298
+ let storage = this.storageServices.get(catalogId);
292
299
  return await storage.findElementsByParentId(parentId, this.type);
293
300
  }
294
301
  async getEditTemplate(id, catalogId, req, modelId) {
@@ -300,7 +307,7 @@ class NavigationItem extends AbstractItem {
300
307
  });
301
308
  }
302
309
  async search(s, catalogId) {
303
- let storage = StorageServices.get(catalogId);
310
+ let storage = this.storageServices.get(catalogId);
304
311
  return await storage.search(s, this.type);
305
312
  }
306
313
  }
@@ -309,13 +316,14 @@ class NavigationGroup extends AbstractGroup {
309
316
  name = "Group";
310
317
  groupField;
311
318
  adminizer;
312
- constructor(adminizer, groupField) {
319
+ constructor(adminizer, groupField, storageServices) {
313
320
  super();
314
321
  this.groupField = groupField;
315
322
  this.adminizer = adminizer;
323
+ this.storageServices = storageServices;
316
324
  }
317
325
  async create(data, catalogId) {
318
- let storage = StorageServices.get(catalogId);
326
+ let storage = this.storageServices.get(catalogId);
319
327
  let storageData = await this.dataPreparation(data, catalogId);
320
328
  delete data.name;
321
329
  delete data.parentId;
@@ -323,7 +331,7 @@ class NavigationGroup extends AbstractGroup {
323
331
  return await storage.setElement(storageData.id, storageData);
324
332
  }
325
333
  async dataPreparation(data, catalogId, sortOrder) {
326
- let storage = StorageServices.get(catalogId);
334
+ let storage = this.storageServices.get(catalogId);
327
335
  let parentId = data.parentId ? data.parentId : 0; // changed from null to 0
328
336
  return {
329
337
  id: uuid(),
@@ -338,19 +346,19 @@ class NavigationGroup extends AbstractGroup {
338
346
  };
339
347
  }
340
348
  async deleteItem(itemId, catalogId) {
341
- let storage = StorageServices.get(catalogId);
349
+ let storage = this.storageServices.get(catalogId);
342
350
  return await storage.removeElementById(itemId);
343
351
  }
344
352
  async find(itemId, catalogId) {
345
- let storage = StorageServices.get(catalogId);
353
+ let storage = this.storageServices.get(catalogId);
346
354
  return await storage.findElementById(itemId);
347
355
  }
348
356
  async update(itemId, data, catalogId) {
349
- let storage = StorageServices.get(catalogId);
357
+ let storage = this.storageServices.get(catalogId);
350
358
  return await storage.setElement(itemId, data);
351
359
  }
352
360
  async updateModelItems(modelId, data, catalogId) {
353
- let storage = StorageServices.get(catalogId);
361
+ let storage = this.storageServices.get(catalogId);
354
362
  return await storage.setElement(modelId, data);
355
363
  }
356
364
  getAddTemplate(req) {
@@ -404,11 +412,11 @@ class NavigationGroup extends AbstractGroup {
404
412
  });
405
413
  }
406
414
  async getChilds(parentId, catalogId) {
407
- let storage = StorageServices.get(catalogId);
415
+ let storage = this.storageServices.get(catalogId);
408
416
  return await storage.findElementsByParentId(parentId, this.type);
409
417
  }
410
418
  async search(s, catalogId) {
411
- let storage = StorageServices.get(catalogId);
419
+ let storage = this.storageServices.get(catalogId);
412
420
  return await storage.search(s, this.type);
413
421
  }
414
422
  }
@@ -418,8 +426,8 @@ class LinkItem extends NavigationGroup {
418
426
  name = 'Link';
419
427
  type = 'link';
420
428
  isGroup = false;
421
- constructor(adminizer) {
422
- super(adminizer, []);
429
+ constructor(adminizer, storageServices) {
430
+ super(adminizer, [], storageServices);
423
431
  }
424
432
  getAddTemplate(req) {
425
433
  let type = 'navigation.link';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "4.3.0-build.117",
4
+ "version": "4.3.0-build.119",
5
5
  "main": "index.js",
6
6
  "exports": {
7
7
  ".": "./index.js",