Add task deletion.
This commit is contained in:
@@ -46,13 +46,7 @@ export class ActiveListTasksComponent implements OnInit, OnDestroy {
|
|||||||
onNewTaskKeyDown(event: KeyboardEvent): void {
|
onNewTaskKeyDown(event: KeyboardEvent): void {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
if (this.newTaskControl.valid) {
|
if (this.newTaskControl.valid) {
|
||||||
const newTask = {
|
this._taskListService.addTask(this.newTaskControl.value as string);
|
||||||
title: this.newTaskControl.value as string,
|
|
||||||
creationDate: new Date(),
|
|
||||||
description: undefined as unknown as string
|
|
||||||
} as Task;
|
|
||||||
|
|
||||||
this._taskListService.addTask(newTask);
|
|
||||||
this.newTaskControl.reset();
|
this.newTaskControl.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<mat-icon class="drag-n-drop">drag_handle</mat-icon>
|
<mat-icon class="drag-n-drop">drag_handle</mat-icon>
|
||||||
<mat-checkbox class="example-margin"></mat-checkbox>
|
<mat-checkbox class="example-margin"></mat-checkbox>
|
||||||
<div class="input-container">
|
<div class="input-container">
|
||||||
<input type="text" [formControl]="titleControl" />
|
<input type="text" #titleInput [formControl]="titleControl"/>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" class="expand icon" (click)="expand()" matRipple>
|
<button type="button" class="expand icon" (click)="expand()" matRipple>
|
||||||
<mat-icon *ngIf="!isExpanded">expand_more</mat-icon>
|
<mat-icon *ngIf="!isExpanded">expand_more</mat-icon>
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
<textarea id="description"></textarea>
|
<textarea id="description"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
|
<div class="row">
|
||||||
<button class="icon raised" matRipple matTooltip="Définir une alerte dans X minutes">
|
<button class="icon raised" matRipple matTooltip="Définir une alerte dans X minutes">
|
||||||
<mat-icon>update</mat-icon>
|
<mat-icon>update</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
@@ -26,6 +27,13 @@
|
|||||||
<mat-icon>delete</mat-icon>
|
<mat-icon>delete</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<button class="raised alert" [disabled]="!task" (click)="delete()">
|
||||||
|
<mat-icon>delete</mat-icon>
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -91,10 +91,17 @@
|
|||||||
|
|
||||||
.actions {
|
.actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
flex-wrap: wrap;
|
|
||||||
max-width: 20%;
|
max-width: 20%;
|
||||||
|
|
||||||
|
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
@@ -102,3 +109,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AfterViewInit, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
|
||||||
import { FormControl } from '@angular/forms';
|
import { FormControl } from '@angular/forms';
|
||||||
import { Task } from 'src/app/core/entity/task';
|
import { Task } from 'src/app/core/entity/task';
|
||||||
import { TaskListService } from 'src/app/core/service/task-list.service';
|
import { TaskListService } from 'src/app/core/service/task-list.service';
|
||||||
@@ -13,6 +13,7 @@ export class TaskDisplayComponent implements AfterViewInit {
|
|||||||
@Input() task?: Task;
|
@Input() task?: Task;
|
||||||
titleControl = new FormControl(this.task?.title);
|
titleControl = new FormControl(this.task?.title);
|
||||||
isExpanded = false;
|
isExpanded = false;
|
||||||
|
@ViewChild('titleInput', {static: true}) titleInput?: ElementRef<HTMLInputElement>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _taskListService: TaskListService
|
private _taskListService: TaskListService
|
||||||
@@ -34,4 +35,10 @@ export class TaskDisplayComponent implements AfterViewInit {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete(): void {
|
||||||
|
if (this.task) {
|
||||||
|
this._taskListService.delete(this.task);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export interface Task {
|
export interface Task {
|
||||||
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
creationDate: Date;
|
creationDate: Date;
|
||||||
description: string;
|
description: string;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class TaskListService {
|
|||||||
return this._storePersistenceService.load();
|
return this._storePersistenceService.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
addTask(task: Task): void {
|
addTask(taskTitle: string): void {
|
||||||
const store = this.store;
|
const store = this.store;
|
||||||
const activeTaskList = store.taskLists.find(taskList => taskList.id === store.activeTaskListId);
|
const activeTaskList = store.taskLists.find(taskList => taskList.id === store.activeTaskListId);
|
||||||
if (!activeTaskList) {
|
if (!activeTaskList) {
|
||||||
@@ -43,7 +43,31 @@ export class TaskListService {
|
|||||||
activeTaskList.tasks = [];
|
activeTaskList.tasks = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
activeTaskList?.tasks.push(task);
|
const newTask = {
|
||||||
|
id: uuidv4(),
|
||||||
|
title: taskTitle,
|
||||||
|
creationDate: new Date(),
|
||||||
|
description: undefined as unknown as string
|
||||||
|
} as Task;
|
||||||
|
|
||||||
|
|
||||||
|
activeTaskList?.tasks.push(newTask);
|
||||||
|
this._store.next(store);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(taskToDelete: Task) {
|
||||||
|
const store = this.store;
|
||||||
|
const activeTaskList = store.taskLists.find(taskList => taskList.id === store.activeTaskListId);
|
||||||
|
if (!activeTaskList) {
|
||||||
|
throw new Error("No active tasklist");
|
||||||
|
}
|
||||||
|
|
||||||
|
const taskIndex = activeTaskList?.tasks.findIndex(task => task.id === taskToDelete.id);
|
||||||
|
if (!taskIndex && taskIndex !== 0) {
|
||||||
|
throw new Error('Unknown task to delete');
|
||||||
|
}
|
||||||
|
|
||||||
|
activeTaskList?.tasks.splice(taskIndex, 1);
|
||||||
this._store.next(store);
|
this._store.next(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user