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 { export interface Task {
date_task: Date; date_task: Date;
id_group: number; id_group?: number;
id_task: number; id_task: number;
name_task: string; name_task: string;
priority_task: number; priority_task: number;
+7 -1
View File
@@ -5,7 +5,13 @@ import { Observable } from 'rxjs';
@Service() @Service()
export class BaseService { export class BaseService {
private readonly http: HttpClient = inject(HttpClient); private readonly http: HttpClient = inject(HttpClient);
private readonly baseAddress: string = "http://127.0.0.1:8080/";
protected get<T>(url: string): Observable<T> { protected get<T>(url: string): Observable<T> {
return this.http.get<T>(url); 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);
} }
} }
+1 -1
View File
@@ -5,6 +5,6 @@ import { Group } from '../model/Group';
@Service() @Service()
export class GroupService extends BaseService { export class GroupService extends BaseService {
public getGroups(): Observable<Group[]> { public getGroups(): Observable<Group[]> {
return this.get<Group[]>("http://127.0.0.1:8080/group"); return this.get<Group[]>("group");
} }
} }
+1 -1
View File
@@ -6,6 +6,6 @@ import { Project } from '../model/Project';
@Service() @Service()
export class ProjectService extends BaseService { export class ProjectService extends BaseService {
public getProjects(): Observable<Project[]> { public getProjects(): Observable<Project[]> {
return this.get<Project[]>("http://127.0.0.1:8080/project"); return this.get<Project[]>("project");
} }
} }
+12 -1
View File
@@ -6,6 +6,17 @@ import { BaseService } from './base.service';
@Service() @Service()
export class TaskService extends BaseService { export class TaskService extends BaseService {
public getTasks(): Observable<Task[]> { 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 }} {{ task.name_task }}
</p> </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> </div>
<h2> <h2>
+32 -1
View File
@@ -6,9 +6,11 @@ import { GroupService } from '../../../services/group.service';
import { Group } from '../../../model/Group'; import { Group } from '../../../model/Group';
import { ProjectService } from '../../../services/project.service'; import { ProjectService } from '../../../services/project.service';
import { Project } from '../../../model/Project'; import { Project } from '../../../model/Project';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Observable } from 'rxjs';
@Component({ @Component({
imports: [RouterOutlet], imports: [RouterOutlet, ReactiveFormsModule],
selector: 'app-root', selector: 'app-root',
styleUrl: './home.component.css', styleUrl: './home.component.css',
templateUrl: './home.component.html', templateUrl: './home.component.html',
@@ -22,6 +24,15 @@ export class Home {
groups: WritableSignal<Group[]> = signal<Group[]>([]); groups: WritableSignal<Group[]> = signal<Group[]>([]);
projects: WritableSignal<Project[]> = signal<Project[]>([]); 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 { public ngOnInit(): void {
this.taskService.getTasks().subscribe((response: Task[]): void => { this.taskService.getTasks().subscribe((response: Task[]): void => {
this.tasks.set(response); this.tasks.set(response);
@@ -35,4 +46,24 @@ export class Home {
this.projects.set(response); 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];
});
});
}
} }