Compare commits

..

6 Commits

Author SHA1 Message Date
Florian THIERRY
760e08a595 Add active-list-tasks component and navigation with home pane. 2022-03-04 17:27:13 +01:00
Florian THIERRY
9173d2220c Add task list selection system. 2022-03-04 16:53:08 +01:00
Florian THIERRY
8e582c96e3 Code cleaning. 2022-03-04 16:10:24 +01:00
Florian THIERRY
da80bc17c0 Refactor store observer mecanism to pilot edition actions. 2022-03-04 16:09:45 +01:00
Florian THIERRY
182cc0bb67 Add task-list creation. 2022-03-04 10:35:54 +01:00
Florian THIERRY
f4d0aa3b27 Add new task list model. 2022-03-04 09:21:08 +01:00
24 changed files with 532 additions and 11 deletions

18
package-lock.json generated
View File

@@ -21,6 +21,7 @@
"ngx-cookie-service": "^12.0.3",
"rxjs": "~6.6.0",
"tslib": "^2.3.0",
"uuid": "^8.3.2",
"zone.js": "~0.11.4"
},
"devDependencies": {
@@ -29,6 +30,7 @@
"@angular/compiler-cli": "~12.2.0",
"@types/jasmine": "~3.8.0",
"@types/node": "^12.11.1",
"@types/uuid": "^8.3.4",
"jasmine-core": "~3.8.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
@@ -2573,6 +2575,12 @@
"integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==",
"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": {
"version": "0.1.9",
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.9.tgz",
@@ -14882,7 +14890,6 @@
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"dev": true,
"bin": {
"uuid": "dist/bin/uuid"
}
@@ -17916,6 +17923,12 @@
"integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==",
"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": {
"version": "0.1.9",
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.9.tgz",
@@ -27377,8 +27390,7 @@
"uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"dev": true
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
},
"validate-npm-package-name": {
"version": "3.0.0",

View File

@@ -23,6 +23,7 @@
"ngx-cookie-service": "^12.0.3",
"rxjs": "~6.6.0",
"tslib": "^2.3.0",
"uuid": "^8.3.2",
"zone.js": "~0.11.4"
},
"devDependencies": {
@@ -31,6 +32,7 @@
"@angular/compiler-cli": "~12.2.0",
"@types/jasmine": "~3.8.0",
"@types/node": "^12.11.1",
"@types/uuid": "^8.3.4",
"jasmine-core": "~3.8.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",

View File

@@ -0,0 +1 @@
<p>active-list-tasks works!</p>

View 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(['/']);
}
}

View File

@@ -1,9 +1,11 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { ActiveListTasksComponent } from './active-list-tasks/active-list-tasks.component';
import { MainPageComponent } from './main-page/main-page.component';
const routes: Routes = [
{ path: '', component: MainPageComponent}
{ path: '', component: MainPageComponent},
{ path: 'task-lists/active', component: ActiveListTasksComponent }
];
@NgModule({

View File

@@ -1 +1,2 @@
<app-header></app-header>
<router-outlet></router-outlet>

View File

@@ -10,20 +10,36 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MatIconModule} from '@angular/material/icon';
import {MatInputModule} from '@angular/material/input';
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({
declarations: [
AppComponent,
MainPageComponent,
AddTaskComponent,
DisplayTaskComponent
DisplayTaskComponent,
TaskListsComponent,
AddTaskListComponent,
HeaderComponent,
ActiveListTasksComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
MatIconModule,
MatInputModule
MatInputModule,
MatDialogModule,
MatButtonModule,
ReactiveFormsModule,
MatSnackBarModule
],
providers: [
CookieService,

View 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>

View 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;
}
}

View 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();
}
}

View File

@@ -0,0 +1,8 @@
import { TaskList } from "./task-list";
export interface Store {
activeTaskListId: string | undefined;
taskLists: TaskList[];
selectedTaskLists: TaskList[];
selectionMode: boolean;
}

View File

@@ -0,0 +1,7 @@
import { Task } from "./task";
export interface TaskList {
id: string;
name: string;
tasks: Task[];
}

View 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;
}
}
}

View 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);
}
}

View File

@@ -1,8 +1,10 @@
<div class="component">
<h1>Todo List</h1>
<!-- <h1>Todo List</h1>
<app-display-task *ngFor="let task of tasks" [task]="task"></app-display-task>
<div id="add-task-btn" *ngIf="!isAddingATask" (click)="createTask()">
<mat-icon>add</mat-icon>
<span>Ajouter une nouvelle tâche...</span>
</div>
</div> -->
<app-task-lists></app-task-lists>
</div>

View File

@@ -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>

View 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();
}
}

View 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>

View 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;
}
}
}

View 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();
}
}

View File

@@ -1,4 +1,26 @@
/* You can add global styles to this file, and also import other style files */
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
View 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