Skip to content

Commit 41e4d86

Browse files
committed
update code
1 parent f9fa419 commit 41e4d86

8 files changed

Lines changed: 357 additions & 107 deletions

File tree

documentation/components/CalendarComponent.html

Lines changed: 255 additions & 78 deletions
Large diffs are not rendered by default.

documentation/coverage.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,9 @@
515515
</td>
516516
<td>component</td>
517517
<td>CalendarComponent</td>
518-
<td align="right" data-sort="100">
519-
<span class="coverage-percent">100 %</span>
520-
<span class="coverage-count">(34/34)</span>
518+
<td align="right" data-sort="97">
519+
<span class="coverage-percent">97 %</span>
520+
<span class="coverage-count">(35/36)</span>
521521
</td>
522522
</tr>
523523
<tr class="very-good">

documentation/injectables/StorageService.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ <h3 id="inputs">
15681568
has_music_url_access: false,
15691569
has_ai_access: false,
15701570
rose_amount: 1000,
1571-
emerald_amount: 300,
1571+
emerald_amount: 500,
15721572
}</code>
15731573
</td>
15741574
</tr>
@@ -1666,7 +1666,7 @@ <h3 id="inputs">
16661666
has_music_url_access: false,
16671667
has_ai_access: false,
16681668
rose_amount: 1000,
1669-
emerald_amount: 300,
1669+
emerald_amount: 500,
16701670
};
16711671

16721672
/** Schema for budget */

documentation/interfaces/Schema.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ <h3 id="inputs">Indexable</h3>
258258
has_music_url_access: false,
259259
has_ai_access: false,
260260
rose_amount: 1000,
261-
emerald_amount: 300,
261+
emerald_amount: 500,
262262
};
263263

264264
/** Schema for budget */

documentation/js/search/search_index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/features/calendar/calendar.component.html

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
class="max-w-[300px] md:max-w-md mx-auto w-full border border-[var(--input-border)] rounded-lg overflow-hidden text-sm">
6969

7070
<!-- Table Header -->
71-
<div class="grid grid-cols-[40%_15%_30%_15%] bg-[var(--color-gray)] text-[var(--color-text)] font-semibold py-2 text-left">
71+
<div
72+
class="grid grid-cols-[40%_15%_30%_15%] bg-[var(--color-gray)] text-[var(--color-text)] font-semibold py-2 text-left">
7273
<span class="pl-3">Color</span>
7374
<span class="text-center">Days</span>
7475
<span class="text-center">Amount</span>
@@ -92,16 +93,18 @@
9293
<div class="font-medium text-center">{{ currency }} {{ item.amount }}</div>
9394
<!-- Edit button (perfectly centered) -->
9495
<div class="flex items-center justify-center">
95-
<button *ngIf="!(item.text === 'No expenses')" (click)="openEditHeapMapModel(item.color)"
96-
class="w-7 h-7 flex items-center justify-center rounded-full hover:bg-[var(--list-hover)] transition-all duration-200 ease-in-out">
96+
<button *ngIf="!(item.text === 'No expenses' || item.color === 'bg-[var(--color-amber)]')"
97+
(click)="openEditHeapMapModel(item.color)"
98+
class="w-[14px] h-[14px] flex items-center justify-center rounded-full transition-all duration-200 ease-in-out">
9799
<img src="assets/img/icon/icons8-edit-50.png" alt="edit"
98100
class="w-[14px] h-[14px] pointer-events-none" style="filter: var(--icon-color2);" />
99101
</button>
100102
</div>
101103
</div>
102104

