@adminforth/dashboard 1.4.2 → 1.5.0
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/custom/api/dashboardApi.ts +0 -4
- package/custom/skills/adminforth-dashboard/SKILL.md +111 -181
- package/dist/custom/api/dashboardApi.d.ts +0 -1
- package/dist/custom/api/dashboardApi.js +0 -5
- package/dist/custom/api/dashboardApi.ts +0 -4
- package/dist/custom/skills/adminforth-dashboard/SKILL.md +111 -181
- package/dist/endpoint/dashboard.d.ts +2 -4
- package/dist/endpoint/dashboard.js +1 -21
- package/dist/endpoint/groups.d.ts +1 -0
- package/dist/endpoint/groups.js +61 -48
- package/dist/endpoint/widgets.d.ts +1 -0
- package/dist/endpoint/widgets.js +80 -62
- package/dist/schema/api.d.ts +0 -867
- package/dist/schema/api.js +0 -5
- package/dist/services/dashboardConfigService.d.ts +4 -0
- package/dist/services/dashboardConfigService.js +46 -0
- package/endpoint/dashboard.ts +2 -33
- package/endpoint/groups.ts +91 -72
- package/endpoint/widgets.ts +114 -88
- package/package.json +1 -1
- package/schema/api.ts +0 -6
- package/services/dashboardConfigService.ts +73 -0
package/dist/endpoint/widgets.js
CHANGED
|
@@ -21,27 +21,33 @@ export function registerWidgetEndpoints(server, ctx) {
|
|
|
21
21
|
response.setStatus(403);
|
|
22
22
|
return { error: 'Dashboard edit is not allowed' };
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
let mutationError = null;
|
|
25
|
+
const updatedDashboard = yield ctx.updateDashboardConfig(body.slug, (config) => {
|
|
26
|
+
const group = config.groups.find((item) => item.id === body.groupId);
|
|
27
|
+
if (!group) {
|
|
28
|
+
mutationError = 'Dashboard group not found';
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const nextOrder = config.widgets.filter((item) => item.group_id === body.groupId).length + 1;
|
|
32
|
+
const widget = {
|
|
33
|
+
id: `widget_${randomUUID()}`,
|
|
34
|
+
group_id: body.groupId,
|
|
35
|
+
label: 'New widget',
|
|
36
|
+
size: 'small',
|
|
37
|
+
order: nextOrder,
|
|
38
|
+
target: 'empty',
|
|
39
|
+
};
|
|
40
|
+
return Object.assign(Object.assign({}, config), { widgets: [...config.widgets, widget] });
|
|
41
|
+
});
|
|
42
|
+
if (!updatedDashboard) {
|
|
26
43
|
response.setStatus(404);
|
|
27
44
|
return { error: 'Dashboard not found' };
|
|
28
45
|
}
|
|
29
|
-
|
|
30
|
-
const group = config.groups.find((item) => item.id === body.groupId);
|
|
31
|
-
if (!group) {
|
|
46
|
+
if (mutationError) {
|
|
32
47
|
response.setStatus(404);
|
|
33
|
-
return { error:
|
|
48
|
+
return { error: mutationError };
|
|
34
49
|
}
|
|
35
|
-
|
|
36
|
-
const widget = {
|
|
37
|
-
id: `widget_${randomUUID()}`,
|
|
38
|
-
group_id: body.groupId,
|
|
39
|
-
label: 'New widget',
|
|
40
|
-
size: 'small',
|
|
41
|
-
order: nextOrder,
|
|
42
|
-
target: 'empty',
|
|
43
|
-
};
|
|
44
|
-
return ctx.persistDashboardConfig(dashboard, Object.assign(Object.assign({}, config), { widgets: [...config.widgets, widget] }));
|
|
50
|
+
return updatedDashboard;
|
|
45
51
|
}),
|
|
46
52
|
});
|
|
47
53
|
server.endpoint({
|
|
@@ -55,39 +61,39 @@ export function registerWidgetEndpoints(server, ctx) {
|
|
|
55
61
|
response.setStatus(403);
|
|
56
62
|
return { error: 'Dashboard edit is not allowed' };
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
let mutationError = null;
|
|
65
|
+
const updatedDashboard = yield ctx.updateDashboardConfig(body.slug, (config) => {
|
|
66
|
+
const widget = config.widgets.find((item) => item.id === body.widgetId);
|
|
67
|
+
if (!widget) {
|
|
68
|
+
mutationError = 'Dashboard widget not found';
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const sortedWidgets = config.widgets
|
|
72
|
+
.filter((item) => item.group_id === widget.group_id)
|
|
73
|
+
.sort((a, b) => a.order - b.order);
|
|
74
|
+
const currentIndex = sortedWidgets.findIndex((item) => item.id === body.widgetId);
|
|
75
|
+
const targetIndex = body.direction === 'up' ? currentIndex - 1 : currentIndex + 1;
|
|
76
|
+
if (targetIndex < 0 || targetIndex >= sortedWidgets.length) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const reorderedWidgets = [...sortedWidgets];
|
|
80
|
+
const [movedWidget] = reorderedWidgets.splice(currentIndex, 1);
|
|
81
|
+
reorderedWidgets.splice(targetIndex, 0, movedWidget);
|
|
82
|
+
const reorderedWidgetIds = new Map(reorderedWidgets.map((item, index) => [item.id, index + 1]));
|
|
83
|
+
return Object.assign(Object.assign({}, config), { widgets: config.widgets.map((item) => {
|
|
84
|
+
var _a;
|
|
85
|
+
return (Object.assign(Object.assign({}, item), { order: (_a = reorderedWidgetIds.get(item.id)) !== null && _a !== void 0 ? _a : item.order }));
|
|
86
|
+
}) });
|
|
87
|
+
});
|
|
88
|
+
if (!updatedDashboard) {
|
|
60
89
|
response.setStatus(404);
|
|
61
90
|
return { error: 'Dashboard not found' };
|
|
62
91
|
}
|
|
63
|
-
|
|
64
|
-
const widget = config.widgets.find((item) => item.id === body.widgetId);
|
|
65
|
-
if (!widget) {
|
|
92
|
+
if (mutationError) {
|
|
66
93
|
response.setStatus(404);
|
|
67
|
-
return { error:
|
|
94
|
+
return { error: mutationError };
|
|
68
95
|
}
|
|
69
|
-
|
|
70
|
-
.filter((item) => item.group_id === widget.group_id)
|
|
71
|
-
.sort((a, b) => a.order - b.order);
|
|
72
|
-
const currentIndex = sortedWidgets.findIndex((item) => item.id === body.widgetId);
|
|
73
|
-
const targetIndex = body.direction === 'up' ? currentIndex - 1 : currentIndex + 1;
|
|
74
|
-
if (targetIndex < 0 || targetIndex >= sortedWidgets.length) {
|
|
75
|
-
return {
|
|
76
|
-
id: dashboard.id,
|
|
77
|
-
slug: dashboard.slug,
|
|
78
|
-
label: dashboard.label,
|
|
79
|
-
revision: dashboard.revision,
|
|
80
|
-
config: ctx.parseStoredDashboardConfig(dashboard.config),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
const reorderedWidgets = [...sortedWidgets];
|
|
84
|
-
const [movedWidget] = reorderedWidgets.splice(currentIndex, 1);
|
|
85
|
-
reorderedWidgets.splice(targetIndex, 0, movedWidget);
|
|
86
|
-
const reorderedWidgetIds = new Map(reorderedWidgets.map((item, index) => [item.id, index + 1]));
|
|
87
|
-
return ctx.persistDashboardConfig(dashboard, Object.assign(Object.assign({}, config), { widgets: config.widgets.map((item) => {
|
|
88
|
-
var _a;
|
|
89
|
-
return (Object.assign(Object.assign({}, item), { order: (_a = reorderedWidgetIds.get(item.id)) !== null && _a !== void 0 ? _a : item.order }));
|
|
90
|
-
}) }));
|
|
96
|
+
return updatedDashboard;
|
|
91
97
|
}),
|
|
92
98
|
});
|
|
93
99
|
server.endpoint({
|
|
@@ -101,18 +107,24 @@ export function registerWidgetEndpoints(server, ctx) {
|
|
|
101
107
|
response.setStatus(403);
|
|
102
108
|
return { error: 'Dashboard edit is not allowed' };
|
|
103
109
|
}
|
|
104
|
-
|
|
105
|
-
|
|
110
|
+
let mutationError = null;
|
|
111
|
+
const updatedDashboard = yield ctx.updateDashboardConfig(body.slug, (config) => {
|
|
112
|
+
const nextWidgets = config.widgets.filter((item) => item.id !== body.widgetId);
|
|
113
|
+
if (nextWidgets.length === config.widgets.length) {
|
|
114
|
+
mutationError = 'Dashboard widget not found';
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return Object.assign(Object.assign({}, config), { widgets: nextWidgets });
|
|
118
|
+
});
|
|
119
|
+
if (!updatedDashboard) {
|
|
106
120
|
response.setStatus(404);
|
|
107
121
|
return { error: 'Dashboard not found' };
|
|
108
122
|
}
|
|
109
|
-
|
|
110
|
-
const nextWidgets = config.widgets.filter((item) => item.id !== body.widgetId);
|
|
111
|
-
if (nextWidgets.length === config.widgets.length) {
|
|
123
|
+
if (mutationError) {
|
|
112
124
|
response.setStatus(404);
|
|
113
|
-
return { error:
|
|
125
|
+
return { error: mutationError };
|
|
114
126
|
}
|
|
115
|
-
return
|
|
127
|
+
return updatedDashboard;
|
|
116
128
|
}),
|
|
117
129
|
});
|
|
118
130
|
server.endpoint({
|
|
@@ -126,22 +138,28 @@ export function registerWidgetEndpoints(server, ctx) {
|
|
|
126
138
|
response.setStatus(403);
|
|
127
139
|
return { error: 'Dashboard edit is not allowed' };
|
|
128
140
|
}
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
let mutationError = null;
|
|
142
|
+
const updatedDashboard = yield ctx.updateDashboardConfig(body.slug, (config) => {
|
|
143
|
+
const widget = config.widgets.find((item) => item.id === body.widgetId);
|
|
144
|
+
if (!widget) {
|
|
145
|
+
mutationError = 'Dashboard widget not found';
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const typedWidgetConfig = body.config;
|
|
149
|
+
const nextWidget = Object.assign(Object.assign({}, typedWidgetConfig), { id: widget.id, group_id: widget.group_id, order: widget.order });
|
|
150
|
+
return Object.assign(Object.assign({}, config), { widgets: config.widgets.map((item) => item.id === body.widgetId
|
|
151
|
+
? nextWidget
|
|
152
|
+
: item) });
|
|
153
|
+
});
|
|
154
|
+
if (!updatedDashboard) {
|
|
131
155
|
response.setStatus(404);
|
|
132
156
|
return { error: 'Dashboard not found' };
|
|
133
157
|
}
|
|
134
|
-
|
|
135
|
-
const widget = config.widgets.find((item) => item.id === body.widgetId);
|
|
136
|
-
if (!widget) {
|
|
158
|
+
if (mutationError) {
|
|
137
159
|
response.setStatus(404);
|
|
138
|
-
return { error:
|
|
160
|
+
return { error: mutationError };
|
|
139
161
|
}
|
|
140
|
-
|
|
141
|
-
const nextWidget = Object.assign(Object.assign({}, typedWidgetConfig), { id: widget.id, group_id: widget.group_id, order: widget.order });
|
|
142
|
-
return ctx.persistDashboardConfig(dashboard, Object.assign(Object.assign({}, config), { widgets: config.widgets.map((item) => item.id === body.widgetId
|
|
143
|
-
? nextWidget
|
|
144
|
-
: item) }));
|
|
162
|
+
return updatedDashboard;
|
|
145
163
|
}),
|
|
146
164
|
});
|
|
147
165
|
server.endpoint({
|