Compare commits
6 Commits
master
...
760e08a595
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
760e08a595 | ||
|
|
9173d2220c | ||
|
|
8e582c96e3 | ||
|
|
da80bc17c0 | ||
|
|
182cc0bb67 | ||
|
|
f4d0aa3b27 |
18
package-lock.json
generated
18
package-lock.json
generated
@@ -21,6 +21,7 @@
|
|||||||
"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",
|
||||||
|
"uuid": "^8.3.2",
|
||||||
"zone.js": "~0.11.4"
|
"zone.js": "~0.11.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -29,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",
|
||||||
@@ -2573,6 +2575,12 @@
|
|||||||
"integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==",
|
"integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/uuid": {
|
||||||
|
"version": "8.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
|
||||||
|
"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",
|
||||||
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.9.tgz",
|
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.9.tgz",
|
||||||
@@ -14882,7 +14890,6 @@
|
|||||||
"version": "8.3.2",
|
"version": "8.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
||||||
"dev": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"uuid": "dist/bin/uuid"
|
"uuid": "dist/bin/uuid"
|
||||||
}
|
}
|
||||||
@@ -17916,6 +17923,12 @@
|
|||||||
"integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==",
|
"integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/uuid": {
|
||||||
|
"version": "8.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
|
||||||
|
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@types/webpack-sources": {
|
"@types/webpack-sources": {
|
||||||
"version": "0.1.9",
|
"version": "0.1.9",
|
||||||
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.9.tgz",
|
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.9.tgz",
|
||||||
@@ -27377,8 +27390,7 @@
|
|||||||
"uuid": {
|
"uuid": {
|
||||||
"version": "8.3.2",
|
"version": "8.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"validate-npm-package-name": {
|
"validate-npm-package-name": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
"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",
|
||||||
|
"uuid": "^8.3.2",
|
||||||
"zone.js": "~0.11.4"
|
"zone.js": "~0.11.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -31,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",
|
||||||
@@ -39,4 +41,4 @@
|
|||||||
"karma-jasmine-html-reporter": "~1.7.0",
|
"karma-jasmine-html-reporter": "~1.7.0",
|
||||||
"typescript": "~4.3.5"
|
"typescript": "~4.3.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,9 +1,11 @@
|
|||||||
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({
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
<router-outlet></router-outlet>
|
<app-header></app-header>
|
||||||
|
<router-outlet></router-outlet>
|
||||||
|
|||||||
@@ -10,20 +10,36 @@ 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 { DisplayTaskComponent } from './display-task/display-task.component';
|
import { DisplayTaskComponent } from './display-task/display-task.component';
|
||||||
|
import { TaskListsComponent } from './task-lists/task-lists.component';
|
||||||
|
import { AddTaskListComponent } from './task-lists/add-task-list/add-task-list.component';
|
||||||
|
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: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
MainPageComponent,
|
MainPageComponent,
|
||||||
AddTaskComponent,
|
AddTaskComponent,
|
||||||
DisplayTaskComponent
|
DisplayTaskComponent,
|
||||||
|
TaskListsComponent,
|
||||||
|
AddTaskListComponent,
|
||||||
|
HeaderComponent,
|
||||||
|
ActiveListTasksComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
BrowserAnimationsModule,
|
BrowserAnimationsModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatInputModule
|
MatInputModule,
|
||||||
|
MatDialogModule,
|
||||||
|
MatButtonModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
MatSnackBarModule
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
CookieService,
|
CookieService,
|
||||||
|
|||||||
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[];
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
124
src/app/core/service/task-list.service.ts
Normal file
124
src/app/core/service/task-list.service.ts
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
import { BehaviorSubject, Observable } from "rxjs";
|
||||||
|
import { Task } from "../entity/task";
|
||||||
|
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({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class TaskListService {
|
||||||
|
private _store: BehaviorSubject<Store> = new BehaviorSubject<Store>(undefined as unknown as Store);
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private _router: Router,
|
||||||
|
private _storePersistenceService: StorePersistenceService
|
||||||
|
) {
|
||||||
|
this.store$.subscribe(store => {
|
||||||
|
this._storePersistenceService.save(store);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get store$(): Observable<Store> {
|
||||||
|
return this._store.asObservable()
|
||||||
|
.pipe(filter(store => !!store));
|
||||||
|
}
|
||||||
|
|
||||||
|
private get store(): Store {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +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> -->
|
||||||
|
|
||||||
|
<app-task-lists></app-task-lists>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/app/task-lists/task-lists.component.html
Normal file
18
src/app/task-lists/task-lists.component.html
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<div class="task-lists">
|
||||||
|
<div *ngFor="let taskList of taskLists" class="task-list-container">
|
||||||
|
<div class="task-list shadowed" (click)="selectActiveTaskList(taskList)" (contextmenu)="$event.preventDefault(); onRightClick(taskList)">
|
||||||
|
<ng-container [ngPlural]="taskList.tasks?.length ?? 0">
|
||||||
|
<ng-template ngPluralCase=">1">
|
||||||
|
{{taskList.tasks?.length}} tâches
|
||||||
|
</ng-template>
|
||||||
|
<ng-template ngPluralCase="other">
|
||||||
|
{{taskList.tasks?.length}} tâche
|
||||||
|
</ng-template>
|
||||||
|
</ng-container>
|
||||||
|
</div>
|
||||||
|
{{taskList.name}}
|
||||||
|
<ng-container *ngIf="isSelectionModeEnabled() && isSelected(taskList)">
|
||||||
|
SELECTED
|
||||||
|
</ng-container>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
26
src/app/task-lists/task-lists.component.scss
Normal file
26
src/app/task-lists/task-lists.component.scss
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
.task-lists {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin: auto;
|
||||||
|
max-width: 80%;
|
||||||
|
|
||||||
|
.task-list-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
margin: 1rem;
|
||||||
|
|
||||||
|
.task-list {
|
||||||
|
width: 150px;
|
||||||
|
height: 150px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: .5rem;
|
||||||
|
background-color: aliceblue;
|
||||||
|
margin-bottom: .5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
src/app/task-lists/task-lists.component.ts
Normal file
56
src/app/task-lists/task-lists.component.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { TaskList } from '../core/entity/task-list';
|
||||||
|
import { TaskListService } from '../core/service/task-list.service';
|
||||||
|
import { AddTaskListComponent } from './add-task-list/add-task-list.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-task-lists',
|
||||||
|
templateUrl: './task-lists.component.html',
|
||||||
|
styleUrls: ['./task-lists.component.scss']
|
||||||
|
})
|
||||||
|
export class TaskListsComponent implements OnInit, OnDestroy {
|
||||||
|
taskLists: TaskList[] = [];
|
||||||
|
private _storeSubscription?: Subscription;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private _dialog: MatDialog,
|
||||||
|
private _taskListService: TaskListService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.taskLists = this._taskListService.getAll();
|
||||||
|
this._storeSubscription = this._taskListService.store$.subscribe(store => {
|
||||||
|
this.taskLists = store.taskLists;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|||||||
14
todo.md
Normal file
14
todo.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Fonctionnalités
|
||||||
|
- Ajouter une tâche
|
||||||
|
- Renommer la tâche
|
||||||
|
- Terminer une tâche
|
||||||
|
- Supprimer une tâche
|
||||||
|
- Saisir la note d'une tâche
|
||||||
|
- Ajouter des sous tâches à une autre
|
||||||
|
- Renommer des sous tâches d'une autre
|
||||||
|
- Terminer des sous tâches d'une autre
|
||||||
|
- Supprimer des sous tâches d'une autre
|
||||||
|
|
||||||
|
- J'aimerai "tagger" une tâche comme "asynchrone/bloquante" (où je dois attendre la fin, genre un build jenkins) et donc être notifié toutes les 5mins d'aller vérifier si la tâche est terminée.
|
||||||
|
- Quand je termine une sous tâche, je veux qu'elle soit archivée pour pouvoir la consulter à postériori
|
||||||
|
- J'aimerai définir un e API sur laquelle je pourrais sauverader mes tâches, à la manière de git
|
||||||
Reference in New Issue
Block a user