103105
<!-- Total Row -->
104-
<div class="grid grid-cols-[40%_15%_30%_15%] items-center py-2 border-t border-[var(--input-border)] text-[var(--color-text)] font-semibold">
106+
<div
107+
class="grid grid-cols-[40%_15%_30%_15%] items-center py-2 border-t border-[var(--input-border)] text-[var(--color-text)] font-semibold">
105108
<span class="col-span-2 text-center">Total</span>
106109
<span class="text-center text-green-500">{{ currency }} {{ totalExpenses }}</span>
107110
</div>
@@ -145,8 +148,23 @@ <h2 class="text-lg font-bold text-[var(--color-text)]">{{ modalTitle }}</h2>
145148
<app-form-model *ngIf="showEditHeatMapModel" [label]="'Edit HeatMap'" (close)="closeEditHeatMapModel()">
146149
<form [formGroup]="heatMapForm" (ngSubmit)="updateHeatMap()">
147150
<label class="block mb-1 font-medium">Amount</label>
148-
<input formControlName="amount" type="number" autocomplete="off" min="0" max="100000000" placeholder="Enter Amount"
151+
<input formControlName="amount" type="number" [min]="minHeatMapAmount" [max]="maxHeatMapAmount"
152+
placeholder="Enter Amount"
149153
class="w-full p-2 rounded border text-[var(--input-text)] bg-[var(--input-bg)] border-[var(--input-border)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-color)] transition-all duration-200" />
154+
<div class="error-message text-[var(--color-error)]"
155+
*ngIf="heatMapForm.get('amount')?.touched && heatMapForm.get('amount')?.errors?.['min'] && isEmeraldModelOpen">
156+
Amount cannot be negative or 0
157+
</div>
158+
159+
<div class="error-message text-[var(--color-error)]"
160+
*ngIf="heatMapForm.get('amount')?.touched && heatMapForm.get('amount')?.errors?.['min'] && isRoseModelOpen">
161+
Amount should be between {{ minHeatMapAmount }} and {{ maxHeatMapAmount }}
162+
</div>
163+
164+
<div class="error-message text-[var(--color-error)]"
165+
*ngIf="heatMapForm.get('amount')?.touched && heatMapForm.get('amount')?.errors?.['max']">
166+
Amount should be between {{ minHeatMapAmount }} and {{ maxHeatMapAmount }}
167+
</div>
150168
<div class="error-message text-[var(--color-error)]"
151169
*ngIf="heatMapForm.get('amount')?.touched && heatMapForm.get('amount')?.errors?.['required']">
152170
Amount is required
@@ -157,4 +175,4 @@ <h2 class="text-lg font-bold text-[var(--color-text)]">{{ modalTitle }}</h2>
157175
<button type="submit" class="px-4 py-2 bg-[var(--color-accent)] text-white rounded">Update</button>
158176
</div>
159177
</form>
160-
</app-form-model>
178+
</app-form-model>

