Azeez98 commited on
Commit
558ce2e
·
verified ·
1 Parent(s): bc55630

Update static/js/index.js

Browse files
Files changed (1) hide show
  1. static/js/index.js +37 -224
static/js/index.js CHANGED
@@ -72,18 +72,50 @@ async function handleDockerFormSubmit(event) {
72
  // event.preventDefault(); // Prevent the form from submitting the traditional way
73
  // const submitButton = document.getElementById('pip-submit-button');
74
  // const messageDiv = document.getElementById('pip-message');
 
 
75
  // submitButton.disabled = true; // Disable the submit button
76
  // messageDiv.textContent = "Downloading dependencies..."; // Show downloading message
77
  // messageDiv.style.display = 'block';
 
 
78
 
79
  // const formData = new FormData(event.target);
 
80
  // try {
81
  // const response = await fetch('/download-dependencies', {
82
  // method: 'POST',
83
  // body: formData
84
  // });
85
  // if (response.ok) {
86
- // const blob = await response.blob();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  // const url = window.URL.createObjectURL(blob);
88
  // const a = document.createElement('a');
89
  // a.style.display = 'none';
@@ -92,86 +124,18 @@ async function handleDockerFormSubmit(event) {
92
  // document.body.appendChild(a);
93
  // a.click();
94
  // window.URL.revokeObjectURL(url);
95
- // messageDiv.textContent = "Download complete!"; // Show download complete message
96
  // } else {
97
- // throw new Error('Download failed');
 
98
  // }
99
  // } catch (error) {
100
  // console.error('Error:', error);
101
- // messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again."; // Show error message in two lines
102
  // } finally {
103
  // submitButton.disabled = false; // Re-enable the submit button after download
104
  // }
105
  // }
106
 
107
- async function handlePipFormSubmit(event) {
108
- event.preventDefault(); // Prevent the form from submitting the traditional way
109
- const submitButton = document.getElementById('pip-submit-button');
110
- const messageDiv = document.getElementById('pip-message');
111
- const progressBar = document.getElementById('progress-bar');
112
- const progressContainer = document.getElementById('progress-container');
113
- submitButton.disabled = true; // Disable the submit button
114
- messageDiv.textContent = "Downloading dependencies..."; // Show downloading message
115
- messageDiv.style.display = 'block';
116
- progressContainer.style.display = 'block';
117
- progressBar.style.width = '0%'; // Reset progress bar
118
-
119
- const formData = new FormData(event.target);
120
-
121
- try {
122
- const response = await fetch('/download-dependencies', {
123
- method: 'POST',
124
- body: formData
125
- });
126
- if (response.ok) {
127
- const reader = response.body.getReader();
128
- const contentLength = response.headers.get('content-length');
129
- const total = parseInt(contentLength, 10);
130
- let loaded = 0;
131
-
132
- const stream = new ReadableStream({
133
- start(controller) {
134
- function push() {
135
- reader.read().then(({ done, value }) => {
136
- if (done) {
137
- controller.close();
138
- updateProgress(progressBar, messageDiv, total, total);
139
- return;
140
- }
141
- loaded += value.length;
142
- updateProgress(progressBar, messageDiv, loaded, total);
143
- controller.enqueue(value);
144
- push();
145
- }).catch(error => {
146
- console.error('Error:', error);
147
- messageDiv.textContent = "Error downloading dependencies.";
148
- });
149
- }
150
- push();
151
- }
152
- });
153
-
154
- const blob = await new Response(stream).blob();
155
- const url = window.URL.createObjectURL(blob);
156
- const a = document.createElement('a');
157
- a.style.display = 'none';
158
- a.href = url;
159
- a.download = 'dependencies.tar.gz';
160
- document.body.appendChild(a);
161
- a.click();
162
- window.URL.revokeObjectURL(url);
163
- } else {
164
- const errorMessage = await response.text();
165
- throw new Error(errorMessage || 'Download failed');
166
- }
167
- } catch (error) {
168
- console.error('Error:', error);
169
- messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again.";
170
- } finally {
171
- submitButton.disabled = false; // Re-enable the submit button after download
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');
@@ -240,100 +204,17 @@ async function handlePipFormSubmit(event) {
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');
258
- // const messageDiv = document.getElementById('pip-message');
259
- // submitButton.disabled = true; // Disable the submit button
260
- // messageDiv.textContent = "Downloading dependencies..."; // Show downloading message
261
- // messageDiv.style.display = 'block';
262
-
263
- // const formData = new FormData(event.target);
264
- // try {
265
- // const response = await fetch('/download-dependencies', {
266
- // method: 'POST',
267
- // body: formData
268
- // });
269
- // if (response.ok) {
270
- // const blob = await response.blob();
271
- // const url = window.URL.createObjectURL(blob);
272
- // const a = document.createElement('a');
273
- // a.style.display = 'none';
274
- // a.href = url;
275
- // a.download = 'dependencies.tar.gz';
276
- // document.body.appendChild(a);
277
- // a.click();
278
- // window.URL.revokeObjectURL(url);
279
- // messageDiv.textContent = "Download complete!"; // Show download complete message
280
- // } else {
281
- // throw new Error('Download failed');
282
- // }
283
- // } catch (error) {
284
- // console.error('Error:', error);
285
- // messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again."; // Show error message in two lines
286
- // } finally {
287
- // submitButton.disabled = false; // Re-enable the submit button after download
288
- // }
289
- // }
290
-
291
- async function handleDebFormSubmit(event) {
292
- event.preventDefault(); // Prevent the form from submitting the traditional way
293
- const submitButton = document.getElementById('deb-submit-button');
294
- const messageDiv = document.getElementById('deb-message');
295
- submitButton.disabled = true; // Disable the submit button
296
- messageDiv.textContent = "Downloading Debian packages..."; // Show downloading message
297
- messageDiv.style.display = 'block';
298
-
299
- const formData = new FormData(event.target);
300
- try {
301
- const response = await fetch('/download-deb-packages', {
302
- method: 'POST',
303
- body: formData
304
- });
305
- if (response.ok) {
306
- const blob = await response.blob();
307
- const url = window.URL.createObjectURL(blob);
308
- const a = document.createElement('a');
309
- a.style.display = 'none';
310
- a.href = url;
311
- a.download = 'deb-packages.tar.gz';
312
- document.body.appendChild(a);
313
- a.click();
314
- window.URL.revokeObjectURL(url);
315
- messageDiv.textContent = "Download complete!"; // Show download complete message
316
  } else {
317
  throw new Error('Download failed');
318
  }
319
  } catch (error) {
320
  console.error('Error:', error);
321
- messageDiv.innerHTML = "Error downloading Debian packages.<br>Please try again."; // Show error message in two lines
322
  } finally {
323
  submitButton.disabled = false; // Re-enable the submit button after download
324
  }
325
  }
326
 
327
- function updateProgress(progressBar, messageDiv, loaded, total) {
328
- const percent = Math.round((loaded / total) * 100);
329
- progressBar.style.width = `${percent}%`;
330
- progressBar.textContent = `${percent}%`;
331
- if (percent >= 100) {
332
- messageDiv.textContent = "Download complete!";
333
- messageDiv.style.display = 'block';
334
- }
335
- }
336
-
337
  function updateProgress(progressBar, messageDiv, loaded, total) {
338
  if (total > 0) {
339
  const percent = Math.round((loaded / total) * 100);
@@ -348,74 +229,6 @@ function updateProgress(progressBar, messageDiv, loaded, total) {
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");
421
  for (let i = 0; i < tabContents.length; i++) {
 
72
  // event.preventDefault(); // Prevent the form from submitting the traditional way
73
  // const submitButton = document.getElementById('pip-submit-button');
74
  // const messageDiv = document.getElementById('pip-message');
75
+ // const progressBar = document.getElementById('progress-bar');
76
+ // const progressContainer = document.getElementById('progress-container');
77
  // submitButton.disabled = true; // Disable the submit button
78
  // messageDiv.textContent = "Downloading dependencies..."; // Show downloading message
79
  // messageDiv.style.display = 'block';
80
+ // progressContainer.style.display = 'block';
81
+ // progressBar.style.width = '0%'; // Reset progress bar
82
 
83
  // const formData = new FormData(event.target);
84
+
85
  // try {
86
  // const response = await fetch('/download-dependencies', {
87
  // method: 'POST',
88
  // body: formData
89
  // });
90
  // if (response.ok) {
91
+ // const reader = response.body.getReader();
92
+ // const contentLength = response.headers.get('content-length');
93
+ // const total = parseInt(contentLength, 10);
94
+ // let loaded = 0;
95
+
96
+ // const stream = new ReadableStream({
97
+ // start(controller) {
98
+ // function push() {
99
+ // reader.read().then(({ done, value }) => {
100
+ // if (done) {
101
+ // controller.close();
102
+ // updateProgress(progressBar, messageDiv, total, total);
103
+ // return;
104
+ // }
105
+ // loaded += value.length;
106
+ // updateProgress(progressBar, messageDiv, loaded, total);
107
+ // controller.enqueue(value);
108
+ // push();
109
+ // }).catch(error => {
110
+ // console.error('Error:', error);
111
+ // messageDiv.textContent = "Error downloading dependencies.";
112
+ // });
113
+ // }
114
+ // push();
115
+ // }
116
+ // });
117
+
118
+ // const blob = await new Response(stream).blob();
119
  // const url = window.URL.createObjectURL(blob);
120
  // const a = document.createElement('a');
121
  // a.style.display = 'none';
 
124
  // document.body.appendChild(a);
125
  // a.click();
126
  // window.URL.revokeObjectURL(url);
 
127
  // } else {
128
+ // const errorMessage = await response.text();
129
+ // throw new Error(errorMessage || 'Download failed');
130
  // }
131
  // } catch (error) {
132
  // console.error('Error:', error);
133
+ // messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again.";
134
  // } finally {
135
  // submitButton.disabled = false; // Re-enable the submit button after download
136
  // }
137
  // }
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  async function handlePipFormSubmit(event) {
140
  event.preventDefault(); // Prevent the form from submitting the traditional way
141
  const submitButton = document.getElementById('pip-submit-button');
 
204
  document.body.appendChild(a);
205
  a.click();
206
  window.URL.revokeObjectURL(url);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  } else {
208
  throw new Error('Download failed');
209
  }
210
  } catch (error) {
211
  console.error('Error:', error);
212
+ messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again.";
213
  } finally {
214
  submitButton.disabled = false; // Re-enable the submit button after download
215
  }
216
  }
217
 
 
 
 
 
 
 
 
 
 
 
218
  function updateProgress(progressBar, messageDiv, loaded, total) {
219
  if (total > 0) {
220
  const percent = Math.round((loaded / total) * 100);
 
229
  progressBar.textContent = '0%';
230
  }
231
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  function openTab(event, tabName) {
233
  const tabContents = document.getElementsByClassName("tabcontent");
234
  for (let i = 0; i < tabContents.length; i++) {