-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo2.html
586 lines (444 loc) · 19.4 KB
/
todo2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.2/font/bootstrap-icons.min.css">
<title>To-Do 2</title>
<style>
h2 {
width: 100%;
/* Make width 100% for responsiveness */
max-width: 450px;
/* Set a maximum width for larger screens */
height: 100px;
margin: 0 auto;
background-color: azure;
}
#tasktobedonelist {
max-height: 300px;
width: 100%;
/* Make width 100% for responsiveness */
max-width: 510px;
/* Set a maximum width for larger screens */
margin-top: 100px;
overflow-y: auto;
margin-left: auto;
margin-right: auto;
}
.clsbtn {
height: 1px;
width: 4px;
margin-right: 2px;
padding: 3px;
}
.clsbtn:hover {
cursor: pointer;
}
#taskdonelist {
min-height: 300px;
width: 100%;
/* Make width 100% for responsiveness */
max-width: 500px;
/* Set a maximum width for larger screens */
overflow-y: auto;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body align="center">
<div class="container-fluid">
<div class="row">
<div class="col mt-3 ms-md-3">
<a href="Home.html" style="text-decoration: none;"><i class="bi bi-chevron-left"></i> Back</a>
</div>
</div>
<div class="row">
<div class="col">
<div id="heading" class="text-center">
<h2 contenteditable="true" class="my-5 text-secondary pt-2">Enter Your Heading here...</h2>
<input type="text" id="inputid" placeholder="Your task..."
class="col-lg-3 col-md-5 col-sm-5 col-9 py-1">
<input type="submit" class="btn btn-primary my-5 col-3 col-md-2 col-lg-1 col-sm-2"
onclick="addtask()" id="submit">
</div>
</div>
</div>
<div class="row">
<div class="col">
<div>
<h5 align="center">Tasks to be done: </h5>
<!--Tasks not done will be appended here-->
<div id="tasktobedonelist" class="border mx-auto my-5">
</div>
</div>
</div>
</div>
<div class="text-end me-3 my-auto mx-auto ">
<button class="btn btn-primary" align="center" id="taskdnbtn" onclick="btnclicked()">Tasks done
▾</button><br>
<a href="#viewprgrs" class="text-dark" style="text-decoration: none;"><button class="btn btn-success mt-2"
id="viewbtn">View Progress</button></a>
</div>
<div class="row">
<div class="col">
<!--Tasks done will be appended here-->
<div id="taskdonelist" class="border">
</div>
</div>
</div>
</div><br><br><br><br><br>
<div id="row">
<div id="col" class="mt-5 pt-5">
<div id="viewprgrs" class="mt-5 pt-5">
<canvas id="myChart" style="width:100%;max-width:700px" class="m-auto"></canvas>
</div><br><br><br>
</div>
</div>
<script>
let input = document.getElementById('inputid');
let tasktobedonelist = document.getElementById('tasktobedonelist');
let taskHeading = document.querySelector('h2');
taskHeading.addEventListener('input', function () {
// Save the content of the 'h2' element to local storage
localStorage.setItem('taskHeading', taskHeading.textContent);
});
// Retrieve the content from local storage on page load
window.addEventListener('load', function () {
let savedTaskHeading = localStorage.getItem('taskHeading');
if (savedTaskHeading) {
// Set the content of the 'h2' element with the saved value
taskHeading.textContent = savedTaskHeading;
}
});
function createTask() {
let adddiv = document.createElement('div');
adddiv.classList.add('input-group', 'mb-2');
adddiv.setAttribute('id', 'task');
adddiv.style.width = '95%';
//chkboxdiv
let chkdiv = document.createElement('div');
chkdiv.classList.add('input-group-text');
//chkbox
let chkbox = document.createElement('input');
chkbox.classList.add('form-check-input', 'mt-0');
chkbox.setAttribute('type', 'checkbox');
chkbox.setAttribute('value', '""');
chkbox.setAttribute('aria-label', 'Checkbox for following text input');
chkbox.removeAttribute('checked');
//textarea
let textarea = document.createElement('input');
textarea.classList.add('form-control');
textarea.setAttribute('type', 'text');
textarea.setAttribute('aria-label', 'Text input with checkbox');
let chkcircle = document.createElement('i');
chkcircle.classList.add('bi', 'bi-check-circle-fill');
//div for clsbtn
let clsbtndiv = document.createElement('div');
clsbtndiv.classList.add('clsbtn');
//clsbtn
let clsbtn = document.createElement('i');
clsbtn.classList.add('bi', 'bi-x');
clsbtn.style.margin = '2px';
//Creation of tasks taking place in tasklist div
//chkbox div appending
adddiv.appendChild(chkdiv);
//appending chkbox to chkboxdiv
chkdiv.appendChild(chkbox);
//appending textarea to main div
adddiv.appendChild(textarea);
//appending clsbtn to clsbtndiv
clsbtndiv.appendChild(clsbtn);
//appending clsbtndiv(with clsbtn) to main div
chkcircle.style.display = 'none';
textarea.addEventListener('click', () => {
chkcircle.style.display = 'block';
chkcircle.style.marginTop = '4px';
chkcircle.style.marginLeft = '3px';
chkcircle.style.cursor = 'pointer';
clsbtndiv.prepend(chkcircle);
adddiv.appendChild(clsbtndiv);
chkcircle.addEventListener('click', () => {
let index = inputarr.indexOf(input.value);
let newval = textarea.value;
inputarr.splice(index, 1, newval);
localStorage.setItem('inputarr', JSON.stringify(inputarr));
console.log("after chkcircle: ", inputarr);
chkcircle.style.display = 'none';
})
})
adddiv.appendChild(clsbtndiv);
//appending the main div to tasklist
tasktobedonelist.appendChild(adddiv);
textarea.value = input.value;
chkbox.addEventListener('click', function () {
let removedchild = tasktobedonelist.removeChild(adddiv);
taskdonelist.appendChild(removedchild);
checkedItem(textarea);
});
//close btn part
clsbtn.addEventListener('click', () => {
localStorage.removeItem(textarea.value);
tasktobedonelist.removeChild(adddiv);
removeItem(textarea, inputarr);
});
clsbtn.addEventListener('click', () => {
localStorage.removeItem(textarea.value);
taskdonelist.removeChild(adddiv);
removeItem(textarea, checkedarr);
});
saveToLocalStorage();
}
let inputarr = [];
function saveToLocalStorage() {
let inputdata = input.value;
inputarr.push(inputdata);
localStorage.setItem('inputarr', JSON.stringify(inputarr));
console.log("this is console part ignore", inputarr);
}
let checkedarr = [];
function checkedItem(taskval) {
let value = taskval.value;
const index = inputarr.indexOf(value);
console.log(value);
if (index !== -1) {
inputarr.splice(index, 1);
console.log('element removed is:', value);
localStorage.setItem('inputarr', JSON.stringify(inputarr));
console.log('Array saved to local storage:', inputarr);
let checkeddata = value;
checkedarr.push(checkeddata);
localStorage.setItem('checkedarr', JSON.stringify(checkedarr));
console.log('checekedarr is: ', checkedarr);
}
}
function removeItem(taskval, arrname) {
let value = taskval.value;
let index = arrname.indexOf(value);
console.log(value);
if (index !== -1) {
arrname.splice(index, 1);
console.log('element removed is:', value);
if (arrname == inputarr) {
localStorage.setItem('inputarr', JSON.stringify(inputarr));
console.log('Array saved to local storage:', inputarr);
}
else {
localStorage.setItem('checkedarr', JSON.stringify(checkedarr));
console.log('Array saved to local storage:', checkedarr);
}
}
}
inputarr = JSON.parse(localStorage.getItem('inputarr')) || [];
checkedarr = JSON.parse(localStorage.getItem('checkedarr')) || [];
function retrievefromLocalStorage() {
console.log(inputarr);
inputarr.forEach(inputdata => {
let adddiv = document.createElement('div');
adddiv.classList.add('input-group', 'mb-2');
adddiv.setAttribute('id', 'task');
adddiv.style.width = '95%';
//chkboxdiv
let chkdiv = document.createElement('div');
chkdiv.classList.add('input-group-text');
//chkbox
let chkbox = document.createElement('input');
chkbox.classList.add('form-check-input', 'mt-0');
chkbox.setAttribute('type', 'checkbox');
chkbox.setAttribute('value', '""');
chkbox.setAttribute('aria-label', 'Checkbox for following text input');
chkbox.removeAttribute('checked');
//textarea
let textarea = document.createElement('input');
textarea.classList.add('form-control');
textarea.setAttribute('type', 'text');
textarea.setAttribute('aria-label', 'Text input with checkbox');
let chkcircle = document.createElement('i');
chkcircle.classList.add('bi', 'bi-check-circle-fill');
//div for clsbtn
let clsbtndiv = document.createElement('div');
clsbtndiv.classList.add('clsbtn');
//clsbtn
let clsbtn = document.createElement('i');
clsbtn.classList.add('bi', 'bi-x');
clsbtn.style.margin = '2px';
//Creation of tasks taking place in tasklist div
//chkbox div appending
adddiv.appendChild(chkdiv);
//appending chkbox to chkboxdiv
chkdiv.appendChild(chkbox);
//appending textarea to main div
adddiv.appendChild(textarea);
//appending clsbtn to clsbtndiv
clsbtndiv.appendChild(clsbtn);
chkcircle.style.display = 'none';
textarea.addEventListener('click', () => {
chkcircle.style.display = 'block';
chkcircle.style.marginTop = '4px';
chkcircle.style.marginLeft = '3px';
chkcircle.style.cursor = 'pointer';
clsbtndiv.prepend(chkcircle);
adddiv.appendChild(clsbtndiv);
chkcircle.addEventListener('click', () => {
let index = inputarr.indexOf(inputdata);
let newval = textarea.value;
inputarr.splice(index, 1, newval);
localStorage.setItem('inputarr', JSON.stringify(inputarr));
console.log("after chkcircle: ", inputarr);
chkcircle.style.display = 'none';
})
})
//appending clsbtndiv(with clsbtn) to main div
adddiv.appendChild(clsbtndiv);
//appending the main div to tasklist
tasktobedonelist.appendChild(adddiv);
textarea.value = inputdata;
chkbox.addEventListener('click', function () {
let removedchild = tasktobedonelist.removeChild(adddiv);
taskdonelist.appendChild(removedchild);
checkedItem(textarea);
});
//close btn part
clsbtn.addEventListener('click', () => {
localStorage.removeItem(textarea.value);
tasktobedonelist.removeChild(adddiv);
removeItem(textarea, inputarr);
});
})
checkedarr.forEach(checkeddata => {
let adddiv = document.createElement('div');
adddiv.classList.add('input-group', 'mb-2');
adddiv.setAttribute('id', 'task');
adddiv.style.width = '95%';
//chkboxdiv
let chkdiv = document.createElement('div');
chkdiv.classList.add('input-group-text');
//chkbox
let chkbox = document.createElement('input');
chkbox.classList.add('form-check-input', 'mt-0');
chkbox.setAttribute('type', 'checkbox');
chkbox.setAttribute('value', '""');
chkbox.setAttribute('aria-label', 'Checkbox for following text input');
chkbox.checked = true;
//textarea
let textarea = document.createElement('input');
textarea.classList.add('form-control');
textarea.setAttribute('type', 'text');
textarea.setAttribute('aria-label', 'Text input with checkbox');
//div for clsbtn
let clsbtndiv = document.createElement('div');
clsbtndiv.classList.add('clsbtn');
//clsbtn
let clsbtn = document.createElement('i');
clsbtn.classList.add('bi', 'bi-x');
clsbtn.style.margin = '2px';
//Creation of tasks taking place in tasklist div
//chkbox div appending
adddiv.appendChild(chkdiv);
//appending chkbox to chkboxdiv
chkdiv.appendChild(chkbox);
//appending textarea to main div
adddiv.appendChild(textarea);
//appending clsbtn to clsbtndiv
clsbtndiv.appendChild(clsbtn);
//appending clsbtndiv(with clsbtn) to main div
adddiv.appendChild(clsbtndiv);
//appending the main div to tasklist
taskdonelist.appendChild(adddiv);
textarea.value = checkeddata;
//close btn part
clsbtn.addEventListener('click', () => {
localStorage.removeItem(textarea.value);
taskdonelist.removeChild(adddiv);
removeItem(textarea, checkedarr);
});
})
}
function addtask() {
if (input.value == "") {
alert("Enter a value!");
}
else {
createTask();
}
input.value = "";
}
let taskdnbtn = document.getElementById('taskdnbtn');
taskdonelist.style.display = 'none';
function btnclicked() {
if (taskdonelist.style.display === 'none') {
taskdonelist.style.display = 'block';
taskdnbtn.innerHTML = 'Tasks done ▴' // Show the element
} else {
taskdonelist.style.display = 'none';
taskdnbtn.innerHTML = 'Tasks done ▾'; // Hide the element
}
}
let taskCompletionPercentages = [0, 0, 0, 0, 0, 0, 0];
let viewbtn = document.getElementById('viewbtn');
viewbtn.addEventListener('click', () => {
//Count of task to be done
let childcount = tasktobedonelist.children.length;
//Count of tasks done
let childcountdn = taskdonelist.children.length;
let totaltasks = childcount + childcountdn;
let percentage = Math.round(childcountdn / totaltasks * 100);
//For days
let day = new Date();
let mon = 'mon';
let tue = 'tue';
let wed = 'wed';
let thu = 'thu';
let fri = 'fri';
let sat = 'sat';
let sun = 'sun';
taskCompletionPercentages[day.getDay()] = percentage;
//Graph part
const ctx = document.getElementById('myChart');
new Chart(ctx, {
type: 'bar',
data: {
labels: [sun, mon, tue, wed, thu, fri, sat],
datasets: [{
label: 'Progress %',
data: taskCompletionPercentages,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(255, 159, 64, 0.2)',
'rgba(255, 205, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(153, 102, 255, 0.2)',
],
borderColor: [
'rgb(255, 99, 132)',
'rgb(255, 159, 64)',
'rgb(255, 205, 86)',
'rgb(75, 192, 192)',
'rgb(54, 162, 235)',
'rgb(153, 102, 255)',
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
max: 100
}
}]
}
}
});
});
retrievefromLocalStorage();
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js">
</script>
</body>
</html>