cloud-ide-element 1.0.58 → 1.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2835,6 +2835,19 @@ class CideEleFileManagerService {
|
|
|
2835
2835
|
this._error.set(errorMessage);
|
|
2836
2836
|
return throwError(() => new Error(errorMessage));
|
|
2837
2837
|
}
|
|
2838
|
+
/**
|
|
2839
|
+
* Get file details by ID
|
|
2840
|
+
* @param fileId The file ID to fetch details for
|
|
2841
|
+
* @returns Observable with file details
|
|
2842
|
+
*/
|
|
2843
|
+
getFileDetails(fileId) {
|
|
2844
|
+
console.log('🔍 [FileManagerService] Fetching file details for ID:', fileId.cyfm_id);
|
|
2845
|
+
// Create a GET request payload similar to the upload structure
|
|
2846
|
+
const payload = {
|
|
2847
|
+
core_file_manager_get: [fileId]
|
|
2848
|
+
};
|
|
2849
|
+
return this.http.post(`${this._baseUrl()}`, payload).pipe(retry(2), catchError(this.handleError.bind(this)), takeUntilDestroyed(this.destroyRef));
|
|
2850
|
+
}
|
|
2838
2851
|
/**
|
|
2839
2852
|
* Angular 20: Service utility methods
|
|
2840
2853
|
*/
|
|
@@ -3178,11 +3191,13 @@ class CideEleFileInputComponent {
|
|
|
3178
3191
|
writeValue(value) {
|
|
3179
3192
|
console.log('📝 [FileInput] writeValue called with:', value);
|
|
3180
3193
|
if (typeof value === 'string') {
|
|
3181
|
-
// Value is an uploaded file ID
|
|
3194
|
+
// Value is an uploaded file ID - fetch file details and set preview
|
|
3182
3195
|
console.log('📝 [FileInput] Value is uploaded file ID:', value);
|
|
3183
3196
|
this.files.set(null);
|
|
3184
3197
|
this.fileNames.set([]);
|
|
3185
3198
|
this.clearPreviews();
|
|
3199
|
+
// Fetch file details to get base64 and set preview
|
|
3200
|
+
this.loadFileDetailsFromId(value);
|
|
3186
3201
|
}
|
|
3187
3202
|
else if (value instanceof FileList) {
|
|
3188
3203
|
// Value is a FileList
|
|
@@ -3391,10 +3406,63 @@ class CideEleFileInputComponent {
|
|
|
3391
3406
|
isImageFile(file) {
|
|
3392
3407
|
return file.type.startsWith('image/');
|
|
3393
3408
|
}
|
|
3409
|
+
loadFileDetailsFromId(fileId) {
|
|
3410
|
+
console.log('🔍 [FileInput] Loading file details for ID:', fileId);
|
|
3411
|
+
this.fileManagerService?.getFileDetails({ cyfm_id: fileId })?.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
|
|
3412
|
+
next: (fileDetails) => {
|
|
3413
|
+
console.log('📋 [FileInput] File details received:', fileDetails);
|
|
3414
|
+
if (fileDetails?.data?.length) {
|
|
3415
|
+
const fileData = fileDetails.data[0];
|
|
3416
|
+
console.log('📁 [FileInput] File data:', fileData);
|
|
3417
|
+
// Set file name from the details
|
|
3418
|
+
if (fileData.cyfm_name) {
|
|
3419
|
+
this.fileNames.set([fileData.cyfm_name]);
|
|
3420
|
+
console.log('📝 [FileInput] File name set:', fileData.cyfm_name);
|
|
3421
|
+
}
|
|
3422
|
+
// If it's an image and we have base64 data, set preview
|
|
3423
|
+
if (this.showPreview() && fileData.cyfm_file_base64) {
|
|
3424
|
+
// Check if it's an image file based on file name or type
|
|
3425
|
+
const isImage = this.isImageFileFromName(fileData.cyfm_name) ||
|
|
3426
|
+
this.isImageFileFromType(fileData.cyfm_type);
|
|
3427
|
+
if (isImage) {
|
|
3428
|
+
// Add data URL prefix if not already present
|
|
3429
|
+
let base64Data = fileData.cyfm_file_base64;
|
|
3430
|
+
if (!base64Data.startsWith('data:')) {
|
|
3431
|
+
const mimeType = fileData.cyfm_type || 'image/jpeg';
|
|
3432
|
+
base64Data = `data:${mimeType};base64,${base64Data}`;
|
|
3433
|
+
}
|
|
3434
|
+
this.previewUrls.set([base64Data]);
|
|
3435
|
+
console.log('🖼️ [FileInput] Preview set from base64 data');
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
else {
|
|
3440
|
+
console.warn('⚠️ [FileInput] No file data found for ID:', fileId);
|
|
3441
|
+
}
|
|
3442
|
+
},
|
|
3443
|
+
error: (error) => {
|
|
3444
|
+
console.error('❌ [FileInput] Error loading file details:', error);
|
|
3445
|
+
this.notificationService.error(`Failed to load file details: ${error.message || 'Unknown error'}`, { duration: 0 });
|
|
3446
|
+
}
|
|
3447
|
+
});
|
|
3448
|
+
}
|
|
3449
|
+
isImageFileFromName(fileName) {
|
|
3450
|
+
if (!fileName)
|
|
3451
|
+
return false;
|
|
3452
|
+
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg'];
|
|
3453
|
+
const lowerFileName = fileName.toLowerCase();
|
|
3454
|
+
return imageExtensions.some(ext => lowerFileName.endsWith(ext));
|
|
3455
|
+
}
|
|
3456
|
+
isImageFileFromType(fileType) {
|
|
3457
|
+
if (!fileType)
|
|
3458
|
+
return false;
|
|
3459
|
+
return fileType.startsWith('image/');
|
|
3460
|
+
}
|
|
3394
3461
|
removePreview(index) {
|
|
3395
3462
|
const currentFiles = this.files();
|
|
3463
|
+
const currentUrls = this.previewUrls();
|
|
3396
3464
|
if (currentFiles && currentFiles.length > index) {
|
|
3397
|
-
//
|
|
3465
|
+
// Handle FileList case - remove file from FileList
|
|
3398
3466
|
const dt = new DataTransfer();
|
|
3399
3467
|
Array.from(currentFiles).forEach((file, i) => {
|
|
3400
3468
|
if (i !== index) {
|
|
@@ -3405,7 +3473,6 @@ class CideEleFileInputComponent {
|
|
|
3405
3473
|
this.files.set(newFiles);
|
|
3406
3474
|
this.fileNames.set(Array.from(newFiles).map(f => f.name));
|
|
3407
3475
|
// Remove the preview URL
|
|
3408
|
-
const currentUrls = this.previewUrls();
|
|
3409
3476
|
if (currentUrls[index] && currentUrls[index].startsWith('blob:')) {
|
|
3410
3477
|
URL.revokeObjectURL(currentUrls[index]);
|
|
3411
3478
|
}
|
|
@@ -3413,6 +3480,16 @@ class CideEleFileInputComponent {
|
|
|
3413
3480
|
this.onChange(newFiles);
|
|
3414
3481
|
this.fileChange.emit(newFiles);
|
|
3415
3482
|
}
|
|
3483
|
+
else if (currentUrls.length > index) {
|
|
3484
|
+
// Handle uploaded file ID case - clear the preview and set control value to null
|
|
3485
|
+
console.log('🗑️ [FileInput] Removing preview for uploaded file ID');
|
|
3486
|
+
// Clear preview
|
|
3487
|
+
this.previewUrls.update(urls => urls.filter((_, i) => i !== index));
|
|
3488
|
+
this.fileNames.set([]);
|
|
3489
|
+
// Set control value to null since we're removing the uploaded file
|
|
3490
|
+
this.onChange(null);
|
|
3491
|
+
this.fileChange.emit(null);
|
|
3492
|
+
}
|
|
3416
3493
|
}
|
|
3417
3494
|
ngOnDestroy() {
|
|
3418
3495
|
// Clean up preview URLs to prevent memory leaks
|