diff --git a/src/js/control-view.js b/src/js/control-view.js index a209c17..240ad8e 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -52,6 +52,7 @@ module.exports = { GCodeNotFound: false, uploadFolder: false, filesUploaded: 0, + totalFiles: 0, }; }, @@ -488,7 +489,9 @@ module.exports = { xhr.onload = function () { this.filesUploaded++; - checkIfAllFilesUploaded(); + if (this.filesUploaded == this.totalFiles) { + this.uploadFolder = false; + } if (xhr.status >= 200 && xhr.status < 300) { console.log("File uploaded " + filename); } else { @@ -535,6 +538,8 @@ module.exports = { upload_folder: async function (e) { this.uploadFolder = true; this.filesUploaded = 0; + this.totalFiles = files.length; + const files = e.target.files || e.dataTransfer.files; if (!files.length) { return; @@ -544,8 +549,6 @@ module.exports = { this.config.non_macros_list = [...this.state.non_macros_list]; this.config.gcode_list = [...this.state.gcode_list]; - const totalFiles = files.length; - for (let file of files) { const reader = new FileReader(); reader.onload = () => { @@ -562,7 +565,9 @@ module.exports = { default: alert(`Unsupported file type: ${extension}`); this.filesUploaded++; - checkIfAllFilesUploaded(); + if (this.filesUploaded == this.totalFiles) { + this.uploadFolder = false; + } return; } @@ -597,7 +602,9 @@ module.exports = { alert("Error uploading file: ", error); this.uploadFolder = false; this.filesUploaded++; - checkIfAllFilesUploaded(); + if (this.filesUploaded == this.totalFiles) { + this.uploadFolder = false; + } }; reader.readAsText(file, "utf-8"); } diff --git a/src/pug/templates/control-view.pug b/src/pug/templates/control-view.pug index 0ac395e..b85e545 100644 --- a/src/pug/templates/control-view.pug +++ b/src/pug/templates/control-view.pug @@ -277,11 +277,10 @@ script#control-view-template(type="text/x-template") message(:show.sync="uploadFolder") h3(slot="header") Uploading div(slot="body") + h3 Uploading files is currently in progress p - | {{filesUploaded}} files uploaded - | Uploading files is currently in progress. + | {{filesUploaded}} files uploaded. | Do not close window. - | div(slot="footer") button.pure-button(title="Execute one program step.", @click="step",