From 7955ccad42d73f512429d49c3598bb9f3cf9aacb Mon Sep 17 00:00:00 2001 From: HarmandI Date: Sat, 5 Mar 2022 09:21:00 +0100 Subject: [PATCH] correction bug list et tache vides --- src/app/app.module.ts | 2 -- src/app/components/tache/tache.component.html | 1 - src/app/components/tache/tache.component.scss | 0 .../components/tache/tache.component.spec.ts | 25 ------------------- src/app/components/tache/tache.component.ts | 15 ----------- .../to-do-list/to-do-list.component.ts | 25 +++++++++---------- .../page-to-do-list.component.html | 2 ++ .../page-to-do-list.component.ts | 23 ++++++++--------- src/app/services/todo.service.ts | 11 +++++++- 9 files changed, 35 insertions(+), 69 deletions(-) delete mode 100644 src/app/components/tache/tache.component.html delete mode 100644 src/app/components/tache/tache.component.scss delete mode 100644 src/app/components/tache/tache.component.spec.ts delete mode 100644 src/app/components/tache/tache.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6fe94e6..31e7e57 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,7 +23,6 @@ import { MeteoComponent } from './components/meteo/meteo.component'; import { CalendrierComponent } from './components/calendrier/calendrier.component'; import { CardMemberComponent } from './components/card-member/card-member.component'; import { ToDoListComponent } from './components/to-do-list/to-do-list.component'; -import { TacheComponent } from './components/tache/tache.component'; import { CardMenuComponent } from './components/card-menu/card-menu.component'; import { FicheContactComponent } from './components/fiche-contact/fiche-contact.component'; import { CreneauComponent } from './components/creneau/creneau.component'; @@ -68,7 +67,6 @@ registerLocaleData(localeFr) CalendrierComponent, CardMemberComponent, ToDoListComponent, - TacheComponent, CardMenuComponent, FicheContactComponent, CreneauComponent, diff --git a/src/app/components/tache/tache.component.html b/src/app/components/tache/tache.component.html deleted file mode 100644 index 191d8ea..0000000 --- a/src/app/components/tache/tache.component.html +++ /dev/null @@ -1 +0,0 @@ -

tache works!

