Update static/js/index.js
Browse files- static/js/index.js +157 -62
static/js/index.js
CHANGED
@@ -172,6 +172,86 @@ async function handlePipFormSubmit(event) {
|
|
172 |
}
|
173 |
}
|
174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
// async function handlePipFormSubmit(event) {
|
176 |
// event.preventDefault(); // Prevent the form from submitting the traditional way
|
177 |
// const submitButton = document.getElementById('pip-submit-button');
|
@@ -254,72 +334,87 @@ function updateProgress(progressBar, messageDiv, loaded, total) {
|
|
254 |
}
|
255 |
}
|
256 |
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
|
|
|
|
|
|
268 |
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
|
271 |
-
|
272 |
-
const response = await fetch('/download-dependencies', {
|
273 |
-
method: 'POST',
|
274 |
-
body: formData
|
275 |
-
});
|
276 |
-
if (response.ok) {
|
277 |
-
const reader = response.body.getReader();
|
278 |
-
const contentLength = response.headers.get('content-length');
|
279 |
-
const total = parseInt(contentLength, 10);
|
280 |
-
let loaded = 0;
|
281 |
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
updateProgress(progressBar, messageDiv, loaded, total);
|
293 |
-
controller.enqueue(value);
|
294 |
-
push();
|
295 |
-
}).catch(error => {
|
296 |
-
console.error('Error:', error);
|
297 |
-
messageDiv.textContent = "Error downloading dependencies.";
|
298 |
-
});
|
299 |
-
}
|
300 |
-
push();
|
301 |
-
}
|
302 |
-
});
|
303 |
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
323 |
|
324 |
function openTab(event, tabName) {
|
325 |
const tabContents = document.getElementsByClassName("tabcontent");
|
|
|
172 |
}
|
173 |
}
|
174 |
|
175 |
+
async function handlePipFormSubmit(event) {
|
176 |
+
event.preventDefault(); // Prevent the form from submitting the traditional way
|
177 |
+
const submitButton = document.getElementById('pip-submit-button');
|
178 |
+
const messageDiv = document.getElementById('pip-message');
|
179 |
+
const progressBar = document.getElementById('progress-bar');
|
180 |
+
const progressContainer = document.getElementById('progress-container');
|
181 |
+
submitButton.disabled = true; // Disable the submit button
|
182 |
+
messageDiv.textContent = "Downloading dependencies..."; // Show downloading message
|
183 |
+
messageDiv.style.display = 'block';
|
184 |
+
progressContainer.style.display = 'block';
|
185 |
+
progressBar.style.width = '0%'; // Reset progress bar
|
186 |
+
|
187 |
+
const formData = new FormData(event.target);
|
188 |
+
|
189 |
+
try {
|
190 |
+
const response = await fetch('/download-dependencies', {
|
191 |
+
method: 'POST',
|
192 |
+
body: formData
|
193 |
+
});
|
194 |
+
|
195 |
+
if (response.ok) {
|
196 |
+
const reader = response.body.getReader();
|
197 |
+
const contentLength = response.headers.get('content-length');
|
198 |
+
const total = contentLength ? parseInt(contentLength, 10) : null;
|
199 |
+
let loaded = 0;
|
200 |
+
|
201 |
+
if (!total) {
|
202 |
+
// Handle case where content-length is not provided
|
203 |
+
messageDiv.textContent = "Warning: Content length is not provided.";
|
204 |
+
}
|
205 |
+
|
206 |
+
const stream = new ReadableStream({
|
207 |
+
start(controller) {
|
208 |
+
function push() {
|
209 |
+
reader.read().then(({ done, value }) => {
|
210 |
+
if (done) {
|
211 |
+
controller.close();
|
212 |
+
if (total) {
|
213 |
+
updateProgress(progressBar, messageDiv, total, total);
|
214 |
+
} else {
|
215 |
+
messageDiv.textContent = "Download complete!";
|
216 |
+
}
|
217 |
+
return;
|
218 |
+
}
|
219 |
+
loaded += value.length;
|
220 |
+
if (total) {
|
221 |
+
updateProgress(progressBar, messageDiv, loaded, total);
|
222 |
+
}
|
223 |
+
controller.enqueue(value);
|
224 |
+
push();
|
225 |
+
}).catch(error => {
|
226 |
+
console.error('Error:', error);
|
227 |
+
messageDiv.textContent = "Error downloading dependencies.";
|
228 |
+
});
|
229 |
+
}
|
230 |
+
push();
|
231 |
+
}
|
232 |
+
});
|
233 |
+
|
234 |
+
const blob = await new Response(stream).blob();
|
235 |
+
const url = window.URL.createObjectURL(blob);
|
236 |
+
const a = document.createElement('a');
|
237 |
+
a.style.display = 'none';
|
238 |
+
a.href = url;
|
239 |
+
a.download = 'dependencies.tar.gz';
|
240 |
+
document.body.appendChild(a);
|
241 |
+
a.click();
|
242 |
+
window.URL.revokeObjectURL(url);
|
243 |
+
} else {
|
244 |
+
const errorMessage = await response.text();
|
245 |
+
throw new Error(errorMessage || 'Download failed');
|
246 |
+
}
|
247 |
+
} catch (error) {
|
248 |
+
console.error('Error:', error);
|
249 |
+
messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again.";
|
250 |
+
} finally {
|
251 |
+
submitButton.disabled = false; // Re-enable the submit button after download
|
252 |
+
}
|
253 |
+
}
|
254 |
+
|
255 |
// async function handlePipFormSubmit(event) {
|
256 |
// event.preventDefault(); // Prevent the form from submitting the traditional way
|
257 |
// const submitButton = document.getElementById('pip-submit-button');
|
|
|
334 |
}
|
335 |
}
|
336 |
|
337 |
+
function updateProgress(progressBar, messageDiv, loaded, total) {
|
338 |
+
if (total > 0) {
|
339 |
+
const percent = Math.round((loaded / total) * 100);
|
340 |
+
progressBar.style.width = `${percent}%`;
|
341 |
+
progressBar.textContent = `${percent}%`;
|
342 |
+
if (percent >= 100) {
|
343 |
+
messageDiv.textContent = "Download complete!";
|
344 |
+
messageDiv.style.display = 'block';
|
345 |
+
}
|
346 |
+
} else {
|
347 |
+
progressBar.style.width = '0%';
|
348 |
+
progressBar.textContent = '0%';
|
349 |
+
}
|
350 |
+
}
|
351 |
|
352 |
+
// async function handlePipFormSubmit(event) {
|
353 |
+
// event.preventDefault();
|
354 |
+
// const submitButton = document.getElementById('pip-submit-button');
|
355 |
+
// const messageDiv = document.getElementById('pip-message');
|
356 |
+
// const progressBar = document.getElementById('progress-bar');
|
357 |
+
// const progressContainer = document.getElementById('progress-container');
|
358 |
+
// submitButton.disabled = true;
|
359 |
+
// messageDiv.textContent = "Downloading dependencies...";
|
360 |
+
// messageDiv.style.display = 'block';
|
361 |
+
// progressContainer.style.display = 'block';
|
362 |
+
// progressBar.style.width = '0%'; // Reset progress bar
|
363 |
|
364 |
+
// const formData = new FormData(event.target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
|
366 |
+
// try {
|
367 |
+
// const response = await fetch('/download-dependencies', {
|
368 |
+
// method: 'POST',
|
369 |
+
// body: formData
|
370 |
+
// });
|
371 |
+
// if (response.ok) {
|
372 |
+
// const reader = response.body.getReader();
|
373 |
+
// const contentLength = response.headers.get('content-length');
|
374 |
+
// const total = parseInt(contentLength, 10);
|
375 |
+
// let loaded = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
|
377 |
+
// const stream = new ReadableStream({
|
378 |
+
// start(controller) {
|
379 |
+
// function push() {
|
380 |
+
// reader.read().then(({ done, value }) => {
|
381 |
+
// if (done) {
|
382 |
+
// controller.close();
|
383 |
+
// updateProgress(progressBar, messageDiv, total, total);
|
384 |
+
// return;
|
385 |
+
// }
|
386 |
+
// loaded += value.length;
|
387 |
+
// updateProgress(progressBar, messageDiv, loaded, total);
|
388 |
+
// controller.enqueue(value);
|
389 |
+
// push();
|
390 |
+
// }).catch(error => {
|
391 |
+
// console.error('Error:', error);
|
392 |
+
// messageDiv.textContent = "Error downloading dependencies.";
|
393 |
+
// });
|
394 |
+
// }
|
395 |
+
// push();
|
396 |
+
// }
|
397 |
+
// });
|
398 |
+
|
399 |
+
// const blob = await new Response(stream).blob();
|
400 |
+
// const url = window.URL.createObjectURL(blob);
|
401 |
+
// const a = document.createElement('a');
|
402 |
+
// a.style.display = 'none';
|
403 |
+
// a.href = url;
|
404 |
+
// a.download = 'dependencies.tar.gz';
|
405 |
+
// document.body.appendChild(a);
|
406 |
+
// a.click();
|
407 |
+
// window.URL.revokeObjectURL(url);
|
408 |
+
// } else {
|
409 |
+
// throw new Error('Download failed');
|
410 |
+
// }
|
411 |
+
// } catch (error) {
|
412 |
+
// console.error('Error:', error);
|
413 |
+
// messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again.";
|
414 |
+
// } finally {
|
415 |
+
// submitButton.disabled = false;
|
416 |
+
// }
|
417 |
+
// }
|
418 |
|
419 |
function openTab(event, tabName) {
|
420 |
const tabContents = document.getElementsByClassName("tabcontent");
|