diff --git a/public/js/app.js b/public/js/app.js index 6e7f707..ed32ced 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -241,10 +241,16 @@ const App = { } else { this.route(); } + + // Set periodic refresh for daily time accounting counter (every 60 seconds) + if (!this.dailyTimerInterval) { + this.dailyTimerInterval = setInterval(() => this.updateDailyTimer(), 60000); + } }, /** Route based on current hash */ route() { + this.updateDailyTimer(); const fullHash = window.location.hash || '#/dashboard'; const hash = fullHash.split('?')[0]; const titleEl = document.getElementById('page-title'); @@ -364,7 +370,18 @@ const App = { throw new Error(errData.error || errData.message || `HTTP ${response.status}`); } - return response.json(); + const data = await response.json(); + + // Automatically update daily timer on any system mutation (POST, PUT, PATCH, DELETE) + const method = (options.method || 'GET').toUpperCase(); + if (method !== 'GET' && !url.includes('/api/users/time-today')) { + setTimeout(() => { + this.updateDailyTimer(); + this.updateSidebarBadges(); + }, 100); + } + + return data; }, /** Ensure lookup data is loaded (cached) */ diff --git a/public/js/views/ticketList.js b/public/js/views/ticketList.js index 28fd936..bbf9004 100644 --- a/public/js/views/ticketList.js +++ b/public/js/views/ticketList.js @@ -237,6 +237,7 @@ const TicketListView = { + `; diff --git a/routes/dashboard.js b/routes/dashboard.js index c5a06c7..d9a5305 100644 --- a/routes/dashboard.js +++ b/routes/dashboard.js @@ -236,6 +236,37 @@ router.get('/settings', (req, res) => { } }); +// POST /api/dashboard/settings — Save settings for the agent +router.post('/settings', (req, res) => { + const activeAgentId = parseInt(req.headers['x-agent-id'], 10) || 1; + const { preview_limit, tickets_per_page } = req.body || {}; + + try { + const existing = db.prepare("SELECT agent_id, preview_limit, tickets_per_page FROM agent_settings WHERE agent_id = ?").get(activeAgentId); + + const newPreviewLimit = preview_limit !== undefined ? parseInt(preview_limit, 10) : (existing ? existing.preview_limit : 10); + const newTicketsPerPage = tickets_per_page !== undefined ? parseInt(tickets_per_page, 10) : (existing ? existing.tickets_per_page : 50); + + if (existing) { + db.prepare(` + UPDATE agent_settings + SET preview_limit = ?, tickets_per_page = ? + WHERE agent_id = ? + `).run(newPreviewLimit, newTicketsPerPage, activeAgentId); + } else { + db.prepare(` + INSERT INTO agent_settings (agent_id, preview_limit, tickets_per_page) + VALUES (?, ?, ?) + `).run(activeAgentId, newPreviewLimit, newTicketsPerPage); + } + + res.json({ success: true, preview_limit: newPreviewLimit, tickets_per_page: newTicketsPerPage }); + } catch (err) { + console.error('Error saving agent settings:', err); + res.status(500).json({ error: err.message }); + } +}); + // GET /api/dashboard/chart-lines router.get('/chart-lines', (req, res) => { try {