Skip to content

Commit 30c62ce

Browse files
committed
feat: add storing of carousel images between closing and opening
1 parent 86afb90 commit 30c62ce

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
:primaryKey="primaryKey"
3838
:openGenerationCarousel="openGenerationCarousel"
3939
@error="handleTableError"
40+
:carouselSaveImages="carouselSaveImages"
41+
:carouselImageIndex="carouselImageIndex"
4042
/>
4143
</div>
4244
<div class="flex w-full flex-col md:flex-row items-stretch md:items-end justify-end gap-3 md:gap-4">
@@ -96,6 +98,8 @@ const tableColumns = ref([]);
9698
const tableColumnsIndexes = ref([]);
9799
const customFieldNames = ref([]);
98100
const selected = ref<any[]>([]);
101+
const carouselSaveImages = ref<any[]>([]);
102+
const carouselImageIndex = ref<any[]>([]);
99103
const isAiResponseReceivedAnalize = ref([]);
100104
const isAiResponseReceivedImage = ref([]);
101105
const primaryKey = props.meta.primaryKey;
@@ -149,6 +153,11 @@ const openDialog = async () => {
149153
}));
150154
}
151155
await Promise.all(tasks);
156+
157+
if (props.meta.isImageGeneration) {
158+
fillCarouselSaveImages();
159+
}
160+
152161
isLoading.value = false;
153162
}
154163
@@ -171,6 +180,23 @@ const closeDialog = () => {
171180
isCriticalError.value = false;
172181
isImageGenerationError.value = false;
173182
errorMessage.value = '';
183+
carouselSaveImages.value = [];
184+
carouselImageIndex.value = [];
185+
}
186+
187+
function fillCarouselSaveImages() {
188+
for (const item of selected.value) {
189+
const tempItem: any = {};
190+
const tempItemIndex: any = {};
191+
for (const [key, value] of Object.entries(item)) {
192+
if (props.meta.outputImageFields?.includes(key)) {
193+
tempItem[key] = [value];
194+
tempItemIndex[key] = 0;
195+
}
196+
}
197+
carouselSaveImages.value.push(tempItem);
198+
carouselImageIndex.value.push(tempItemIndex);
199+
}
174200
}
175201
176202
function formatLabel(str) {

custom/VisionTable.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@
9191
<div>
9292
<GenerationCarousel
9393
v-if="openGenerationCarousel[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
94-
:images="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
94+
:images="carouselSaveImages[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
9595
:recordId="item[primaryKey]"
9696
:meta="props.meta"
9797
:fieldName="n"
98+
:carouselImageIndex="carouselImageIndex[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
9899
@error="handleError"
99100
@close="openGenerationCarousel[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n] = false"
100101
@selectImage="updateSelectedImage"
102+
@updateCarouselIndex="updateActiveIndex"
101103
/>
102104
</div>
103105
</div>
@@ -134,6 +136,8 @@ const props = defineProps<{
134136
openGenerationCarousel: any
135137
isError: boolean,
136138
errorMessage: string
139+
carouselSaveImages: any[]
140+
carouselImageIndex: any[]
137141
}>();
138142
const emit = defineEmits(['error']);
139143
@@ -193,4 +197,8 @@ function handleError({ isError, errorMessage }) {
193197
});
194198
}
195199
200+
function updateActiveIndex(newIndex: number, id: any, fieldName: string) {
201+
props.carouselImageIndex[props.tableColumnsIndexes.findIndex(el => el[props.primaryKey] === id)][fieldName] = newIndex;
202+
}
203+
196204
</script>

0 commit comments

Comments
 (0)