From ff263099c7aad61fdd58dfe29a2788c557d4ef19 Mon Sep 17 00:00:00 2001 From: karthik Date: Mon, 15 Sep 2025 14:15:02 +0530 Subject: [PATCH] =?UTF-8?q?fix=20:=20label=20part=20(restriction)=20?= =?UTF-8?q?=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../touch-pad-menu.component.ts | 87 +++++++++++++++++-- 1 file changed, 79 insertions(+), 8 deletions(-) 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 bc47ca7..b0fb5ea 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 @@ -143,7 +143,10 @@ export class TouchPadMenuComponent implements OnInit, OnDestroy { this.maxRowsReached = selections.length >= 5; const totalAmount = selections.reduce((sum: number, selection: SelectionData) => sum + (selection.total || 0), 0); this.totalAmountLimitReached = totalAmount >= 5000; - this.blockedLabels = this.labelRestrictionService.getBlockedLabels(selections); + + // NEW: + this.refreshBlockedLabels(this.selectedLabel); + if (!this.totalAmountLimitReached) { this.showLimitPopup = false; } @@ -389,6 +392,8 @@ export class TouchPadMenuComponent implements OnInit, OnDestroy { this.runnerCount = this.getRunnerCountForLeg(this.multiLegBaseRaceIdx, 0) || 12; this.numbers = Array.from({ length: 30 }, (_, i) => i + 1); this.numbersFlat = this.numberRows.flat(); + // Call after pool change + this.refreshBlockedLabels(label); } else { this.currentPool = null; this.multiLegBaseRaceIdx = 0; @@ -399,6 +404,8 @@ export class TouchPadMenuComponent implements OnInit, OnDestroy { }); // --- NEW: Update actualRunners for single race --- this.setActualRunners(); + // Call after pool change + this.refreshBlockedLabels(label); } //----------------------------------ADDED THIS ----------------------------------------------------- @@ -421,9 +428,13 @@ export class TouchPadMenuComponent implements OnInit, OnDestroy { const totalExisting = currentSelections.reduce((sum, r) => sum + r.total, 0); if (totalExisting + totalNew <= 5000) { this.selectionService.setSelections([...currentSelections, ...blankRows]); + // Call after setSelections + this.refreshBlockedLabels(label); } } this.selectionService.updatePartial({ label: '', numbers: [], value: 0, total: 0 }); + // Call before return in WSP + this.refreshBlockedLabels(label); return; } //----------------------------------ended here---------------------------------------------------- @@ -440,6 +451,8 @@ export class TouchPadMenuComponent implements OnInit, OnDestroy { this.multiLegGroups = [[], [], [], [], []]; this.selectionService.updatePartial({ label }); + // recompute blocked labels including newly-selected label + this.refreshBlockedLabels(label); } private getBaseRaceIndexForPool(poolName: string): number { @@ -564,6 +577,8 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) { return sel; }); this.selectionService.setSelections(updated); + // Call after setSelections + this.refreshBlockedLabels(this.selectedLabel); } } } @@ -630,6 +645,8 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) { }); this.selectionService.setSelections(updatedSelections); + // Call after setSelections + this.refreshBlockedLabels(this.selectedLabel); this.padValue = ''; this.updateCanPrint(); } @@ -662,6 +679,8 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) { }); this.selectionService.setSelections(updatedSelections); + // Call after setSelections + this.refreshBlockedLabels(this.selectedLabel); // Only increment stage if not at the last stage (PLP) if (this.wspTicketStage < 2) { @@ -759,6 +778,8 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) { }); this.selectionService.setSelections(updatedSelections); + // Call after setSelections + this.refreshBlockedLabels(this.selectedLabel); const currentTotal = updatedSelections.find(sel => sel.label === targetLabel)?.total || 0; if (currentTotal === 0 && value > 0) { @@ -766,6 +787,8 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) { this.selectionService.setSelections( updatedSelections.filter(sel => sel.label !== targetLabel || sel.numbers.length > 0) ); + // Call after setSelections + this.refreshBlockedLabels(this.selectedLabel); this.wspTicketStage = 0; this.padValue = ''; this.selectedNumbers = []; @@ -937,9 +960,13 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) { const currentSelections = this.selectionService.getSelections(); const nonWSPSelections = currentSelections.filter(sel => !['WNP', 'SHP', 'PLP'].includes(sel.label)); this.selectionService.setSelections([...nonWSPSelections, ...virtualRows]); + // Call after setSelections + this.refreshBlockedLabels(this.selectedLabel); } this.selectionService.finalizeCurrentRow(); + // Call after finalizeCurrentRow + this.refreshBlockedLabels(null); this.resetSelections(); } @@ -1092,7 +1119,23 @@ const winLabels = allRows.map(row => { let expandedLegs: string[] = legs.map((leg, i) => { // Find race index for this leg let raceIdx = raceIndices.length > i ? raceIndices[i] - 1 : (baseRaceIdx - 1 + i); - + // let expanded = leg.flatMap(n => + // n === 'F' + // ? this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString()) + // : [n] + // ); + // let expanded = leg.flatMap((n, idx) => { + // if (n === 'F') { + // const horses = this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString()).join(','); + // const isFirst = idx === 0; + // const isLast = idx === leg.length - 1; + // if (isFirst && !isLast) return [`${horses}-`]; + // if (!isFirst && isLast) return [`-${horses}`]; + // if (isFirst && isLast) return [horses]; // only F in the leg + // return [`-${horses}-`]; + // } + // return [n]; + // }); let expanded = leg.flatMap((n) => { if (n === 'F') { // Expand F → horse numbers, no extra dashes @@ -1116,7 +1159,21 @@ const winLabels = allRows.map(row => { // 🐎 Expand 'F' to full horse numbers for other pools if (displayNumbers.includes('F')) { - + // displayNumbers = displayNumbers.flatMap(n => + // n === 'F' ? this.getHorseNumbersForSelectedRace().map(num => num.toString()) : [n] + // ); +// displayNumbers = displayNumbers.flatMap((n, idx, arr) => { +// if (n === 'F') { +// const horses = this.getHorseNumbersForSelectedRace().map(num => num.toString()).join(','); + // const isFirst = idx === 0; + // const isLast = idx === arr.length - 1; + // if (isFirst && !isLast) return [`${horses}-`]; + // if (!isFirst && isLast) return [`-${horses}`]; + // if (isFirst && isLast) return [horses]; // only F + // return [`-${horses}-`]; + // } + // return [n]; +// }); displayNumbers = displayNumbers.flatMap((n) => { if (n === 'F') { // Expand F → horse numbers, no extra dashes @@ -1392,7 +1449,6 @@ try { // this.erase(); // Uncomment if you want to clear on error } - //---------------------------------------------- BACK END ENDS HERE ----------------------------------------------------- // read issueT from localStorage let issueT: any = null; @@ -1500,6 +1556,8 @@ try { //--------------------Ended Print here ----------------------------- this.selectionService.finalizeCurrentRow(); + // Call after finalizeCurrentRow + this.refreshBlockedLabels(null); this.resetSelections(); } @@ -1507,6 +1565,7 @@ try { erase() { this.selectionService.clearSelections(); this.resetSelections(); + this.refreshBlockedLabels(null); this.cdr.markForCheck(); // <-- Force UI update } @@ -1532,8 +1591,8 @@ try { this.fieldInput = ''; this.fieldFEntered = false; this.wspTicketStage = 0; - // Explicitly reset blocked labels - this.blockedLabels = this.labelRestrictionService.getBlockedLabels([]); + // Explicitly reset blocked labels (no current label) + this.refreshBlockedLabels(null); this.updateCanPrint(); this.sharedStateService.updateSharedData({ type: 'multiLegPoolEnd', value: null }); this.cdr.markForCheck(); // <-- Force UI update @@ -1816,6 +1875,8 @@ try { this.poolReplaceOpen = false; // Update selection service with new label this.selectionService.updatePartial({ label }); + // recompute blocked labels including newly-selected label + this.refreshBlockedLabels(label); } closePoolReplaceModal() { this.poolReplaceOpen = false; } @@ -1856,6 +1917,8 @@ try { this.runnerCount = this.getRunnerCountForLeg(this.multiLegBaseRaceIdx, 0) || 12; this.numbers = Array.from({ length: 30 }, (_, i) => i + 1); this.numbersFlat = this.numberRows.flat(); + // Call after pool change + this.refreshBlockedLabels('TRE'); } closeTrePopup() { this.trePopupVisible = false; } @@ -1920,6 +1983,14 @@ try { currentRow.value <= 100 && currentRow.total > 0; } -} - + // add this in the component class (near other helpers) + private refreshBlockedLabels(currentLabel?: string | null) { + // Pass finalized selections and optionally the in-progress/current label + const finalized = this.selectionService.getSelections(); + this.blockedLabels = this.labelRestrictionService.getBlockedLabels(finalized, currentLabel ?? this.selectedLabel); + console.log('[DEBUG] refreshBlockedLabels -> selectedLabel:', currentLabel ?? this.selectedLabel, 'blocked:', Array.from(this.blockedLabels)); + // Ensure OnPush UI updates + try { this.cdr.markForCheck(); } catch (e) { /* ignore */ } + } +} \ No newline at end of file