src/app/features/calendar/calendar.component.ts

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,32 @@ export class CalendarComponent implements OnInit {
6565
* Each item contains the color category, total days, and total amount
6666
* used to render the heatmap legend and summary table.
6767
*/
68-
heatmapSummary: HeatmapSummary[] = [];
68+
heatmapSummary: HeatmapSummary[] = [
69+
{
70+
color: 'bg-[var(--color-rose)]',
71+
days: 0,
72+
amount: 0,
73+
text: ''
74+
},
75+
{
76+
color: 'bg-[var(--color-amber)]',
77+
days: 0,
78+
amount: 0,
79+
text: ''
80+
},
81+
{
82+
color: 'bg-[var(--color-emerald)]',
83+
days: 0,
84+
amount: 0,
85+
text: ''
86+
},
87+
{
88+
color: 'bg-[var(--color-gray)]',
89+
days: 0,
90+
amount: 0,
91+
text: ''
92+
}
93+
];
6994

7095
/** Controls the visibility of the Edit Heatmap modal */
7196
showEditHeatMapModel = false;
@@ -79,8 +104,11 @@ export class CalendarComponent implements OnInit {
79104
/** Tracks whether the Emerald color modal is currently open */
80105
isEmeraldModelOpen: boolean = false;
81106

82-
/** Tracks whether the Amber color modal is currently open */
83-
isAmberModelOpen: boolean = false;
107+
/** Defines the minimum allowed value for the heatmap amount input field in the edit modal, used for form validation. */
108+
minHeatMapAmount = 0;
109+
110+
/** Defines the maximum allowed value for the heatmap amount input field in the edit modal, used for form validation. */
111+
maxHeatMapAmount = 0;
84112

85113
/**
86114
* Creates an instance of CalendarComponent.
@@ -134,7 +162,7 @@ export class CalendarComponent implements OnInit {
134162
*/
135163
renderCalendar(year: number, month: number): void {
136164
this.calendarDays = [];
137-
this.heatmapSummary = [];
165+
this.heatmapSummary = this.resetHeatmapSummary();
138166
const today = new Date(this.configService.getLocalTime());
139167
const firstDay = new Date(year, month, 1).getDay();
140168
const daysInMonth = new Date(year, month + 1, 0).getDate();
@@ -232,7 +260,7 @@ export class CalendarComponent implements OnInit {
232260
private getHeatClass(amount: number): string {
233261
if (this.isShowHeatmap === false) return 'bg-[var(--color-surface)]';
234262
const rose_amount = this.userService.getValue<number>('rose_amount') ?? 1000;
235-
const emerald_amount = this.userService.getValue<number>('emerald_amount') ?? 300;
263+
const emerald_amount = this.userService.getValue<number>('emerald_amount') ?? 500;
236264
if (amount === 0) {
237265
this.addOrUpdateHeatMapSummary('bg-[var(--color-gray)]', amount, 'No expenses')
238266
return 'bg-[var(--color-gray)]';
@@ -282,6 +310,7 @@ export class CalendarComponent implements OnInit {
282310
if (existing) {
283311
existing.days += 1;
284312
existing.amount += amount;
313+
existing.text = message;
285314
} else {
286315
this.heatmapSummary.push({
287316
color: color,
@@ -300,7 +329,6 @@ export class CalendarComponent implements OnInit {
300329
this.showEditHeatMapModel = false;
301330
this.isEmeraldModelOpen = false;
302331
this.isRoseModelOpen = false;
303-
this.isAmberModelOpen = false;
304332
}
305333

306334
/**
@@ -314,20 +342,18 @@ export class CalendarComponent implements OnInit {
314342
this.heatMapForm.reset({
315343
amount: this.userService.getValue<number>('rose_amount') ?? 1000,
316344
});
345+
this.minHeatMapAmount = (this.userService.getValue<number>('emerald_amount') ?? 500) + 1;
346+
this.maxHeatMapAmount = 100000000 - 1;
317347
this.isRoseModelOpen = true;
318348
}
319349
if (color === 'bg-[var(--color-emerald)]') {
320350
this.heatMapForm.reset({
321-
amount: this.userService.getValue<number>('emerald_amount') ?? 300,
351+
amount: this.userService.getValue<number>('emerald_amount') ?? 500,
322352
});
353+
this.minHeatMapAmount = 1;
354+
this.maxHeatMapAmount = (this.userService.getValue<number>('rose_amount') ?? 1000) - 1;
323355
this.isEmeraldModelOpen = true;
324356
}
325-
if (color === 'bg-[var(--color-amber)]') {
326-
this.heatMapForm.reset({
327-
amount: this.userService.getValue<number>('emerald_amount') ?? 300,
328-
});
329-
this.isAmberModelOpen = true;
330-
}
331357
this.showEditHeatMapModel = !this.showEditHeatMapModel;
332358
}
333359

@@ -341,7 +367,7 @@ export class CalendarComponent implements OnInit {
341367
return;
342368
}
343369
const { amount } = this.heatMapForm.value;
344-
if (this.isEmeraldModelOpen || this.isAmberModelOpen) {
370+
if (this.isEmeraldModelOpen) {
345371
this.userService.update('emerald_amount', amount);
346372
}
347373
if (this.isRoseModelOpen) {
@@ -350,4 +376,33 @@ export class CalendarComponent implements OnInit {
350376
this.renderCalendar(this.currentYear, this.currentMonth);
351377
this.closeEditHeatMapModel();
352378
}
379+
380+
resetHeatmapSummary(): HeatmapSummary[] {
381+
const rose_amount = this.userService.getValue<number>('rose_amount') ?? 1000;
382+
const emerald_amount = this.userService.getValue<number>('emerald_amount') ?? 500;
383+
this.heatmapSummary = this.heatmapSummary.map(item => {
384+
if (item.color === 'bg-[var(--color-rose)]') {
385+
item.days = 0;
386+
item.amount = 0;
387+
item.text = `> ${rose_amount}`;
388+
}
389+
if (item.color === 'bg-[var(--color-emerald)]') {
390+
item.days = 0;
391+
item.amount = 0;
392+
item.text = `< ${emerald_amount}`;
393+
}
394+
if (item.color === 'bg-[var(--color-amber)]') {
395+
item.days = 0;
396+
item.amount = 0;
397+
item.text = `${emerald_amount} - ${rose_amount}`;
398+
}
399+
if (item.color === 'bg-[var(--color-gray)]') {
400+
item.days = 0;
401+
item.amount = 0;
402+
item.text = 'No expenses';
403+
}
404+
return item;
405+
})
406+
return this.heatmapSummary;
407+
}
353408
}

src/app/service/localStorage/storage.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class StorageService {
7171
has_music_url_access: false,
7272
has_ai_access: false,
7373
rose_amount: 1000,
74-
emerald_amount: 300,
74+
emerald_amount: 500,
7575
};
7676

7777
/** Schema for budget */

0 commit comments

Comments
 (0)