From f2d4558b80d4c97d1b5c252d93f3690ec46cd76f Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Sat, 18 Jul 2026 19:57:01 +0000 Subject: [PATCH] Make dashboard/home link role-aware: counter -> inventory, cashier -> POS --- pos/static/js/app-init.js | 18 ++++++++++++++++++ pos/static/pwa/sw.js | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pos/static/js/app-init.js b/pos/static/js/app-init.js index e713666..fcd20a1 100644 --- a/pos/static/js/app-init.js +++ b/pos/static/js/app-init.js @@ -190,6 +190,21 @@ } catch(e) { return true; } } + function updateHomeLinks(userRole, userPerms) { + // Point the dashboard/home icon to the role-specific default page. + var homeHref = '/pos/dashboard'; + if (userRole === 'counter' && userPerms.indexOf('inventory.view') !== -1) { + homeHref = '/pos/inventory'; + } else if (userRole === 'cashier' && userPerms.indexOf('pos.sell') !== -1) { + homeHref = '/pos/sale'; + } else if (userRole === 'workshop' && userPerms.indexOf('workshop.view') !== -1 && moduleEnabled('workshop')) { + homeHref = '/pos/workshop'; + } + document.querySelectorAll('a[href="/pos/dashboard"]').forEach(function(a) { + a.setAttribute('href', homeHref); + }); + } + function isPageAllowed(pagePath, userRole, userPerms) { if (userRole === 'owner' || userRole === 'admin') return true; @@ -298,11 +313,14 @@ if (typeof window.renderSidebar === 'function') { window.renderSidebar(window.POS_USER.modules || JSON.parse(localStorage.getItem('pos_modules') || '{}')); } + updateHomeLinks(window.POS_USER.role, window.POS_USER.permissions); }).catch(function() { enforcePageGuard(role, payload.permissions || []); + updateHomeLinks(role, payload.permissions || []); }); } catch(e) { enforcePageGuard(role, payload.permissions || []); + updateHomeLinks(role, payload.permissions || []); } // ─── Preload enabled modules for sidebar filtering ─── diff --git a/pos/static/pwa/sw.js b/pos/static/pwa/sw.js index b7a53fd..717e45e 100644 --- a/pos/static/pwa/sw.js +++ b/pos/static/pwa/sw.js @@ -6,7 +6,7 @@ // The fetch handler normalizes static asset URLs (strips ?v= query strings) // so templates can use cache-busting query params freely. -const VERSION = 53; +const VERSION = 54; const CACHE_NAME = 'nexus-pos-v' + VERSION; const APP_SHELL = [