adminizer 4.3.0-build.88 → 4.3.0-build.90

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.
@@ -1,7 +1,7 @@
1
1
  import { ControllerHelper } from "../helpers/controllerHelper";
2
2
  import { RequestProcessor } from "../lib/requestProcessor";
3
3
  import { FieldsHelper } from "../helpers/fieldsHelper";
4
- // import {saveRelationsMediaManager} from "../lib/media-manager/helpers/MediaManagerHelper";
4
+ import { saveRelationsMediaManager } from "../lib/media-manager/helpers/MediaManagerHelper";
5
5
  import { DataAccessor } from "../lib/DataAccessor";
6
6
  import { Adminizer } from "../lib/Adminizer";
7
7
  import inertiaAddHelper from "../helpers/inertiaAddHelper";
@@ -88,7 +88,7 @@ export default async function add(req, res) {
88
88
  try {
89
89
  let record = await entity.model.create(reqData, dataAccessor);
90
90
  // save associations media to json
91
- // await saveRelationsMediaManager(fields, rawReqData, entity.model.identity, record.id)
91
+ await saveRelationsMediaManager(fields, rawReqData, entity.model.identity, record.id);
92
92
  Adminizer.log.debug(`A new record was created: `, record);
93
93
  if (req.body.jsonPopupCatalog) {
94
94
  dataAccessor = new DataAccessor(req.adminizer, req.user, entity, "edit");
@@ -1,9 +1,7 @@
1
1
  import { ControllerHelper } from "../helpers/controllerHelper";
2
2
  import { RequestProcessor } from "../lib/requestProcessor";
3
3
  import { FieldsHelper } from "../helpers/fieldsHelper";
4
- import { getRelationsMediaManager,
5
- // saveRelationsMediaManager
6
- } from "../lib/media-manager/helpers/MediaManagerHelper";
4
+ import { getRelationsMediaManager, saveRelationsMediaManager } from "../lib/media-manager/helpers/MediaManagerHelper";
7
5
  import { DataAccessor } from "../lib/DataAccessor";
8
6
  import { Adminizer } from "../lib/Adminizer";
9
7
  import inertiaAddHelper from "../helpers/inertiaAddHelper";
@@ -114,7 +112,7 @@ export default async function edit(req, res) {
114
112
  }
115
113
  try {
116
114
  let newRecord = await entity.model.update(params, reqData, dataAccessor);
117
- // await saveRelationsMediaManager(fields, rawReqData, entity.model.identity, newRecord[0].id)
115
+ await saveRelationsMediaManager(fields, rawReqData, entity.model.identity, newRecord[0].id);
118
116
  Adminizer.log.debug(`Record was updated: `, newRecord);
119
117
  if (req.body.jsonPopupCatalog) {
120
118
  return res.json({ record: newRecord });
@@ -1,4 +1,5 @@
1
1
  import { ControllerHelper } from "../helpers/controllerHelper";
2
+ import { deleteRelationsMediaManager } from "../lib/media-manager/helpers/MediaManagerHelper";
2
3
  import { DataAccessor } from "../lib/DataAccessor";
3
4
  import { Adminizer } from "../lib/Adminizer";
4
5
  export default async function remove(req, res) {
@@ -61,7 +62,7 @@ export default async function remove(req, res) {
61
62
  destroyedRecord = await entity.model.destroy(q, dataAccessor);
62
63
  console.log(destroyedRecord[0]);
63
64
  // delete relations media manager
64
- // await deleteRelationsMediaManager(req.adminizer, entity.name, destroyedRecord)
65
+ await deleteRelationsMediaManager(req.adminizer, entity.name, destroyedRecord);
65
66
  }
66
67
  catch (e) {
67
68
  Adminizer.log.error('adminpanel > error', e);
@@ -192,6 +192,22 @@ export declare abstract class AbstractMediaManager {
192
192
  data: MediaManagerItem[];
193
193
  next: boolean;
194
194
  }>;
195
+ /**
196
+ * Save Relations.
197
+ * @param data
198
+ * @param model model in which a mediafile connection was added
199
+ * @param modelId Id in the model in which the mediafile was added
200
+ * @param widgetName
201
+ */
202
+ abstract setRelations(data: MediaManagerWidgetData[],
203
+ /**
204
+ * widget model in which a mediafile connection was added
205
+ */
206
+ model: string,
207
+ /**
208
+ * widget Id in the model in which the mediafile was added
209
+ */
210
+ modelId: string, widgetName: string): Promise<void>;
195
211
  abstract getItemsList(items: MediaManagerWidgetItem[]): Promise<MediaManagerWidgetClientItem[]>;
196
212
  /**
197
213
  * Search all items.
@@ -1,8 +1,9 @@
1
- import { AbstractMediaManager, MediaManagerItem, File, MediaManagerWidgetItem, MediaManagerWidgetClientItem, SortCriteria } from "./AbstractMediaManager";
1
+ import { AbstractMediaManager, MediaManagerItem, File, MediaManagerWidgetItem, MediaManagerWidgetData, MediaManagerWidgetClientItem, SortCriteria } from "./AbstractMediaManager";
2
2
  import { Adminizer } from "../Adminizer";
3
3
  export declare class DefaultMediaManager extends AbstractMediaManager {
4
4
  readonly itemTypes: File<MediaManagerItem>[];
5
5
  model: string;
6
+ modelAssoc: string;
6
7
  id: string;
7
8
  protected readonly adminizer: Adminizer;
8
9
  constructor(adminizer: Adminizer, id: string, urlPathPrefix: string, fileStoragePath: string);
@@ -11,5 +12,6 @@ export declare class DefaultMediaManager extends AbstractMediaManager {
11
12
  next: boolean;
12
13
  }>;
13
14
  searchAll(s: string, group: string): Promise<MediaManagerItem[]>;
15
+ setRelations(data: MediaManagerWidgetData[], model: string, modelId: string, widgetName: string): Promise<void>;
14
16
  getItemsList(items: MediaManagerWidgetItem[]): Promise<MediaManagerWidgetClientItem[]>;
15
17
  }
@@ -4,7 +4,7 @@ import { ApplicationItem, ImageItem, TextItem, VideoItem } from "./Items";
4
4
  export class DefaultMediaManager extends AbstractMediaManager {
5
5
  itemTypes = [];
6
6
  model = "mediamanagerap";
7
- // public modelAssoc: string = "mediamanagerassociationsap";
7
+ modelAssoc = "mediamanagerassociationsap";
8
8
  id;
9
9
  adminizer;
10
10
  constructor(adminizer, id, urlPathPrefix, fileStoragePath) {
@@ -55,29 +55,27 @@ export class DefaultMediaManager extends AbstractMediaManager {
55
55
  }
56
56
  return data;
57
57
  }
58
- // public async setRelations(data: MediaManagerWidgetData[], model: string, modelId: string, widgetName: string,): Promise<void> {
59
- // let modelAssociations = await this.adminizer.modelHandler.model.get(this.modelAssoc)["_find"]({
60
- // where: {modelId: modelId, model: model, widgetName: widgetName},
61
- // });
62
- //
63
- // for (const modelAssociation of modelAssociations) {
64
- // const q: Record<string, any> = {};
65
- // const pk = this.adminizer.modelHandler.model.get(this.modelAssoc).primaryKey;
66
- // q[pk] = modelAssociation.id;
67
- // await this.adminizer.modelHandler.model.get(this.modelAssoc)["_destroy"](q);
68
- // }
69
- //
70
- // for (const [key, widgetItem] of data.entries()) {
71
- // await this.adminizer.modelHandler.model.get(this.modelAssoc)["_create"]({
72
- // mediaManagerId: this.id,
73
- // model: model,
74
- // modelId: modelId,
75
- // file: widgetItem.id,
76
- // widgetName: widgetName,
77
- // sortOrder: key + 1,
78
- // });
79
- // }
80
- // }
58
+ async setRelations(data, model, modelId, widgetName) {
59
+ let modelAssociations = await this.adminizer.modelHandler.model.get(this.modelAssoc)["_find"]({
60
+ where: { modelId: modelId, model: model, widgetName: widgetName },
61
+ });
62
+ for (const modelAssociation of modelAssociations) {
63
+ const q = {};
64
+ const pk = this.adminizer.modelHandler.model.get(this.modelAssoc).primaryKey;
65
+ q[pk] = modelAssociation.id;
66
+ await this.adminizer.modelHandler.model.get(this.modelAssoc)["_destroy"](q);
67
+ }
68
+ for (const [key, widgetItem] of data.entries()) {
69
+ await this.adminizer.modelHandler.model.get(this.modelAssoc)["_create"]({
70
+ mediaManagerId: this.id,
71
+ model: model,
72
+ modelId: modelId,
73
+ file: widgetItem.id,
74
+ widgetName: widgetName,
75
+ sortOrder: key + 1,
76
+ });
77
+ }
78
+ }
81
79
  async getItemsList(items) {
82
80
  let widgetItems = [];
83
81
  for (const item of items) {
@@ -1,5 +1,7 @@
1
- import { MediaManagerItem, MediaManagerWidgetJSON } from "../AbstractMediaManager";
1
+ import { Fields } from "../../../helpers/fieldsHelper";
2
+ import { MediaManagerItem, MediaManagerWidgetItem, MediaManagerWidgetJSON } from "../AbstractMediaManager";
2
3
  import { Adminizer } from "../../Adminizer";
4
+ type PostParams = Record<string, string | number | boolean | object | string[] | number[] | null>;
3
5
  /**
4
6
  * Create a random file name with prefix and type. If prefix is true, the file name will be prefixed with a random string.
5
7
  * @param filenameOrig
@@ -14,14 +16,24 @@ export declare function randomFileName(filenameOrig: string, type: string, prefi
14
16
  * @param model
15
17
  * @param recordId
16
18
  */
19
+ export declare function saveRelationsMediaManager(fields: Fields, reqData: PostParams, model: string, recordId: string): Promise<void>;
17
20
  /**
18
21
  * Get realtions
19
22
  * @param data
20
23
  */
21
24
  export declare function getRelationsMediaManager(data: MediaManagerWidgetJSON): Promise<import("../AbstractMediaManager").MediaManagerWidgetClientItem[]>;
25
+ /**
26
+ * Delate Ralations
27
+ * @param model
28
+ * @param record
29
+ */
30
+ export declare function deleteRelationsMediaManager(adminizer: Adminizer, model: string, record: {
31
+ [p: string]: string | MediaManagerWidgetItem[];
32
+ }[]): Promise<void>;
22
33
  /**
23
34
  * @param adminizer
24
35
  * @param variants
25
36
  * @param model
26
37
  */
27
38
  export declare function populateVariants(adminizer: Adminizer, variants: MediaManagerItem[], model: string): Promise<MediaManagerItem[]>;
39
+ export {};
@@ -18,17 +18,17 @@ export function randomFileName(filenameOrig, type, prefix) {
18
18
  * @param model
19
19
  * @param recordId
20
20
  */
21
- // export async function saveRelationsMediaManager(fields: Fields, reqData: PostParams, model: string, recordId: string) {
22
- // for (let prop in reqData) {
23
- // let fieldConfigConfig = fields[prop].config as BaseFieldConfig;
24
- // let options = fieldConfigConfig.options as MediaManagerOptionsField;
25
- // if (fieldConfigConfig.type === 'mediamanager') {
26
- // let data = reqData[prop] as MediaManagerWidgetData[];
27
- // let mediaManager = MediaManagerHandler.get(options?.id ?? 'default')
28
- // await mediaManager.setRelations(data, model, recordId, prop)
29
- // }
30
- // }
31
- // }
21
+ export async function saveRelationsMediaManager(fields, reqData, model, recordId) {
22
+ for (let prop in reqData) {
23
+ let fieldConfigConfig = fields[prop].config;
24
+ let options = fieldConfigConfig.options;
25
+ if (fieldConfigConfig.type === 'mediamanager') {
26
+ let data = reqData[prop];
27
+ let mediaManager = MediaManagerHandler.get(options?.id ?? 'default');
28
+ await mediaManager.setRelations(data, model, recordId, prop);
29
+ }
30
+ }
31
+ }
32
32
  /**
33
33
  * Get realtions
34
34
  * @param data
@@ -37,25 +37,23 @@ export async function getRelationsMediaManager(data) {
37
37
  let mediaManager = MediaManagerHandler.get(data.mediaManagerId);
38
38
  return await mediaManager.getItemsList(data.list ?? []);
39
39
  }
40
- // /**
41
- // * Delate Ralations
42
- // * @param model
43
- // * @param record
44
- // */
45
- // export async function deleteRelationsMediaManager(adminizer: Adminizer, model: string, record: {
46
- // [p: string]: string | MediaManagerWidgetItem[]
47
- // }[]) {
48
- // let config = adminizer.config.models[model] as ModelConfig
49
- // for (const key of Object.keys(record[0])) {
50
- // let field = config.fields[key] as BaseFieldConfig
51
- // if (field && field.type === 'mediamanager') {
52
- // const option = field.options as MediaManagerOptionsField
53
- // let mediaManager = MediaManagerHandler.get(option?.id ?? 'default')
54
- // let emptyData: MediaManagerWidgetData[] = []
55
- // await mediaManager.setRelations(emptyData, model, record[0].id as string, key)
56
- // }
57
- // }
58
- // }
40
+ /**
41
+ * Delate Ralations
42
+ * @param model
43
+ * @param record
44
+ */
45
+ export async function deleteRelationsMediaManager(adminizer, model, record) {
46
+ let config = adminizer.config.models[model];
47
+ for (const key of Object.keys(record[0])) {
48
+ let field = config.fields[key];
49
+ if (field && field.type === 'mediamanager') {
50
+ const option = field.options;
51
+ let mediaManager = MediaManagerHandler.get(option?.id ?? 'default');
52
+ let emptyData = [];
53
+ await mediaManager.setRelations(emptyData, model, record[0].id, key);
54
+ }
55
+ }
56
+ }
59
57
  /**
60
58
  * @param adminizer
61
59
  * @param variants
@@ -104,6 +104,8 @@ export async function up({ context }) {
104
104
  await context.createTable("groupapuserap", {
105
105
  UserAPId: { type: DataTypes.INTEGER, allowNull: false, references: { model: "userap", key: "id" } },
106
106
  GroupAPId: { type: DataTypes.INTEGER, allowNull: false, references: { model: "groupap", key: "id" } },
107
+ createdAt: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
108
+ updatedAt: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
107
109
  });
108
110
  }
109
111
  export async function down({ context }) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "4.3.0-build.88",
4
+ "version": "4.3.0-build.90",
5
5
  "main": "index.js",
6
6
  "exports": {
7
7
  ".": "./index.js",