Toutes les fonctionnalités to do list ok

This commit is contained in:
HarmandI 2022-02-27 15:51:53 +01:00
parent cb1498a215
commit 59b55b35a7
6 changed files with 134 additions and 81 deletions

View file

@ -3,10 +3,12 @@
class="todo-title" class="todo-title"
placeholder="Titre" placeholder="Titre"
value="{{ todo.nom }}" value="{{ todo.nom }}"
[(ngModel)]="todo.nom"
(keyup.enter)="updateTodo(todo)"
/> />
<div>
<button (click)="effacerList()">Effacer la To Do List</button> <i class="bi bi-trash3" (click)="deleteTodo(todo.id)"></i>
</div>
<input <input
type="text" type="text"
class="todo-input" class="todo-input"
@ -15,8 +17,6 @@
(keyup.enter)="addTache(todo.id)" (keyup.enter)="addTache(todo.id)"
/> />
<div class="element" *ngFor="let tache of todo.taches"> <div class="element" *ngFor="let tache of todo.taches">
<div class="element-gauche"> <div class="element-gauche">
<input <input
@ -45,11 +45,9 @@
/> />
</ng-template> </ng-template>
</div> </div>
<div class="deleteTache" (click)="deleteTodo(tache.id)">&times;</div> <div class="deleteTache" (click)="deleteTache(tache.id)">&times;</div>
</div> </div>
<div class="extra-container"> <div class="extra-container">
<div> <div>
<label <label
@ -60,7 +58,7 @@
/>Selectionner toutes les tâches</label />Selectionner toutes les tâches</label
> >
</div> </div>
<div>{{ toDoRest() }} tâches</div> <div>{{ toDoRest() }} tâches restantes</div>
</div> </div>
<div class="extra-container"> <div class="extra-container">
<!-- <div> <!-- <div>
@ -81,5 +79,4 @@
</button> </button>
</div> </div>
--> -->
</div> </div>

View file

@ -39,26 +39,36 @@ export class ToDoListComponent implements OnInit {
this.filter = 'tous'; this.filter = 'tous';
this.idTodo = 4; this.idTodo = 4;
this.todoTitle = ''; this.todoTitle = '';
}
//supprimer la todoList
deleteTodo(id: number): void {
this.TodoService.deleteTodoById(id).subscribe((resp) => {
window.location.reload();
});
} }
//ajouter tache //ajouter tache
addTache(idTodoList : number) {//idTodoList id que la todoList que l'on récupère addTache(idTodoList: number) {
//idTodoList id que la todoList que l'on récupère
console.log(idTodoList); console.log(idTodoList);
const tache: Tache = { const tache: Tache = {
id: 0, id: 0,
texte: this.todoTitle, texte: this.todoTitle,
etat: false, etat: false,
editing: false, editing: false,
};
}
console.log(this.tache); console.log(this.tache);
this.TodoService.addTache(tache, idTodoList).subscribe((resp) => { this.TodoService.addTache(tache, idTodoList).subscribe((resp) => {
window.location.reload(); window.location.reload();
}) });
} }
//modifier le titre de la to-do-list
updateTodo(todoList: ToDoList): void {
this.TodoService.updateTodo(todoList)?.subscribe((resp) => {
window.location.reload();
});
}
//modifier par l'input //modifier par l'input
modifier(tache: Tache): void { modifier(tache: Tache): void {
@ -76,8 +86,7 @@ console.log(idTodoList);
this.TodoService.updateTache(tache).subscribe((resp) => { this.TodoService.updateTache(tache).subscribe((resp) => {
console.log(tache); console.log(tache);
window.location.reload(); window.location.reload();
}) });
} }
// annuler la modification // annuler la modification
@ -87,14 +96,11 @@ console.log(idTodoList);
} }
//supprimer la tache //supprimer la tache
deleteTodo(id: number) { deleteTache(id: number) {
this.TodoService.deleteTacheById(id).subscribe( this.TodoService.deleteTacheById(id).subscribe((resp) => {
resp =>{
window.location.reload(); window.location.reload();
});
} }
);}
//nombre de tâches restantes //nombre de tâches restantes
toDoRest(): number { toDoRest(): number {
@ -136,5 +142,3 @@ console.log(idTodoList);
return this.todo return this.todo
} */ } */
} }

View file

