diff --git a/frontend/Exence/src/app/private/dashboard/categories/categories.component.html b/frontend/Exence/src/app/private/dashboard/categories/categories.component.html index f4320f9..fbf62c9 100644 --- a/frontend/Exence/src/app/private/dashboard/categories/categories.component.html +++ b/frontend/Exence/src/app/private/dashboard/categories/categories.component.html @@ -1,5 +1,5 @@ - @if (categories() && categories().length) { + @if (hasTransactions) { Top categories
- @for (category of categories(); track category.id) { + @for (category of categorySummaries(); track category.id) {
-
+
{{ category.emoji }} {{ category.name }}
-
{{ calcPercentage(category.totalAmount) }}%
+
+ {{ calcPercentage(category.totalAmount) }}% +
- +
}
} @else { - -
-

Add categories to discover your spending patterns!

-
-
- - Create - + @if (hasCategories) { + +
+

+ Add transactions to discover your spending patterns! +

+
+
+ + Create transaction + + } @else { + +
+

+ Add categories to discover your spending patterns! +

+
+
+ + Create category + + } } diff --git a/frontend/Exence/src/app/private/dashboard/categories/categories.component.ts b/frontend/Exence/src/app/private/dashboard/categories/categories.component.ts index de6b1dd..e426af0 100644 --- a/frontend/Exence/src/app/private/dashboard/categories/categories.component.ts +++ b/frontend/Exence/src/app/private/dashboard/categories/categories.component.ts @@ -1,4 +1,4 @@ -import { Component, inject, input } from '@angular/core'; +import { Component, inject, input, output } from '@angular/core'; import { MatCardModule } from '@angular/material/card'; import { MatDialog } from '@angular/material/dialog'; import { MatProgressBarModule } from '@angular/material/progress-bar'; @@ -9,6 +9,8 @@ import { ButtonComponent } from '../../../shared/button/button.component'; import { DisplaySizeService } from '../../../shared/display-size.service'; import { SnackbarService } from '../../../shared/snackbar/snackbar.service'; import { CreateCategoryDialogComponent } from '../../transactions-and-categories/create-category-dialog/create-category-dialog.component'; +import { CreateTransactionDialogComponent, CreateTransactionDialogData } from '../../transactions-and-categories/create-transaction-dialog/create-transaction-dialog.component'; +import { Transaction } from 'src/app/data-model/modules/transaction/Transaction'; // TODO move to interval filter component when created export enum DateInterval { @@ -34,19 +36,44 @@ export class CategoriesComponent extends BaseComponent { private readonly dialog = inject(MatDialog); totalExpense = input.required(); - categories = input.required(); + categorySummaries = input.required(); + categories = input.required(); - openCreateCategoryDialog(): void { + dataChangedEvent = output(); + + public openCreateCategoryDialog(): void { this.dialog.open( CreateCategoryDialogComponent, undefined - ).afterClosed().subscribe((newCategory) => { + ).afterClosed().subscribe((newCategory?: Category) => { if (newCategory) { this.snackbarService.showSuccess(`Category '${newCategory.emoji}' created successfully!`); + this.dataChangedEvent.emit(); } }); } + public openCreateTransactionDialog(): void { + this.dialog.open( + CreateTransactionDialogComponent, undefined + ).afterClosed().subscribe( + (newTransaction?: Transaction) => { + if (newTransaction) { + this.snackbarService.showSuccess(`Transaction '${newTransaction.title.slice(0, 10)}${newTransaction.title.length > 10 ? '...' : ''}' created successfully!`); + this.dataChangedEvent.emit(); + } + } + ); + } + calcPercentage(amount: number): number { return Math.floor((amount / this.totalExpense()) * 100); } + + get hasCategories(): boolean { + return this.categories().length > 0; + } + + get hasTransactions(): boolean { + return this.categorySummaries().length > 0; + } } diff --git a/frontend/Exence/src/app/private/dashboard/dashboard.component.html b/frontend/Exence/src/app/private/dashboard/dashboard.component.html index 1768232..5f1c88a 100644 --- a/frontend/Exence/src/app/private/dashboard/dashboard.component.html +++ b/frontend/Exence/src/app/private/dashboard/dashboard.component.html @@ -38,7 +38,9 @@