-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
137 lines (123 loc) · 6.24 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ToDo Web Application</title>
<!-- Google Fonts -->
<link href='https://fonts.googleapis.com/css?family=Arima Madurai' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Battambang' rel='stylesheet'>
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<!-- angular.js -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</head>
<body class="container-fluid bg-light">
<div ng-app="myApp" ng-controller="todoCtrl" class="container-fluid bg-light">
<div class="row">
<div class="col bg-light" style="font-family: 'Battambang';">
<h3 class="text-center shadow rounded text-warning border border-rounded border-gradient-secondary border-3 m-2 p-3">
ToDo Web Application</h3>
</div>
</div>
<div class="row" style="font-family: 'Arima Madurai';">
<form>
<div class="container mt-4">
<div class="input-group mb-1 shadow">
<input type="text" class="form-control" ng-model="t1" placeholder="Enter your task here...">
<button class="btn btn-secondary" ng-click="add(t1)" type="submit">Add Task</button>
</div>
</div>
</form>
<div class="d-flex justify-content-around">
<div class="col-10 border rounded border-gradient border-0.5 m-2">
<h4 class="text-center text-secondary pt-2">To Be Done:</h4>
<div class="container-fluid border border-gradient border-2 text-success">
<ol>
<li ng-repeat="x in todoList" class="pt-2"> {{x.task}}
<button class="btn btn-sm ml-4 btn-success" ng-click="markDone($index)"
type="submit">Mark Done</button>
<hr>
</li>
</ol>
</div>
</div>
</div>
<div class="d-flex justify-content-around">
<div class="col-10 border rounded border-gradient border-0.5 m-2">
<h4 class="text-center text-secondary pt-2">Done:</h4>
<div class="container-fluid border border-gradient border-2 text-dark">
<ol>
<li ng-repeat="x in doneList" class="pt-2"> <s>{{x.task}}</s>
<button class="btn btn-sm ml-4 btn-danger" ng-click="deleteTask($index)"
type="submit">Delete</button>
<hr>
</li>
</ol>
</div>
</div>
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('todoCtrl', function ($scope, $window) {
$scope.todoList = [];
$scope.doneList = [];
$scope.add = function (task) {
if (typeof (task) == "undefined" || task == "" || task == null) {
$window.alert("Please enter a task");
} else {
try {
var storedTodoList = JSON.parse(localStorage.getItem('todoList')) || [];
if (storedTodoList.some(function (item) { return item.task === task; })) {
$window.alert("The same task already exists");
return;
}
var newTodoItem = {
id: storedTodoList.length + 1,
task: task
};
storedTodoList.push(newTodoItem);
localStorage.setItem('todoList', JSON.stringify(storedTodoList));
console.log('Todo item added successfully.');
$scope.todoList = storedTodoList;
$scope.t1 = '';
} catch (error) {
console.error('Error while adding todo item:', error);
}
}
};
$scope.markDone = function (index) {
var task = $scope.todoList[index];
$scope.doneList.push(task);
$scope.todoList.splice(index, 1);
updateLocalStorage();
};
$scope.deleteTask = function (index) {
$scope.doneList.splice(index, 1);
updateLocalStorage();
};
function updateLocalStorage() {
localStorage.setItem('todoList', JSON.stringify($scope.todoList));
localStorage.setItem('doneList', JSON.stringify($scope.doneList));
}
$scope.getItem = function () {
try {
var storedTodoList = JSON.parse(localStorage.getItem('todoList')) || [];
var storedDoneList = JSON.parse(localStorage.getItem('doneList')) || [];
$scope.todoList = storedTodoList;
$scope.doneList = storedDoneList;
} catch (error) {
console.error('Error retrieving the todoList:', error);
}
};
$scope.getItem();
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
crossorigin="anonymous"></script>
</body>
</html>