todo en cours

This commit is contained in:
HarmandI 2022-02-14 11:28:50 +01:00
parent 9287f531d2
commit efb86420d0
10 changed files with 143 additions and 87 deletions

10
package-lock.json generated
View File

@ -2325,11 +2325,6 @@
"integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==",
"dev": true
},
"angular-autofocus-fix": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/angular-autofocus-fix/-/angular-autofocus-fix-0.1.2.tgz",
"integrity": "sha512-P5l24by1q6CSaRW/yrjJis56SuECQwXGbwFOfrk6URn3ir+uDrabykF1vjQwKYPrhF2W/JdBfXeMwuKnQ94Bmg=="
},
"ansi-colors": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz",
@ -2649,6 +2644,11 @@
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.1.3.tgz",
"integrity": "sha512-fcQztozJ8jToQWXxVuEyXWW+dSo8AiXWKwiSSrKWsRB/Qt+Ewwza+JWoLKiTuQLaEPhdNAJ7+Dosc9DOIqNy7Q=="
},
"bootstrap-icons": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/bootstrap-icons/-/bootstrap-icons-1.7.2.tgz",
"integrity": "sha512-NiR2PqC73AQOPdVSu6GJfnk+hN2z6powcistXk1JgPnKuoV2FSdSl26w931Oz9HYbKCcKUSB6ncZTYJAYJl3QQ=="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",

View File

@ -19,6 +19,7 @@
"@angular/platform-browser-dynamic": "~13.0.0",
"@angular/router": "~13.0.0",
"bootstrap": "^5.1.3",
"bootstrap-icons": "^1.7.2",
"jwt-decode": "^3.1.2",
"ngx-autofocus-fix": "^1.0.4",
"rxjs": "~7.4.0",

View File

@ -1,40 +1,55 @@
<input
type="text"
class="todo-title"
placeholder="Titre"
value = "{{todo.nom}}"
/>
<div>
<button (click)="effacerList()">Effacer la To Do List</button>
</div>
<input
type="text"
class="todo-input"
placeholder="Ajoute une nouvelle Tâche"
placeholder="+ Nouvelle Tâche"
[(ngModel)]="todoTitle"
(keyup.enter)="addTitle()"
(keyup.enter)="addTache()"
/>
<div class="element" *ngFor="let todo of todosFilter()">
<div class="element" *ngFor="let tache of todo.taches">
<div class="element-gauche">
<input
type="checkbox"
[(ngModel)]="todo.completed"
(change)="doneEdit(todo)"
[(ngModel)]="tache.etat"
(change)="doneEdit(tache)"
checked="checked"
/>
<div
*ngIf="!todo.editing; else editingTodo"
*ngIf="!tache.editing; else editingTodo"
class="nomTache"
[ngClass]="{ completed: todo.completed }"
(dblclick)="modifier(todo)"
[ngClass]="{ completed: tache.etat }"
(dblclick)="modifier(tache)"
>
{{ todo.title }}
{{ tache.texte }}
</div>
<ng-template #editingTodo>
<input
type="text"
class="modifier-element"
[(ngModel)]="todo.title"
(blur)="doneEdit(todo)"
(keyup.enter)="doneEdit(todo)"
(keyup.esc)="cancelEdit(todo)"
[(ngModel)]="tache.texte"
(blur)="doneEdit(tache)"
(keyup.enter)="doneEdit(tache)"
(keyup.esc)="cancelEdit(tache)"
autofocus
/>
</ng-template>
</div>
<div class="deleteTache" (click)="deleteTodo(todo.id)">&times;</div>
<div class="deleteTache" (click)="deleteTodo(tache.id)">&times;</div>
</div>
<div class="extra-container">
<div>
<label
@ -66,7 +81,5 @@
</button>
</div>
<div>
<button (click)="effacerList()">Effacer la To Do List</button>
</div>
</div>

View File

