update task functionality

This commit is contained in:
Huffle 2025-05-18 16:34:49 +02:00
parent 1f21924805
commit 6e07d44733
4 changed files with 14 additions and 4 deletions

View File

@ -45,8 +45,8 @@ export class EditTaskPage implements OnInit {
this.form.setValue({ this.form.setValue({
name: task.name, name: task.name,
reward: task.reward, reward: task.reward,
assigned: task.assigned assigned: task.assigned !== null ? task.assigned : 0
}) });
}); });
} }
} }
@ -66,7 +66,9 @@ export class EditTaskPage implements OnInit {
if (this.isAddMode) { if (this.isAddMode) {
this.taskService.createTask(task); this.taskService.createTask(task);
} else {} } else {
this.taskService.updateTask(this.id, task);
}
this.router.navigate(['/tabs/tasks']); this.router.navigate(['/tabs/tasks']);
} }

View File

@ -15,7 +15,7 @@
<mat-icon>filter_alt</mat-icon> <mat-icon>filter_alt</mat-icon>
</div> </div>
<div class="list"> <div class="list">
<div class="task" *ngFor="let task of tasks$ | async"> <div class="task" (click)="updateTask(task.id)" *ngFor="let task of tasks$ | async">
<button>Done</button> <button>Done</button>
<div class="name">{{ task.name }}</div> <div class="name">{{ task.name }}</div>
<div <div

View File

@ -36,4 +36,8 @@ export class TasksPage implements ViewWillEnter {
createTask() { createTask() {
this.router.navigate(['add'], { relativeTo: this.route }); this.router.navigate(['add'], { relativeTo: this.route });
} }
updateTask(id: number) {
this.router.navigate(['edit', id], { relativeTo: this.route });
}
} }

View File

@ -22,4 +22,8 @@ export class TaskService {
createTask(task: Partial<Task>) { createTask(task: Partial<Task>) {
this.http.post(`${this.url}/tasks`, task).subscribe(); this.http.post(`${this.url}/tasks`, task).subscribe();
} }
updateTask(id: number, task: Partial<Task>) {
this.http.put(`${this.url}/task/${id}`, task).subscribe();
}
} }