Compare commits

...

1 Commits

Author SHA1 Message Date
Sylvain a03322b52d feat: Ajout d'une tâche 2026-09-22 20:32:14 +02:00
7 changed files with 80 additions and 10 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
export interface Task {
date_task: Date;
id_group: number;
id_group?: number;
id_task: number;
name_task: string;
priority_task: number;
+8 -2
View File
@@ -5,7 +5,13 @@ import { Observable } from 'rxjs';
@Service()
export class BaseService {
private readonly http: HttpClient = inject(HttpClient);
protected get<T>(url: string):Observable<T> {
return this.http.get<T>(url);
private readonly baseAddress: string = "http://127.0.0.1:8080/";
protected get<T>(url: string): Observable<T> {
return this.http.get<T>(this.baseAddress + url);
}
protected post<T>(url: string, body: T): Observable<T> {
return this.http.post<T>(this.baseAddress + url, body);
}
}
+3 -3
View File
@@ -3,8 +3,8 @@ import { BaseService } from './base.service';
import { Observable } from 'rxjs';
import { Group } from '../model/Group';
@Service()
export class GroupService extends BaseService{
public getGroups():Observable<Group[]>{
return this.get<Group[]>("http://127.0.0.1:8080/group");
export class GroupService extends BaseService {
public getGroups(): Observable<Group[]> {
return this.get<Group[]>("group");
}
}
+1 -1
View File
@@ -6,6 +6,6 @@ import { Project } from '../model/Project';
@Service()
export class ProjectService extends BaseService {
public getProjects(): Observable<Project[]> {
return this.get<Project[]>("http://127.0.0.1:8080/project");
return this.get<Project[]>("project");
}
}
+13 -2
View File
@@ -4,8 +4,19 @@ import { Task } from '../model/Task';
import { BaseService } from './base.service';
@Service()
export class TaskService extends BaseService{
export class TaskService extends BaseService {
public getTasks(): Observable<Task[]> {
return this.get<Task[]>("http://127.0.0.1:8080/task");
return this.get<Task[]>("task");
}
public addTask(name: string, dueDate: string | null, priority: string | null, status: string | null): Observable<Task> {
let body: Task = {
name_task: name,
date_task: new Date(dueDate!),
priority_task: parseInt(priority!),
status_task: status!,
id_task: 0
}
return this.post<Task>("task/add", body);
}
}
+22
View File
@@ -11,6 +11,28 @@
{{ task.name_task }}
</p>
}
<button (click)="toggleForm()">
Ajouter une tâche
</button>
@if (showTaskForm){
<form [formGroup]="newTaskForm" (ngSubmit)="submitTask()">
<label for="name-task">Nom </label>
<input id="name-task" type="text" formControlName="name" />
<label for="date-task">Date limite </label>
<input id="date-task" type="date" formControlName="dueDate" />
<label for="priority-task">Priorité </label>
<input id="priority-task" type="number" formControlName="priority" />
<label for="status-task">Statut </label>
<input id="status-task" type="status" formControlName="status" />
<button type="submit" [disabled]="!newTaskForm.valid">Valider</button>
</form>
}
</div>
<h2>
+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];
});
});
}
}