@ -1,5 +1,15 @@
.todo-title {
width: 25%;
padding: 10px 18px;
font-size: xx-large;
margin-bottom: 16px;
&:focus {
outline: 0;
}
}
.todo-input {
width: 100%;
width: 20%;
padding: 10px 18px;
font-size: 18px;
margin-bottom: 16px;
@ -7,6 +17,8 @@
outline: 0;
}
}
.element {
margin-bottom: 12px;
display: flex;
@ -16,6 +28,7 @@
}
.deleteTache {
width: 75%;
cursor: pointer;
margin-left: 14px;
&:hover {
@ -40,11 +53,12 @@
margin-left: 12px;
width: 100%;
padding: 10px;
border: 1px solid #ccc; //override defaults
border: 1px solid rgb(204, 204, 204); //override defaults
font-family: 'Avenir', Helvetica, Arial, sans-serif;
&:focus {
outline: none;
background-color:aquamarine;
}
}
@ -53,15 +67,6 @@
color: grey;
}
.extra-container {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 16px;
border-top: 1px solid lightgrey;
padding-top: 14px;
margin-bottom: 14px;
}
button {
font-size: 14px;

View File

@ -1,5 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Todo } from 'src/app/interfaces/todo';
import { TodoService } from 'src/app/services/todo.service';
@Component({
selector: 'app-to-do-list',
@ -7,6 +9,7 @@ import { Todo } from 'src/app/interfaces/todo';
styleUrls: ['./to-do-list.component.scss'],
})
export class ToDoListComponent implements OnInit {
@Input() todo : any;
public beforeEditCache: string;
public todos: Todo[];
public todoTitle: string;
@ -14,8 +17,9 @@ export class ToDoListComponent implements OnInit {
public filter : string;
public casesRestantes : boolean;
public masterSelected: boolean;
public result : any;
constructor() {
constructor(private TodoService : TodoService, private router: Router ) {
this.beforeEditCache = '';
this.todos = [];
this.todoTitle = '';
@ -23,9 +27,11 @@ export class ToDoListComponent implements OnInit {
this.filter ='';
this.casesRestantes=true;
this.masterSelected= false;
}
ngOnInit(): void {
//this.refreshTodo();
this.beforeEditCache = '';
this.casesRestantes=true;
this.filter='tous';
@ -53,8 +59,11 @@ export class ToDoListComponent implements OnInit {
];
}
//ajouter tache
addTitle(): void {
if (this.todoTitle.trim().length === 0) {
addTache(): void {
this.TodoService.addTache(todo).subscribe((resp)=>{
this.router.navigate(['to-do-list'])
})
/* if (this.todoTitle.trim().length === 0) {
return;
}
@ -65,8 +74,13 @@ export class ToDoListComponent implements OnInit {
editing: false,
});
this.todoTitle = '';
this.idTodo++;
this.idTodo++; */
}
/* if (contact.nom !== '') {
this.repertoireService.addContact(contact).subscribe((resp) => {
this.router.navigate(['repertoire/']);
}); */
//modifier la tâche
modifier(todo: Todo): void {
@ -90,9 +104,14 @@ export class ToDoListComponent implements OnInit {
}
//supprimer la tache
deleteTodo(id: number): void {
this.todos = this.todos.filter((todo) => todo.id !== id);
deleteTodo(id: number) {
this.TodoService.deleteTacheById(id).subscribe(
resp =>{
window.location.reload();
}
);}
//nombre de tâches restantes
toDoRest(): number{

View File

@ -1,5 +1,9 @@
<app-header></app-header>
<app-side-bar></app-side-bar>
<div class="container">
<app-to-do-list></app-to-do-list>
<div class="d-flex align-items-stretch">
<div class="row">
<div class="col" *ngFor="let todos of result">
<app-to-do-list [todo]="todos"> </app-to-do-list>
</div>
</div>
</div>

View File

@ -1,4 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { TodoService } from 'src/app/services/todo.service';
@Component({
selector: 'app-page-to-do-list',
@ -6,10 +9,18 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./page-to-do-list.component.scss']
})
export class PageToDoListComponent implements OnInit {
public result : any;
constructor() { }
constructor(private TodoService : TodoService) { }
ngOnInit(): void {
this.TodoService.getToDoListByTeamId().subscribe((data :any)=>{
this.result = data;
console.log(data);
});
}
}

View File

@ -1,43 +0,0 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class TodoServiceService {
private toDoList: any;
private apiUrl: string;
constructor(private http: HttpClient) {
this.apiUrl = environment.apiUrl;
}
//consulter toDoList
getToDoList(){
this.toDoList = this.http.get(`${this.apiUrl}/todolist/team/{team_id}`);
return this.toDoList;
console.log(this.toDoList)
}
//ajouter une tache
addTitle(title:string){
this.toDoList.push({
title:title,
isChecked: false
});
}
// cocher et décocher la checkbox
checkOrUnCheckTitle($key: string,flag: boolean){
this.toDoList.update($key,{isChecked:flag});
}
//supprimer la tache
removeTitle($key : string){
this.toDoList.remove($key);
}
}

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { TodoService } from './todo.service';
describe('TodoService', () => {
let service: TodoService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TodoService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,30 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { Todo } from '../interfaces/todo';
@Injectable({
providedIn: 'root',
})
export class TodoService {
private toDoList: any;
private apiUrl: string;
constructor(private http: HttpClient) {
this.apiUrl = environment.apiUrl;
}
getToDoListByTeamId(): Observable<any> {
return this.http.get(`${this.apiUrl}/todolist/team/1`);
}
deleteTacheById(idTache: any): Observable<any> {
return this.http.delete(`${this.apiUrl}/taches/delete/${idTache}`,{responseType:'text'});
}
addTache(todo:Todo): Observable<any> {
console.log(todo);
return this.http.post(`${this.apiUrl}/taches/add`, todo);
}
}