feat: suppression d'une tâche
This commit is contained in:
@@ -14,4 +14,10 @@ export class BaseService {
|
|||||||
protected post<T>(url: string, body: T): Observable<T> {
|
protected post<T>(url: string, body: T): Observable<T> {
|
||||||
return this.http.post<T>(this.baseAddress + url, body);
|
return this.http.post<T>(this.baseAddress + url, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected delete<T>(url: string): Observable<T> {
|
||||||
|
return this.http.delete<T>(`${this.baseAddress}${url}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ export class TaskService extends BaseService {
|
|||||||
return this.get<Task[]>("task");
|
return this.get<Task[]>("task");
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTask(name: string, dueDate: string | null, priority: string | null, status: string | null): Observable<Task> {
|
public addTask(name: string,
|
||||||
|
dueDate: string | null,
|
||||||
|
priority: string | null,
|
||||||
|
status: string | null): Observable<Task> {
|
||||||
let body: Task = {
|
let body: Task = {
|
||||||
name_task: name,
|
name_task: name,
|
||||||
date_task: new Date(dueDate!),
|
date_task: new Date(dueDate!),
|
||||||
@@ -19,4 +22,8 @@ export class TaskService extends BaseService {
|
|||||||
}
|
}
|
||||||
return this.post<Task>("task/add", body);
|
return this.post<Task>("task/add", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public deleteTask(id_task: number): Observable<void> {
|
||||||
|
return this.delete<void>(`task/delete?id=${id_task}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,16 @@
|
|||||||
Section tâches
|
Section tâches
|
||||||
</h2>
|
</h2>
|
||||||
<div>
|
<div>
|
||||||
|
<div>
|
||||||
@for (task of tasks(); track task.id_task) {
|
@for (task of tasks(); track task.id_task) {
|
||||||
<p>
|
<p>
|
||||||
{{ task.name_task }}
|
{{ task.name_task }}
|
||||||
</p>
|
</p>
|
||||||
}
|
|
||||||
|
|
||||||
|
<button (click)="deleteTask(task.id_task)">Supprimer la tâche </button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
<button (click)="toggleTaskForm()">
|
<button (click)="toggleTaskForm()">
|
||||||
Ajouter une tâche
|
Ajouter une tâche
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -49,17 +49,32 @@ export class Home {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
public ngOnInit(): void {
|
public ngOnInit(): void {
|
||||||
this.taskService.getTasks().subscribe((response: Task[]): void => {
|
this.taskService.getTasks().subscribe({
|
||||||
|
next: (response: Task[]) => {
|
||||||
this.tasks.set(response);
|
this.tasks.set(response);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(`Récupération des tâches impossible\nErreur:${error.error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.groupService.getGroups().subscribe((response: Group[]): void => {
|
this.groupService.getGroups().subscribe({
|
||||||
|
next: (response: Group[]) => {
|
||||||
this.groups.set(response);
|
this.groups.set(response);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(`Récupération des groupes impossible\nErreur:${error.error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.projectService.getProjects().subscribe((response: Project[]): void => {
|
this.projectService.getProjects().subscribe({
|
||||||
|
next: (response: Project[]) => {
|
||||||
this.projects.set(response);
|
this.projects.set(response);
|
||||||
})
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(`Récupération des projets impossible\nErreur:${error.error.message}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toggleTaskForm(): void {
|
public toggleTaskForm(): void {
|
||||||
@@ -75,10 +90,33 @@ export class Home {
|
|||||||
this.newTaskForm.controls.priority.value,
|
this.newTaskForm.controls.priority.value,
|
||||||
this.newTaskForm.controls.status.value);
|
this.newTaskForm.controls.status.value);
|
||||||
|
|
||||||
response.subscribe(response => {
|
response.subscribe({
|
||||||
|
next: (response) => {
|
||||||
this.tasks.update(values => {
|
this.tasks.update(values => {
|
||||||
return [...values, response];
|
return [...values, response];
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(`L'ajout de tâche est impossible\nErreur:${error.error.message}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deleteTask
|
||||||
|
*/
|
||||||
|
public deleteTask(id_task: number) {
|
||||||
|
let response: Observable<void> = this.taskService.deleteTask(id_task);
|
||||||
|
|
||||||
|
response.subscribe({
|
||||||
|
next: () => {
|
||||||
|
this.tasks.update((tasks) => {
|
||||||
|
return tasks.filter(((task) => task.id_task != id_task));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(`La suppression de tâche est impossible\nErreur:${error.error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,10 +130,15 @@ export class Home {
|
|||||||
public submitGroup() {
|
public submitGroup() {
|
||||||
let response: Observable<Group> = this.groupService.addGroup(this.newGroupForm.controls.name.value!);
|
let response: Observable<Group> = this.groupService.addGroup(this.newGroupForm.controls.name.value!);
|
||||||
|
|
||||||
response.subscribe(response => {
|
response.subscribe({
|
||||||
|
next: (response) => {
|
||||||
this.groups.update(values => {
|
this.groups.update(values => {
|
||||||
return [...values, response];
|
return [...values, response];
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(`L'ajout d'un groupe est impossible\nErreur:${error.error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +152,15 @@ export class Home {
|
|||||||
public submitProject() {
|
public submitProject() {
|
||||||
let response: Observable<Project> = this.projectService.addProject(this.newProjectForm.controls.name.value!);
|
let response: Observable<Project> = this.projectService.addProject(this.newProjectForm.controls.name.value!);
|
||||||
|
|
||||||
response.subscribe(response => {
|
response.subscribe({
|
||||||
|
next: (response) => {
|
||||||
this.projects.update(values => {
|
this.projects.update(values => {
|
||||||
return [...values, response];
|
return [...values, response];
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(`L'ajout d'un projet est impossible\nErreur:${error.error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user