Merge pull request #80 from AlineRinquin/isa2

correction bug list et tache vides
This commit is contained in:
AlineRinquin 2022-03-05 12:34:53 +01:00 committed by GitHub
commit 80ebbf2ec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 69 deletions

View File

@ -23,7 +23,6 @@ import { MeteoComponent } from './components/meteo/meteo.component';
import { CalendrierComponent } from './components/calendrier/calendrier.component'; import { CalendrierComponent } from './components/calendrier/calendrier.component';
import { CardMemberComponent } from './components/card-member/card-member.component'; import { CardMemberComponent } from './components/card-member/card-member.component';
import { ToDoListComponent } from './components/to-do-list/to-do-list.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 { CardMenuComponent } from './components/card-menu/card-menu.component';
import { FicheContactComponent } from './components/fiche-contact/fiche-contact.component'; import { FicheContactComponent } from './components/fiche-contact/fiche-contact.component';
import { CreneauComponent } from './components/creneau/creneau.component'; import { CreneauComponent } from './components/creneau/creneau.component';
@ -68,7 +67,6 @@ registerLocaleData(localeFr)
CalendrierComponent, CalendrierComponent,
CardMemberComponent, CardMemberComponent,
ToDoListComponent, ToDoListComponent,
TacheComponent,
CardMenuComponent, CardMenuComponent,
FicheContactComponent, FicheContactComponent,
CreneauComponent, CreneauComponent,

View File

@ -1 +0,0 @@
<p>tache works!</p>

View File

