Skip to content

Commit 101889b

Browse files
authored
Merge pull request #47 from devforth/inlinelist
Inlinelist
2 parents 13cb448 + 7dcb46d commit 101889b

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

adminforth/plugins/foreign-inline-list/custom/InlineList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ watch([filters], async () => {
182182
183183
async function startBulkAction(actionId) {
184184
const data = await callAdminForthApi({
185-
path: '/start_bulk_action',
185+
path: `/plugin/${props.meta.pluginInstanceId}/start_bulk_action`,
186186
method: 'POST',
187187
body: {
188188
resourceId: listResource.value.resourceId,

adminforth/plugins/foreign-inline-list/index.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
3535
}
3636
// exclude "plugins" key
3737
const resourceCopy = JSON.parse(JSON.stringify({ ...resource, plugins: undefined }));
38-
const { allowedActions } = await interpretResource(adminUser, resource, {}, ActionCheckSource.DisplayButtons, this.adminforth);
3938

40-
4139
if (this.options.modifyTableResourceConfig) {
4240
this.options.modifyTableResourceConfig(resourceCopy);
4341
}
42+
43+
const { allowedActions } = await interpretResource(adminUser, resourceCopy, {}, ActionCheckSource.DisplayButtons, this.adminforth);
44+
4445
return {
4546
resource: {
4647
...resourceCopy,
@@ -52,7 +53,52 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
5253
};
5354
}
5455
});
56+
server.endpoint({
57+
method: 'POST',
58+
path: `/plugin/${this.pluginInstanceId}/start_bulk_action`,
59+
handler: async ({ body, adminUser, tr }) => {
60+
const { resourceId, actionId, recordIds } = body;
61+
const resource = this.adminforth.config.resources.find((res) => res.resourceId == resourceId);
62+
if (!resource) {
63+
return { error: await tr(`Resource {resourceId} not found`, 'errors', { resourceId }) };
64+
}
65+
66+
const resourceCopy = JSON.parse(JSON.stringify({ ...resource, plugins: undefined }));
5567

68+
69+
if (this.options.modifyTableResourceConfig) {
70+
this.options.modifyTableResourceConfig(resourceCopy);
71+
}
72+
73+
const { allowedActions } = await interpretResource(
74+
adminUser,
75+
resourceCopy,
76+
{ requestBody: body },
77+
ActionCheckSource.BulkActionRequest,
78+
this.adminforth
79+
);
80+
81+
const action = resourceCopy.options.bulkActions.find((act) => act.id == actionId);
82+
if (!action) {
83+
return { error: await tr(`Action {actionId} not found`, 'errors', { actionId }) };
84+
}
85+
86+
if (action.allowed) {
87+
const execAllowed = await action.allowed({ adminUser, resourceCopy, selectedIds: recordIds, allowedActions });
88+
if (!execAllowed) {
89+
return { error: await tr(`Action "{actionId}" not allowed`, 'errors', { actionId: action.label }) };
90+
}
91+
}
92+
const response = await action.action({selectedIds: recordIds, adminUser, resourceCopy, tr});
93+
94+
return {
95+
actionId,
96+
recordIds,
97+
resourceId,
98+
...response
99+
}
100+
}
101+
})
56102
}
57103

58104
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {

0 commit comments

Comments
 (0)