feat: Ajout d'une tâche

This commit is contained in:
2026-09-22 20:32:14 +02:00
parent f2ad1ed735
commit a03322b52d
7 changed files with 80 additions and 10 deletions
+32 -1
View File
@@ -6,9 +6,11 @@ import { GroupService } from '../../../services/group.service';
import { Group } from '../../../model/Group';
import { ProjectService } from '../../../services/project.service';
import { Project } from '../../../model/Project';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Observable } from 'rxjs';
@Component({
imports: [RouterOutlet],
imports: [RouterOutlet, ReactiveFormsModule],
selector: 'app-root',
styleUrl: './home.component.css',
templateUrl: './home.component.html',
@@ -22,6 +24,15 @@ export class Home {
groups: WritableSignal<Group[]> = signal<Group[]>([]);
projects: WritableSignal<Project[]> = signal<Project[]>([]);
newTaskForm = new FormGroup({
name: new FormControl('', Validators.required),
dueDate: new FormControl(''),
priority: new FormControl(''),
status: new FormControl(''),
});
showTaskForm: boolean = false;
public ngOnInit(): void {
this.taskService.getTasks().subscribe((response: Task[]): void => {
this.tasks.set(response);
@@ -35,4 +46,24 @@ export class Home {
this.projects.set(response);
})
}
public toggleForm(): void {
this.showTaskForm = !this.showTaskForm;
}
/**
* submitTask
*/
public submitTask(): void {
let response: Observable<Task> = this.taskService.addTask(this.newTaskForm.controls.name.value!,
this.newTaskForm.controls.dueDate.value,
this.newTaskForm.controls.priority.value,
this.newTaskForm.controls.status.value);
response.subscribe(response => {
this.tasks.update(values => {
return [...values, response];
});
});
}
}