-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.component.ts
More file actions
102 lines (97 loc) · 2.96 KB
/
tasks.component.ts
File metadata and controls
102 lines (97 loc) · 2.96 KB
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
import { Component } from '@angular/core';
import {TaskService} from '../../services/task.service';
import {Task} from '../../../Task';
import {Router} from '@angular/router';
@Component({
moduleId: module.id,
selector: 'tasks',
templateUrl: 'tasks.component.html'
})
export class TasksComponent {
tasks: Task[];
static id:Number=0;
name: string;
description:string;
progress:string;
books:string;
uid:Number;
constructor(private taskService:TaskService,private route:Router){
this.taskService.getTasks()
.subscribe(tasks => {
console.log("Tasks received successfully");
console.log(tasks);
this.tasks = tasks;
});
}
handleError(error:any):Promise<any>{
console.error("An error occured",error);
return Promise.reject(error.message || error);
}
get UserId(){
return this.taskService.getUdata().subscribe(data=>{
this.uid=+(data[0]['id']);
})
}
addT(event:Event):void{
event.preventDefault();
var newTask = {
name:this.name,
description:this.description,
progress:this.progress,
books:this.books
}
this.taskService.addTask(this.name,this.description,this.progress,this.books,this.uid)
.subscribe(task => {
this.tasks.push(task);
console.log("Request Succesful");
console.log(task);
this.name= '';
this.description='',
this.books=''
},
err=>this.handleError(err));
}
addT1(event:Event):void{
event.preventDefault();
var newTask = {
name:this.name,
description:this.description,
progress:this.progress,
books:this.books
}
this.taskService.addTask1(this.name,this.description,this.progress,this.books,this.uid)
.subscribe(task => {
this.tasks.push(task);
console.log("Request Succesful");
console.log(task);
this.name= '';
this.description='',
this.books=''
},
err=>this.handleError(err));
}
goBack(){
this.route.navigate(['/user',this.uid]);
}
deleteT(id:Number):void{
var tasks = this.tasks;
this.taskService.deleteTask(id).subscribe(data => {
for(var i = 0;i < tasks.length;i++){
if(tasks[i]._id == id){
tasks.splice(i, 1);
}
}
},
err=>this.handleError(err));
}
/*updateStatus(task:Task){
var _task = {
_id:task._id,
title: task.title,
isDone: !task.isDone
};
this.taskService.updateStatus(_task).subscribe(data => {
task.isDone = !task.isDone;
});
}*/
}