Compare commits
6 Commits
d2cfa4d0f8
...
760e08a595
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
760e08a595 | ||
|
|
9173d2220c | ||
|
|
8e582c96e3 | ||
|
|
da80bc17c0 | ||
|
|
182cc0bb67 | ||
|
|
f4d0aa3b27 |
8
package-lock.json
generated
8
package-lock.json
generated
@@ -18,7 +18,6 @@
|
|||||||
"@angular/platform-browser": "~12.2.0",
|
"@angular/platform-browser": "~12.2.0",
|
||||||
"@angular/platform-browser-dynamic": "~12.2.0",
|
"@angular/platform-browser-dynamic": "~12.2.0",
|
||||||
"@angular/router": "~12.2.0",
|
"@angular/router": "~12.2.0",
|
||||||
"@types/uuid": "^8.3.4",
|
|
||||||
"ngx-cookie-service": "^12.0.3",
|
"ngx-cookie-service": "^12.0.3",
|
||||||
"rxjs": "~6.6.0",
|
"rxjs": "~6.6.0",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.3.0",
|
||||||
@@ -31,6 +30,7 @@
|
|||||||
"@angular/compiler-cli": "~12.2.0",
|
"@angular/compiler-cli": "~12.2.0",
|
||||||
"@types/jasmine": "~3.8.0",
|
"@types/jasmine": "~3.8.0",
|
||||||
"@types/node": "^12.11.1",
|
"@types/node": "^12.11.1",
|
||||||
|
"@types/uuid": "^8.3.4",
|
||||||
"jasmine-core": "~3.8.0",
|
"jasmine-core": "~3.8.0",
|
||||||
"karma": "~6.3.0",
|
"karma": "~6.3.0",
|
||||||
"karma-chrome-launcher": "~3.1.0",
|
"karma-chrome-launcher": "~3.1.0",
|
||||||
@@ -2578,7 +2578,8 @@
|
|||||||
"node_modules/@types/uuid": {
|
"node_modules/@types/uuid": {
|
||||||
"version": "8.3.4",
|
"version": "8.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
|
||||||
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw=="
|
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/webpack-sources": {
|
"node_modules/@types/webpack-sources": {
|
||||||
"version": "0.1.9",
|
"version": "0.1.9",
|
||||||
@@ -17925,7 +17926,8 @@
|
|||||||
"@types/uuid": {
|
"@types/uuid": {
|
||||||
"version": "8.3.4",
|
"version": "8.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
|
||||||
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw=="
|
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/webpack-sources": {
|
"@types/webpack-sources": {
|
||||||
"version": "0.1.9",
|
"version": "0.1.9",
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
"@angular/platform-browser": "~12.2.0",
|
"@angular/platform-browser": "~12.2.0",
|
||||||
"@angular/platform-browser-dynamic": "~12.2.0",
|
"@angular/platform-browser-dynamic": "~12.2.0",
|
||||||
"@angular/router": "~12.2.0",
|
"@angular/router": "~12.2.0",
|
||||||
"@types/uuid": "^8.3.4",
|
|
||||||
"ngx-cookie-service": "^12.0.3",
|
"ngx-cookie-service": "^12.0.3",
|
||||||
"rxjs": "~6.6.0",
|
"rxjs": "~6.6.0",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.3.0",
|
||||||
@@ -33,6 +32,7 @@
|
|||||||
"@angular/compiler-cli": "~12.2.0",
|
"@angular/compiler-cli": "~12.2.0",
|
||||||
"@types/jasmine": "~3.8.0",
|
"@types/jasmine": "~3.8.0",
|
||||||
"@types/node": "^12.11.1",
|
"@types/node": "^12.11.1",
|
||||||
|
"@types/uuid": "^8.3.4",
|
||||||
"jasmine-core": "~3.8.0",
|
"jasmine-core": "~3.8.0",
|
||||||
"karma": "~6.3.0",
|
"karma": "~6.3.0",
|
||||||
"karma-chrome-launcher": "~3.1.0",
|
"karma-chrome-launcher": "~3.1.0",
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<p>active-list-tasks works!</p>
|
||||||
42
src/app/active-list-tasks/active-list-tasks.component.ts
Normal file
42
src/app/active-list-tasks/active-list-tasks.component.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { TaskList } from '../core/entity/task-list';
|
||||||
|
import { TaskListService } from '../core/service/task-list.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-active-list-tasks',
|
||||||
|
templateUrl: './active-list-tasks.component.html',
|
||||||
|
styleUrls: ['./active-list-tasks.component.scss']
|
||||||
|
})
|
||||||
|
export class ActiveListTasksComponent implements OnInit, OnDestroy {
|
||||||
|
private _activeTaskList?: TaskList;
|
||||||
|
private _storeSubscription?: Subscription;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private _router: Router,
|
||||||
|
private _taskListService: TaskListService,
|
||||||
|
private _snackBar: MatSnackBar
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this._storeSubscription = this._taskListService.store$.subscribe(store => {
|
||||||
|
if (store.activeTaskListId) {
|
||||||
|
this._activeTaskList = store.taskLists.find(taskList => taskList.id === store.activeTaskListId);
|
||||||
|
if (!this._activeTaskList) {
|
||||||
|
this._backToTaskListPane();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this._storeSubscription?.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _backToTaskListPane(): void {
|
||||||
|
this._snackBar.open('La task-list active n\'existe pas dans le store.', 'Fermer', {duration: 5000});
|
||||||
|
this._router.navigate(['/']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { RouterModule, Routes } from '@angular/router';
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
|
import { ActiveListTasksComponent } from './active-list-tasks/active-list-tasks.component';
|
||||||
import { MainPageComponent } from './main-page/main-page.component';
|
import { MainPageComponent } from './main-page/main-page.component';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: '', component: MainPageComponent}
|
{ path: '', component: MainPageComponent},
|
||||||
|
{ path: 'task-lists/active', component: ActiveListTasksComponent }
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [RouterModule.forRoot(routes)],
|
imports: [RouterModule.forRoot(routes)],
|
||||||
exports: [RouterModule]
|
exports: [RouterModule]
|
||||||
})
|
})
|
||||||
export class AppRoutingModule {}
|
export class AppRoutingModule { }
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
<app-header></app-header>
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
@@ -1,22 +1,23 @@
|
|||||||
import { APP_INITIALIZER, NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { CookieService } from 'ngx-cookie-service';
|
import { CookieService } from 'ngx-cookie-service';
|
||||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
||||||
|
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { MainPageComponent } from './main-page/main-page.component';
|
import { MainPageComponent } from './main-page/main-page.component';
|
||||||
import { AddTaskComponent } from './add-task/add-task.component';
|
import { AddTaskComponent } from './add-task/add-task.component';
|
||||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import { MatInputModule } from '@angular/material/input';
|
import {MatInputModule} from '@angular/material/input';
|
||||||
import { MatDialogModule } from '@angular/material/dialog';
|
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
|
||||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
|
||||||
import { DisplayTaskComponent } from './display-task/display-task.component';
|
import { DisplayTaskComponent } from './display-task/display-task.component';
|
||||||
import { TaskListsComponent } from './task-lists/task-lists.component';
|
import { TaskListsComponent } from './task-lists/task-lists.component';
|
||||||
import { AddNewListComponent } from './task-lists/add-new-list/add-new-list.component';
|
import { AddTaskListComponent } from './task-lists/add-task-list/add-task-list.component';
|
||||||
import { initTaskListService, TaskListService } from './core/service/task-list.service';
|
import {MatDialogModule} from '@angular/material/dialog';
|
||||||
|
import {MatButtonModule} from '@angular/material/button';
|
||||||
|
import {ReactiveFormsModule} from '@angular/forms';
|
||||||
|
import {MatSnackBarModule} from '@angular/material/snack-bar';
|
||||||
|
import { HeaderComponent } from './core/components/header/header.component';
|
||||||
|
import { ActiveListTasksComponent } from './active-list-tasks/active-list-tasks.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@@ -25,28 +26,23 @@ import { initTaskListService, TaskListService } from './core/service/task-list.s
|
|||||||
AddTaskComponent,
|
AddTaskComponent,
|
||||||
DisplayTaskComponent,
|
DisplayTaskComponent,
|
||||||
TaskListsComponent,
|
TaskListsComponent,
|
||||||
AddNewListComponent
|
AddTaskListComponent,
|
||||||
|
HeaderComponent,
|
||||||
|
ActiveListTasksComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
BrowserAnimationsModule,
|
BrowserAnimationsModule,
|
||||||
FormsModule,
|
|
||||||
ReactiveFormsModule,
|
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
MatSnackBarModule
|
MatSnackBarModule
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
CookieService,
|
CookieService,
|
||||||
{
|
|
||||||
provide: APP_INITIALIZER,
|
|
||||||
useFactory: initTaskListService,
|
|
||||||
deps: [TaskListService],
|
|
||||||
multi: true
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
|
|||||||
18
src/app/core/components/header/header.component.html
Normal file
18
src/app/core/components/header/header.component.html
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<nav>
|
||||||
|
<span class="title" routerLink="/">
|
||||||
|
To Do
|
||||||
|
</span>
|
||||||
|
<button mat-raised-button
|
||||||
|
*ngIf="!activeTaskList"
|
||||||
|
(click)="openNewListForm()">
|
||||||
|
Nouvelle liste
|
||||||
|
</button>
|
||||||
|
<button mat-raised-button
|
||||||
|
*ngIf="activeTaskList"
|
||||||
|
(click)="goTaskListsPane()">
|
||||||
|
<mat-icon>chevron_left</mat-icon>
|
||||||
|
</button>
|
||||||
|
<div *ngIf="activeTaskList">
|
||||||
|
Liste active : {{activeTaskList.name}}
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
14
src/app/core/components/header/header.component.scss
Normal file
14
src/app/core/components/header/header.component.scss
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
nav {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
height: 4rem;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
margin: 0 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
41
src/app/core/components/header/header.component.ts
Normal file
41
src/app/core/components/header/header.component.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { AddTaskListComponent } from 'src/app/task-lists/add-task-list/add-task-list.component';
|
||||||
|
import { TaskList } from '../../entity/task-list';
|
||||||
|
import { TaskListService } from '../../service/task-list.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-header',
|
||||||
|
templateUrl: './header.component.html',
|
||||||
|
styleUrls: ['./header.component.scss']
|
||||||
|
})
|
||||||
|
export class HeaderComponent implements OnInit, OnDestroy {
|
||||||
|
private _storeSubscription?: Subscription;
|
||||||
|
activeTaskList?: TaskList;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private _dialog: MatDialog,
|
||||||
|
private _router: Router,
|
||||||
|
private _taskListService: TaskListService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this._storeSubscription = this._taskListService.store$.subscribe(store => {
|
||||||
|
this.activeTaskList = store.taskLists.find(taskList => store.activeTaskListId === taskList.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this._storeSubscription?.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
openNewListForm(): void {
|
||||||
|
this._dialog.open(AddTaskListComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
goTaskListsPane(): void {
|
||||||
|
this._taskListService.removeActiveTaskList();
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/app/core/entity/store.ts
Normal file
8
src/app/core/entity/store.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { TaskList } from "./task-list";
|
||||||
|
|
||||||
|
export interface Store {
|
||||||
|
activeTaskListId: string | undefined;
|
||||||
|
taskLists: TaskList[];
|
||||||
|
selectedTaskLists: TaskList[];
|
||||||
|
selectionMode: boolean;
|
||||||
|
}
|
||||||
7
src/app/core/entity/task-list.ts
Normal file
7
src/app/core/entity/task-list.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { Task } from "./task";
|
||||||
|
|
||||||
|
export interface TaskList {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
tasks: Task[];
|
||||||
|
}
|
||||||
@@ -2,6 +2,4 @@ export interface Task {
|
|||||||
title: string;
|
title: string;
|
||||||
creationDate: Date;
|
creationDate: Date;
|
||||||
description: string;
|
description: string;
|
||||||
subtasks: Task[];
|
|
||||||
isAsync: boolean;
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Task } from "./task";
|
|
||||||
|
|
||||||
export interface TaskList {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
tasks: Task[],
|
|
||||||
achievedTasks: Task[];
|
|
||||||
abandonnedTasks: Task[];
|
|
||||||
}
|
|
||||||
38
src/app/core/service/store-persistence.service.ts
Normal file
38
src/app/core/service/store-persistence.service.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
import { CookieService } from "ngx-cookie-service";
|
||||||
|
import { Store } from "../entity/store";
|
||||||
|
|
||||||
|
const COOKIE_NAME = 'todo-store';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class StorePersistenceService {
|
||||||
|
constructor(
|
||||||
|
private _cookieService: CookieService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
save(store: Store): void {
|
||||||
|
const serializedStore = JSON.stringify(store);
|
||||||
|
this._cookieService.set(COOKIE_NAME, serializedStore);
|
||||||
|
}
|
||||||
|
|
||||||
|
load(): Store {
|
||||||
|
const serializedStore = this._cookieService.get(COOKIE_NAME);
|
||||||
|
|
||||||
|
if (serializedStore?.length) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(serializedStore);
|
||||||
|
} catch (jsonParseError) {
|
||||||
|
throw new Error(`JsonSerializationException: Invalid format for store in cookie "${COOKIE_NAME}".`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
activeTaskListId: undefined,
|
||||||
|
taskLists: [],
|
||||||
|
selectedTaskLists: [],
|
||||||
|
selectionMode: false
|
||||||
|
} as Store;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { TaskListService } from './task-list.service';
|
|
||||||
|
|
||||||
describe('TaskListService', () => {
|
|
||||||
let service: TaskListService;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
TestBed.configureTestingModule({});
|
|
||||||
service = TestBed.inject(TaskListService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be created', () => {
|
|
||||||
expect(service).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,35 +1,124 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from "@angular/core";
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import { BehaviorSubject, Observable } from "rxjs";
|
||||||
import { TaskList } from '../entity/taskList';
|
import { Task } from "../entity/task";
|
||||||
import { TaskPersistenceService } from './task-persistence.service';
|
import { TaskList } from "../entity/task-list";
|
||||||
|
import { StorePersistenceService } from "./store-persistence.service";
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
import { filter } from 'rxjs/operators';
|
||||||
|
import { Store } from "../entity/store";
|
||||||
|
import { Router } from "@angular/router";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class TaskListService {
|
export class TaskListService {
|
||||||
private _taskListsSubject: BehaviorSubject<TaskList[]> = new BehaviorSubject<TaskList[]>([]);
|
private _store: BehaviorSubject<Store> = new BehaviorSubject<Store>(undefined as unknown as Store);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _taskPersistenceService: TaskPersistenceService
|
private _router: Router,
|
||||||
) {}
|
private _storePersistenceService: StorePersistenceService
|
||||||
|
) {
|
||||||
init(): void {
|
this.store$.subscribe(store => {
|
||||||
const taskLists = this._taskPersistenceService.getAll();
|
this._storePersistenceService.save(store);
|
||||||
this._taskListsSubject.next(taskLists);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
add(taskList: TaskList): void {
|
get store$(): Observable<Store> {
|
||||||
const taskLists = this._taskPersistenceService.getAll();
|
return this._store.asObservable()
|
||||||
taskLists.push(taskList);
|
.pipe(filter(store => !!store));
|
||||||
this._taskPersistenceService.save(taskLists);
|
|
||||||
this._taskListsSubject.next(taskLists);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get taskLists$(): Observable<TaskList[]> {
|
private get store(): Store {
|
||||||
return this._taskListsSubject.asObservable();
|
return this._storePersistenceService.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
addTask(task: Task): void {
|
||||||
|
const store = this.store;
|
||||||
|
const activeTaskList = store.taskLists.find(taskList => taskList.id === store.activeTaskListId);
|
||||||
|
if (!activeTaskList) {
|
||||||
|
throw new Error("No active tasklist");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!activeTaskList.tasks) {
|
||||||
|
activeTaskList.tasks = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
activeTaskList?.tasks.push(task);
|
||||||
|
this._store.next(store);
|
||||||
|
}
|
||||||
|
|
||||||
|
createTaskList(taskListName: string): void {
|
||||||
|
const newTaskList = {
|
||||||
|
id: uuidv4(),
|
||||||
|
name: taskListName,
|
||||||
|
tasks: []
|
||||||
|
} as TaskList;
|
||||||
|
|
||||||
|
const store = this.store;
|
||||||
|
store.taskLists.push(newTaskList);
|
||||||
|
this._store.next(store);
|
||||||
|
}
|
||||||
|
|
||||||
|
getAll(): TaskList[] {
|
||||||
|
return this.store.taskLists ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
setActive(taskList: TaskList): void {
|
||||||
|
const store = this.store;
|
||||||
|
store.activeTaskListId = taskList.id;
|
||||||
|
this._store.next(store);
|
||||||
|
this._router.navigate(['/task-lists/active']);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeActiveTaskList(): void {
|
||||||
|
const store = this.store;
|
||||||
|
delete store.activeTaskListId;
|
||||||
|
this._store.next(store);
|
||||||
|
this._router.navigate(['/']);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectTaskList(taskList: TaskList): void {
|
||||||
|
this.enableSelectionMode();
|
||||||
|
|
||||||
|
const store = this.store;
|
||||||
|
|
||||||
|
if (!store.selectedTaskLists) {
|
||||||
|
store.selectedTaskLists = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (store.selectedTaskLists.some(tl => tl.id === taskList.id)) {
|
||||||
|
const selectedTaskListIndex = store.selectedTaskLists.findIndex(tl => tl.id === taskList.id);
|
||||||
|
store.selectedTaskLists.splice(selectedTaskListIndex, 1);
|
||||||
|
|
||||||
|
if (!store.selectedTaskLists.length) {
|
||||||
|
store.selectionMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._store.next(store);
|
||||||
|
} else {
|
||||||
|
store.selectedTaskLists.push(taskList);
|
||||||
|
this._store.next(store);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isSelected(taskList: TaskList): boolean {
|
||||||
|
const store = this.store;
|
||||||
|
return store.selectedTaskLists && store.selectedTaskLists.some(tl => tl.id === taskList.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
isSelectionModeEnabled(): boolean {
|
||||||
|
return this.store.selectionMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
enableSelectionMode(): void {
|
||||||
|
const store = this.store;
|
||||||
|
store.selectionMode = true;
|
||||||
|
this._store.next(store);
|
||||||
|
}
|
||||||
|
|
||||||
|
disableSelectionMode(): void {
|
||||||
|
const store = this.store;
|
||||||
|
store.selectionMode = true;
|
||||||
|
this._store.next(store);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initTaskListService(taskListService: TaskListService) {
|
|
||||||
return () => taskListService.init();
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CookieService } from 'ngx-cookie-service';
|
import { CookieService } from 'ngx-cookie-service';
|
||||||
import { Task } from '../entity/task';
|
import { Task } from '../entity/task';
|
||||||
import { TaskList } from '../entity/taskList';
|
|
||||||
|
|
||||||
const COOKIE_NAME = 'todo-data';
|
const COOKIE_NAME = 'todo-data';
|
||||||
|
|
||||||
@@ -13,17 +12,17 @@ export class TaskPersistenceService {
|
|||||||
private _cookieService: CookieService
|
private _cookieService: CookieService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
save(taskLists: TaskList[]): void {
|
save(tasks: Task[]): void {
|
||||||
this._cookieService.set(COOKIE_NAME, JSON.stringify(taskLists));
|
this._cookieService.set(COOKIE_NAME, JSON.stringify(tasks));
|
||||||
}
|
}
|
||||||
|
|
||||||
getAll(): TaskList[] {
|
getAll(): Task[] {
|
||||||
const serializedTaskLists = this._cookieService.get(COOKIE_NAME);
|
const serializedTasks = this._cookieService.get(COOKIE_NAME);
|
||||||
let result: TaskList[] = [];
|
let result: Task[] = [];
|
||||||
try {
|
try {
|
||||||
result = JSON.parse(serializedTaskLists);
|
result = JSON.parse(serializedTasks);
|
||||||
} catch(jsonParseError) {
|
} catch(jsonParseError) {
|
||||||
console.log(`Unable to parse task lists from cookie: ${serializedTaskLists}`);
|
console.log(`Unable to parse tasks from cookie: ${serializedTasks}`);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ export class TaskService {
|
|||||||
constructor(
|
constructor(
|
||||||
private _taskPersistenceService: TaskPersistenceService
|
private _taskPersistenceService: TaskPersistenceService
|
||||||
) {
|
) {
|
||||||
const taskLists = this._taskPersistenceService.getAll() || [];
|
const tasks = this._taskPersistenceService.getAll() || [];
|
||||||
// this._tasks.next(taskLists);
|
this._tasks.next(tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
get tasks(): Observable<Task[]> {
|
get tasks(): Observable<Task[]> {
|
||||||
@@ -28,11 +28,11 @@ export class TaskService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _saveTasks(): void {
|
private _saveTasks(): void {
|
||||||
// this._taskPersistenceService.save(this._tasks.value);
|
this._taskPersistenceService.save(this._tasks.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
const tasks = this._taskPersistenceService.getAll();
|
const tasks = this._taskPersistenceService.getAll();
|
||||||
// this._tasks.next(tasks);
|
this._tasks.next(tasks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
<!-- <div class="component">
|
<div class="component">
|
||||||
<h1>Todo List</h1>
|
<!-- <h1>Todo List</h1>
|
||||||
<app-display-task *ngFor="let task of tasks" [task]="task"></app-display-task>
|
<app-display-task *ngFor="let task of tasks" [task]="task"></app-display-task>
|
||||||
<div id="add-task-btn" *ngIf="!isAddingATask" (click)="createTask()">
|
<div id="add-task-btn" *ngIf="!isAddingATask" (click)="createTask()">
|
||||||
<mat-icon>add</mat-icon>
|
<mat-icon>add</mat-icon>
|
||||||
<span>Ajouter une nouvelle tâche...</span>
|
<span>Ajouter une nouvelle tâche...</span>
|
||||||
</div>
|
</div> -->
|
||||||
</div> -->
|
|
||||||
<app-task-lists></app-task-lists>
|
<app-task-lists></app-task-lists>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
<h1>Création d'une liste de tâches</h1>
|
|
||||||
<form [formGroup]="taskListForm" (ngSubmit)="onSubmit()" ngNativeValidate>
|
|
||||||
<mat-form-field>
|
|
||||||
<mat-label>Nom de la liste</mat-label>
|
|
||||||
<input matInput formControlName="name" required>
|
|
||||||
<mat-error *ngIf="!taskListForm.controls.name.valid">
|
|
||||||
Veuillez saisir le nom de la liste.
|
|
||||||
</mat-error>
|
|
||||||
</mat-form-field>
|
|
||||||
<div class="actions">
|
|
||||||
<button mat-raised-button
|
|
||||||
type="button"
|
|
||||||
(click)="close()">
|
|
||||||
Annuler
|
|
||||||
</button>
|
|
||||||
<button mat-raised-button
|
|
||||||
type="submit"
|
|
||||||
color="primary">
|
|
||||||
Créer une liste
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
form {
|
|
||||||
width: 20rem;
|
|
||||||
|
|
||||||
mat-form-field {
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
input {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.actions {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { Component } from '@angular/core';
|
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
||||||
import { MatDialogRef } from '@angular/material/dialog';
|
|
||||||
import { TaskList } from 'src/app/core/entity/taskList';
|
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-add-new-list',
|
|
||||||
templateUrl: './add-new-list.component.html',
|
|
||||||
styleUrls: ['./add-new-list.component.scss']
|
|
||||||
})
|
|
||||||
export class AddNewListComponent {
|
|
||||||
taskListForm: FormGroup;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private _dialogRef: MatDialogRef<AddNewListComponent>,
|
|
||||||
private _formBuilder: FormBuilder
|
|
||||||
) {
|
|
||||||
this.taskListForm = this._formBuilder.group(
|
|
||||||
{
|
|
||||||
name: [undefined, Validators.required]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
onSubmit(): void {
|
|
||||||
if (this.taskListForm.valid) {
|
|
||||||
const newList = {
|
|
||||||
id: uuidv4(),
|
|
||||||
name: this.taskListForm.controls.name.value,
|
|
||||||
tasks: [],
|
|
||||||
achievedTasks: [],
|
|
||||||
abandonnedTasks: []
|
|
||||||
} as TaskList;
|
|
||||||
this._dialogRef.close(newList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(): void {
|
|
||||||
this._dialogRef.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<form [formGroup]="addTaskListFormGroup" (submit)="onSubmit()" ngNativeValidate>
|
||||||
|
<p>
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Nom de la liste</mat-label>
|
||||||
|
<input matInput autofocus id="task-name-input" name="task-name-input" formControlName="name" />
|
||||||
|
<mat-error *ngIf="form.name.invalid">
|
||||||
|
Veuillez saisir le nom de la task-list.
|
||||||
|
</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</p>
|
||||||
|
<div>
|
||||||
|
<button mat-raised-button type="button" (click)="close()">Annuler</button>
|
||||||
|
<button mat-raised-button type="submit">Créer une liste</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
42
src/app/task-lists/add-task-list/add-task-list.component.ts
Normal file
42
src/app/task-lists/add-task-list/add-task-list.component.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { MatDialogRef } from '@angular/material/dialog';
|
||||||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
import { TaskList } from 'src/app/core/entity/task-list';
|
||||||
|
import { TaskListService } from 'src/app/core/service/task-list.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-add-task-list',
|
||||||
|
templateUrl: './add-task-list.component.html',
|
||||||
|
styleUrls: ['./add-task-list.component.scss']
|
||||||
|
})
|
||||||
|
export class AddTaskListComponent {
|
||||||
|
addTaskListFormGroup: FormGroup = this._formBuilder.group({
|
||||||
|
name: [undefined, Validators.required]
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private _dialogRef: MatDialogRef<AddTaskListComponent>,
|
||||||
|
private _formBuilder: FormBuilder,
|
||||||
|
private _snackBar: MatSnackBar,
|
||||||
|
private _taskListService: TaskListService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
get form(): any {
|
||||||
|
return this.addTaskListFormGroup.controls;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmit(): void {
|
||||||
|
if (this.addTaskListFormGroup.valid) {
|
||||||
|
this._taskListService.createTaskList(this.addTaskListFormGroup.controls.name.value);
|
||||||
|
this._snackBar.open('La task-list a été créée.', 'Fermer', {duration: 5000});
|
||||||
|
this.close();
|
||||||
|
} else {
|
||||||
|
this._snackBar.open('Veuillez vérifier les informations saisies.', 'Fermer', {duration: 5000});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(): void {
|
||||||
|
this._dialogRef.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,18 @@
|
|||||||
<button mat-raised-button (click)="addNewList()">Nouvelle liste</button>
|
<div class="task-lists">
|
||||||
<div class="task-list-container">
|
<div *ngFor="let taskList of taskLists" class="task-list-container">
|
||||||
<div *ngFor="let list of taskLists$ | async" class="task-list">
|
<div class="task-list shadowed" (click)="selectActiveTaskList(taskList)" (contextmenu)="$event.preventDefault(); onRightClick(taskList)">
|
||||||
<div class="card">
|
<ng-container [ngPlural]="taskList.tasks?.length ?? 0">
|
||||||
<span *ngIf="list?.tasks?.length">
|
<ng-template ngPluralCase=">1">
|
||||||
{{list?.tasks?.length}} tâches
|
{{taskList.tasks?.length}} tâches
|
||||||
</span>
|
</ng-template>
|
||||||
<span *ngIf="!list?.tasks?.length">
|
<ng-template ngPluralCase="other">
|
||||||
Aucune tâche
|
{{taskList.tasks?.length}} tâche
|
||||||
</span>
|
</ng-template>
|
||||||
</div>
|
</ng-container>
|
||||||
<h3>{{list?.name}}</h3>
|
|
||||||
</div>
|
</div>
|
||||||
|
{{taskList.name}}
|
||||||
|
<ng-container *ngIf="isSelectionModeEnabled() && isSelected(taskList)">
|
||||||
|
SELECTED
|
||||||
|
</ng-container>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,23 +1,26 @@
|
|||||||
.task-list-container {
|
.task-lists {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin: auto;
|
||||||
|
max-width: 80%;
|
||||||
|
|
||||||
|
.task-list-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: column;
|
||||||
flex-wrap: wrap;
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
margin: 1rem;
|
||||||
|
|
||||||
.task-list {
|
.task-list {
|
||||||
width: 10rem;
|
width: 150px;
|
||||||
margin: 1rem;
|
height: 150px;
|
||||||
|
display: flex;
|
||||||
.card {
|
justify-content: center;
|
||||||
height: 10rem;
|
align-items: center;
|
||||||
border: 1px solid black;
|
border-radius: .5rem;
|
||||||
display: flex;
|
background-color: aliceblue;
|
||||||
justify-content: center;
|
margin-bottom: .5rem;
|
||||||
align-items: center;
|
|
||||||
border-radius: .3rem;
|
|
||||||
}
|
|
||||||
h3 {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,56 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { TaskList } from '../core/entity/taskList';
|
import { TaskList } from '../core/entity/task-list';
|
||||||
import { TaskListService } from '../core/service/task-list.service';
|
import { TaskListService } from '../core/service/task-list.service';
|
||||||
import { AddNewListComponent } from './add-new-list/add-new-list.component';
|
import { AddTaskListComponent } from './add-task-list/add-task-list.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-task-lists',
|
selector: 'app-task-lists',
|
||||||
templateUrl: './task-lists.component.html',
|
templateUrl: './task-lists.component.html',
|
||||||
styleUrls: ['./task-lists.component.scss']
|
styleUrls: ['./task-lists.component.scss']
|
||||||
})
|
})
|
||||||
export class TaskListsComponent implements OnInit {
|
export class TaskListsComponent implements OnInit, OnDestroy {
|
||||||
taskLists$?: Observable<TaskList[]>;
|
taskLists: TaskList[] = [];
|
||||||
private _taskListsSubscription?: Subscription;
|
private _storeSubscription?: Subscription;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _dialog: MatDialog,
|
private _dialog: MatDialog,
|
||||||
private _taskListService: TaskListService
|
private _taskListService: TaskListService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.taskLists$ = this._taskListService.taskLists$;
|
this.taskLists = this._taskListService.getAll();
|
||||||
}
|
this._storeSubscription = this._taskListService.store$.subscribe(store => {
|
||||||
|
this.taskLists = store.taskLists;
|
||||||
addNewList(): void {
|
|
||||||
const dialogRef = this._dialog.open(AddNewListComponent);
|
|
||||||
dialogRef.afterClosed().subscribe(newList => {
|
|
||||||
this._taskListService.add(newList);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this._storeSubscription?.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
openNewListForm(): void {
|
||||||
|
this._dialog.open(AddTaskListComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectActiveTaskList(taskList: TaskList): void {
|
||||||
|
if (this.isSelectionModeEnabled()) {
|
||||||
|
this._taskListService.selectTaskList(taskList);
|
||||||
|
} else {
|
||||||
|
this._taskListService.setActive(taskList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onRightClick(taskList: TaskList): void {
|
||||||
|
this._taskListService.selectTaskList(taskList);
|
||||||
|
}
|
||||||
|
|
||||||
|
isSelected(taskList: TaskList): boolean {
|
||||||
|
return this._taskListService.isSelected(taskList);
|
||||||
|
}
|
||||||
|
|
||||||
|
isSelectionModeEnabled(): boolean {
|
||||||
|
return this._taskListService.isSelectionModeEnabled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,26 @@
|
|||||||
/* You can add global styles to this file, and also import other style files */
|
/* You can add global styles to this file, and also import other style files */
|
||||||
|
|
||||||
html, body { height: 100%; }
|
html, body { height: 100%; }
|
||||||
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: Roboto, "Helvetica Neue", sans-serif;
|
||||||
|
padding-top: 4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.shadowed {
|
||||||
|
box-shadow: 0px 2px 1px -1px rgba(0, 0, 0, 0.2),0px 1px 1px 0px rgba(0, 0, 0, 0.14),0px 1px 3px 0px rgba(0, 0, 0, 0.12);
|
||||||
|
transition: box-shadow .2s ease-out;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
box-shadow: 0 .2em .5em #777;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
a.no-style {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user