Initial commit
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"expense-tracker-front": {
|
||||
"projectType": "application",
|
||||
"schematics": {
|
||||
"@schematics/angular:component": {
|
||||
"style": "scss"
|
||||
}
|
||||
},
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:application",
|
||||
"options": {
|
||||
"outputPath": "dist/expense-tracker-front",
|
||||
"index": "src/index.html",
|
||||
"browser": "src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"assets": ["src/favicon.ico", "src/assets"],
|
||||
"styles": ["src/styles.scss"],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "2kb",
|
||||
"maximumError": "4kb"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "expense-tracker-front:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "expense-tracker-front:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development",
|
||||
"options": {
|
||||
"proxyConfig": "proxy.conf.json"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"polyfills": ["zone.js", "zone.js/testing"],
|
||||
"tsConfig": "tsconfig.spec.json",
|
||||
"assets": ["src/favicon.ico", "src/assets"],
|
||||
"styles": ["src/styles.scss"],
|
||||
"scripts": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"cli": {
|
||||
"analytics": "aabece4b-fd7f-4d54-901e-5b589e8ceeb8"
|
||||
}
|
||||
}
|
||||
Generated
+14301
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "expense-tracker-front",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^17.3.0",
|
||||
"@angular/cdk": "^17.3.0",
|
||||
"@angular/common": "^17.3.0",
|
||||
"@angular/compiler": "^17.3.0",
|
||||
"@angular/core": "^17.3.0",
|
||||
"@angular/forms": "^17.3.0",
|
||||
"@angular/material": "^17.3.0",
|
||||
"@angular/platform-browser": "^17.3.0",
|
||||
"@angular/platform-browser-dynamic": "^17.3.0",
|
||||
"@angular/router": "^17.3.0",
|
||||
"echarts": "^5.5.1",
|
||||
"ngx-echarts": "^17.1.0",
|
||||
"papaparse": "^5.4.1",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.6.2",
|
||||
"zone.js": "~0.14.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^17.3.0",
|
||||
"@angular/cli": "^17.3.0",
|
||||
"@angular/compiler-cli": "^17.3.0",
|
||||
"@types/jasmine": "~5.1.0",
|
||||
"@types/papaparse": "^5.3.14",
|
||||
"jasmine-core": "~5.1.0",
|
||||
"karma": "~6.4.0",
|
||||
"karma-chrome-launcher": "~3.2.0",
|
||||
"karma-coverage": "~2.2.0",
|
||||
"karma-jasmine": "~5.1.0",
|
||||
"karma-jasmine-html-reporter": "~2.1.0",
|
||||
"typescript": "~5.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"/api": {
|
||||
"target": "http://localhost:5000",
|
||||
"secure": false,
|
||||
"changeOrigin": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
standalone: true,
|
||||
imports: [RouterOutlet],
|
||||
template: '<router-outlet />',
|
||||
})
|
||||
export class AppComponent {}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
||||
import { provideHttpClient } from '@angular/common/http';
|
||||
import { provideEcharts } from 'ngx-echarts';
|
||||
import { routes } from './app.routes';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideRouter(routes),
|
||||
provideAnimationsAsync(),
|
||||
provideHttpClient(),
|
||||
provideEcharts(),
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
import { Routes } from '@angular/router';
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn, Router } from '@angular/router';
|
||||
import { catchError, map, EMPTY } from 'rxjs';
|
||||
|
||||
import { AppLayoutComponent } from './shared/components/app-layout/app-layout.component';
|
||||
import { MonthService } from './core/services/month.service';
|
||||
import { Month } from './core/models/month.model';
|
||||
|
||||
const currentMonthResolver: ResolveFn<Month> = () => {
|
||||
const monthService = inject(MonthService);
|
||||
const router = inject(Router);
|
||||
|
||||
return monthService.getMonths().pipe(
|
||||
map((months) => {
|
||||
if (!months || months.length === 0) {
|
||||
router.navigate(['/admin']);
|
||||
return EMPTY as unknown as Month;
|
||||
}
|
||||
const sorted = [...months].sort((a, b) => {
|
||||
if (a.year !== b.year) return b.year - a.year;
|
||||
return b.month - a.month;
|
||||
});
|
||||
router.navigate(['/home', sorted[0].id], { replaceUrl: true });
|
||||
return sorted[0];
|
||||
}),
|
||||
catchError(() => {
|
||||
router.navigate(['/admin']);
|
||||
return EMPTY;
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: AppLayoutComponent,
|
||||
children: [
|
||||
{ path: '', redirectTo: 'home/current', pathMatch: 'full' },
|
||||
{
|
||||
path: 'home/current',
|
||||
resolve: { month: currentMonthResolver },
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
path: 'home/:monthId',
|
||||
loadComponent: () =>
|
||||
import('./features/home/home.component').then((m) => m.HomeComponent),
|
||||
},
|
||||
{
|
||||
path: 'admin',
|
||||
loadComponent: () =>
|
||||
import('./features/admin/admin.component').then((m) => m.AdminComponent),
|
||||
},
|
||||
{
|
||||
path: 'import',
|
||||
loadComponent: () =>
|
||||
import('./features/import/import-csv.component').then(
|
||||
(m) => m.ImportCsvComponent
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
{ path: '**', redirectTo: 'home/current' },
|
||||
];
|
||||
@@ -0,0 +1,10 @@
|
||||
export interface Category {
|
||||
id: string;
|
||||
name: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export interface CreateCategoryDto {
|
||||
name: string;
|
||||
color: string;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
export type EntryType = 'INCOME' | 'EXPENSE';
|
||||
|
||||
export interface Entry {
|
||||
id: string;
|
||||
monthId: string;
|
||||
type: EntryType;
|
||||
amount: number;
|
||||
label: string;
|
||||
categoryId: string | null;
|
||||
categoryName: string | null;
|
||||
entryDate: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface CreateEntryDto {
|
||||
type: EntryType;
|
||||
amount: number;
|
||||
label: string;
|
||||
categoryId: string | null;
|
||||
entryDate: string;
|
||||
}
|
||||
|
||||
export interface UpdateEntryDto {
|
||||
type: EntryType;
|
||||
amount: number;
|
||||
label: string;
|
||||
categoryId: string | null;
|
||||
entryDate: string;
|
||||
}
|
||||
|
||||
export interface ImportResult {
|
||||
importedCount: number;
|
||||
errorCount: number;
|
||||
errors: ImportError[];
|
||||
}
|
||||
|
||||
export interface ImportError {
|
||||
line: number;
|
||||
message: string;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './month.model';
|
||||
export * from './entry.model';
|
||||
export * from './category.model';
|
||||
export * from './settings.model';
|
||||
@@ -0,0 +1,20 @@
|
||||
export interface Month {
|
||||
id: string;
|
||||
year: number;
|
||||
month: number;
|
||||
defaultSalary: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface CreateMonthDto {
|
||||
year: number;
|
||||
month: number;
|
||||
defaultSalary: number;
|
||||
}
|
||||
|
||||
export interface MonthSummary {
|
||||
monthId: string;
|
||||
totalIncome: number;
|
||||
totalExpense: number;
|
||||
balance: number;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export interface AppSetting {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface UpdateDefaultSalaryDto {
|
||||
value: number;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Category, CreateCategoryDto } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CategoryService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getCategories(): Observable<Category[]> {
|
||||
return this.http.get<Category[]>('/api/categories');
|
||||
}
|
||||
|
||||
createCategory(dto: CreateCategoryDto): Observable<Category> {
|
||||
return this.http.post<Category>('/api/categories', dto);
|
||||
}
|
||||
|
||||
deleteCategory(id: string): Observable<void> {
|
||||
return this.http.delete<void>(`/api/categories/${id}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Entry, CreateEntryDto, UpdateEntryDto, ImportResult } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class EntryService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getEntries(monthId: string): Observable<Entry[]> {
|
||||
return this.http.get<Entry[]>(`/api/months/${monthId}/entries`);
|
||||
}
|
||||
|
||||
createEntry(monthId: string, dto: CreateEntryDto): Observable<Entry> {
|
||||
return this.http.post<Entry>(`/api/months/${monthId}/entries`, dto);
|
||||
}
|
||||
|
||||
updateEntry(id: string, dto: UpdateEntryDto): Observable<Entry> {
|
||||
return this.http.put<Entry>(`/api/entries/${id}`, dto);
|
||||
}
|
||||
|
||||
deleteEntry(id: string): Observable<void> {
|
||||
return this.http.delete<void>(`/api/entries/${id}`);
|
||||
}
|
||||
|
||||
importCsv(monthId: string, file: File): Observable<ImportResult> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return this.http.post<ImportResult>(`/api/months/${monthId}/entries/import`, formData);
|
||||
}
|
||||
|
||||
exportExcel(monthId: string, fileName: string): Observable<Blob> {
|
||||
return this.http.get(`/api/months/${monthId}/entries/export?fileName=${encodeURIComponent(fileName)}`, {
|
||||
responseType: 'blob',
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Month, CreateMonthDto, MonthSummary } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class MonthService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getMonths(): Observable<Month[]> {
|
||||
return this.http.get<Month[]>('/api/months');
|
||||
}
|
||||
|
||||
createMonth(dto: CreateMonthDto): Observable<Month> {
|
||||
return this.http.post<Month>('/api/months', dto);
|
||||
}
|
||||
|
||||
getSummary(monthId: string): Observable<MonthSummary> {
|
||||
return this.http.get<MonthSummary>(`/api/months/${monthId}/summary`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, map } from 'rxjs';
|
||||
import { AppSetting } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SettingsService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getSettings(): Observable<AppSetting[]> {
|
||||
return this.http.get<AppSetting[]>('/api/settings');
|
||||
}
|
||||
|
||||
getDefaultSalary(): Observable<number> {
|
||||
return this.getSettings().pipe(
|
||||
map((settings) => {
|
||||
const setting = settings.find((s) => s.key === 'default_salary');
|
||||
return setting ? Number(setting.value) : 0;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
updateDefaultSalary(value: number): Observable<AppSetting> {
|
||||
return this.http.put<AppSetting>('/api/settings/default_salary', { value });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<div class="admin-page">
|
||||
<h1 class="page-title">Administration</h1>
|
||||
|
||||
<!-- ─────────────────────────────────────────────
|
||||
Section 1 — Paramètres globaux
|
||||
───────────────────────────────────────────── -->
|
||||
<mat-card class="admin-card">
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
<mat-icon>tune</mat-icon>
|
||||
Paramètres globaux
|
||||
</mat-card-title>
|
||||
</mat-card-header>
|
||||
|
||||
<mat-card-content>
|
||||
<p class="section-hint">
|
||||
Salaire mensuel par défaut appliqué lors de la création d'un nouveau mois.
|
||||
</p>
|
||||
|
||||
<div class="form-row">
|
||||
<mat-form-field appearance="outline" class="salary-field">
|
||||
<mat-label>Salaire par défaut (€)</mat-label>
|
||||
<input
|
||||
matInput
|
||||
type="number"
|
||||
min="0"
|
||||
[formControl]="salaryControl"
|
||||
placeholder="Ex : 2500"
|
||||
/>
|
||||
<mat-error *ngIf="salaryControl.hasError('required')">Champ requis.</mat-error>
|
||||
<mat-error *ngIf="salaryControl.hasError('min')">Valeur minimale : 0.</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<button
|
||||
mat-flat-button
|
||||
color="primary"
|
||||
[disabled]="salaryControl.invalid"
|
||||
(click)="saveSalary()"
|
||||
>
|
||||
<mat-icon>save</mat-icon>
|
||||
Enregistrer
|
||||
</button>
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
<!-- ─────────────────────────────────────────────
|
||||
Section 2 — Catégories
|
||||
───────────────────────────────────────────── -->
|
||||
<mat-card class="admin-card">
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
<mat-icon>label</mat-icon>
|
||||
Catégories
|
||||
</mat-card-title>
|
||||
</mat-card-header>
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<!-- Liste existante -->
|
||||
<div class="category-list" *ngIf="categories.length > 0; else noCategories">
|
||||
<div class="category-item" *ngFor="let cat of categories">
|
||||
<span class="color-dot" [style.background-color]="cat.color"></span>
|
||||
<span class="category-name">{{ cat.name }}</span>
|
||||
<button
|
||||
mat-icon-button
|
||||
color="warn"
|
||||
aria-label="Supprimer {{ cat.name }}"
|
||||
(click)="deleteCategory(cat)"
|
||||
>
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #noCategories>
|
||||
<p class="empty-hint">Aucune catégorie pour l'instant.</p>
|
||||
</ng-template>
|
||||
|
||||
<mat-divider class="section-divider"></mat-divider>
|
||||
|
||||
<!-- Formulaire d'ajout -->
|
||||
<p class="subsection-label">Ajouter une catégorie</p>
|
||||
<div class="form-row add-category-row">
|
||||
<mat-form-field appearance="outline" class="category-name-field">
|
||||
<mat-label>Nom</mat-label>
|
||||
<input matInput [formControl]="newCategoryName" placeholder="Ex : Alimentation" />
|
||||
<mat-error *ngIf="newCategoryName.hasError('required')">Nom requis.</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<div class="color-picker-wrapper">
|
||||
<label class="color-label">Couleur</label>
|
||||
<input
|
||||
type="color"
|
||||
class="color-input"
|
||||
[formControl]="newCategoryColor"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
mat-flat-button
|
||||
color="accent"
|
||||
[disabled]="newCategoryName.invalid"
|
||||
(click)="addCategory()"
|
||||
>
|
||||
<mat-icon>add</mat-icon>
|
||||
Ajouter
|
||||
</button>
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
<!-- ─────────────────────────────────────────────
|
||||
Section 3 — Export Excel
|
||||
───────────────────────────────────────────── -->
|
||||
<mat-card class="admin-card">
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
<mat-icon>download</mat-icon>
|
||||
Export Excel
|
||||
</mat-card-title>
|
||||
</mat-card-header>
|
||||
|
||||
<mat-card-content>
|
||||
<p class="section-hint">
|
||||
Exporter toutes les saisies d'un mois au format <code>.xlsx</code>.
|
||||
</p>
|
||||
|
||||
<div class="form-row">
|
||||
<mat-form-field appearance="outline" class="month-select-field">
|
||||
<mat-label>Mois à exporter</mat-label>
|
||||
<mat-select [formControl]="selectedMonthId">
|
||||
<mat-option *ngFor="let m of months" [value]="m.id">
|
||||
{{ m.month | number:'2.0-0' }} / {{ m.year }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<button
|
||||
mat-flat-button
|
||||
color="primary"
|
||||
[disabled]="!selectedMonthId.value"
|
||||
(click)="exportExcel()"
|
||||
>
|
||||
<mat-icon>table_view</mat-icon>
|
||||
Télécharger .xlsx
|
||||
</button>
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</div>
|
||||
@@ -0,0 +1,172 @@
|
||||
.admin-page {
|
||||
max-width: 720px;
|
||||
margin: 0 auto;
|
||||
padding: 24px 16px 48px;
|
||||
|
||||
.page-title {
|
||||
font-size: 1.6rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 24px;
|
||||
color: #1f2328;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Cards ──────────────────────────────────────────
|
||||
|
||||
.admin-card {
|
||||
margin-bottom: 24px;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
box-shadow: none;
|
||||
|
||||
mat-card-header {
|
||||
padding: 16px 20px 0;
|
||||
|
||||
mat-card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: #1f2328;
|
||||
|
||||
mat-icon {
|
||||
font-size: 1.2rem;
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
color: #3b82d4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mat-card-content {
|
||||
padding: 12px 20px 20px;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Hints & labels ─────────────────────────────────
|
||||
|
||||
.section-hint {
|
||||
font-size: 0.85rem;
|
||||
color: #57606a;
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
.subsection-label {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
color: #1f2328;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
font-size: 0.85rem;
|
||||
color: #57606a;
|
||||
font-style: italic;
|
||||
margin: 4px 0 12px;
|
||||
}
|
||||
|
||||
// ── Form rows ──────────────────────────────────────
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
|
||||
button {
|
||||
margin-top: 4px;
|
||||
height: 48px;
|
||||
white-space: nowrap;
|
||||
|
||||
mat-icon {
|
||||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.salary-field,
|
||||
.month-select-field {
|
||||
flex: 1 1 240px;
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
// ── Category list ──────────────────────────────────
|
||||
|
||||
.category-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 6px 4px;
|
||||
border-radius: 6px;
|
||||
transition: background 0.15s;
|
||||
|
||||
&:hover {
|
||||
background: #f7f8fa;
|
||||
}
|
||||
|
||||
.category-name {
|
||||
flex: 1;
|
||||
font-size: 0.92rem;
|
||||
color: #1f2328;
|
||||
}
|
||||
}
|
||||
|
||||
.color-dot {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
border: 1px solid rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
// ── Divider ────────────────────────────────────────
|
||||
|
||||
.section-divider {
|
||||
margin: 12px 0 20px;
|
||||
}
|
||||
|
||||
// ── Add category row ───────────────────────────────
|
||||
|
||||
.add-category-row {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.category-name-field {
|
||||
flex: 1 1 200px;
|
||||
min-width: 140px;
|
||||
}
|
||||
|
||||
// ── Color picker ───────────────────────────────────
|
||||
|
||||
.color-picker-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.color-label {
|
||||
font-size: 0.75rem;
|
||||
color: #57606a;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.color-input {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 6px;
|
||||
padding: 2px;
|
||||
cursor: pointer;
|
||||
background: none;
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ReactiveFormsModule, FormControl, Validators } from '@angular/forms';
|
||||
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatListModule } from '@angular/material/list';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
|
||||
import { SettingsService } from '../../core/services/settings.service';
|
||||
import { CategoryService } from '../../core/services/category.service';
|
||||
import { MonthService } from '../../core/services/month.service';
|
||||
import { EntryService } from '../../core/services/entry.service';
|
||||
import { Category, Month } from '../../core/models';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
ReactiveFormsModule,
|
||||
MatCardModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatButtonModule,
|
||||
MatSelectModule,
|
||||
MatListModule,
|
||||
MatIconModule,
|
||||
MatSnackBarModule,
|
||||
MatDividerModule,
|
||||
],
|
||||
templateUrl: './admin.component.html',
|
||||
styleUrls: ['./admin.component.scss'],
|
||||
})
|
||||
export class AdminComponent implements OnInit {
|
||||
// Section 1 — Salaire par défaut
|
||||
salaryControl = new FormControl<number | null>(null, [Validators.required, Validators.min(0)]);
|
||||
|
||||
// Section 2 — Catégories
|
||||
categories: Category[] = [];
|
||||
newCategoryName = new FormControl('', [Validators.required, Validators.minLength(1)]);
|
||||
newCategoryColor = new FormControl('#3b82d4');
|
||||
|
||||
// Section 3 — Export Excel
|
||||
months: Month[] = [];
|
||||
selectedMonthId = new FormControl<string | null>(null);
|
||||
|
||||
constructor(
|
||||
private settingsService: SettingsService,
|
||||
private categoryService: CategoryService,
|
||||
private monthService: MonthService,
|
||||
private entryService: EntryService,
|
||||
private snackBar: MatSnackBar,
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadDefaultSalary();
|
||||
this.loadCategories();
|
||||
this.loadMonths();
|
||||
}
|
||||
|
||||
// — Section 1 —
|
||||
|
||||
private loadDefaultSalary(): void {
|
||||
this.settingsService.getDefaultSalary().subscribe({
|
||||
next: (value) => this.salaryControl.setValue(value),
|
||||
error: () => this.showError('Impossible de charger le salaire par défaut.'),
|
||||
});
|
||||
}
|
||||
|
||||
saveSalary(): void {
|
||||
if (this.salaryControl.invalid || this.salaryControl.value == null) return;
|
||||
this.settingsService.updateDefaultSalary(this.salaryControl.value).subscribe({
|
||||
next: () => this.snackBar.open('Salaire enregistré.', 'OK', { duration: 3000 }),
|
||||
error: () => this.showError('Erreur lors de l\'enregistrement du salaire.'),
|
||||
});
|
||||
}
|
||||
|
||||
// — Section 2 —
|
||||
|
||||
private loadCategories(): void {
|
||||
this.categoryService.getCategories().subscribe({
|
||||
next: (cats) => (this.categories = cats),
|
||||
error: () => this.showError('Impossible de charger les catégories.'),
|
||||
});
|
||||
}
|
||||
|
||||
addCategory(): void {
|
||||
if (this.newCategoryName.invalid) return;
|
||||
const dto = {
|
||||
name: this.newCategoryName.value!.trim(),
|
||||
color: this.newCategoryColor.value ?? '#3b82d4',
|
||||
};
|
||||
this.categoryService.createCategory(dto).subscribe({
|
||||
next: () => {
|
||||
this.newCategoryName.reset('');
|
||||
this.newCategoryColor.reset('#3b82d4');
|
||||
this.loadCategories();
|
||||
this.snackBar.open('Catégorie ajoutée.', 'OK', { duration: 3000 });
|
||||
},
|
||||
error: () => this.showError('Erreur lors de l\'ajout de la catégorie.'),
|
||||
});
|
||||
}
|
||||
|
||||
deleteCategory(cat: Category): void {
|
||||
if (!confirm(`Supprimer la catégorie "${cat.name}" ?`)) return;
|
||||
this.categoryService.deleteCategory(cat.id).subscribe({
|
||||
next: () => {
|
||||
this.categories = this.categories.filter((c) => c.id !== cat.id);
|
||||
this.snackBar.open('Catégorie supprimée.', 'OK', { duration: 3000 });
|
||||
},
|
||||
error: (err: HttpErrorResponse) => {
|
||||
if (err.status === 409) {
|
||||
this.showError('Catégorie utilisée par des saisies — suppression impossible.');
|
||||
} else {
|
||||
this.showError('Erreur lors de la suppression.');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// — Section 3 —
|
||||
|
||||
private loadMonths(): void {
|
||||
this.monthService.getMonths().subscribe({
|
||||
next: (months) => (this.months = months),
|
||||
error: () => this.showError('Impossible de charger les mois.'),
|
||||
});
|
||||
}
|
||||
|
||||
exportExcel(): void {
|
||||
const monthId = this.selectedMonthId.value;
|
||||
if (!monthId) return;
|
||||
const month = this.months.find((m) => m.id === monthId);
|
||||
if (!month) return;
|
||||
const mm = String(month.month).padStart(2, '0');
|
||||
const fileName = `suivi-${mm}-${month.year}.xlsx`;
|
||||
this.entryService.exportExcel(monthId, fileName).subscribe({
|
||||
next: (blob) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
},
|
||||
error: () => this.showError('Erreur lors de l\'export Excel.'),
|
||||
});
|
||||
}
|
||||
|
||||
// — Helpers —
|
||||
|
||||
private showError(message: string): void {
|
||||
this.snackBar.open(message, 'Fermer', { duration: 5000, panelClass: 'snack-error' });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ReactiveFormsModule, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
|
||||
import { EntryService } from '../../../core/services/entry.service';
|
||||
import { CategoryService } from '../../../core/services/category.service';
|
||||
import { Category } from '../../../core/models/category.model';
|
||||
import { EntryType } from '../../../core/models/entry.model';
|
||||
|
||||
export interface AddEntryDialogData {
|
||||
monthId: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-entry-modal',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
ReactiveFormsModule,
|
||||
MatDialogModule,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatSelectModule,
|
||||
MatButtonToggleModule,
|
||||
],
|
||||
template: `
|
||||
<h2 mat-dialog-title>Ajouter une saisie</h2>
|
||||
|
||||
<mat-dialog-content>
|
||||
<form [formGroup]="form" class="entry-form">
|
||||
<mat-button-toggle-group formControlName="type" class="type-toggle">
|
||||
<mat-button-toggle value="EXPENSE">💸 Dépense</mat-button-toggle>
|
||||
<mat-button-toggle value="INCOME">💰 Entrée</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Libellé</mat-label>
|
||||
<input matInput formControlName="label" placeholder="Ex: Courses Lidl" />
|
||||
<mat-error *ngIf="form.get('label')?.hasError('required')">Champ requis</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Montant (€)</mat-label>
|
||||
<input matInput type="number" formControlName="amount" min="0.01" step="0.01" />
|
||||
<mat-error *ngIf="form.get('amount')?.hasError('required')">Champ requis</mat-error>
|
||||
<mat-error *ngIf="form.get('amount')?.hasError('min')">Doit être supérieur à 0</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline" *ngIf="isExpense">
|
||||
<mat-label>Catégorie</mat-label>
|
||||
<mat-select formControlName="categoryId">
|
||||
<mat-option [value]="null">— Sans catégorie —</mat-option>
|
||||
<mat-option *ngFor="let cat of categories" [value]="cat.id">
|
||||
{{ cat.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Date</mat-label>
|
||||
<input matInput type="date" formControlName="entryDate" />
|
||||
<mat-error *ngIf="form.get('entryDate')?.hasError('required')">Champ requis</mat-error>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button (click)="dialogRef.close(null)">Annuler</button>
|
||||
<button mat-flat-button color="primary" (click)="submit()" [disabled]="saving">
|
||||
{{ saving ? 'Enregistrement…' : 'Ajouter' }}
|
||||
</button>
|
||||
</mat-dialog-actions>
|
||||
`,
|
||||
styles: [`
|
||||
.entry-form { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; min-width: 360px; }
|
||||
.type-toggle { margin-bottom: 4px; }
|
||||
mat-form-field { width: 100%; }
|
||||
`],
|
||||
})
|
||||
export class AddEntryModalComponent implements OnInit {
|
||||
form: FormGroup;
|
||||
categories: Category[] = [];
|
||||
saving = false;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<AddEntryModalComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: AddEntryDialogData,
|
||||
private fb: FormBuilder,
|
||||
private entryService: EntryService,
|
||||
private categoryService: CategoryService,
|
||||
) {
|
||||
const today = new Date().toISOString().substring(0, 10);
|
||||
this.form = this.fb.group({
|
||||
type: ['EXPENSE'],
|
||||
amount: [null, [Validators.required, Validators.min(0.01)]],
|
||||
label: ['', Validators.required],
|
||||
categoryId: [null],
|
||||
entryDate: [today, Validators.required],
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.categoryService.getCategories().subscribe((cats) => (this.categories = cats));
|
||||
}
|
||||
|
||||
get isExpense(): boolean {
|
||||
return this.form.get('type')?.value === 'EXPENSE';
|
||||
}
|
||||
|
||||
submit(): void {
|
||||
if (this.form.invalid) {
|
||||
this.form.markAllAsTouched();
|
||||
return;
|
||||
}
|
||||
const { type, amount, label, categoryId, entryDate } = this.form.value;
|
||||
this.saving = true;
|
||||
this.entryService
|
||||
.createEntry(this.data.monthId, {
|
||||
type: type as EntryType,
|
||||
amount: +amount,
|
||||
label,
|
||||
categoryId: type === 'EXPENSE' ? (categoryId ?? null) : null,
|
||||
entryDate,
|
||||
})
|
||||
.subscribe({
|
||||
next: (entry) => this.dialogRef.close(entry),
|
||||
error: () => {
|
||||
this.saving = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import {
|
||||
Component, Input, OnChanges, SimpleChanges,
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgxEchartsDirective } from 'ngx-echarts';
|
||||
import type { EChartsOption } from 'echarts';
|
||||
|
||||
import { Entry } from '../../../core/models/entry.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, NgxEchartsDirective],
|
||||
template: `
|
||||
<div class="chart-wrapper">
|
||||
<div
|
||||
echarts
|
||||
[options]="chartOptions"
|
||||
[initOpts]="{ renderer: 'canvas' }"
|
||||
class="echart"
|
||||
></div>
|
||||
</div>
|
||||
`,
|
||||
styles: [`
|
||||
.chart-wrapper { width: 100%; height: 320px; }
|
||||
.echart { width: 100%; height: 100%; }
|
||||
`],
|
||||
})
|
||||
export class ChartComponent implements OnChanges {
|
||||
@Input() entries: Entry[] = [];
|
||||
@Input() totalIncome = 0;
|
||||
|
||||
chartOptions: EChartsOption = {};
|
||||
|
||||
ngOnChanges(_changes: SimpleChanges): void {
|
||||
this.buildOptions();
|
||||
}
|
||||
|
||||
private buildOptions(): void {
|
||||
const daysInMonth = this.getDaysInMonth();
|
||||
const days = Array.from({ length: daysInMonth }, (_, i) => i + 1);
|
||||
|
||||
// Cumulative expenses: one point per day
|
||||
const cumulativeExpenses: number[] = [];
|
||||
let cumul = 0;
|
||||
for (let day = 1; day <= daysInMonth; day++) {
|
||||
cumul += this.entries
|
||||
.filter((e) => e.type === 'EXPENSE' && new Date(e.entryDate).getDate() === day)
|
||||
.reduce((sum, e) => sum + e.amount, 0);
|
||||
cumulativeExpenses.push(+cumul.toFixed(2));
|
||||
}
|
||||
|
||||
const incomeData = Array(daysInMonth).fill(this.totalIncome);
|
||||
|
||||
this.chartOptions = {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
formatter: (params: any) => {
|
||||
const lines = (params as any[]).map(
|
||||
(p: any) => `${p.marker} ${p.seriesName}: <b>${(p.value as number).toFixed(2)} €</b>`
|
||||
);
|
||||
return `Jour ${(params as any[])[0].axisValue}<br/>${lines.join('<br/>')}`;
|
||||
},
|
||||
},
|
||||
legend: { bottom: 0, textStyle: { color: '#57606a' } },
|
||||
grid: { top: 16, right: 16, bottom: 48, left: 56 },
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: days.map(String),
|
||||
name: 'Jour',
|
||||
nameLocation: 'end',
|
||||
axisLine: { lineStyle: { color: '#e5e7eb' } },
|
||||
axisTick: { show: false },
|
||||
axisLabel: { color: '#57606a', fontSize: 11 },
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
axisLabel: { formatter: '{value} €', color: '#57606a', fontSize: 11 },
|
||||
splitLine: { lineStyle: { color: '#f3f4f6' } },
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: 'Fonds disponibles',
|
||||
type: 'line',
|
||||
data: incomeData,
|
||||
symbol: 'none',
|
||||
lineStyle: { color: '#22c55e', type: 'dashed', width: 2.5 },
|
||||
itemStyle: { color: '#22c55e' },
|
||||
},
|
||||
{
|
||||
name: 'Dépenses cumulées',
|
||||
type: 'line',
|
||||
data: cumulativeExpenses,
|
||||
smooth: true,
|
||||
symbol: 'circle',
|
||||
symbolSize: 4,
|
||||
lineStyle: { color: '#ef4444', width: 2.5 },
|
||||
itemStyle: { color: '#ef4444' },
|
||||
areaStyle: {
|
||||
color: {
|
||||
type: 'linear',
|
||||
x: 0, y: 0, x2: 0, y2: 1,
|
||||
colorStops: [
|
||||
{ offset: 0, color: 'rgba(239,68,68,0.25)' },
|
||||
{ offset: 1, color: 'rgba(239,68,68,0.02)' },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
private getDaysInMonth(): number {
|
||||
if (this.entries.length > 0) {
|
||||
const d = new Date(this.entries[0].entryDate);
|
||||
return new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
|
||||
}
|
||||
const now = new Date();
|
||||
return new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
|
||||
import { Entry } from '../../../core/models/entry.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-entry-list',
|
||||
standalone: true,
|
||||
imports: [CommonModule, MatIconModule, MatButtonModule],
|
||||
template: `
|
||||
<div class="entry-list">
|
||||
<div *ngIf="entries.length === 0" class="empty-state">
|
||||
<mat-icon>inbox</mat-icon>
|
||||
<p>Aucune saisie pour ce mois.</p>
|
||||
</div>
|
||||
|
||||
<div *ngFor="let entry of entries" class="entry-item">
|
||||
<mat-icon class="type-icon" [class.income]="entry.type === 'INCOME'" [class.expense]="entry.type === 'EXPENSE'">
|
||||
{{ entry.type === 'INCOME' ? 'arrow_downward' : 'arrow_upward' }}
|
||||
</mat-icon>
|
||||
|
||||
<div class="entry-info">
|
||||
<span class="entry-label">{{ entry.label }}</span>
|
||||
<span class="entry-meta">
|
||||
{{ entry.entryDate | date:'dd/MM/yyyy' }}
|
||||
<span *ngIf="entry.categoryName" class="category-badge">{{ entry.categoryName }}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<span class="entry-amount" [class.income]="entry.type === 'INCOME'" [class.expense]="entry.type === 'EXPENSE'">
|
||||
{{ entry.type === 'INCOME' ? '+' : '-' }}{{ entry.amount | number:'1.2-2' }} €
|
||||
</span>
|
||||
|
||||
<button mat-icon-button class="delete-btn" (click)="onDelete(entry)" aria-label="Supprimer">
|
||||
<mat-icon>delete_outline</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
styles: [`
|
||||
.entry-list { display: flex; flex-direction: column; gap: 8px; }
|
||||
.empty-state { display: flex; flex-direction: column; align-items: center; color: #9ca3af; padding: 32px 0; }
|
||||
.empty-state mat-icon { font-size: 48px; width: 48px; height: 48px; }
|
||||
.entry-item {
|
||||
display: flex; align-items: center; gap: 12px;
|
||||
padding: 12px 16px; background: #fff; border: 1px solid #e5e7eb;
|
||||
border-radius: 8px; transition: background 0.15s;
|
||||
}
|
||||
.entry-item:hover { background: #f7f8fa; }
|
||||
.type-icon { flex-shrink: 0; font-size: 20px; width: 20px; height: 20px; }
|
||||
.type-icon.income { color: #22c55e; }
|
||||
.type-icon.expense { color: #ef4444; }
|
||||
.entry-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
|
||||
.entry-label { font-weight: 500; color: #1f2328; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.entry-meta { font-size: 12px; color: #57606a; display: flex; align-items: center; gap: 6px; margin-top: 2px; }
|
||||
.category-badge {
|
||||
background: #e0e7ff; color: #4338ca; font-size: 11px;
|
||||
padding: 1px 8px; border-radius: 999px; font-weight: 500;
|
||||
}
|
||||
.entry-amount { font-weight: 600; font-size: 15px; white-space: nowrap; }
|
||||
.entry-amount.income { color: #22c55e; }
|
||||
.entry-amount.expense { color: #ef4444; }
|
||||
.delete-btn { flex-shrink: 0; color: #9ca3af; }
|
||||
.delete-btn:hover { color: #ef4444; }
|
||||
`],
|
||||
})
|
||||
export class EntryListComponent {
|
||||
@Input() entries: Entry[] = [];
|
||||
@Output() entryDeleted = new EventEmitter<string>();
|
||||
|
||||
onDelete(entry: Entry): void {
|
||||
if (confirm(`Supprimer « ${entry.label} » ?`)) {
|
||||
this.entryDeleted.emit(entry.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { Subscription, combineLatest } from 'rxjs';
|
||||
import { switchMap, tap } from 'rxjs/operators';
|
||||
|
||||
import { MonthService } from '../../core/services/month.service';
|
||||
import { EntryService } from '../../core/services/entry.service';
|
||||
import { MonthNavComponent } from '../../shared/components/month-nav/month-nav.component';
|
||||
import { EntryListComponent } from './entry-list/entry-list.component';
|
||||
import { ChartComponent } from './chart/chart.component';
|
||||
import { AddEntryModalComponent } from './add-entry-modal/add-entry-modal.component';
|
||||
import { Month, MonthSummary } from '../../core/models/month.model';
|
||||
import { Entry } from '../../core/models/entry.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
MatDialogModule,
|
||||
MatButtonModule,
|
||||
MatIconModule,
|
||||
MonthNavComponent,
|
||||
EntryListComponent,
|
||||
ChartComponent,
|
||||
],
|
||||
template: `
|
||||
<div class="home-container">
|
||||
<!-- Month navigation -->
|
||||
<app-month-nav
|
||||
[months]="months"
|
||||
[currentMonthId]="currentMonthId"
|
||||
(navigate)="onNavigate($event)"
|
||||
></app-month-nav>
|
||||
|
||||
<!-- KPI cards -->
|
||||
<div class="kpi-grid" *ngIf="summary">
|
||||
<div class="kpi-card balance">
|
||||
<span class="kpi-label">Solde</span>
|
||||
<span class="kpi-value">{{ summary.balance | number:'1.2-2' }} €</span>
|
||||
</div>
|
||||
<div class="kpi-card income">
|
||||
<span class="kpi-label">Total entrées</span>
|
||||
<span class="kpi-value">{{ summary.totalIncome | number:'1.2-2' }} €</span>
|
||||
</div>
|
||||
<div class="kpi-card expense">
|
||||
<span class="kpi-label">Total dépenses</span>
|
||||
<span class="kpi-value">{{ summary.totalExpense | number:'1.2-2' }} €</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add entry button -->
|
||||
<div class="action-bar">
|
||||
<button mat-flat-button color="primary" (click)="openAddEntry()">
|
||||
<mat-icon>add</mat-icon>
|
||||
Ajouter une saisie
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Main grid: entry list + chart -->
|
||||
<div class="main-grid">
|
||||
<section class="panel">
|
||||
<h2 class="panel-title">Saisies du mois</h2>
|
||||
<app-entry-list
|
||||
[entries]="entries"
|
||||
(entryDeleted)="onEntryDeleted($event)"
|
||||
></app-entry-list>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<h2 class="panel-title">Évolution des dépenses</h2>
|
||||
<app-chart
|
||||
[entries]="entries"
|
||||
[totalIncome]="summary?.totalIncome ?? 0"
|
||||
></app-chart>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
styles: [`
|
||||
.home-container { padding: 24px; max-width: 1200px; margin: 0 auto; }
|
||||
|
||||
/* KPI */
|
||||
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 24px 0 0; }
|
||||
.kpi-card {
|
||||
padding: 20px 24px; border-radius: 12px; border: 1px solid #e5e7eb;
|
||||
display: flex; flex-direction: column; gap: 4px;
|
||||
}
|
||||
.kpi-card.balance { background: #ede9fe; border-color: #c4b5fd; }
|
||||
.kpi-card.income { background: #dcfce7; border-color: #86efac; }
|
||||
.kpi-card.expense { background: #fee2e2; border-color: #fca5a5; }
|
||||
.kpi-label { font-size: 13px; color: #57606a; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
|
||||
.kpi-value { font-size: 26px; font-weight: 700; color: #1f2328; }
|
||||
.kpi-card.balance .kpi-value { color: #6d28d9; }
|
||||
.kpi-card.income .kpi-value { color: #16a34a; }
|
||||
.kpi-card.expense .kpi-value { color: #dc2626; }
|
||||
|
||||
/* Action bar */
|
||||
.action-bar { margin: 20px 0 0; display: flex; justify-content: flex-end; }
|
||||
|
||||
/* Main grid */
|
||||
.main-grid {
|
||||
display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 20px;
|
||||
}
|
||||
.panel { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 20px; }
|
||||
.panel-title { font-size: 15px; font-weight: 600; color: #1f2328; margin: 0 0 16px; }
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.kpi-grid { grid-template-columns: 1fr; }
|
||||
.main-grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
`],
|
||||
})
|
||||
export class HomeComponent implements OnInit, OnDestroy {
|
||||
months: Month[] = [];
|
||||
currentMonthId = '';
|
||||
summary: MonthSummary | null = null;
|
||||
entries: Entry[] = [];
|
||||
|
||||
private sub = new Subscription();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private monthService: MonthService,
|
||||
private entryService: EntryService,
|
||||
private dialog: MatDialog,
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
// Load months list for the nav
|
||||
this.sub.add(
|
||||
this.monthService.getMonths().subscribe((m) => (this.months = m))
|
||||
);
|
||||
|
||||
// React to route param changes
|
||||
this.sub.add(
|
||||
this.route.paramMap.pipe(
|
||||
tap((params) => { this.currentMonthId = params.get('monthId') ?? ''; }),
|
||||
switchMap((params) => {
|
||||
const id = params.get('monthId') ?? '';
|
||||
return combineLatest([
|
||||
this.monthService.getSummary(id),
|
||||
this.entryService.getEntries(id),
|
||||
]);
|
||||
})
|
||||
).subscribe(([summary, entries]) => {
|
||||
this.summary = summary;
|
||||
this.entries = entries;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
|
||||
onNavigate(monthId: string): void {
|
||||
this.router.navigate(['/home', monthId]);
|
||||
}
|
||||
|
||||
openAddEntry(): void {
|
||||
const ref = this.dialog.open(AddEntryModalComponent, {
|
||||
data: { monthId: this.currentMonthId },
|
||||
width: '440px',
|
||||
disableClose: false,
|
||||
});
|
||||
ref.afterClosed().subscribe((result) => {
|
||||
if (result) {
|
||||
this.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onEntryDeleted(entryId: string): void {
|
||||
this.entryService.deleteEntry(entryId).subscribe(() => this.reload());
|
||||
}
|
||||
|
||||
private reload(): void {
|
||||
if (!this.currentMonthId) return;
|
||||
combineLatest([
|
||||
this.monthService.getSummary(this.currentMonthId),
|
||||
this.entryService.getEntries(this.currentMonthId),
|
||||
]).subscribe(([summary, entries]) => {
|
||||
this.summary = summary;
|
||||
this.entries = entries;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<div class="import-page">
|
||||
<mat-card class="import-card">
|
||||
<mat-card-header>
|
||||
<mat-card-title>Import CSV</mat-card-title>
|
||||
<mat-card-subtitle>Importez vos saisies depuis un fichier CSV</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<!-- Zone drag & drop -->
|
||||
<div
|
||||
class="drop-zone"
|
||||
[class.dragover]="isDragOver"
|
||||
(dragover)="onDragOver($event)"
|
||||
(dragleave)="onDragLeave($event)"
|
||||
(drop)="onDrop($event)"
|
||||
(click)="fileInput.click()"
|
||||
>
|
||||
<mat-icon class="drop-icon">folder_open</mat-icon>
|
||||
<p class="drop-text">
|
||||
Glisser-déposer ou <span class="drop-link">sélectionner un fichier .csv</span>
|
||||
</p>
|
||||
<p class="drop-hint" *ngIf="!selectedFile">Format export bancaire (séparateur ;) — colonnes utilisées : Date de comptabilisation, Libelle operation, Sous categorie, Debit, Credit</p>
|
||||
<p class="drop-file-name" *ngIf="selectedFile">📄 {{ selectedFile.name }}</p>
|
||||
<input
|
||||
#fileInput
|
||||
type="file"
|
||||
accept=".csv"
|
||||
style="display:none"
|
||||
(change)="onFileSelected($event)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Sélecteur du mois -->
|
||||
<div class="month-selector">
|
||||
<mat-form-field appearance="outline" class="month-field">
|
||||
<mat-label>Mois cible</mat-label>
|
||||
<mat-select [(ngModel)]="selectedMonthId">
|
||||
<mat-option *ngFor="let m of months" [value]="m.id">
|
||||
{{ formatMonth(m) }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
<!-- Aperçu des 10 premières lignes -->
|
||||
<div class="preview-section" *ngIf="previewRows.length > 0">
|
||||
<h3 class="preview-title">Aperçu ({{ previewRows.length }} première(s) ligne(s))</h3>
|
||||
<div class="preview-table-wrapper">
|
||||
<table class="preview-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th *ngFor="let col of previewColumns">{{ col }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let row of previewRows">
|
||||
<td *ngFor="let col of previewColumns">{{ row[col] }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Barre de progression -->
|
||||
<mat-progress-bar *ngIf="isImporting" mode="indeterminate" class="progress-bar"></mat-progress-bar>
|
||||
|
||||
<!-- Message d'erreur global -->
|
||||
<div class="error-banner" *ngIf="errorMessage">
|
||||
<mat-icon>error_outline</mat-icon>
|
||||
<span>{{ errorMessage }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Rapport d'import -->
|
||||
<div class="result-section" *ngIf="importResult">
|
||||
<div class="result-badges">
|
||||
<span class="badge badge-success">
|
||||
<mat-icon>check_circle</mat-icon>
|
||||
{{ importResult.importedCount }} ligne(s) importée(s)
|
||||
</span>
|
||||
<span class="badge badge-error" *ngIf="importResult.errorCount > 0">
|
||||
<mat-icon>cancel</mat-icon>
|
||||
{{ importResult.errorCount }} erreur(s)
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="error-list" *ngIf="importResult.errors.length > 0">
|
||||
<h4 class="error-list-title">Détail des erreurs</h4>
|
||||
<ul>
|
||||
<li *ngFor="let err of importResult.errors">
|
||||
<span class="error-line">Ligne {{ err.line }}</span> — {{ err.message }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</mat-card-content>
|
||||
|
||||
<mat-card-actions align="end">
|
||||
<button
|
||||
mat-raised-button
|
||||
color="primary"
|
||||
[disabled]="!selectedFile || !selectedMonthId || isImporting"
|
||||
(click)="importCsv()"
|
||||
>
|
||||
<mat-icon>upload</mat-icon>
|
||||
Importer
|
||||
</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
@@ -0,0 +1,235 @@
|
||||
.import-page {
|
||||
padding: 24px;
|
||||
max-width: 860px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.import-card {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
// — Drop zone —
|
||||
|
||||
.drop-zone {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 2px dashed #b0bec5;
|
||||
border-radius: 8px;
|
||||
padding: 40px 24px;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s, background-color 0.2s;
|
||||
background-color: #f7f8fa;
|
||||
user-select: none;
|
||||
margin-bottom: 24px;
|
||||
|
||||
&:hover {
|
||||
border-color: #3b82d4;
|
||||
background-color: #edf4ff;
|
||||
}
|
||||
|
||||
&.dragover {
|
||||
border-color: #3b82d4;
|
||||
background-color: #dbeafe;
|
||||
}
|
||||
}
|
||||
|
||||
.drop-icon {
|
||||
font-size: 48px;
|
||||
height: 48px;
|
||||
width: 48px;
|
||||
color: #78909c;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.drop-text {
|
||||
font-size: 15px;
|
||||
color: #1f2328;
|
||||
margin: 0 0 4px;
|
||||
}
|
||||
|
||||
.drop-link {
|
||||
color: #3b82d4;
|
||||
font-weight: 500;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.drop-hint {
|
||||
font-size: 12px;
|
||||
color: #57606a;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.drop-file-name {
|
||||
font-size: 13px;
|
||||
color: #3b82d4;
|
||||
font-weight: 500;
|
||||
margin: 4px 0 0;
|
||||
}
|
||||
|
||||
// — Month selector —
|
||||
|
||||
.month-selector {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.month-field {
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
// — Preview table —
|
||||
|
||||
.preview-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.preview-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #57606a;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.preview-table-wrapper {
|
||||
overflow-x: auto;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.preview-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 13px;
|
||||
|
||||
th {
|
||||
background-color: #f7f8fa;
|
||||
color: #57606a;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 6px 12px;
|
||||
color: #1f2328;
|
||||
border-bottom: 1px solid #f0f1f3;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
tbody tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
tbody tr:nth-child(even) {
|
||||
background-color: #fafbfc;
|
||||
}
|
||||
}
|
||||
|
||||
// — Progress bar —
|
||||
|
||||
.progress-bar {
|
||||
margin-bottom: 16px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
// — Error banner —
|
||||
|
||||
.error-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
background-color: #fef2f2;
|
||||
border: 1px solid #fecaca;
|
||||
border-radius: 6px;
|
||||
padding: 10px 14px;
|
||||
margin-bottom: 16px;
|
||||
color: #dc2626;
|
||||
font-size: 14px;
|
||||
|
||||
mat-icon {
|
||||
font-size: 18px;
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// — Result section —
|
||||
|
||||
.result-section {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.result-badges {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 14px;
|
||||
border-radius: 20px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
|
||||
mat-icon {
|
||||
font-size: 18px;
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.badge-success {
|
||||
background-color: #d1fae5;
|
||||
color: #065f46;
|
||||
|
||||
mat-icon {
|
||||
color: #059669;
|
||||
}
|
||||
}
|
||||
|
||||
.badge-error {
|
||||
background-color: #fee2e2;
|
||||
color: #991b1b;
|
||||
|
||||
mat-icon {
|
||||
color: #dc2626;
|
||||
}
|
||||
}
|
||||
|
||||
.error-list-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #57606a;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.error-list {
|
||||
background-color: #fff9f9;
|
||||
border: 1px solid #fecaca;
|
||||
border-radius: 6px;
|
||||
padding: 12px 16px;
|
||||
|
||||
ul {
|
||||
margin: 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
li {
|
||||
font-size: 13px;
|
||||
color: #1f2328;
|
||||
padding: 3px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.error-line {
|
||||
font-weight: 600;
|
||||
color: #dc2626;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
|
||||
import Papa from 'papaparse';
|
||||
|
||||
import { EntryService } from '../../core/services/entry.service';
|
||||
import { MonthService } from '../../core/services/month.service';
|
||||
import { Month, ImportResult } from '../../core/models';
|
||||
|
||||
@Component({
|
||||
selector: 'app-import-csv',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
MatCardModule,
|
||||
MatButtonModule,
|
||||
MatSelectModule,
|
||||
MatFormFieldModule,
|
||||
MatProgressBarModule,
|
||||
MatIconModule,
|
||||
],
|
||||
templateUrl: './import-csv.component.html',
|
||||
styleUrls: ['./import-csv.component.scss'],
|
||||
})
|
||||
export class ImportCsvComponent implements OnInit {
|
||||
months: Month[] = [];
|
||||
selectedMonthId: string | null = null;
|
||||
|
||||
selectedFile: File | null = null;
|
||||
previewRows: Record<string, string>[] = [];
|
||||
previewColumns: string[] = [];
|
||||
|
||||
importResult: ImportResult | null = null;
|
||||
isImporting = false;
|
||||
errorMessage: string | null = null;
|
||||
|
||||
isDragOver = false;
|
||||
|
||||
constructor(
|
||||
private entryService: EntryService,
|
||||
private monthService: MonthService,
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.monthService.getMonths().subscribe({
|
||||
next: (months) => (this.months = months),
|
||||
error: () => (this.errorMessage = 'Impossible de charger la liste des mois.'),
|
||||
});
|
||||
}
|
||||
|
||||
onDragOver(event: DragEvent): void {
|
||||
event.preventDefault();
|
||||
this.isDragOver = true;
|
||||
}
|
||||
|
||||
onDragLeave(event: DragEvent): void {
|
||||
event.preventDefault();
|
||||
this.isDragOver = false;
|
||||
}
|
||||
|
||||
onDrop(event: DragEvent): void {
|
||||
event.preventDefault();
|
||||
this.isDragOver = false;
|
||||
const file = event.dataTransfer?.files?.[0] ?? null;
|
||||
if (file) {
|
||||
this.loadFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
onFileSelected(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0] ?? null;
|
||||
if (file) {
|
||||
this.loadFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
// Columns shown in the preview table (subset of the full bank CSV)
|
||||
readonly PREVIEW_COLUMNS = [
|
||||
'Date de comptabilisation',
|
||||
'Libelle operation',
|
||||
'Sous categorie',
|
||||
'Debit',
|
||||
'Credit',
|
||||
];
|
||||
|
||||
private loadFile(file: File): void {
|
||||
this.selectedFile = file;
|
||||
this.importResult = null;
|
||||
this.errorMessage = null;
|
||||
Papa.parse<Record<string, string>>(file, {
|
||||
header: true,
|
||||
delimiter: ';',
|
||||
preview: 10,
|
||||
skipEmptyLines: true,
|
||||
complete: (result) => {
|
||||
this.previewRows = result.data;
|
||||
this.previewColumns = this.PREVIEW_COLUMNS.filter(
|
||||
col => (result.meta.fields ?? []).includes(col)
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
importCsv(): void {
|
||||
if (!this.selectedFile || !this.selectedMonthId) return;
|
||||
this.isImporting = true;
|
||||
this.errorMessage = null;
|
||||
this.importResult = null;
|
||||
this.entryService.importCsv(this.selectedMonthId, this.selectedFile).subscribe({
|
||||
next: (result) => {
|
||||
this.importResult = result;
|
||||
this.isImporting = false;
|
||||
},
|
||||
error: () => {
|
||||
this.errorMessage = 'Une erreur est survenue lors de l\'import. Vérifiez le fichier et réessayez.';
|
||||
this.isImporting = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
formatMonth(m: Month): string {
|
||||
return `${String(m.month).padStart(2, '0')} / ${m.year}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<div class="app-layout">
|
||||
<app-sidebar />
|
||||
<main class="main-content">
|
||||
<router-outlet />
|
||||
</main>
|
||||
</div>
|
||||
@@ -0,0 +1,11 @@
|
||||
.app-layout {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1.5rem;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { SidebarComponent } from '../sidebar/sidebar.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-layout',
|
||||
standalone: true,
|
||||
imports: [RouterOutlet, SidebarComponent],
|
||||
templateUrl: './app-layout.component.html',
|
||||
styleUrls: ['./app-layout.component.scss'],
|
||||
})
|
||||
export class AppLayoutComponent {}
|
||||
@@ -0,0 +1,23 @@
|
||||
<div class="month-nav">
|
||||
<button
|
||||
mat-icon-button
|
||||
[disabled]="!prevMonth"
|
||||
[matTooltip]="prevMonth ? 'Mois précédent' : ''"
|
||||
(click)="goToPrev()"
|
||||
aria-label="Mois précédent"
|
||||
>
|
||||
<mat-icon>chevron_left</mat-icon>
|
||||
</button>
|
||||
|
||||
<span class="month-title">{{ title }}</span>
|
||||
|
||||
<button
|
||||
mat-icon-button
|
||||
[disabled]="!nextMonth"
|
||||
[matTooltip]="nextMonth ? 'Mois suivant' : ''"
|
||||
(click)="goToNext()"
|
||||
aria-label="Mois suivant"
|
||||
>
|
||||
<mat-icon>chevron_right</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
.month-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.month-title {
|
||||
min-width: 180px;
|
||||
text-align: center;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { MatIconButton } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
|
||||
import { Month } from '../../../core/models/month.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-month-nav',
|
||||
standalone: true,
|
||||
imports: [MatIconButton, MatIconModule, MatTooltipModule],
|
||||
templateUrl: './month-nav.component.html',
|
||||
styleUrls: ['./month-nav.component.scss'],
|
||||
})
|
||||
export class MonthNavComponent {
|
||||
@Input() months: Month[] = [];
|
||||
@Input() currentMonthId: string = '';
|
||||
@Output() navigate = new EventEmitter<string>();
|
||||
|
||||
get sorted(): Month[] {
|
||||
return [...this.months].sort((a, b) => {
|
||||
if (a.year !== b.year) return a.year - b.year;
|
||||
return a.month - b.month;
|
||||
});
|
||||
}
|
||||
|
||||
get currentIndex(): number {
|
||||
return this.sorted.findIndex((m) => m.id === this.currentMonthId);
|
||||
}
|
||||
|
||||
get currentMonth(): Month | undefined {
|
||||
return this.sorted[this.currentIndex];
|
||||
}
|
||||
|
||||
get prevMonth(): Month | undefined {
|
||||
const idx = this.currentIndex;
|
||||
return idx > 0 ? this.sorted[idx - 1] : undefined;
|
||||
}
|
||||
|
||||
get nextMonth(): Month | undefined {
|
||||
const idx = this.currentIndex;
|
||||
return idx < this.sorted.length - 1 ? this.sorted[idx + 1] : undefined;
|
||||
}
|
||||
|
||||
get title(): string {
|
||||
if (!this.currentMonth) return '';
|
||||
return new Intl.DateTimeFormat('fr-FR', { month: 'long', year: 'numeric' }).format(
|
||||
new Date(this.currentMonth.year, this.currentMonth.month - 1)
|
||||
);
|
||||
}
|
||||
|
||||
goToPrev(): void {
|
||||
if (this.prevMonth) this.navigate.emit(this.prevMonth.id);
|
||||
}
|
||||
|
||||
goToNext(): void {
|
||||
if (this.nextMonth) this.navigate.emit(this.nextMonth.id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<nav class="sidebar-nav">
|
||||
<div class="sidebar-header">
|
||||
<span class="sidebar-title">Suivi Dépenses</span>
|
||||
</div>
|
||||
|
||||
<mat-nav-list class="nav-links">
|
||||
<a mat-list-item routerLink="/home/current" routerLinkActive="active">
|
||||
<mat-icon matListItemIcon>home</mat-icon>
|
||||
<span matListItemTitle>Accueil</span>
|
||||
</a>
|
||||
<a mat-list-item routerLink="/admin" routerLinkActive="active">
|
||||
<mat-icon matListItemIcon>settings</mat-icon>
|
||||
<span matListItemTitle>Administration</span>
|
||||
</a>
|
||||
<a mat-list-item routerLink="/import" routerLinkActive="active">
|
||||
<mat-icon matListItemIcon>upload_file</mat-icon>
|
||||
<span matListItemTitle>Import CSV</span>
|
||||
</a>
|
||||
</mat-nav-list>
|
||||
|
||||
<mat-divider />
|
||||
|
||||
<div class="months-section">
|
||||
<span class="months-label">Mois</span>
|
||||
<mat-nav-list class="months-list">
|
||||
@for (month of (months$ | async) ?? []; track month.id) {
|
||||
<a
|
||||
mat-list-item
|
||||
[routerLink]="['/home', month.id]"
|
||||
routerLinkActive="active"
|
||||
class="month-item"
|
||||
>
|
||||
<span matListItemTitle>{{ monthLabel(month) }}</span>
|
||||
</a>
|
||||
}
|
||||
</mat-nav-list>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-footer">
|
||||
<button mat-stroked-button class="new-month-btn" (click)="openNewMonthModal()">
|
||||
<mat-icon>add</mat-icon>
|
||||
Nouveau mois
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -0,0 +1,107 @@
|
||||
:host {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 210px;
|
||||
flex-shrink: 0;
|
||||
height: 100vh;
|
||||
background-color: #1e1e2e;
|
||||
color: #cdd6f4;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 1.25rem 1rem 0.75rem;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.sidebar-title {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: #a6adc8;
|
||||
}
|
||||
|
||||
.nav-links,
|
||||
.months-list {
|
||||
--mdc-list-list-item-label-text-color: #cdd6f4;
|
||||
--mdc-list-list-item-leading-icon-color: #a6adc8;
|
||||
|
||||
mat-icon {
|
||||
color: #a6adc8;
|
||||
}
|
||||
}
|
||||
|
||||
.months-section {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.months-label {
|
||||
display: block;
|
||||
padding: 0.75rem 1rem 0.25rem;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: #585b70;
|
||||
}
|
||||
|
||||
.months-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
// Active state for nav items
|
||||
::ng-deep .mat-mdc-list-item.active,
|
||||
::ng-deep a.active .mdc-list-item__primary-text {
|
||||
background-color: rgba(137, 80, 252, 0.25) !important;
|
||||
color: #cba6f7 !important;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
::ng-deep mat-nav-list a.active {
|
||||
background-color: rgba(137, 80, 252, 0.25);
|
||||
border-radius: 6px;
|
||||
|
||||
.mdc-list-item__primary-text {
|
||||
color: #cba6f7;
|
||||
}
|
||||
|
||||
mat-icon {
|
||||
color: #cba6f7;
|
||||
}
|
||||
}
|
||||
|
||||
mat-divider {
|
||||
border-color: rgba(255, 255, 255, 0.08) !important;
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.sidebar-footer {
|
||||
padding: 0.75rem 1rem 1rem;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.new-month-btn {
|
||||
width: 100%;
|
||||
color: #cba6f7 !important;
|
||||
border-color: rgba(203, 166, 247, 0.4) !important;
|
||||
|
||||
mat-icon {
|
||||
color: #cba6f7;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: rgba(137, 80, 252, 0.15) !important;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { Router, RouterLink, RouterLinkActive } from '@angular/router';
|
||||
import { AsyncPipe, NgFor, NgClass } from '@angular/common';
|
||||
import { Observable } from 'rxjs';
|
||||
import { MatListModule } from '@angular/material/list';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
|
||||
import { MonthService } from '../../../core/services/month.service';
|
||||
import { Month } from '../../../core/models/month.model';
|
||||
import { NewMonthModalComponent } from '../../modals/new-month-modal/new-month-modal.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-sidebar',
|
||||
standalone: true,
|
||||
imports: [
|
||||
RouterLink,
|
||||
RouterLinkActive,
|
||||
AsyncPipe,
|
||||
NgFor,
|
||||
NgClass,
|
||||
MatListModule,
|
||||
MatIconModule,
|
||||
MatButtonModule,
|
||||
MatDividerModule,
|
||||
],
|
||||
templateUrl: './sidebar.component.html',
|
||||
styleUrls: ['./sidebar.component.scss'],
|
||||
})
|
||||
export class SidebarComponent implements OnInit {
|
||||
private monthService = inject(MonthService);
|
||||
private router = inject(Router);
|
||||
private dialog = inject(MatDialog);
|
||||
|
||||
months$!: Observable<Month[]>;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadMonths();
|
||||
}
|
||||
|
||||
loadMonths(): void {
|
||||
this.months$ = this.monthService.getMonths();
|
||||
}
|
||||
|
||||
openNewMonthModal(): void {
|
||||
const ref = this.dialog.open(NewMonthModalComponent, { width: '420px' });
|
||||
ref.afterClosed().subscribe((newMonth: Month | undefined) => {
|
||||
this.loadMonths();
|
||||
if (newMonth) {
|
||||
this.router.navigate(['/home', newMonth.id]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
monthLabel(m: Month): string {
|
||||
return new Intl.DateTimeFormat('fr-FR', { month: 'long', year: 'numeric' }).format(
|
||||
new Date(m.year, m.month - 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<h2 mat-dialog-title>Nouveau mois</h2>
|
||||
|
||||
<mat-dialog-content>
|
||||
<form [formGroup]="form" class="modal-form">
|
||||
|
||||
@if (error) {
|
||||
<p class="form-error">{{ error }}</p>
|
||||
}
|
||||
|
||||
<mat-form-field appearance="outline" class="full-width">
|
||||
<mat-label>Année</mat-label>
|
||||
<input matInput type="number" formControlName="year" min="2000" />
|
||||
@if (form.get('year')?.invalid && form.get('year')?.touched) {
|
||||
<mat-error>Année invalide (minimum 2000)</mat-error>
|
||||
}
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline" class="full-width">
|
||||
<mat-label>Mois</mat-label>
|
||||
<mat-select formControlName="month">
|
||||
@for (opt of monthOptions; track opt.value) {
|
||||
<mat-option [value]="opt.value">{{ opt.label }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
@if (form.get('month')?.invalid && form.get('month')?.touched) {
|
||||
<mat-error>Sélectionnez un mois valide</mat-error>
|
||||
}
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline" class="full-width">
|
||||
<mat-label>Salaire par défaut (€)</mat-label>
|
||||
<input matInput type="number" formControlName="defaultSalary" min="0" />
|
||||
@if (form.get('defaultSalary')?.invalid && form.get('defaultSalary')?.touched) {
|
||||
<mat-error>Le salaire doit être ≥ 0</mat-error>
|
||||
}
|
||||
</mat-form-field>
|
||||
|
||||
</form>
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button (click)="cancel()">Annuler</button>
|
||||
<button
|
||||
mat-flat-button
|
||||
color="primary"
|
||||
[disabled]="form.invalid || submitting"
|
||||
(click)="submit()"
|
||||
>
|
||||
{{ submitting ? 'Création…' : 'Créer' }}
|
||||
</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,16 @@
|
||||
.modal-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding-top: 0.5rem;
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form-error {
|
||||
color: var(--mat-sys-error, #b00020);
|
||||
font-size: 0.85rem;
|
||||
margin: 0 0 0.5rem;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { ReactiveFormsModule, FormBuilder, Validators } from '@angular/forms';
|
||||
import { MatDialogRef, MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
|
||||
import { MonthService } from '../../../core/services/month.service';
|
||||
import { SettingsService } from '../../../core/services/settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-new-month-modal',
|
||||
standalone: true,
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatSelectModule,
|
||||
MatButtonModule,
|
||||
],
|
||||
templateUrl: './new-month-modal.component.html',
|
||||
styleUrls: ['./new-month-modal.component.scss'],
|
||||
})
|
||||
export class NewMonthModalComponent implements OnInit {
|
||||
private fb = inject(FormBuilder);
|
||||
private monthService = inject(MonthService);
|
||||
private settingsService = inject(SettingsService);
|
||||
private dialogRef = inject(MatDialogRef<NewMonthModalComponent>);
|
||||
|
||||
readonly monthOptions = [
|
||||
{ value: 1, label: 'Janvier' },
|
||||
{ value: 2, label: 'Février' },
|
||||
{ value: 3, label: 'Mars' },
|
||||
{ value: 4, label: 'Avril' },
|
||||
{ value: 5, label: 'Mai' },
|
||||
{ value: 6, label: 'Juin' },
|
||||
{ value: 7, label: 'Juillet' },
|
||||
{ value: 8, label: 'Août' },
|
||||
{ value: 9, label: 'Septembre' },
|
||||
{ value: 10, label: 'Octobre' },
|
||||
{ value: 11, label: 'Novembre' },
|
||||
{ value: 12, label: 'Décembre' },
|
||||
];
|
||||
|
||||
form = this.fb.group({
|
||||
year: [
|
||||
new Date().getFullYear(),
|
||||
[Validators.required, Validators.min(2000)],
|
||||
],
|
||||
month: [
|
||||
(new Date().getMonth() + 2 > 12 ? 1 : new Date().getMonth() + 2),
|
||||
[Validators.required, Validators.min(1), Validators.max(12)],
|
||||
],
|
||||
defaultSalary: [
|
||||
0,
|
||||
[Validators.required, Validators.min(0)],
|
||||
],
|
||||
});
|
||||
|
||||
submitting = false;
|
||||
error: string | null = null;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.settingsService.getDefaultSalary().subscribe({
|
||||
next: (salary) => this.form.patchValue({ defaultSalary: salary }),
|
||||
});
|
||||
}
|
||||
|
||||
submit(): void {
|
||||
if (this.form.invalid || this.submitting) return;
|
||||
this.submitting = true;
|
||||
this.error = null;
|
||||
|
||||
const { year, month, defaultSalary } = this.form.value;
|
||||
this.monthService
|
||||
.createMonth({ year: year!, month: month!, defaultSalary: defaultSalary! })
|
||||
.subscribe({
|
||||
next: (newMonth) => {
|
||||
this.submitting = false;
|
||||
this.dialogRef.close(newMonth);
|
||||
},
|
||||
error: () => {
|
||||
this.submitting = false;
|
||||
this.error = 'Erreur lors de la création du mois. Veuillez réessayer.';
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Month } from '../../core/models/month.model';
|
||||
|
||||
@Pipe({
|
||||
name: 'monthTitle',
|
||||
standalone: true,
|
||||
})
|
||||
export class MonthTitlePipe implements PipeTransform {
|
||||
transform(month: Month): string {
|
||||
if (!month) return '';
|
||||
return new Intl.DateTimeFormat('fr-FR', { month: 'long', year: 'numeric' }).format(
|
||||
new Date(month.year, month.month - 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Suivi Dépenses</title>
|
||||
<base href="/">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,6 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { appConfig } from './app/app.config';
|
||||
import { AppComponent } from './app/app.component';
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig)
|
||||
.catch((err) => console.error(err));
|
||||
@@ -0,0 +1,35 @@
|
||||
@use '@angular/material' as mat;
|
||||
|
||||
@include mat.core();
|
||||
|
||||
$primary: mat.m2-define-palette(mat.$m2-deep-purple-palette, 600, 300, 900);
|
||||
$accent: mat.m2-define-palette(mat.$m2-purple-palette, A200, A100, A400);
|
||||
$warn: mat.m2-define-palette(mat.$m2-red-palette);
|
||||
|
||||
$theme: mat.m2-define-light-theme(
|
||||
(
|
||||
color: (
|
||||
primary: $primary,
|
||||
accent: $accent,
|
||||
warn: $warn,
|
||||
),
|
||||
typography: mat.m2-define-typography-config(),
|
||||
density: 0,
|
||||
)
|
||||
);
|
||||
|
||||
@include mat.all-component-themes($theme);
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
font-family: Roboto, 'Helvetica Neue', sans-serif;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/app",
|
||||
"types": []
|
||||
},
|
||||
"files": [
|
||||
"src/main.ts"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist/out-tsc",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": true,
|
||||
"declaration": false,
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "bundler",
|
||||
"importHelpers": true,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"useDefineForClassFields": false,
|
||||
"lib": ["ES2022", "dom"]
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user