From eae411d9b92581ef0997beda4dd00e4502134973 Mon Sep 17 00:00:00 2001 From: karthik Date: Wed, 23 Jul 2025 14:54:25 +0530 Subject: [PATCH] feat : added erase option functionality --- .../selection.service/selection.service.ts | 44 ++++++++++++++++--- .../touch-pad-menu.component.html | 2 +- .../touch-pad-menu.component.ts | 5 +++ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/btc-UI/src/app/components/selection.service/selection.service.ts b/btc-UI/src/app/components/selection.service/selection.service.ts index bfd8de7..030be3d 100644 --- a/btc-UI/src/app/components/selection.service/selection.service.ts +++ b/btc-UI/src/app/components/selection.service/selection.service.ts @@ -10,9 +10,11 @@ export interface SelectionData { @Injectable({ providedIn: 'root' }) export class SelectionService { + // Stores finalized selections private selections = new BehaviorSubject([]); selections$ = this.selections.asObservable(); + // Stores current "in-progress" row private currentRow = new BehaviorSubject({ label: '', numbers: [], @@ -21,27 +23,55 @@ export class SelectionService { }); currentRow$ = this.currentRow.asObservable(); + // ✅ Update only part of the current row (label / numbers / value) updatePartial(update: Partial) { const current = this.currentRow.value; - this.currentRow.next({ ...current, ...update }); + + const updated: SelectionData = { + ...current, + ...update + }; + + // Recalculate total only if both value and numbers exist + if (updated.numbers.length > 0 && updated.value > 0) { + updated.total = updated.numbers.length * updated.value * 10; + } else { + updated.total = 0; + } + + this.currentRow.next(updated); } + // ✅ Finalize the current row and push it to the finalized list finalizeCurrentRow() { const completed = this.currentRow.value; - if (!completed.label || completed.numbers.length === 0 || !completed.value) return; + + // Validation: must have label, numbers, and valid value + if (!completed.label || completed.numbers.length === 0 || completed.value <= 0) return; const total = completed.numbers.length * completed.value * 10; - const finalRow = { ...completed, total }; + const finalRow: SelectionData = { ...completed, total }; - const updated = [...this.selections.value, finalRow]; - this.selections.next(updated); + const updatedSelections = [...this.selections.value, finalRow]; + this.selections.next(updatedSelections); // Reset current row - this.currentRow.next({ label: '', numbers: [], value: 0, total: 0 }); + this.currentRow.next({ + label: '', + numbers: [], + value: 0, + total: 0 + }); } + // ✅ Clear everything (for ERASE) clearSelections() { this.selections.next([]); - this.currentRow.next({ label: '', numbers: [], value: 0, total: 0 }); + this.currentRow.next({ + label: '', + numbers: [], + value: 0, + total: 0 + }); } } diff --git a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html index 8415d20..9e75cb0 100755 --- a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html +++ b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html @@ -6,7 +6,7 @@
- +
diff --git a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts index 08e2ac9..159a84b 100755 --- a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts +++ b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts @@ -113,6 +113,11 @@ export class TouchPadMenuComponent implements OnInit { this.resetSelections(); } + erase() { + this.selectionService.clearSelections(); + this.resetSelections(); // Clear local selections + } + resetSelections() { this.selectedLabel = null; this.selectedNumbers = [];