Skip to content

Commit 076ad08

Browse files
committed
Merge branch 'main' of github.com:devforth/adminforth-bulk-ai-flow
2 parents 9ec41af + 75be31b commit 076ad08

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

custom/ImageGenerationCarousel.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ import { ProgressBar } from '@/afcl';
189189
const { t: $t } = useI18n();
190190
191191
const prompt = ref('');
192-
const emit = defineEmits(['close', 'selectImage', 'error']);
193-
const props = defineProps(['meta', 'record', 'images', 'recordId', 'prompt', 'fieldName', 'isError', 'errorMessage']);
192+
const emit = defineEmits(['close', 'selectImage', 'error', 'updateCarouselIndex']);
193+
const props = defineProps(['meta', 'record', 'images', 'recordId', 'prompt', 'fieldName', 'isError', 'errorMessage', 'carouselImageIndex']);
194194
const images = ref([]);
195195
const loading = ref(false);
196196
const attachmentFiles = ref<string[]>([])
@@ -204,12 +204,14 @@ function minifyField(field: string): string {
204204
205205
const caurosel = ref(null);
206206
onMounted(async () => {
207-
images.value.push((props.images || []));
207+
for (const img of props.images || []) {
208+
images.value.push(img);
209+
}
208210
const temp = await getGenerationPrompt() || '';
209211
prompt.value = temp[props.fieldName];
210212
await nextTick();
211213
212-
const currentIndex = caurosel.value?.getActiveItem()?.position || 0;
214+
const currentIndex = props.carouselImageIndex || 0;
213215
caurosel.value = new Carousel(
214216
document.getElementById('gallery'),
215217
images.value.map((img, index) => {
@@ -294,6 +296,12 @@ async function confirmImage() {
294296
const currentIndex = caurosel.value?.getActiveItem()?.position || 0;
295297
const img = images.value[currentIndex];
296298
299+
props.images.splice(0, props.images.length);
300+
for (const i of images.value) {
301+
props.images.push(i);
302+
}
303+
304+
emit('updateCarouselIndex', currentIndex, props.recordId, props.fieldName);
297305
emit('selectImage', img, props.recordId, props.fieldName);
298306
emit('close');
299307

custom/VisionAction.vue

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
header="Bulk AI Flow"
1111
class="!max-w-full w-full lg:w-[1600px] !lg:max-w-[1600px]"
1212
:buttons="[
13-
{ label: checkedCount > 1 ? 'Save fields' : 'Save field', options: { disabled: isLoading || checkedCount < 1 || isCriticalError, loader: isLoading, class: 'w-fit sm:w-40' }, onclick: (dialog) => { saveData(); dialog.hide(); } },
13+
{ label: checkedCount > 1 ? 'Save fields' : 'Save field', options: { disabled: isLoading || checkedCount < 1 || isCriticalError || isFetchingRecords, loader: isLoading, class: 'w-fit sm:w-40' }, onclick: (dialog) => { saveData(); dialog.hide(); } },
1414
{ label: 'Cancel', onclick: (dialog) => dialog.hide() },
1515
]"
1616
>
@@ -31,6 +31,8 @@
3131
:primaryKey="primaryKey"
3232
:openGenerationCarousel="openGenerationCarousel"
3333
@error="handleTableError"
34+
:carouselSaveImages="carouselSaveImages"
35+
:carouselImageIndex="carouselImageIndex"
3436
/>
3537
</div>
3638
<div class="text-red-600 flex items-center w-full">
@@ -73,11 +75,14 @@ const tableColumns = ref([]);
7375
const tableColumnsIndexes = ref([]);
7476
const customFieldNames = ref([]);
7577
const selected = ref<any[]>([]);
78+
const carouselSaveImages = ref<any[]>([]);
79+
const carouselImageIndex = ref<any[]>([]);
7680
const isAiResponseReceivedAnalize = ref([]);
7781
const isAiResponseReceivedImage = ref([]);
7882
const primaryKey = props.meta.primaryKey;
7983
const openGenerationCarousel = ref([]);
8084
const isLoading = ref(false);
85+
const isFetchingRecords = ref(false);
8186
const isError = ref(false);
8287
const isCriticalError = ref(false);
8388
const isImageGenerationError = ref(false);
@@ -102,7 +107,7 @@ const openDialog = async () => {
102107
return acc;
103108
},{[primaryKey]: records.value[i][primaryKey]} as Record<string, boolean>);
104109
}
105-
isLoading.value = true;
110+
isFetchingRecords.value = true;
106111
const tasks = [];
107112
if (props.meta.isFieldsForAnalizeFromImages) {
108113
tasks.push(runAiAction({
@@ -126,14 +131,34 @@ const openDialog = async () => {
126131
}));
127132
}
128133
await Promise.all(tasks);
129-
isLoading.value = false;
134+
135+
if (props.meta.isImageGeneration) {
136+
fillCarouselSaveImages();
137+
}
138+
139+
isFetchingRecords.value = false;
130140
}
131141
132142
watch(selected, (val) => {
133143
//console.log('Selected changed:', val);
134144
checkedCount.value = val.filter(item => item.isChecked === true).length;
135145
}, { deep: true });
136146
147+
function fillCarouselSaveImages() {
148+
for (const item of selected.value) {
149+
const tempItem: any = {};
150+
const tempItemIndex: any = {};
151+
for (const [key, value] of Object.entries(item)) {
152+
if (props.meta.outputImageFields?.includes(key)) {
153+
tempItem[key] = [value];
154+
tempItemIndex[key] = 0;
155+
}
156+
}
157+
carouselSaveImages.value.push(tempItem);
158+
carouselImageIndex.value.push(tempItemIndex);
159+
}
160+
}
161+
137162
138163
function formatLabel(str) {
139164
return str

custom/VisionTable.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@
9494
<div>
9595
<GenerationCarousel
9696
v-if="openGenerationCarousel[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
97-
:images="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
97+
:images="carouselSaveImages[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
9898
:recordId="item[primaryKey]"
9999
:meta="props.meta"
100100
:fieldName="n"
101+
:carouselImageIndex="carouselImageIndex[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
101102
@error="handleError"
102103
@close="openGenerationCarousel[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n] = false"
103104
@selectImage="updateSelectedImage"
105+
@updateCarouselIndex="updateActiveIndex"
104106
/>
105107
</div>
106108
</div>
@@ -135,6 +137,8 @@ const props = defineProps<{
135137
openGenerationCarousel: any
136138
isError: boolean,
137139
errorMessage: string
140+
carouselSaveImages: any[]
141+
carouselImageIndex: any[]
138142
}>();
139143
const emit = defineEmits(['error']);
140144
@@ -182,6 +186,10 @@ function handleError({ isError, errorMessage }) {
182186
});
183187
}
184188
189+
function updateActiveIndex(newIndex: number, id: any, fieldName: string) {
190+
props.carouselImageIndex[props.tableColumnsIndexes.findIndex(el => el[props.primaryKey] === id)][fieldName] = newIndex;
191+
}
192+
185193
</script>
186194

187195
<style scoped>

index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,13 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
322322
for( const [index, record] of records.entries() ) {
323323
records[index]._label = this.resourceConfig.recordLabel(records[index]);
324324
}
325+
const order = Object.fromEntries(body.body.record.map((id, i) => [id, i]));
326+
327+
const sortedRecords = records.sort(
328+
(a, b) => order[a.id] - order[b.id]
329+
);
325330
return {
326-
records,
331+
records: sortedRecords,
327332
};
328333
}
329334
});
@@ -390,7 +395,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
390395
}
391396
}
392397
try {
393-
const AuditLogPlugin = this.adminforth.getPluginByClassName('AuditLogPlugin');
398+
const AuditLogPlugin:any = this.adminforth.getPluginByClassName('AuditLogPlugin');
394399
if (AuditLogPlugin) {
395400

396401
for (const [key, value] of Object.entries(oldRecord)) {

0 commit comments

Comments
 (0)