| | |
| | | if (event === 'data-ready') { |
| | | this.stores.ready.push(storeName); |
| | | if (this.storesReady()) { |
| | | this.checkRecovery().then(()=>{}); |
| | | this.checkRecovery().then(() => {}); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | Object.preventExtensions(upload); |
| | | await this.stores.uploads.save(upload); |
| | | |
| | | if (this.fields.has(upload.field)) { |
| | | let field = this.fields.get(upload.field); |
| | | console.log('Upload Status: ', upload.status); |
| | | switch (upload.status) { |
| | | case 'local_processing': |
| | | this.notify('upload-received', { |
| | | field: field.element, |
| | | id: upload.id |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | return upload; |
| | | } |
| | | |
| | |
| | | RECOVERY |
| | | *************************************************************/ |
| | | async checkRecovery() { |
| | | const pendingUploads = this.stores.uploads.filterByIndex({status: ['local_processing', 'queued', 'uploading']}); |
| | | const allGroups = Array.from(this.stores.groups.data.values()); |
| | | for (const group of allGroups) { |
| | | const hasUploads = this.stores.uploads.filterByIndex({group: group.id}).length > 0; |
| | | if (!hasUploads) { |
| | | await this.stores.groups.delete(group.id); |
| | | } |
| | | const hasUploads = this.stores.uploads.filterByIndex({ group: group.id }).length > 0; |
| | | if (!hasUploads) await this.stores.groups.delete(group.id); |
| | | } |
| | | if (pendingUploads.length === 0) return; |
| | | |
| | | // Group by source page |
| | | const bySource = new Map(); |
| | | pendingUploads.forEach(upload => { |
| | | const src = upload.src || 'unknown'; |
| | | if (!bySource.has(src)) bySource.set(src, []); |
| | | bySource.get(src).push(upload); |
| | | }); |
| | | |
| | | let data = { |
| | | bySource: bySource, |
| | | pendingUploads: pendingUploads |
| | | }; |
| | | |
| | | document.body.append(this.templates.create('restoreNotification', data)); |
| | | let notification = document.querySelector('dialog.restore-uploads'); |
| | | this.restoreModal = new window.jvbModal(notification); |
| | | this.restoreSelection = new window.jvbHandleSelection(notification, |
| | | { |
| | | wrapper: { |
| | | wrapper: '.restore-field', |
| | | id: 'selection' |
| | | }, |
| | | items: '.item-grid.restore', |
| | | selectAll: { |
| | | bulkControls: '.selection-actions', |
| | | checkbox: '#select-all-restore', |
| | | count: '.selection-count' |
| | | } |
| | | }); |
| | | this.restoreModal.handleOpen(); |
| | | } |
| | | //TODO: Old method of checkRecovery. All recovery logic has moved to the FormController.js |
| | | // async checkRecovery() { |
| | | // const pendingUploads = this.stores.uploads.filterByIndex({status: ['local_processing', 'queued', 'uploading']}); |
| | | // const allGroups = Array.from(this.stores.groups.data.values()); |
| | | // for (const group of allGroups) { |
| | | // const hasUploads = this.stores.uploads.filterByIndex({group: group.id}).length > 0; |
| | | // if (!hasUploads) { |
| | | // await this.stores.groups.delete(group.id); |
| | | // } |
| | | // } |
| | | // if (pendingUploads.length === 0) return; |
| | | // |
| | | // // Group by source page |
| | | // const bySource = new Map(); |
| | | // pendingUploads.forEach(upload => { |
| | | // const src = upload.src || 'unknown'; |
| | | // if (!bySource.has(src)) bySource.set(src, []); |
| | | // bySource.get(src).push(upload); |
| | | // }); |
| | | // |
| | | // let data = { |
| | | // bySource: bySource, |
| | | // pendingUploads: pendingUploads |
| | | // }; |
| | | // |
| | | // document.body.append(this.templates.create('restoreNotification', data)); |
| | | // let notification = document.querySelector('dialog.restore-uploads'); |
| | | // this.restoreModal = new window.jvbModal(notification); |
| | | // this.restoreSelection = new window.jvbHandleSelection(notification, |
| | | // { |
| | | // wrapper: { |
| | | // wrapper: '.restore-field', |
| | | // id: 'selection' |
| | | // }, |
| | | // items: '.item-grid.restore', |
| | | // selectAll: { |
| | | // bulkControls: '.selection-actions', |
| | | // checkbox: '#select-all-restore', |
| | | // count: '.selection-count' |
| | | // } |
| | | // }); |
| | | // this.restoreModal.handleOpen(); |
| | | // } |
| | | |
| | | async handleRestoreSelected() { |
| | | if (!this.restoreSelection) return; |
| | | |
| | | let selected = Array.from(this.restoreSelection.selectedItems); |
| | | if (selected.length === 0) { |
| | | return; |
| | | } |
| | | |
| | | await this.restoreSelectedUploads(selected); |
| | | } |
| | | async handleRestoreAll() { |
| | | if (!this.restoreModal) return; |
| | | const allUploads = Array.from(this.restoreModal.modal.querySelectorAll('.item.upload')).map(item => item.dataset.uploadId); |
| | | |
| | | await this.restoreSelectedUploads(allUploads); |
| | | } |
| | | |
| | | // async handleRestoreSelected() { |
| | | // if (!this.restoreSelection) return; |
| | | // |
| | | // let selected = Array.from(this.restoreSelection.selectedItems); |
| | | // if (selected.length === 0) { |
| | | // return; |
| | | // } |
| | | // |
| | | // await this.restoreSelectedUploads(selected); |
| | | // } |
| | | // async handleRestoreAll() { |
| | | // if (!this.restoreModal) return; |
| | | // const allUploads = Array.from(this.restoreModal.modal.querySelectorAll('.item.upload')).map(item => item.dataset.uploadId); |
| | | // |
| | | // await this.restoreSelectedUploads(allUploads); |
| | | // } |
| | | // |
| | | async restoreSelectedUploads(selectedUploads) { |
| | | let currentPage = window.location.href; |
| | | |
| | |
| | | }); |
| | | await this.addToGroup(upload.id, null); |
| | | } |
| | | } |
| | | // |
| | | // cleanupRestore() { |
| | | // this.restoreModal.handleClose(); |
| | | // this.restoreSelection.destroy(); |
| | | // this.restoreSelection = null; |
| | | // this.restoreModal.destroy(); |
| | | // this.restoreModal.modal.remove(); |
| | | // this.restoreModal = null; |
| | | // } |
| | | |
| | | this.cleanupRestore(); |
| | | async restoreUploads(uploadIds) { |
| | | const uploads = uploadIds.map(id => this.stores.uploads.get(id)).filter(Boolean); |
| | | if (uploads.length === 0) return; |
| | | await this.restoreSelectedUploads(uploads.map(u => u.id)); |
| | | } |
| | | |
| | | cleanupRestore() { |
| | | this.restoreModal.handleClose(); |
| | | this.restoreSelection.destroy(); |
| | | this.restoreSelection = null; |
| | | this.restoreModal.destroy(); |
| | | this.restoreModal.modal.remove(); |
| | | this.restoreModal = null; |
| | | async clearUploads(uploadIds) { |
| | | await Promise.all(uploadIds.map(id => this.clearUpload(id))); |
| | | } |
| | | /******************************************************************************* |
| | | STATUS MANAGEMENT |