57
57
</div >
58
58
</div >
59
59
60
+ <div v-if =" errorMessage" class =" absolute flex items-center justify-center w-full h-full z-50 bg-white/80 dark:bg-gray-900/80 rounded-lg" >
61
+ <div class =" pt-20 text-red-500 dark:text-red-400 text-lg font-semibold" >
62
+ {{ errorMessage }}
63
+ </div >
64
+ </div >
65
+
60
66
61
67
<div id =" gallery" class =" relative w-full" data-carousel =" static" >
62
68
<!-- Carousel wrapper -->
118
124
<!-- Modal footer -->
119
125
<div class =" flex items-center p-4 md:p-5 border-t border-gray-200 rounded-b dark:border-gray-600" >
120
126
<button type =" button" @click =" confirmImage"
121
- :disabled =" loading"
127
+ :disabled =" loading || images.length === 0 "
122
128
class =" text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center
123
129
dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800
124
130
disabled:opacity-50 disabled:cursor-not-allowed"
@@ -248,6 +254,8 @@ const loadingTimer: Ref<number | null> = ref(null);
248
254
249
255
const historicalRuns: Ref <number []> = ref ([]);
250
256
257
+ const errorMessage: Ref <string | null > = ref (null );
258
+
251
259
const historicalAverage: Ref <number | null > = computed (() => {
252
260
if (historicalRuns .value .length === 0 ) return null ;
253
261
const sum = historicalRuns .value .reduce ((a , b ) => a + b , 0 );
@@ -262,6 +270,7 @@ function formatTime(seconds: number): string {
262
270
263
271
264
272
async function generateImages() {
273
+ errorMessage .value = null ;
265
274
loading .value = true ;
266
275
loadingTimer .value = 0 ;
267
276
const start = Date .now ();
@@ -271,7 +280,8 @@ async function generateImages() {
271
280
}, 100 );
272
281
const currentIndex = caurosel .value ?.getActiveItem ()?.position || 0 ;
273
282
274
- let resp;
283
+ let resp = null ;
284
+ let error = null ;
275
285
try {
276
286
resp = await callAdminForthApi ({
277
287
path: ` /plugin/${props .meta .pluginInstanceId }/generate_images ` ,
@@ -287,15 +297,25 @@ async function generateImages() {
287
297
historicalRuns .value .push (loadingTimer .value );
288
298
clearInterval (ticker );
289
299
loadingTimer .value = null ;
290
-
291
- }
292
- if (resp .error ) {
293
- adminforth .alert ({
294
- message: $t (' Error: {error}' , { error: JSON .stringify (resp .error ) }),
295
- variant: ' danger' ,
296
- timeout: 15 ,
297
- });
298
300
loading .value = false ;
301
+ }
302
+ if (resp ?.error ) {
303
+ error = resp .error ;
304
+ }
305
+ if (! resp ) {
306
+ error = $t (' Error generating images, something went wrong' );
307
+ }
308
+
309
+ if (error ) {
310
+ if (images .value .length === 0 ) {
311
+ errorMessage .value = error ;
312
+ } else {
313
+ adminforth .alert ({
314
+ message: error ,
315
+ variant: ' danger' ,
316
+ timeout: ' unlimited' ,
317
+ });
318
+ }
299
319
return ;
300
320
}
301
321
0 commit comments