@ -3,9 +3,6 @@ import { Team } from './team';
export interface ToDoList { export interface ToDoList {
nom: string; nom: string;
team: Team;
taches: Tache[]; taches: Tache[];
id: number; id: number;
} }

View file

@ -1,10 +1,23 @@
<app-header></app-header> <app-header></app-header>
<div class="row">
<div class="col-md-auto">
<app-side-bar></app-side-bar> <app-side-bar></app-side-bar>
</div>
<div class="col menu text-center">
<h2>To-Do-List</h2>
<div class="d-flex align-items-stretch"></div>
<input
type="text"
class="todo-input"
placeholder="+ Nouvelle To-Do-List"
[(ngModel)]="todoListTitle"
(keyup.enter)="addTodoByTeamId()"
/>
<div class="d-flex align-items-stretch"> <div class="d-flex align-items-stretch">
<div class="row"> <div class="col" *ngFor="let todos of listTodos">
<div class="col" *ngFor="let todos of result">
<app-to-do-list [todo]="todos"> </app-to-do-list> <app-to-do-list [todo]="todos"> </app-to-do-list>
</div> </div>
</div> </div>
</div> </div>
</div>

View file

@ -1,26 +1,50 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ToDoList } from 'src/app/models/to-do-list';
import { TodoService } from 'src/app/services/todo.service'; import { TodoService } from 'src/app/services/todo.service';
import { Team } from 'src/app/models/team';
@Component({ @Component({
selector: 'app-page-to-do-list', selector: 'app-page-to-do-list',
templateUrl: './page-to-do-list.component.html', templateUrl: './page-to-do-list.component.html',
styleUrls: ['./page-to-do-list.component.scss'] styleUrls: ['./page-to-do-list.component.scss'],
}) })
export class PageToDoListComponent implements OnInit { export class PageToDoListComponent implements OnInit {
public result: any; public result: any;
public listTodos: any[];
public todoListTitle: string;
public idTodo: number;
constructor(private TodoService : TodoService) { } constructor(private TodoService: TodoService) {
this.listTodos = [];
this.todoListTitle = '';
this.idTodo = 0;
}
ngOnInit(): void { ngOnInit(): void {
this.TodoService.getToDoListByTeamId().subscribe((data :any)=>{ this.TodoService.getToDoListByTeamId()?.subscribe((listTodos: any) => {
console.log(listTodos);
this.result = data; this.listTodos = listTodos;
console.log(data); this.todoListTitle = '';
this.idTodo = 0;
});
}
//Ajouter une todo List
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();
});
}
} }

View file

@ -4,6 +4,8 @@ import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { Tache } from '../models/tache'; import { Tache } from '../models/tache';
import { ToDoList } from '../models/to-do-list'; import { ToDoList } from '../models/to-do-list';
import { TodoList } from '../todo-list';
import { TokenService } from './token.service';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@ -12,12 +14,13 @@ export class TodoService {
private toDoList: any; private toDoList: any;
private apiUrl: string; private apiUrl: string;
constructor(private http: HttpClient) { constructor(private http: HttpClient, private tokenService: TokenService) {
this.apiUrl = environment.apiUrl; this.apiUrl = environment.apiUrl;
} }
getToDoListByTeamId(): Observable<any> { getToDoListByTeamId(): Observable<any> | void {
return this.http.get(`${this.apiUrl}/todolist/team/1`); const teamId = this.tokenService.getCurrentTeamId();
return this.http.get(`${this.apiUrl}/todolist/team/${teamId}`);
} }
deleteTacheById(idTache: any): Observable<any> { deleteTacheById(idTache: any): Observable<any> {
@ -35,4 +38,19 @@ export class TodoService {
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);
} }
addTodoByTeamId(newtodoList: TodoList): Observable<any> {
const teamId = this.tokenService.getCurrentTeamId();
console.log(newtodoList + 'newtodoList');
return this.http.post(`${this.apiUrl}/todolist/add/${teamId}`, newtodoList);
}
deleteTodoById(idTodo: any): Observable<any> {
return this.http.delete(`${this.apiUrl}/todolist/delete/${idTodo}`, {
responseType: 'text',
});
}
updateTodo(todoList: TodoList): Observable<any> {
console.log(todoList);
return this.http.put(`${this.apiUrl}/todolist/update/666`, todoList);
}
} }