feat: Ajout d'une tâche
This commit is contained in:
+1
-1
@@ -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;
|
||||
|
||||
@@ -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,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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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];
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user