@5minds/node-red-dashboard-2-processcube-dynamic-form 2.7.0-develop-86aad3-mh4xebm6 → 2.7.1

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.
@@ -203,9 +203,9 @@
203
203
  </div>
204
204
  </v-card-text>
205
205
  <v-card-actions>
206
- <a :href="modalFile.url" :download="modalFile.name">
207
- <v-btn variant="tonal" rounded="lg">Herunterladen</v-btn>
208
- </a>
206
+ <v-btn variant="tonal" rounded="lg" @click="downloadFile(modalFile)">
207
+ Herunterladen
208
+ </v-btn>
209
209
  <v-spacer></v-spacer>
210
210
  <v-btn variant="flat" rounded="lg" @click="closeFileModal">Schließen</v-btn>
211
211
  </v-card-actions>
@@ -1688,6 +1688,99 @@ export default {
1688
1688
  this.fileModalOpen = false;
1689
1689
  this.modalFile = null;
1690
1690
  },
1691
+ downloadFile(file) {
1692
+ if (!file || !file.url || !file.name) return;
1693
+
1694
+ // For Object URLs (newly uploaded files), we need to use a different approach
1695
+ if (file.isObjectUrl) {
1696
+ // Find the original file from formData
1697
+ const fieldId = this.findFieldIdForFile(file);
1698
+ if (fieldId) {
1699
+ const fieldData = this.formData[fieldId];
1700
+ const originalFile = this.findOriginalFile(fieldData, file.name);
1701
+
1702
+ if (originalFile) {
1703
+ const link = document.createElement('a');
1704
+ link.href = URL.createObjectURL(originalFile);
1705
+ link.download = file.name;
1706
+ document.body.appendChild(link);
1707
+ link.click();
1708
+ document.body.removeChild(link);
1709
+ URL.revokeObjectURL(link.href);
1710
+ return;
1711
+ }
1712
+ }
1713
+ }
1714
+
1715
+ // For data URLs (base64 encoded files from server)
1716
+ if (file.url.startsWith('data:')) {
1717
+ const link = document.createElement('a');
1718
+ link.href = file.url;
1719
+ link.download = file.name;
1720
+ document.body.appendChild(link);
1721
+ link.click();
1722
+ document.body.removeChild(link);
1723
+ return;
1724
+ }
1725
+
1726
+ // Fallback for regular URLs
1727
+ const link = document.createElement('a');
1728
+ link.href = file.url;
1729
+ link.download = file.name;
1730
+ link.target = '_blank';
1731
+ document.body.appendChild(link);
1732
+ link.click();
1733
+ document.body.removeChild(link);
1734
+ },
1735
+ findFieldIdForFile(file) {
1736
+ // Search through all file fields to find which one contains this file
1737
+ if (!this.userTask || !this.userTask.userTaskConfig || !this.userTask.userTaskConfig.formFields) {
1738
+ return null;
1739
+ }
1740
+
1741
+ const fileFields = this.userTask.userTaskConfig.formFields.filter(field => field.type === 'file');
1742
+
1743
+ for (const field of fileFields) {
1744
+ const previews = this.getFilePreviewsForField(field.id);
1745
+ if (previews.some(preview => preview.name === file.name && preview.url === file.url)) {
1746
+ return field.id;
1747
+ }
1748
+ }
1749
+ return null;
1750
+ },
1751
+ findOriginalFile(fieldData, fileName) {
1752
+ if (!fieldData) return null;
1753
+
1754
+ if (Array.isArray(fieldData)) {
1755
+ for (const item of fieldData) {
1756
+ const file = this.extractFileFromItem(item);
1757
+ if (file && file.name === fileName) {
1758
+ return file;
1759
+ }
1760
+ }
1761
+ } else {
1762
+ const file = this.extractFileFromItem(fieldData);
1763
+ if (file && file.name === fileName) {
1764
+ return file;
1765
+ }
1766
+ }
1767
+ return null;
1768
+ },
1769
+ extractFileFromItem(item) {
1770
+ if (item instanceof File) {
1771
+ return item;
1772
+ }
1773
+ if (item && item.file instanceof File) {
1774
+ return item.file;
1775
+ }
1776
+ if (item instanceof FileList && item.length > 0) {
1777
+ return item[0];
1778
+ }
1779
+ if (item && item.file instanceof FileList && item.file.length > 0) {
1780
+ return item.file[0];
1781
+ }
1782
+ return null;
1783
+ },
1691
1784
  },
1692
1785
  };
1693
1786