Skip to content

Commit e0b04b0

Browse files
committed
Revert "Merge pull request #11 from devforth/feature/AdminForth/1073/update-foreigninlineli-to-crea"
This reverts commit 32490de, reversing changes made to d29e881.
1 parent 8ba0201 commit e0b04b0

File tree

2 files changed

+14
-52
lines changed

2 files changed

+14
-52
lines changed

custom/InlineList.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,9 @@ onMounted( async () => {
364364
}
365365
const foreighResourceId = props.meta.foreignResourceId;
366366
listResource.value = (await callAdminForthApi({
367-
path: `/get_resource`,
367+
path: `/plugin/${props.meta.pluginInstanceId}/get_resource`,
368368
method: 'POST',
369-
body: {
370-
resourceId: foreighResourceId,
371-
},
369+
body: {},
372370
})).resource;
373371
374372
if (listResource.value?.options?.allowedActions?.create && listResourceRefColumn.value && !listResourceRefColumn.value.showIn.create) {

index.ts

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
1414
options: PluginOptions;
1515
adminforth: IAdminForth;
1616

17-
activationOrder: number = -10000000;
18-
1917
constructor(options: PluginOptions) {
2018
super(options, import.meta.url);
2119
this.options = options;
@@ -124,15 +122,16 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
124122
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
125123
super.modifyResourceConfig(adminforth, resourceConfig);
126124
this.adminforth = adminforth;
127-
this.foreignResource = adminforth.config.resources.find((resource) => resource.resourceId === this.options.foreignResourceId);
128125

126+
// get resource with foreignResourceId
127+
this.foreignResource = adminforth.config.resources.find((resource) => resource.resourceId === this.options.foreignResourceId);
129128
if (!this.foreignResource) {
130129
const similar = suggestIfTypo(adminforth.config.resources.map((res) => res.resourceId), this.options.foreignResourceId);
131130
throw new Error(`ForeignInlineListPlugin: Resource with ID "${this.options.foreignResourceId}" not found. ${similar ? `Did you mean "${similar}"?` : ''}`);
132131
}
133-
const idOfNewCopy = `${this.foreignResource.resourceId}_inline_list__from_${this.resourceConfig.resourceId}__`;
134132

135133

134+
const defaultSort = this.foreignResource.options?.defaultSort;
136135
const newColumn = {
137136
name: `foreignInlineList_${this.foreignResource.resourceId}`,
138137
label: 'Foreign Inline List',
@@ -152,7 +151,15 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
152151
...this.options,
153152
pluginInstanceId: this.pluginInstanceId,
154153
disableForeignListResourceRefColumn: this.options.disableForeignListResourceRefColumn,
155-
foreignResourceId: idOfNewCopy
154+
...(defaultSort
155+
? {
156+
defaultSort: {
157+
field: defaultSort.columnName,
158+
direction: defaultSort.direction,
159+
}
160+
}
161+
: {}
162+
)
156163
}
157164
}
158165
},
@@ -195,48 +202,5 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
195202
} else {
196203
resourceConfig.columns.push(newColumn);
197204
}
198-
199-
// get resource with foreignResourceId
200-
this.copyOfForeignResource = clone({ ...this.foreignResource, plugins: [] });
201-
202-
// if we install on plugin which is already a copy, adjust foreignResource references
203-
if (this.resourceConfig.resourceId.includes('_inline_list__from_')) {
204-
const originalResourceIdPart = this.resourceConfig.resourceId.split('_inline_list__from_')[0];
205-
// find column in copied resource which is foreignResource.resourceId equal to originalResourceIdPart
206-
// and change it to point to this.resourceConfig.resourceId
207-
const foreignRefColumn = this.copyOfForeignResource.columns.find(col => col.foreignResource?.resourceId === originalResourceIdPart);
208-
if (foreignRefColumn) {
209-
foreignRefColumn.foreignResource.resourceId = this.resourceConfig.resourceId;
210-
}
211-
}
212-
213-
// if foreignInlineList_ column already created, remove it
214-
this.copyOfForeignResource.columns = this.copyOfForeignResource.columns.filter(col => !col.name.startsWith('foreignInlineList_'));
215-
// we should not cate about modifications made by other plugins, while activationOrder of this plugin is very low (negative)
216-
217-
this.copyOfForeignResource.resourceId = idOfNewCopy;
218-
adminforth.config.resources.push(this.copyOfForeignResource);
219-
220-
if (this.options.modifyTableResourceConfig) {
221-
this.options.modifyTableResourceConfig(this.copyOfForeignResource);
222-
}
223-
224-
// now we need to create a copy of all plugins of foreignResource,
225-
for (const plugin of this.foreignResource.plugins || []) {
226-
const options = plugin.pluginOptions;
227-
// call constructor
228-
const pluginCopy = new (plugin.constructor as any)(options);
229-
this.copyOfForeignResource.plugins.push(pluginCopy);
230-
}
231-
232-
// activate plugins for the copyOfForeignResource
233-
for (const plugin of this.copyOfForeignResource.plugins.sort((a, b) => a.activationOrder - b.activationOrder)) {
234-
// if there already is a plugin with same instanceUniqueRepresentation, skip
235-
if (plugin.modifyResourceConfig) {
236-
await plugin.modifyResourceConfig(adminforth, this.copyOfForeignResource);
237-
}
238-
}
239-
240-
241205
}
242206
}

0 commit comments

Comments
 (0)