| |
| class BatchService { |
| constructor() { |
| this.batches = []; |
| this.nextId = 1; |
| } |
|
|
| createBatch(type, file) { |
| return new Promise((resolve) => { |
| const newBatch = { |
| id: this.nextId++, |
| type, |
| status: 'PENDING', |
| fileName: file.name, |
| createdAt: new Date().toISOString() |
| }; |
| |
| this.batches.unshift(newBatch); |
| |
| |
| setTimeout(() => { |
| newBatch.status = 'RUNNING'; |
| setTimeout(() => { |
| newBatch.status = 'COMPLETED'; |
| }, 2000); |
| }, 1000); |
| |
| resolve(newBatch); |
| }); |
| } |
|
|
| getAllBatches() { |
| return new Promise((resolve) => { |
| resolve([...this.batches]); |
| }); |
| } |
|
|
| downloadResult(batchId) { |
| return new Promise((resolve) => { |
| |
| const batch = this.batches.find(b => b.id === batchId); |
| if (batch) { |
| const blob = new Blob([`Processed ${batch.type} results for ${batch.fileName}`], { type: 'text/plain' }); |
| const url = URL.createObjectURL(blob); |
| const a = document.createElement('a'); |
| a.href = url; |
| a.download = `processed_${batch.fileName.replace('.csv', '')}_${batchId}.txt`; |
| document.body.appendChild(a); |
| a.click(); |
| document.body.removeChild(a); |
| URL.revokeObjectURL(url); |
| } |
| resolve(); |
| }); |
| } |
| } |
|
|
| |
| window.batchService = new BatchService(); |