1
1
<template >
2
2
<div v-if =" showButtons" class =" button-group d-flex justify-content-between align-items-center" >
3
+ <div
4
+ v-if =" isDeletingItems"
5
+ class =" position-fixed d-flex justify-content-center align-items-center"
6
+ style =" background-color : rgba (255 , 255 , 255 , 0.7 ); z-index : 1050 ; inset : 0 "
7
+ >
8
+ <div class =" card p-3 shadow-sm" >
9
+ <div class =" text-center" >
10
+ <font-awesome-icon
11
+ :icon =" ['fa', 'sync']"
12
+ class =" fa-2x text-primary mb-2"
13
+ :spin =" true"
14
+ aria-label =" loading"
15
+ />
16
+ <p class =" mb-0 mt-1" >Deleting {{ itemCount }} items...</p >
17
+ </div >
18
+ </div >
19
+ </div >
3
20
<div class =" button-left" >
4
21
<button
5
22
v-if =" dataType === 'samples'"
@@ -157,11 +174,16 @@ export default {
157
174
" open-add-to-collection-modal" ,
158
175
" delete-selected-items" ,
159
176
" update:filters" ,
177
+ " deletion-started" ,
178
+ " deletion-completed" ,
179
+ " deletion-error" ,
160
180
],
161
181
data () {
162
182
return {
163
183
localFilters: { ... this .filters },
164
184
isSelectedDropdownVisible: false ,
185
+ isDeletingItems: false ,
186
+ itemCount: 0 ,
165
187
};
166
188
},
167
189
watch: {
@@ -187,15 +209,32 @@ export default {
187
209
}
188
210
this .isSelectedDropdownVisible = false ;
189
211
},
190
- deleteItems (ids ) {
191
- if (this .dataType === " samples" ) {
192
- ids .forEach ((id ) => deleteSample (id));
193
- } else if (this .dataType === " collections" ) {
194
- ids .forEach ((id ) => deleteCollection (id, { collection_id: id }));
195
- } else if (this .dataType === " startingMaterials" ) {
196
- ids .forEach ((id ) => deleteStartingMaterial (id));
197
- } else if (this .dataType === " equipment" ) {
198
- ids .forEach ((id ) => deleteEquipment (id));
212
+ async deleteItems (ids ) {
213
+ try {
214
+ this .itemCount = ids .length ;
215
+ this .isDeletingItems = true ;
216
+ this .$emit (" deletion-started" );
217
+
218
+ let deletePromises = [];
219
+
220
+ if (this .dataType === " samples" ) {
221
+ deletePromises = ids .map ((id ) => deleteSample (id));
222
+ } else if (this .dataType === " collections" ) {
223
+ deletePromises = ids .map ((id ) => deleteCollection (id, { collection_id: id }));
224
+ } else if (this .dataType === " startingMaterials" ) {
225
+ deletePromises = ids .map ((id ) => deleteStartingMaterial (id));
226
+ } else if (this .dataType === " equipment" ) {
227
+ deletePromises = ids .map ((id ) => deleteEquipment (id));
228
+ }
229
+
230
+ await Promise .all (deletePromises);
231
+
232
+ this .$emit (" deletion-completed" );
233
+ } catch (error) {
234
+ console .error (" Error during batch deletion:" , error);
235
+ this .$emit (" deletion-error" , error);
236
+ } finally {
237
+ this .isDeletingItems = false ;
199
238
}
200
239
},
201
240
handleAddToCollection () {
0 commit comments