diff --git a/btc-UI/electron/main.js b/btc-UI/electron/main.js index 9c4576c..b105e91 100644 --- a/btc-UI/electron/main.js +++ b/btc-UI/electron/main.js @@ -1,5 +1,6 @@ const { app, BrowserWindow, screen, ipcMain } = require('electron'); const path = require('path'); +const fs = require('fs'); let mainWindow; let screenWindow; @@ -20,7 +21,7 @@ function createWindows() { } }); - mainWindow.loadURL('http://10.83.77.61:4200/login'); + mainWindow.loadURL('http://10.74.231.124:4200/login'); screenWindow = new BrowserWindow({ x: secondary.bounds.x, @@ -35,10 +36,23 @@ function createWindows() { } }); - screenWindow.loadURL('http://10.83.77.61:4200/shared-display'); + screenWindow.loadURL('http://10.74.231.124:4200/shared-display'); ipcMain.on('open-second-screen', () => screenWindow.show()); ipcMain.on('close-second-screen', () => screenWindow.hide()); + + // ✅ IPC to return BTID + ipcMain.handle('get-btid', () => { + try { + const filePath = path.join(process.env.HOME || process.env.USERPROFILE, 'BTID', 'betting.txt'); + const content = fs.readFileSync(filePath, 'utf-8'); + const match = content.match(/Btid\s*=\s*(\d+)/i); + return match ? match[1] : null; + } catch (err) { + console.error('Error reading betting.txt:', err); + return null; + } + }); } app.whenReady().then(createWindows); diff --git a/btc-UI/electron/preload.js b/btc-UI/electron/preload.js index 2aa4217..8492231 100644 --- a/btc-UI/electron/preload.js +++ b/btc-UI/electron/preload.js @@ -3,4 +3,7 @@ const { contextBridge, ipcRenderer } = require('electron'); contextBridge.exposeInMainWorld('electronAPI', { openSecondScreen: () => ipcRenderer.send('open-second-screen'), closeSecondScreen: () => ipcRenderer.send('close-second-screen'), -}); + + // ✅ Ask main process for Btid + getBtid: () => ipcRenderer.invoke('get-btid') +}); \ No newline at end of file diff --git a/btc-UI/src/app/components/navbar/navbar.component.html b/btc-UI/src/app/components/navbar/navbar.component.html index 4608ed9..5f661d6 100755 --- a/btc-UI/src/app/components/navbar/navbar.component.html +++ b/btc-UI/src/app/components/navbar/navbar.component.html @@ -12,7 +12,7 @@ - B.T.No: 1111 + B.T.No: {{ btid }} diff --git a/btc-UI/src/app/components/navbar/navbar.component.ts b/btc-UI/src/app/components/navbar/navbar.component.ts index 799de81..d7fb1d0 100755 --- a/btc-UI/src/app/components/navbar/navbar.component.ts +++ b/btc-UI/src/app/components/navbar/navbar.component.ts @@ -18,7 +18,8 @@ export class NavbarComponent implements OnInit, OnDestroy { screenWidth: number = window.innerWidth; private subscription!: Subscription; userName: string = ''; - + btid: string | null = null; + liveStatusOk: boolean = true; showVenueModal = false; @@ -76,6 +77,7 @@ export class NavbarComponent implements OnInit, OnDestroy { ngOnInit() { this.userName = localStorage.getItem('userName') || ''; + this.btid = localStorage.getItem('btid'); // Use NgZone to run setInterval outside Angular's change detection this.zone.runOutsideAngular(() => { setInterval(() => { diff --git a/btc-UI/src/app/login/login.component.ts b/btc-UI/src/app/login/login.component.ts index 425e518..572f9cf 100755 --- a/btc-UI/src/app/login/login.component.ts +++ b/btc-UI/src/app/login/login.component.ts @@ -215,69 +215,74 @@ export class LoginComponent implements OnInit, OnDestroy { + // ✅ Updated onSubmit with BTID + async onSubmit(): Promise { + if (this.loginForm.invalid) { + this.loginForm.markAllAsTouched(); + return; + } - onSubmit(): void { - if (this.loginForm.invalid) { - this.loginForm.markAllAsTouched(); - return; - } + const { email, password } = this.loginForm.value; - const { email, password } = this.loginForm.value; - this.btcService.userLogin(email, password).subscribe({ - next: (response) => { - const employee = response.body; - console.log('🧠 Raw employee response:', employee); + this.btcService.userLogin(email, password).subscribe({ + next: async (response) => { + const employee = response.body; + console.log('🧠 Raw employee response:', employee); - const userName = employee?.userName || 'Unknown User'; - const employeeId = employee?.userIdNumber || email; + const userName = employee?.userName || 'Unknown User'; + const employeeId = employee?.userIdNumber || email; - console.log('✅ Parsed name:', userName); - console.log('✅ Parsed ID:', employeeId); + console.log('✅ Parsed name:', userName); + console.log('✅ Parsed ID:', employeeId); - this.passwordStatus = true; + this.passwordStatus = true; - // Prepare print data - const printData = { - name: userName, - employeeId: employeeId, - action: 'login', - type: 'login' // ← ADD THIS -}; + // ✅ Fetch BTID from Electron preload + const btid = await (window as any).electronAPI?.getBtid?.(); + console.log("📦 BTID from file:", btid); + // Prepare print data + const printData = { + name: userName, + employeeId: employeeId, + action: 'login', + type: 'login' + }; - // Store in localStorage - localStorage.setItem('userName', userName); - localStorage.setItem('employeeId', employeeId); - localStorage.setItem('password', password); + // ✅ Store in localStorage + localStorage.setItem('userName', userName); + localStorage.setItem('employeeId', employeeId); + localStorage.setItem('password', password); + localStorage.setItem('btid', btid || "unknown"); - // Optional print logic - fetch('http://localhost:9100/print', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(printData), - }) - .then((res) => { - if (!res.ok) throw new Error('Print failed'); - console.log('🖨️ Print successful'); + // ✅ Optional second screen + navigate + // fetch('http://localhost:9100/print', { + // method: 'POST', + // headers: { 'Content-Type': 'application/json' }, + // body: JSON.stringify(printData), + // }) + // .then((res) => { + // if (!res.ok) throw new Error('Print failed'); + // console.log('🖨️ Print successful'); // Open second screen (window as any).electronAPI?.openSecondScreen?.(); // // Navigate to home this.router.navigate(['/home']); - }) - .catch((err) => { - console.error('‼️ Print failed', err); - this.loginError = 'Login OK, but printing failed.'; - }); + // }) + // .catch((err) => { + // console.error('‼️ Print failed', err); + // this.loginError = 'Login OK, but printing failed.'; + // }); - }, + // }, + // error: () => { + // this.loginError = 'Invalid login credentials'; + }, + }); + } - error: () => { - this.loginError = 'Invalid login credentials'; - }, - }); -} showConfirmModal : boolean = false;