Merge pull request #26 from AlineRinquin/isa

Isa
This commit is contained in:
AlineRinquin 2022-02-15 15:04:50 +01:00 committed by GitHub
commit fea0ac9524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 204 additions and 119 deletions

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(todo.id)"
/>
<div class="element" *ngFor="let todo of todosFilter()">
{{todo}}
<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
@ -48,7 +63,7 @@
<div>{{ toDoRest() }} tâches</div>
</div>
<div class="extra-container">
<div>
<!-- <div>
<button [ngClass]="{ active: filter === 'tous' }" (click)="filter = 'tous'">
Toutes la To Do List
</button>
@ -65,8 +80,6 @@
Terminées
</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,9 @@
import { Component, OnInit } from '@angular/core';
import { Todo } from 'src/app/interfaces/todo';
import { Component, Input, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Tache} from 'src/app/models/tache';
import { ToDoList} from 'src/app/models/to-do-list';
import { TodoService } from 'src/app/services/todo.service';
import { TodoList } from 'src/app/todo-list';
@Component({
selector: 'app-to-do-list',
@ -7,54 +11,72 @@ import { Todo } from 'src/app/interfaces/todo';
styleUrls: ['./to-do-list.component.scss'],
})
export class ToDoListComponent implements OnInit {
@Input() todo!: ToDoList;
public beforeEditCache: string;
public todos: Todo[];
//public todos: ToDoList[];
public todoTitle: string;
public idTodo: number;
public filter : string;
public casesRestantes : boolean;
public masterSelected: boolean;
public result : any;
public tache : Tache [];
constructor() {
constructor(private TodoService : TodoService, private router: Router ) {
this.beforeEditCache = '';
this.todos = [];
//this.todos = [];
this.todoTitle = '';
this.idTodo = 0;
this.filter ='';
this.casesRestantes=true;
this.masterSelected= false;
this.tache = [];
}
ngOnInit(): void {
//this.refreshTodo();
this.beforeEditCache = '';
this.casesRestantes=true;
this.filter='tous';
this.idTodo = 4;
this.todoTitle = '';
this.todos = [
/* this.todos = [
{
id: 1,
title: 'Finish Angular Screencast',
completed: false,
texte: 'Finish Angular Screencast',
etat: false,
editing: false,
},
{
id: 2,
title: 'Take over world',
completed: false,
texte: 'Take over world',
etat: false,
editing: false,
},
{
id: 3,
title: 'One more thing',
completed: false,
texte: 'One more thing',
etat: false,
editing: false,
},
];
]; */
}
//ajouter tache
addTitle(): void {
if (this.todoTitle.trim().length === 0) {
addTache(idTodoList : number) {//idTodoList id que la todoList que l'on récupère
console.log(idTodoList);
const tache: Tache = {
id : 0,
texte: this.todoTitle,
etat : false,
editing : false,
}
console.log(this.tache);
this.TodoService.addTache(tache,idTodoList).subscribe((resp)=>{
window.location.reload();
})
/* if (this.todoTitle.trim().length === 0) {
return;
}
@ -65,55 +87,65 @@ 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 {
this.beforeEditCache = todo.title;
todo.editing = true;
modifier(tache: Tache): void {
this.beforeEditCache = tache.texte;
tache.editing = true;
}
// modifier l'apparence focus
doneEdit(todo: Todo): void {
if (todo.title.trim().length === 0) {
todo.title = this.beforeEditCache;
doneEdit(tache: Tache): void {
if (tache.texte.trim().length === 0) {
tache.texte = this.beforeEditCache;
}
this.casesRestantes= this.casesQuiRestes();
todo.editing = false;
tache.editing = false;
}
// annuler la modification
cancelEdit(todo: Todo): void {
todo.title = this.beforeEditCache;
todo.editing = false;
cancelEdit(tache: Tache): void {
tache.texte = this.beforeEditCache;
tache.editing = false;
}
//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{
return this.todos.filter(todo=> !todo.completed).length;
return this.todo.taches.filter((tache: Tache)=> !tache.etat).length;
}
//Cocher toutes les tâches de la liste
listComplete(): boolean {
return this.todos.filter(todo=> todo.completed).length>0;
return this.todo.taches.filter((tache: Tache)=> tache).length>0;
}
//Effacer la to do list
effacerList(): void {
this.todos = [];
//this.todo = [];
}
//cocher toutes les cases de la todoList
cocherAllTodoList(): void {
for (var i = 0; i < this.todos.length; i++) {
this.todos[i].completed = this.masterSelected;
for (var i = 0; i < this.todo.taches.length; i++) {
this.todo.taches[i].etat = this.masterSelected;
}
this.cocherAllTodoList();
}
@ -123,16 +155,16 @@ export class ToDoListComponent implements OnInit {
}
//barre de filtre des tâches
todosFilter(): Todo[] {
/* todosFilter(): ToDoList[] {
if(this.filter === 'tous'){
return this.todos
return this.todo.taches
}else if (this.filter === 'active'){
return this.todos.filter(todo=> !todo.completed)
return this.todo.taches.filter((tache: Tache)=> !tache.etat)
}else if (this.filter === 'complete'){
return this.todos.filter(todo=>todo.completed)
}
return this.todos
return this.todo.taches.filter((tache: Tache)=>tache.etat)
}
return this.todo
} */
}

View File

@ -1,7 +1,7 @@
export interface Todo {
id : number,
title : string,
completed: boolean,
editing: boolean
texte : string,
etat: boolean,
// todoListId: number // FK
}

10
src/app/models/tache.ts Normal file
View File

@ -0,0 +1,10 @@
import { ToDoList } from './to-do-list';
export interface Tache {
id : number,
texte: string,
etat : boolean,
editing : boolean
}

View File

@ -1,7 +1,11 @@
import { Tache } from './tache';
import { Team } from './team';
export interface ToDoList {
nom: string;
team: Team;
tache: string;
taches: Tache [];
id: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,31 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { Tache } from '../models/tache';
import { ToDoList } from '../models/to-do-list';
@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(newtache: Tache,idTodoList:number): Observable<any> {
console.log(newtache);
return this.http.post(`${this.apiUrl}/taches/add/${idTodoList}`, newtache);
}
}

2
src/app/todo-list.ts Normal file
View File

@ -0,0 +1,2 @@
export interface TodoList {
}