adminizer 4.3.0-build.86 → 4.3.0-build.88
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/controllers/add.js +2 -2
- package/controllers/edit.js +5 -3
- package/controllers/form.js +10 -1
- package/controllers/remove.js +1 -2
- package/helpers/formHelper.js +3 -1
- package/helpers/inertiaFromHelper.js +12 -0
- package/interfaces/types.d.ts +1 -1
- package/lib/media-manager/AbstractMediaManager.d.ts +1 -17
- package/lib/media-manager/DefaultMediaManager.d.ts +2 -4
- package/lib/media-manager/DefaultMediaManager.js +28 -29
- package/lib/media-manager/helpers/MediaManagerHelper.d.ts +5 -8
- package/lib/media-manager/helpers/MediaManagerHelper.js +35 -33
- package/lib/notifications/GeneralNotificationService.js +3 -0
- package/package.json +1 -1
package/controllers/add.js
CHANGED
|
@@ -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 {
|
|
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");
|
package/controllers/edit.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ControllerHelper } from "../helpers/controllerHelper";
|
|
2
2
|
import { RequestProcessor } from "../lib/requestProcessor";
|
|
3
3
|
import { FieldsHelper } from "../helpers/fieldsHelper";
|
|
4
|
-
import { getRelationsMediaManager,
|
|
4
|
+
import { getRelationsMediaManager,
|
|
5
|
+
// saveRelationsMediaManager
|
|
6
|
+
} from "../lib/media-manager/helpers/MediaManagerHelper";
|
|
5
7
|
import { DataAccessor } from "../lib/DataAccessor";
|
|
6
8
|
import { Adminizer } from "../lib/Adminizer";
|
|
7
9
|
import inertiaAddHelper from "../helpers/inertiaAddHelper";
|
|
@@ -27,8 +29,8 @@ export default async function edit(req, res) {
|
|
|
27
29
|
}
|
|
28
30
|
let record;
|
|
29
31
|
let dataAccessor;
|
|
32
|
+
const id = req.params.id;
|
|
30
33
|
try {
|
|
31
|
-
const id = req.params.id;
|
|
32
34
|
dataAccessor = new DataAccessor(req.adminizer, req.user, entity, "edit");
|
|
33
35
|
record = await entity.model.findOne({ id: id }, dataAccessor);
|
|
34
36
|
if (!record)
|
|
@@ -112,7 +114,7 @@ export default async function edit(req, res) {
|
|
|
112
114
|
}
|
|
113
115
|
try {
|
|
114
116
|
let newRecord = await entity.model.update(params, reqData, dataAccessor);
|
|
115
|
-
await saveRelationsMediaManager(fields, rawReqData, entity.model.identity, newRecord[0].id)
|
|
117
|
+
// await saveRelationsMediaManager(fields, rawReqData, entity.model.identity, newRecord[0].id)
|
|
116
118
|
Adminizer.log.debug(`Record was updated: `, newRecord);
|
|
117
119
|
if (req.body.jsonPopupCatalog) {
|
|
118
120
|
return res.json({ record: newRecord });
|
package/controllers/form.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FormHelper } from "../helpers/formHelper";
|
|
2
2
|
import { Adminizer } from "../lib/Adminizer";
|
|
3
3
|
import inertiaFormHelper from "../helpers/inertiaFromHelper";
|
|
4
|
+
import { getRelationsMediaManager } from "../lib/media-manager/helpers/MediaManagerHelper";
|
|
4
5
|
export default async function form(req, res) {
|
|
5
6
|
let slug = req.params.slug;
|
|
6
7
|
// Check slug
|
|
@@ -54,7 +55,15 @@ export default async function form(req, res) {
|
|
|
54
55
|
}
|
|
55
56
|
for (let key of Object.keys(form)) {
|
|
56
57
|
try {
|
|
57
|
-
|
|
58
|
+
if (key === 'mediamanager') {
|
|
59
|
+
form[key].value = await getRelationsMediaManager({
|
|
60
|
+
list: await req.adminizer.config.forms.get(slug, key),
|
|
61
|
+
mediaManagerId: form[key].options?.id ?? "default"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
form[key].value = await req.adminizer.config.forms.get(slug, key);
|
|
66
|
+
}
|
|
58
67
|
}
|
|
59
68
|
catch (e) {
|
|
60
69
|
Adminizer.log.silly(`'${slug}' property was not found in storage, using source file`);
|
package/controllers/remove.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ControllerHelper } from "../helpers/controllerHelper";
|
|
2
|
-
import { deleteRelationsMediaManager } from "../lib/media-manager/helpers/MediaManagerHelper";
|
|
3
2
|
import { DataAccessor } from "../lib/DataAccessor";
|
|
4
3
|
import { Adminizer } from "../lib/Adminizer";
|
|
5
4
|
export default async function remove(req, res) {
|
|
@@ -62,7 +61,7 @@ export default async function remove(req, res) {
|
|
|
62
61
|
destroyedRecord = await entity.model.destroy(q, dataAccessor);
|
|
63
62
|
console.log(destroyedRecord[0]);
|
|
64
63
|
// delete relations media manager
|
|
65
|
-
await deleteRelationsMediaManager(req.adminizer, entity.name, destroyedRecord)
|
|
64
|
+
// await deleteRelationsMediaManager(req.adminizer, entity.name, destroyedRecord)
|
|
66
65
|
}
|
|
67
66
|
catch (e) {
|
|
68
67
|
Adminizer.log.error('adminpanel > error', e);
|
package/helpers/formHelper.js
CHANGED
|
@@ -22,7 +22,9 @@ export class FormHelper {
|
|
|
22
22
|
}
|
|
23
23
|
let form = path.basename(formJson, '.json');
|
|
24
24
|
try {
|
|
25
|
-
|
|
25
|
+
const filePath = path.join(formsDirectoryPath, formJson);
|
|
26
|
+
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
27
|
+
adminizer.config.forms.data[form] = JSON.parse(fileContent);
|
|
26
28
|
}
|
|
27
29
|
catch (error) {
|
|
28
30
|
Adminizer.log.error(`Adminpanel > Error when reading ${formJson}: ${error}`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { inputText, setSelectMany, getControlsOptions } from "./inertiaAddHelper";
|
|
2
|
+
import { MediaManagerHandler } from "../lib/media-manager/MediaManagerHandler";
|
|
2
3
|
export default function inertiaFormHelper(req, postLink, formData) {
|
|
3
4
|
let props = {
|
|
4
5
|
fields: [],
|
|
@@ -71,6 +72,17 @@ export default function inertiaFormHelper(req, postLink, formData) {
|
|
|
71
72
|
fieldType = 'geoJson';
|
|
72
73
|
options = getControlsOptions(field, req, fieldType, 'leaflet');
|
|
73
74
|
}
|
|
75
|
+
if (type === 'mediamanager') {
|
|
76
|
+
const mOptions = field.options;
|
|
77
|
+
const mediaManager = MediaManagerHandler.get(mOptions.id || 'default');
|
|
78
|
+
if (!mediaManager) {
|
|
79
|
+
options = {};
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
fieldType = 'mediamanager';
|
|
83
|
+
options = mOptions;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
74
86
|
props.fields.push({
|
|
75
87
|
label: label,
|
|
76
88
|
tooltip: tooltip,
|
package/interfaces/types.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface PropsField {
|
|
|
23
23
|
disabled?: boolean;
|
|
24
24
|
required?: boolean;
|
|
25
25
|
isIn?: string[] | number[] | boolean[];
|
|
26
|
-
options?: Record<string,
|
|
26
|
+
options?: Record<string, any> | Record<string, any>[];
|
|
27
27
|
}
|
|
28
28
|
export interface DiffChanges {
|
|
29
29
|
field: string;
|
|
@@ -192,23 +192,7 @@ 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>;
|
|
211
|
-
abstract getRelations(items: MediaManagerWidgetItem[]): Promise<MediaManagerWidgetClientItem[]>;
|
|
195
|
+
abstract getItemsList(items: MediaManagerWidgetItem[]): Promise<MediaManagerWidgetClientItem[]>;
|
|
212
196
|
/**
|
|
213
197
|
* Search all items.
|
|
214
198
|
* If not this.allowSearch = true then it will not come here
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { AbstractMediaManager, MediaManagerItem, File, MediaManagerWidgetItem,
|
|
1
|
+
import { AbstractMediaManager, MediaManagerItem, File, MediaManagerWidgetItem, 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;
|
|
7
6
|
id: string;
|
|
8
7
|
protected readonly adminizer: Adminizer;
|
|
9
8
|
constructor(adminizer: Adminizer, id: string, urlPathPrefix: string, fileStoragePath: string);
|
|
@@ -12,6 +11,5 @@ export declare class DefaultMediaManager extends AbstractMediaManager {
|
|
|
12
11
|
next: boolean;
|
|
13
12
|
}>;
|
|
14
13
|
searchAll(s: string, group: string): Promise<MediaManagerItem[]>;
|
|
15
|
-
|
|
16
|
-
getRelations(items: MediaManagerWidgetItem[]): Promise<MediaManagerWidgetClientItem[]>;
|
|
14
|
+
getItemsList(items: MediaManagerWidgetItem[]): Promise<MediaManagerWidgetClientItem[]>;
|
|
17
15
|
}
|
|
@@ -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
|
-
modelAssoc = "mediamanagerassociationsap";
|
|
7
|
+
// public modelAssoc: string = "mediamanagerassociationsap";
|
|
8
8
|
id;
|
|
9
9
|
adminizer;
|
|
10
10
|
constructor(adminizer, id, urlPathPrefix, fileStoragePath) {
|
|
@@ -19,7 +19,7 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
19
19
|
this.adminizer = adminizer;
|
|
20
20
|
}
|
|
21
21
|
async getAll(limit, skip, sort, group) {
|
|
22
|
-
//
|
|
22
|
+
//TODO refactor CRUD functions for DataAccessor usage
|
|
23
23
|
let data = await this.adminizer.modelHandler.model.get(this.model)["_find"]({
|
|
24
24
|
where: { parent: null, group: group },
|
|
25
25
|
limit: limit,
|
|
@@ -41,7 +41,7 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
async searchAll(s, group) {
|
|
44
|
-
//
|
|
44
|
+
//TODO refactor CRUD functions for DataAccessor usage
|
|
45
45
|
let data = await this.adminizer.modelHandler.model.get(this.model)["_find"]({
|
|
46
46
|
where: { filename: { contains: s }, parent: null, group: group },
|
|
47
47
|
sort: "createdAt DESC",
|
|
@@ -55,34 +55,33 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
55
55
|
}
|
|
56
56
|
return data;
|
|
57
57
|
}
|
|
58
|
-
async setRelations(data, model, modelId, widgetName) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
async getRelations(items) {
|
|
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
|
+
// }
|
|
81
|
+
async getItemsList(items) {
|
|
83
82
|
let widgetItems = [];
|
|
84
83
|
for (const item of items) {
|
|
85
|
-
//
|
|
84
|
+
//TODO refactor CRUD functions for DataAccessor usage
|
|
86
85
|
let file = (await this.adminizer.modelHandler.model.get(this.model)["_find"]({
|
|
87
86
|
where: { id: item.id }
|
|
88
87
|
}, { populate: [["variants", { sort: "createdAt DESC" }]] }))[0];
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MediaManagerItem, MediaManagerWidgetItem, MediaManagerWidgetJSON } from "../AbstractMediaManager";
|
|
1
|
+
import { MediaManagerItem, MediaManagerWidgetJSON } from "../AbstractMediaManager";
|
|
3
2
|
import { Adminizer } from "../../Adminizer";
|
|
4
|
-
type PostParams = Record<string, string | number | boolean | object | string[] | number[] | null>;
|
|
5
3
|
/**
|
|
6
4
|
* Create a random file name with prefix and type. If prefix is true, the file name will be prefixed with a random string.
|
|
7
5
|
* @param filenameOrig
|
|
@@ -16,15 +14,14 @@ export declare function randomFileName(filenameOrig: string, type: string, prefi
|
|
|
16
14
|
* @param model
|
|
17
15
|
* @param recordId
|
|
18
16
|
*/
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Get realtions
|
|
19
|
+
* @param data
|
|
20
|
+
*/
|
|
20
21
|
export declare function getRelationsMediaManager(data: MediaManagerWidgetJSON): Promise<import("../AbstractMediaManager").MediaManagerWidgetClientItem[]>;
|
|
21
|
-
export declare function deleteRelationsMediaManager(adminizer: Adminizer, model: string, record: {
|
|
22
|
-
[p: string]: string | MediaManagerWidgetItem[];
|
|
23
|
-
}[]): Promise<void>;
|
|
24
22
|
/**
|
|
25
23
|
* @param adminizer
|
|
26
24
|
* @param variants
|
|
27
25
|
* @param model
|
|
28
26
|
*/
|
|
29
27
|
export declare function populateVariants(adminizer: Adminizer, variants: MediaManagerItem[], model: string): Promise<MediaManagerItem[]>;
|
|
30
|
-
export {};
|
|
@@ -18,42 +18,44 @@ export function randomFileName(filenameOrig, type, prefix) {
|
|
|
18
18
|
* @param model
|
|
19
19
|
* @param recordId
|
|
20
20
|
*/
|
|
21
|
-
export async function saveRelationsMediaManager(fields, reqData, model, recordId) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
* Get realtions
|
|
34
|
-
* @param data
|
|
35
|
-
*/
|
|
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
|
+
// }
|
|
32
|
+
/**
|
|
33
|
+
* Get realtions
|
|
34
|
+
* @param data
|
|
35
|
+
*/
|
|
36
36
|
export async function getRelationsMediaManager(data) {
|
|
37
37
|
let mediaManager = MediaManagerHandler.get(data.mediaManagerId);
|
|
38
|
-
return await mediaManager.
|
|
39
|
-
}
|
|
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
|
-
}
|
|
38
|
+
return await mediaManager.getItemsList(data.list ?? []);
|
|
56
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
|
+
// }
|
|
57
59
|
/**
|
|
58
60
|
* @param adminizer
|
|
59
61
|
* @param variants
|
|
@@ -26,6 +26,9 @@ export class GeneralNotificationService extends AbstractNotificationService {
|
|
|
26
26
|
if (this.adminizer.accessRightsHelper.hasPermission(`notification-${this.notificationClass}`, user)) {
|
|
27
27
|
await this.createUserNotification(notificationDB.id, user.id);
|
|
28
28
|
}
|
|
29
|
+
else {
|
|
30
|
+
Adminizer.log.error(`[${this.notificationClass}] User ${user.id} doesn't have permission to receive this notification`);
|
|
31
|
+
}
|
|
29
32
|
}
|
|
30
33
|
catch (error) {
|
|
31
34
|
Adminizer.log.error('Error creating UserNotificationAP:', error);
|