diff options
author | Johannes Zellner <johannes@cloudron.io> | 2017-02-05 08:21:02 -0800 |
---|---|---|
committer | Johannes Zellner <johannes@cloudron.io> | 2017-02-05 08:21:02 -0800 |
commit | fea6789c72b7ef5b69281d8866f4ae0475135d4a (patch) | |
tree | 34956c830d65ef36a10a6ecb6b866ac3e8956dfd /frontend | |
parent | 74c0064c7dca1c0a96eef4962adb6cd61f33ec6c (diff) | |
download | Surfer-fea6789c72b7ef5b69281d8866f4ae0475135d4a.tar.gz Surfer-fea6789c72b7ef5b69281d8866f4ae0475135d4a.tar.zst Surfer-fea6789c72b7ef5b69281d8866f4ae0475135d4a.zip |
Show upload progress per files
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/index.html | 17 | ||||
-rw-r--r-- | frontend/js/app.js | 32 |
2 files changed, 41 insertions, 8 deletions
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 @@ | |||
85 | </div> | 85 | </div> |
86 | </div> | 86 | </div> |
87 | 87 | ||
88 | <div class="container" v-show="uploadStatus.busy" v-cloak> | ||
89 | <div class="row"> | ||
90 | <div class="col-lg-12"> | ||
91 | <p>Uploading... ({{ uploadStatus.done }} / {{ uploadStatus.count }}) </p> | ||
92 | <center> | ||
93 | <div class="progress"> | ||
94 | <div class="progress-bar progress-bar-striped" role="progressbar" v-bind:style="{ width: uploadStatus.percentDone + '%' }"> | ||
95 | <span class="sr-only">{{ uploadStatus.percentDone }}% Complete</span> | ||
96 | </div> | ||
97 | </div> | ||
98 | </center> | ||
99 | </div> | ||
100 | </div> | ||
101 | </div> | ||
102 | |||
88 | <div class="container" v-show="!session.valid && !busy" v-cloak> | 103 | <div class="container" v-show="!session.valid && !busy" v-cloak> |
89 | <div class="row"> | 104 | <div class="row"> |
90 | <div class="col-lg-6 col-lg-offset-3"> | 105 | <div class="col-lg-6 col-lg-offset-3"> |
@@ -106,7 +121,7 @@ | |||
106 | <div class="container main" v-show="session.valid && !busy" v-cloak> | 121 | <div class="container main" v-show="session.valid && !busy" v-cloak> |
107 | <div class="row"> | 122 | <div class="row"> |
108 | <div class="col-lg-12"> | 123 | <div class="col-lg-12"> |
109 | <center> | 124 | <center v-show="!uploadStatus.busy"> |
110 | <form id="fileUploadForm"> | 125 | <form id="fileUploadForm"> |
111 | <input type="file" v-el:upload style="display: none" id="uploadInput" multiple/> | 126 | <input type="file" v-el:upload style="display: none" id="uploadInput" multiple/> |
112 | <button class="btn btn-primary" v-on:click.stop.prevent="upload()" id="uploadButton">Upload</button> | 127 | <button class="btn btn-primary" v-on:click.stop.prevent="upload()" id="uploadButton">Upload</button> |
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() { | |||
124 | 124 | ||
125 | function upload() { | 125 | function upload() { |
126 | $(app.$els.upload).on('change', function () { | 126 | $(app.$els.upload).on('change', function () { |
127 | app.busy = true; | ||
128 | 127 | ||
129 | // detach event handler | 128 | // detach event handler |
130 | $(app.$els.upload).off('change'); | 129 | $(app.$els.upload).off('change'); |
131 | 130 | ||
132 | var length = app.$els.upload.files.length; | 131 | app.uploadStatus = { |
133 | var done = 0; | 132 | busy: true, |
133 | count: app.$els.upload.files.length, | ||
134 | done: 0, | ||
135 | percentDone: 0 | ||
136 | }; | ||
134 | 137 | ||
135 | function uploadFile(file) { | 138 | function uploadFile(file) { |
136 | var path = encode(sanitize(app.path + '/' + file.name)); | 139 | var path = encode(sanitize(app.path + '/' + file.name)); |
@@ -143,16 +146,25 @@ function upload() { | |||
143 | if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode); | 146 | if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode); |
144 | if (error) console.error(error); | 147 | if (error) console.error(error); |
145 | 148 | ||
146 | ++done; | 149 | app.uploadStatus.done += 1; |
150 | app.uploadStatus.percentDone = Math.round(app.uploadStatus.done / app.uploadStatus.count * 100); | ||
151 | |||
152 | console.log(Math.round(app.uploadStatus.done / app.uploadStatus.count * 100)) | ||
153 | |||
154 | if (app.uploadStatus.done >= app.uploadStatus.count) { | ||
155 | app.uploadStatus = { | ||
156 | busy: false, | ||
157 | count: 0, | ||
158 | done: 0, | ||
159 | percentDone: 100 | ||
160 | }; | ||
147 | 161 | ||
148 | if (done >= length) { | ||
149 | app.busy = false; | ||
150 | refresh(); | 162 | refresh(); |
151 | } | 163 | } |
152 | }); | 164 | }); |
153 | } | 165 | } |
154 | 166 | ||
155 | for(var i = 0; i < length; i++) { | 167 | for(var i = 0; i < app.uploadStatus.count; ++i) { |
156 | uploadFile(app.$els.upload.files[i]); | 168 | uploadFile(app.$els.upload.files[i]); |
157 | } | 169 | } |
158 | }); | 170 | }); |
@@ -233,6 +245,12 @@ var app = new Vue({ | |||
233 | el: '#app', | 245 | el: '#app', |
234 | data: { | 246 | data: { |
235 | busy: true, | 247 | busy: true, |
248 | uploadStatus: { | ||
249 | busy: false, | ||
250 | count: 0, | ||
251 | done: 0, | ||
252 | percentDone: 50 | ||
253 | }, | ||
236 | path: '/', | 254 | path: '/', |
237 | pathParts: [], | 255 | pathParts: [], |
238 | session: { | 256 | session: { |