- Improved file input handling in bulk operations: added in-memory blob storage, reset on re-selection, and error handling for file reading. Adjusted indentation and refined event logic.

This commit is contained in:
Jan 2025-09-29 18:52:53 +02:00
parent f9828029a9
commit ee989d1bfc

View file

@ -26,13 +26,13 @@
<div class="bulk-operation-caption">validity period</div>
<div class="bulk-operation-data">
<div class="period-select-container">
<dropdown :options="periods"
emptyText="No property set available"
class="period-select"
placeholder="Select a property set"
v-model="selectedPeriod"
:disabled="!showValidityPeriod"
></dropdown>
<dropdown :options="periods"
emptyText="No property set available"
class="period-select"
placeholder="Select a property set"
v-model="selectedPeriod"
:disabled="!showValidityPeriod"
></dropdown>
</div>
</div>
@ -77,11 +77,11 @@
</box>
<div class="bulk-operation-box-status-container">
<div class="bulk-operation-status">
<div class="bulk-operation-status">
<div class="bulk-operation-header">History</div>
<div v-if="this.bulkOperationStore.getBulkOperations.length === 0" class="empty-container">No recent bulk operations</div>
<bulk-operation v-else v-for="bulk in this.bulkOperationStore.getBulkOperations" :key="bulk.id" :operation="bulk" @download="fetchFile"></bulk-operation>
</div>
</div>
</div>
</div>
@ -112,6 +112,7 @@ export default {
importDataset: "NODE",
selectedFileName: null,
selectedFile: null,
fileBlob: null, // Blob im RAM gespeichert
uploading: false,
processId: null,
}
@ -126,7 +127,7 @@ export default {
async isSelected(newVal) {
if(newVal === true)
await this.validityPeriodStore.loadPeriods();
await this.bulkOperationStore.manageStatus();
await this.bulkOperationStore.manageStatus();
}
},
computed: {
@ -185,22 +186,60 @@ export default {
await this.bulkOperationStore.scheduleDownload(this.exportDataset, isCurrent ? null : this.selectedPeriod);
}
},
inputFile(event) {
async inputFile(event) {
const file = event.target.files[0];
if (file) {
this.selectedFile = file;
this.selectedFileName = file.name;
try {
// Datei sofort in den RAM laden als Blob
this.fileBlob = await this.readFileAsBlob(file);
// File-Objekt mit dem Blob erstellen, das den originalen Namen und Typ behält
this.selectedFile = new File([this.fileBlob], file.name, { type: file.type });
this.selectedFileName = file.name;
logger.info(`File loaded into memory: ${file.name} (${(file.size / 1024).toFixed(2)} KB)`);
} catch (error) {
logger.error('Error reading file:', error);
this.selectedFile = null;
this.selectedFileName = null;
this.fileBlob = null;
}
} else {
this.selectedFile = null;
this.selectedFileName = null;
this.fileBlob = null;
}
// Input zurücksetzen, damit dieselbe Datei erneut ausgewählt werden kann
event.target.value = '';
},
readFileAsBlob(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
// ArrayBuffer in Blob konvertieren
const blob = new Blob([e.target.result], { type: file.type });
resolve(blob);
};
reader.onerror = (error) => {
reject(error);
};
// Datei als ArrayBuffer lesen
reader.readAsArrayBuffer(file);
});
},
async uploadFile() {
if (!this.selectedFile)
return;
await this.bulkOperationStore.scheduleUpload(this.importDataset, this.selectedFile);
const file = this.selectedFile;
this.selectedFile = null;
this.selectedFileName = null;
await this.bulkOperationStore.scheduleUpload(this.importDataset, file);
}
}
}