From: Johannes Zellner Date: Sun, 5 Feb 2017 16:21:02 +0000 (-0800) Subject: Show upload progress per files X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=fea6789c72b7ef5b69281d8866f4ae0475135d4a;p=perso%2FImmae%2FProjets%2FNodejs%2FSurfer.git Show upload progress per files --- diff --git a/frontend/index.html b/frontend/index.html index 056f29c..4c16ed5 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -85,6 +85,21 @@ +
+
+
+

Uploading... ({{ uploadStatus.done }} / {{ uploadStatus.count }})

+
+
+
+ {{ uploadStatus.percentDone }}% Complete +
+
+
+
+
+
+
@@ -106,7 +121,7 @@
-
+
diff --git a/frontend/js/app.js b/frontend/js/app.js index 9a2e532..e0464f8 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -124,13 +124,16 @@ function up() { function upload() { $(app.$els.upload).on('change', function () { - app.busy = true; // detach event handler $(app.$els.upload).off('change'); - var length = app.$els.upload.files.length; - var done = 0; + app.uploadStatus = { + busy: true, + count: app.$els.upload.files.length, + done: 0, + percentDone: 0 + }; function uploadFile(file) { var path = encode(sanitize(app.path + '/' + file.name)); @@ -143,16 +146,25 @@ function upload() { if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode); if (error) console.error(error); - ++done; + app.uploadStatus.done += 1; + app.uploadStatus.percentDone = Math.round(app.uploadStatus.done / app.uploadStatus.count * 100); + + console.log(Math.round(app.uploadStatus.done / app.uploadStatus.count * 100)) + + if (app.uploadStatus.done >= app.uploadStatus.count) { + app.uploadStatus = { + busy: false, + count: 0, + done: 0, + percentDone: 100 + }; - if (done >= length) { - app.busy = false; refresh(); } }); } - for(var i = 0; i < length; i++) { + for(var i = 0; i < app.uploadStatus.count; ++i) { uploadFile(app.$els.upload.files[i]); } }); @@ -233,6 +245,12 @@ var app = new Vue({ el: '#app', data: { busy: true, + uploadStatus: { + busy: false, + count: 0, + done: 0, + percentDone: 50 + }, path: '/', pathParts: [], session: {