Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<mat-card class="h-100 categories">
@if (categories() && categories().length) {
@if (hasTransactions) {
<mat-card-header>
<mat-card-title
class="d-flex flex-row flex-nowrap gap-2 justify-content-between align-items-center mb-2 w-100"
Expand All @@ -15,37 +15,66 @@ <h2 class="header-2 m-0">Top categories</h2>
</mat-card-header>
<mat-card-content>
<div class="d-flex flex-column gap-4">
@for (category of categories(); track category.id) {
@for (category of categorySummaries(); track category.id) {
<div class="d-flex flex-column gap-1 align-items-center">
<div class="d-flex flex-row flex-nowrap justify-content-between align-items-center w-100">
<div
class="d-flex flex-row flex-nowrap justify-content-between align-items-center w-100"
>
<div class="d-flex flex-row flex-nowrap gap-2">
<span class="">{{ category.emoji }}</span>
{{ category.name }}
</div>

<div class="fw-semibold">{{ calcPercentage(category.totalAmount) }}%</div>
<div class="fw-semibold">
{{ calcPercentage(category.totalAmount) }}%
</div>
</div>
<mat-progress-bar [value]="calcPercentage(category.totalAmount)" />
<mat-progress-bar
[value]="calcPercentage(category.totalAmount)"
/>
</div>
}
</div>
</mat-card-content>
} @else {
<mat-card-content>
<div class="d-flex align-items-center justify-content-center">
<h2 class="header-2 text-center">Add categories to discover your spending patterns!</h2>
</div>
</mat-card-content>
<mat-card-actions class="justify-content-center">
<ex-button
color="primary"
matIcon="add"
collapsedStyle="outlined"
collapseUnder="md"
filled
(click)="openCreateCategoryDialog()"
>Create</ex-button
>
</mat-card-actions>
@if (hasCategories) {
<mat-card-content>
<div class="d-flex align-items-center justify-content-center">
<h2 class="header-2 text-center">
Add transactions to discover your spending patterns!
</h2>
</div>
</mat-card-content>
<mat-card-actions class="justify-content-center">
<ex-button
color="primary"
matIcon="add"
collapsedStyle="outlined"
collapseUnder="md"
filled
(click)="openCreateTransactionDialog()"
>Create transaction</ex-button
>
</mat-card-actions>
} @else {
<mat-card-content>
<div class="d-flex align-items-center justify-content-center">
<h2 class="header-2 text-center">
Add categories to discover your spending patterns!
</h2>
</div>
</mat-card-content>
<mat-card-actions class="justify-content-center">
<ex-button
color="primary"
matIcon="add"
collapsedStyle="outlined"
collapseUnder="md"
filled
(click)="openCreateCategoryDialog()"
>Create category</ex-button
>
</mat-card-actions>
}
}
</mat-card>
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand All @@ -34,19 +36,44 @@ export class CategoriesComponent extends BaseComponent {
private readonly dialog = inject(MatDialog);

totalExpense = input.required<number>();
categories = input.required<CategorySummaryResponse[]>();
categorySummaries = input.required<CategorySummaryResponse[]>();
categories = input.required<Category[]>();

openCreateCategoryDialog(): void {
dataChangedEvent = output<void>();

public openCreateCategoryDialog(): void {
this.dialog.open<CreateCategoryDialogComponent, undefined, Category>(
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, CreateTransactionDialogData, Transaction>(
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Az Exenceben mi követünk egy kód sorrendet ts fileok esetén amire van is eslint config, ami ahogy látom neked most nem nagyon akar működni.

fieldek (erre nincs külön, de itt is próbáljuk tartani a private readonly -> private -> readonly/public sorrendet tartani)
getterek, setterek
constructor
public methodok
private methodok

Próbáld meg, hogy Ctrl + Shift + P és Restart ESLint Server ezzel jónak kellene lennie.

  • meggondoltam magam legyenek inkább computed valuek, jobbak mint a getterek mert nem számtjuk ki őket minden rerendernél, hanem cachelve vannak és csak akkor számítódnaki ki újra, ha az a dolog változik amit benne használunk (mondjuk itt a categories InputSignal)

return this.categories().length > 0;
}

get hasTransactions(): boolean {
return this.categorySummaries().length > 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nekem ez is megfelel, rád van bízva megváltoztatod-e de én a legtöbb helyen így csinálom:

Suggested change
return this.categorySummaries().length > 0;
return !!this.categorySummaries().length;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
<ex-categories
class="h-100"
[totalExpense]="totals.totalExpense"
[categories]="topCategories!"
[categorySummaries]="topCategories!"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legyen konzisztensen topCategories.

[categories]="categories"
(dataChangedEvent)="onDataChanged()"
/>
</div>

Expand Down
Loading