@ -1,25 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TacheComponent } from './tache.component';
describe('TacheComponent', () => {
let component: TacheComponent;
let fixture: ComponentFixture<TacheComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ TacheComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(TacheComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -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 {
}
}

View File

@ -40,14 +40,15 @@ export class ToDoListComponent implements OnInit {
this.idTodo = 4; this.idTodo = 4;
this.todoTitle = ''; this.todoTitle = '';
} }
//supprimer la todoList //supprimer la todoList en fonction de son id
deleteTodo(id: number): void { deleteTodo(id: number): void {
window.alert('La to-do-List a bien été supprimé!');
this.TodoService.deleteTodoById(id).subscribe((resp) => { this.TodoService.deleteTodoById(id).subscribe((resp) => {
window.location.reload(); window.location.reload();
}); });
} }
//ajouter tache
//ajouter tache par l'id de son parent todoList
addTache(idTodoList: number) { addTache(idTodoList: number) {
//idTodoList id que la todoList que l'on récupère //idTodoList id que la todoList que l'on récupère
console.log(idTodoList); console.log(idTodoList);
@ -58,9 +59,13 @@ export class ToDoListComponent implements OnInit {
editing: false, editing: false,
}; };
console.log(this.tache); console.log(this.tache);
this.TodoService.addTache(tache, idTodoList).subscribe((resp) => { if (this.todoTitle != '') {
window.location.reload(); 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 //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 { modifier(tache: Tache): void {
this.beforeEditCache = tache.texte; this.beforeEditCache = tache.texte;
tache.editing = true; tache.editing = true;
} }
// ajouter la modification dans la liste // modifier une tâche validation de l'input
doneEdit(tache: Tache): void { doneEdit(tache: Tache): void {
if (tache.texte.trim().length === 0) { if (tache.texte.trim().length === 0) {
tache.texte = this.beforeEditCache; tache.texte = this.beforeEditCache;
@ -112,12 +117,6 @@ export class ToDoListComponent implements OnInit {
return this.todo.taches.filter((tache: Tache) => tache).length > 0; 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 //cocher toutes les cases de la todoList
cocherAllTodoList(): void { cocherAllTodoList(): void {
for (var i = 0; i < this.todo.taches.length; i++) { for (var i = 0; i < this.todo.taches.length; i++) {

View File

@ -25,3 +25,5 @@
</div> </div>
</div> </div>
</div> </div>
<app-footer></app-footer>

View File

@ -21,6 +21,7 @@ export class PageToDoListComponent implements OnInit {
} }
ngOnInit(): void { 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) => { this.TodoService.getToDoListByTeamId()?.subscribe((listTodos: any) => {
console.log(listTodos); console.log(listTodos);
this.listTodos = listTodos; this.listTodos = listTodos;
@ -28,23 +29,21 @@ export class PageToDoListComponent implements OnInit {
this.idTodo = 0; this.idTodo = 0;
}); });
} }
//Ajouter une todo List
//Ajouter une todo List si l'input n'est pas vide
addTodoByTeamId() { addTodoByTeamId() {
const todoList: ToDoList = { const todoList: ToDoList = {
nom: this.todoListTitle, nom: this.todoListTitle,
taches: [], taches: [],
id: 0, id: 0,
}; };
this.TodoService.addTodoByTeamId(todoList)?.subscribe((resp) => { if (this.todoListTitle != '') {
console.log(todoList); this.TodoService.addTodoByTeamId(todoList)?.subscribe((resp) => {
window.location.reload(); console.log(todoList);
}); window.location.reload(); //rafraîchit l'aperçu
} });
}else{
deleteTodo(id: number): void { window.alert('Il faut saisir du texte'); // sinon msg d'erreur
window.alert('La to-do-List a bien été supprimé!'); }
this.TodoService.deleteTodoById(id).subscribe((resp) => {
window.location.reload();
});
} }
} }

View File

@ -18,37 +18,46 @@ export class TodoService {
this.apiUrl = environment.apiUrl; this.apiUrl = environment.apiUrl;
} }
//recupère les todolistexistantes en BDD par le tokenService en fonction de l'iD de la team
getToDoListByTeamId(): Observable<any> | void { getToDoListByTeamId(): Observable<any> | void {
const teamId = this.tokenService.getCurrentTeamId(); const teamId = this.tokenService.getCurrentTeamId();
return this.http.get(`${this.apiUrl}/todolist/team/${teamId}`); return this.http.get(`${this.apiUrl}/todolist/team/${teamId}`);
} }
//supprime les taches par l'id dela tache dans la todoList
deleteTacheById(idTache: any): Observable<any> { deleteTacheById(idTache: any): Observable<any> {
return this.http.delete(`${this.apiUrl}/taches/delete/${idTache}`, { return this.http.delete(`${this.apiUrl}/taches/delete/${idTache}`, {
responseType: 'text', responseType: 'text',
}); });
} }
//ajoute une tache avec auto-incrémentation de l'id dans la todolist
addTache(newtache: Tache, idTodoList: number): Observable<any> { addTache(newtache: Tache, idTodoList: number): Observable<any> {
// console.log(newtache); // console.log(newtache);
return this.http.post(`${this.apiUrl}/taches/add/${idTodoList}`, newtache); return this.http.post(`${this.apiUrl}/taches/add/${idTodoList}`, newtache);
} }
// modifie une tâche par son id
updateTache(tache: Tache): Observable<any> { updateTache(tache: Tache): Observable<any> {
console.log(tache); // console.log(tache);
return this.http.put(`${this.apiUrl}/taches/update/1`, 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<any> { addTodoByTeamId(newtodoList: TodoList): Observable<any> {
const teamId = this.tokenService.getCurrentTeamId(); const teamId = this.tokenService.getCurrentTeamId();
console.log(newtodoList + 'newtodoList'); console.log(newtodoList + 'newtodoList');
return this.http.post(`${this.apiUrl}/todolist/add/${teamId}`, newtodoList); return this.http.post(`${this.apiUrl}/todolist/add/${teamId}`, newtodoList);
} }
//suprime une todoList en fonction de son id
deleteTodoById(idTodo: any): Observable<any> { deleteTodoById(idTodo: any): Observable<any> {
return this.http.delete(`${this.apiUrl}/todolist/delete/${idTodo}`, { return this.http.delete(`${this.apiUrl}/todolist/delete/${idTodo}`, {
responseType: 'text', responseType: 'text',
}); });
} }
//modfie une todoList par son id
updateTodo(todoList: TodoList): Observable<any> { updateTodo(todoList: TodoList): Observable<any> {
console.log(todoList); console.log(todoList);
return this.http.put(`${this.apiUrl}/todolist/update/666`, todoList); return this.http.put(`${this.apiUrl}/todolist/update/666`, todoList);