diff --git a/db.json b/db.json
index 080b02d..7cdfca1 100644
--- a/db.json
+++ b/db.json
@@ -1,10 +1,16 @@
{
"tasks": [
{
- "title": "ty po sa milktea hahaha",
+ "title": "coffee",
"completed": false,
"editing": false,
"id": 2
+ },
+ {
+ "title": "sleep",
+ "completed": false,
+ "editing": false,
+ "id": 3
}
]
}
\ No newline at end of file
diff --git a/src/app/Todo-List-App/containers/TodoList/todo-list.component.html b/src/app/Todo-List-App/containers/TodoList/todo-list.component.html
index 2770c60..b8791d1 100644
--- a/src/app/Todo-List-App/containers/TodoList/todo-list.component.html
+++ b/src/app/Todo-List-App/containers/TodoList/todo-list.component.html
@@ -4,7 +4,7 @@
-
+
@@ -12,7 +12,7 @@
@@ -43,10 +43,9 @@
{{ remaining()}} uncompleted tasks
-
+
You've selected an item
-
\ No newline at end of file
diff --git a/src/app/Todo-List-App/containers/TodoList/todo-list.component.ts b/src/app/Todo-List-App/containers/TodoList/todo-list.component.ts
index 47f104b..68b0df4 100644
--- a/src/app/Todo-List-App/containers/TodoList/todo-list.component.ts
+++ b/src/app/Todo-List-App/containers/TodoList/todo-list.component.ts
@@ -29,6 +29,7 @@ export class TodoList{
tasks:Tasks[] = [];
beforeEditing: string;
today: number = Date.now();
+ completed: Tasks[] = [];
constructor(private todoService: TodoService){
@@ -45,7 +46,6 @@ export class TodoList{
}
addTask(){
- //restricting empty string
if(this.taskTitle.trim().length === 0){
return;
}
@@ -66,8 +66,6 @@ export class TodoList{
editing: false
})
this.taskTitle ='';
-
- // this.taskId++;
}
toggleEdit(event: Tasks){
@@ -87,9 +85,6 @@ export class TodoList{
}));
}
- console(){
- console.log("try function");
- }
doneEditing(task: Tasks):void{
if(task.title.trim().length === 0){
@@ -110,28 +105,41 @@ export class TodoList{
atleastOneCompleted(): boolean{
return this.tasks.filter(task => task.completed).length > 0;
}
+
//delete function
- deleteTask(tasks: Tasks){
- this.tasks = this.tasks.filter(task => task.id !== tasks.id);
+ deleteTask(taskId){
+ this.tasks = this.tasks.filter(task => task.id !== taskId);
- this.todoService.deleteTask(tasks)
+ this.todoService.deleteTask(taskId)
.subscribe(data => this.tasks.filter(task => {
- return task.id !== data;
+ return task !== data;
}))
+
+
+ }
+
+ deleteAllTask(){
+ const selectedProducts = this.tasks.filter(product => product.completed).map(p => p.id);
+ console.log (selectedProducts);
+
+ selectedProducts.forEach(value => {
+ this.todoService.deleteTask(value)
+ .subscribe(res => {
+ this.tasks = this.tasks.filter(task => !task.completed);
+ });
+ });
+
+ // if(selectedProducts && selectedProducts.length === 1) {
+
+ // }
+ // else{
+ // this.todoService.deleteAllTask(selectedProducts)
+ // .subscribe(data => console.log("more than 1 elements"));
+ // }
}
- clearCompleted(tasks: Tasks){
- // this.tasks = this.tasks.filter(task => !task.completed);
-
- // this.todoService.deleteAllTask(tasks)
- // .subscribe(data => this.tasks.filter(task => {
- // return task.completed !== data;
- // }))
- }
-
- selectAll():void{
- this.tasks.forEach(task => task.completed =
- (event.target).checked);
+ selectAll(event):void{
+ this.tasks.forEach(x => x.completed = event.target.checked)
}
}
\ No newline at end of file
diff --git a/src/app/Todo-List-App/services/todo.service.ts b/src/app/Todo-List-App/services/todo.service.ts
index 89aa2bd..a6b82f5 100644
--- a/src/app/Todo-List-App/services/todo.service.ts
+++ b/src/app/Todo-List-App/services/todo.service.ts
@@ -26,12 +26,17 @@ export class TodoService{
.pipe(map((response: any) => response.json()));
}
- deleteTask(task: Tasks){
- return this.http.delete(URL + '/' + task.id);
+ deleteTask(id:number){
+ return this.http.delete(URL + '/' + id);
}
- deleteAllTask(task: Tasks){
- return this.http.delete(URL + '/' + task.id);
+ deleteAllTask(id: number[]){
+ return this.http.delete(URL + '/' + id);
+
+
+ // .pipe(map((res:any) => {
+ // res.json();
+ // }))
}