Spaces:
Building
Building
Update flare-ui/src/app/dialogs/version-edit-dialog/version-edit-dialog.component.ts
Browse files
flare-ui/src/app/dialogs/version-edit-dialog/version-edit-dialog.component.ts
CHANGED
@@ -323,7 +323,7 @@ export default class VersionEditDialogComponent implements OnInit {
|
|
323 |
});
|
324 |
}
|
325 |
|
326 |
-
|
327 |
if (this.versionForm.invalid || !this.selectedVersion) {
|
328 |
this.snackBar.open('Please fix all validation errors', 'Close', { duration: 3000 });
|
329 |
return;
|
@@ -355,17 +355,57 @@ export default class VersionEditDialogComponent implements OnInit {
|
|
355 |
|
356 |
this.snackBar.open('Version saved successfully', 'Close', { duration: 3000 });
|
357 |
|
358 |
-
// Update last_update_date
|
359 |
-
|
360 |
-
|
|
|
361 |
|
362 |
} catch (error: any) {
|
363 |
-
if (error.status === 409) {
|
364 |
-
|
365 |
-
|
366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
});
|
368 |
-
await this.reloadProject();
|
369 |
} else {
|
370 |
this.snackBar.open(error.error?.detail || 'Failed to save version', 'Close', {
|
371 |
duration: 5000,
|
|
|
323 |
});
|
324 |
}
|
325 |
|
326 |
+
async saveVersion() {
|
327 |
if (this.versionForm.invalid || !this.selectedVersion) {
|
328 |
this.snackBar.open('Please fix all validation errors', 'Close', { duration: 3000 });
|
329 |
return;
|
|
|
355 |
|
356 |
this.snackBar.open('Version saved successfully', 'Close', { duration: 3000 });
|
357 |
|
358 |
+
// Update last_update_date for next save
|
359 |
+
this.versionForm.patchValue({
|
360 |
+
last_update_date: new Date().toISOString()
|
361 |
+
});
|
362 |
|
363 |
} catch (error: any) {
|
364 |
+
if (error.status === 409 || error.requiresReload) {
|
365 |
+
// Race condition detected
|
366 |
+
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
367 |
+
width: '500px',
|
368 |
+
data: {
|
369 |
+
title: 'Version Modified',
|
370 |
+
message: 'This version was modified by another user. Do you want to reload and lose your changes, or save anyway?',
|
371 |
+
confirmText: 'Reload',
|
372 |
+
cancelText: 'Save Anyway',
|
373 |
+
confirmColor: 'primary'
|
374 |
+
}
|
375 |
+
});
|
376 |
+
|
377 |
+
dialogRef.afterClosed().subscribe(async (shouldReload) => {
|
378 |
+
if (shouldReload) {
|
379 |
+
// Reload version
|
380 |
+
await this.reloadProject();
|
381 |
+
if (this.selectedVersion) {
|
382 |
+
const updated = this.versions.find(v => v.id === this.selectedVersion!.id);
|
383 |
+
if (updated) {
|
384 |
+
this.loadVersion(updated);
|
385 |
+
}
|
386 |
+
}
|
387 |
+
} else {
|
388 |
+
// Force save by removing last_update_date check
|
389 |
+
const forceUpdateData = { ...updateData };
|
390 |
+
delete forceUpdateData.last_update_date;
|
391 |
+
|
392 |
+
try {
|
393 |
+
await this.apiService.updateVersion(
|
394 |
+
this.project.id,
|
395 |
+
this.selectedVersion!.id,
|
396 |
+
forceUpdateData
|
397 |
+
).toPromise();
|
398 |
+
|
399 |
+
this.snackBar.open('Version saved (forced)', 'Close', { duration: 3000 });
|
400 |
+
await this.reloadProject();
|
401 |
+
} catch (err: any) {
|
402 |
+
this.snackBar.open(err.error?.detail || 'Failed to save version', 'Close', {
|
403 |
+
duration: 5000,
|
404 |
+
panelClass: 'error-snackbar'
|
405 |
+
});
|
406 |
+
}
|
407 |
+
}
|
408 |
});
|
|
|
409 |
} else {
|
410 |
this.snackBar.open(error.error?.detail || 'Failed to save version', 'Close', {
|
411 |
duration: 5000,
|