-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo-list.html
181 lines (172 loc) · 4.98 KB
/
todo-list.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Vue Test</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
<!-- Icons -->
<link href="assets/vendor/nucleo/css/nucleo.css" rel="stylesheet">
<link href="assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link type="text/css" href="assets/css/argon.min.css" rel="stylesheet">
<link type="text/css" href="assets/css/animate.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<style type="text/css">
body,html{
height:100%;
}
.todo-wrapper{
}
.todo-head{
}
.todo-body{
background-color: #172b4d;
color:white;
}
.todo-body ul{
list-style: none;
padding: 20px;
text-align: left;
color:white;
}
.todo-body ul li{
border-bottom: 1px dashed gray;
margin-bottom: 5px;
}
.todo-footer {
background: #182a50;
margin: 0px;
padding: 5px 0px 20px 0px;
}
.task-completed{
text-decoration: line-through;
color: #7080a2;
}
.no-tasks{
padding: 10px 0px;
}
</style>
</head>
<body>
<div class="container h-100" id="app">
<div class="row justify-content-center align-items-center">
<div class="col-sm-12 col-md-6 mx-auto text-center todo-wrapper h-50">
<div class="todo-head">
<todo-head v-bind:tasks="todosList"></todo-head>
</div>
<div class="todo-body h-100">
<ul class="h-100" v-if="todosList.length>0">
<todo-item
v-for="todo in todosList"
v-bind:todo="todo"
v-bind:key = "todo.id"
>
</todo-item>
</ul>
<div class="no-tasks animate tada" v-if="todosList.length==0">Add a Task Below.</div>
</div>
<div class="todo-footer row">
<div class="col-sm-12 col-md-12">
<div class="form-group">
<div class="input-group input-group-alternative mb-4">
<input class="form-control" placeholder="Add New Task" type="text" v-model="newitem" id="new-task" @keyup.enter="addNew">
<div class="input-group-append">
<span class="input-group-text"><i class="ni ni-bullet-list-67"></i></span>
</div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-12">
<button type="button" v-on:click="addNew" class="btn btn-sm btn-primary">Add New</button>
<button type="button" v-on:click="addNew" class="btn btn-sm btn-primary">Save Changes</button>
</div>
</div>
</div>
</div>
</div>
<!-- Core -->
<script src="assets/vendor/jquery/jquery.min.js"></script>
<script src="assets/vendor/popper/popper.min.js"></script>
<script src="assets/vendor/bootstrap/bootstrap.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<!-- Theme JS -->
<script src="assets/js/argon.min.js"></script>
<script type="text/javascript">
Vue.component('todo-head',{
props: ['tasks'],
template: `<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="#">TODO LIST</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-default" aria-controls="navbar-default" aria-expanded="false" aria-label="Toggle navigation">
</button>
<span class="badge badge-secondary">{{ tasks.length }}</span>
</div>
</nav>`
})
Vue.component('todo-item', {
props: ['todo'],
template: `
<li class="h-40 row animated fadeInUp" v-bind:class="{ 'task-completed' : todo.isCompleted }">
<div class="col-1 col-sm-1 col-md-1">{{ todo.id }}</div>
<div
class="col-8 col-sm-8 col-md-8"> {{ todo.task }} </div>
<div class="col-6 col-sm-2 col-md-2 text-right"> <button v-on:click="onTaskDone(todo)" class="btn btn-primary btn-sm">done</button></div>
<div class="col-6 col-sm-1 col-md-1 text-left"> <button v-on:click="onTaskDelete(todo)" class="btn btn-danger btn-sm">X</button></div>
</li>`,
methods: {
onTaskClick: function(todo){
console.log(todo);
},
onTaskDone : function(todo){
todo.isCompleted = true;
},
onTaskDelete : function(todo){
this.$parent.todosList.splice(this.$parent.todosList.findIndex(function(i){
return i.id === todo.id;
}), 1);
this.renumberList(app.todosList);
}
}
})
var app = new Vue({
el: '#app',
data :{
newitem : '',
todosList:[]
},
methods: {
addNew : function(){
if(!this.valueExists(this.newitem)){
this.todosList.push({id: this.todosList.length+1, task: this.newitem, isCompleted: false});
this.newitem='';
}else{
swal({
title: "Brrrrr!",
text: "Its already in the list",
icon: "warning",
button: "Oh Okay!",
});
}
},
valueExists : function(value){
return this.todosList.some(function(el){
return el.task === value;
});
}
},
watch: {
todosList:{
handler: function(val,oldval){
var count=1;
val.forEach(function(x){
x.id = count++;
});
},
deep:true
}
}
});
</script>
</body>
</html>