diff --git a/src/app/components/tache/tache.component.scss b/src/app/components/tache/tache.component.scss deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/components/tache/tache.component.spec.ts b/src/app/components/tache/tache.component.spec.ts deleted file mode 100644 index 44bc16a..0000000 --- a/src/app/components/tache/tache.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { TacheComponent } from './tache.component'; - -describe('TacheComponent', () => { - let component: TacheComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ TacheComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(TacheComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/components/tache/tache.component.ts b/src/app/components/tache/tache.component.ts deleted file mode 100644 index 5b7b6c5..0000000 --- a/src/app/components/tache/tache.component.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Component, OnInit } from '@angular/core'; - -@Component({ - selector: 'app-tache', - templateUrl: './tache.component.html', - styleUrls: ['./tache.component.scss'] -}) -export class TacheComponent implements OnInit { - - constructor() { } - - ngOnInit(): void { - } - -} diff --git a/src/app/components/to-do-list/to-do-list.component.ts b/src/app/components/to-do-list/to-do-list.component.ts index f5dd560..09d58aa 100644 --- a/src/app/components/to-do-list/to-do-list.component.ts +++ b/src/app/components/to-do-list/to-do-list.component.ts @@ -40,14 +40,15 @@ export class ToDoListComponent implements OnInit { this.idTodo = 4; this.todoTitle = ''; } - //supprimer la todoList + //supprimer la todoList en fonction de son id deleteTodo(id: number): void { + window.alert('La to-do-List a bien été supprimé!'); this.TodoService.deleteTodoById(id).subscribe((resp) => { window.location.reload(); }); } - //ajouter tache + //ajouter tache par l'id de son parent todoList addTache(idTodoList: number) { //idTodoList id que la todoList que l'on récupère console.log(idTodoList); @@ -58,9 +59,13 @@ export class ToDoListComponent implements OnInit { editing: false, }; console.log(this.tache); - this.TodoService.addTache(tache, idTodoList).subscribe((resp) => { - window.location.reload(); - }); + if (this.todoTitle != '') { + this.TodoService.addTache(tache, idTodoList).subscribe((resp) => { + window.location.reload(); + }); + } else { + window.alert('Il faut saisir du texte'); // sinon msg d'erreur + } } //modifier le titre de la to-do-list @@ -70,13 +75,13 @@ export class ToDoListComponent implements OnInit { }); } - //modifier par l'input + //modifier la tâche par l'input modifier(tache: Tache): void { this.beforeEditCache = tache.texte; tache.editing = true; } - // ajouter la modification dans la liste + // modifier une tâche validation de l'input doneEdit(tache: Tache): void { if (tache.texte.trim().length === 0) { tache.texte = this.beforeEditCache; @@ -112,12 +117,6 @@ export class ToDoListComponent implements OnInit { return this.todo.taches.filter((tache: Tache) => tache).length > 0; } - //Effacer la to do list - - effacerList(): void { - //this.todo = []; - } - //cocher toutes les cases de la todoList cocherAllTodoList(): void { for (var i = 0; i < this.todo.taches.length; i++) { diff --git a/src/app/pages/page-to-do-list/page-to-do-list.component.html b/src/app/pages/page-to-do-list/page-to-do-list.component.html index 69b5838..143367f 100644 --- a/src/app/pages/page-to-do-list/page-to-do-list.component.html +++ b/src/app/pages/page-to-do-list/page-to-do-list.component.html @@ -25,3 +25,5 @@ + + diff --git a/src/app/pages/page-to-do-list/page-to-do-list.component.ts b/src/app/pages/page-to-do-list/page-to-do-list.component.ts index b9732e8..a850dda 100644 --- a/src/app/pages/page-to-do-list/page-to-do-list.component.ts +++ b/src/app/pages/page-to-do-list/page-to-do-list.component.ts @@ -21,6 +21,7 @@ export class PageToDoListComponent implements OnInit { } ngOnInit(): void { + //récupère les todoLists existantes en fonctoin de l'id de la team en utilisant le service this.TodoService.getToDoListByTeamId()?.subscribe((listTodos: any) => { console.log(listTodos); this.listTodos = listTodos; @@ -28,23 +29,21 @@ export class PageToDoListComponent implements OnInit { this.idTodo = 0; }); } - //Ajouter une todo List + + //Ajouter une todo List si l'input n'est pas vide addTodoByTeamId() { const todoList: ToDoList = { nom: this.todoListTitle, taches: [], id: 0, }; - this.TodoService.addTodoByTeamId(todoList)?.subscribe((resp) => { - console.log(todoList); - window.location.reload(); - }); - } - - deleteTodo(id: number): void { - window.alert('La to-do-List a bien été supprimé!'); - this.TodoService.deleteTodoById(id).subscribe((resp) => { - window.location.reload(); - }); + if (this.todoListTitle != '') { + this.TodoService.addTodoByTeamId(todoList)?.subscribe((resp) => { + console.log(todoList); + window.location.reload(); //rafraîchit l'aperçu + }); + }else{ + window.alert('Il faut saisir du texte'); // sinon msg d'erreur + } } } diff --git a/src/app/services/todo.service.ts b/src/app/services/todo.service.ts index 6528ebb..31e14f1 100644 --- a/src/app/services/todo.service.ts +++ b/src/app/services/todo.service.ts @@ -18,37 +18,46 @@ export class TodoService { this.apiUrl = environment.apiUrl; } + //recupère les todolistexistantes en BDD par le tokenService en fonction de l'iD de la team getToDoListByTeamId(): Observable | void { const teamId = this.tokenService.getCurrentTeamId(); return this.http.get(`${this.apiUrl}/todolist/team/${teamId}`); } + //supprime les taches par l'id dela tache dans la todoList deleteTacheById(idTache: any): Observable { return this.http.delete(`${this.apiUrl}/taches/delete/${idTache}`, { responseType: 'text', }); } + //ajoute une tache avec auto-incrémentation de l'id dans la todolist addTache(newtache: Tache, idTodoList: number): Observable { // console.log(newtache); return this.http.post(`${this.apiUrl}/taches/add/${idTodoList}`, newtache); } + // modifie une tâche par son id updateTache(tache: Tache): Observable { - console.log(tache); + // console.log(tache); return this.http.put(`${this.apiUrl}/taches/update/1`, tache); } + + //ajoute ne todoList sur une team (par son id) via le token addTodoByTeamId(newtodoList: TodoList): Observable { const teamId = this.tokenService.getCurrentTeamId(); console.log(newtodoList + 'newtodoList'); return this.http.post(`${this.apiUrl}/todolist/add/${teamId}`, newtodoList); } + //suprime une todoList en fonction de son id deleteTodoById(idTodo: any): Observable { return this.http.delete(`${this.apiUrl}/todolist/delete/${idTodo}`, { responseType: 'text', }); } + + //modfie une todoList par son id updateTodo(todoList: TodoList): Observable { console.log(todoList); return this.http.put(`${this.apiUrl}/todolist/update/666`, todoList);