fix: ora il timer del tempo consuntivato si aggiorna ogni 60 secondi.

This commit is contained in:
Gabriele Cimaschi committed 2026-08-26 13:58:36 +02:00
1 parent a36e501596
commit 37c5f0c500
3 files changed
+50 -1

No files matched your search

+18 -1
View File
@@ -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) */
+1
View File
@@ -237,6 +237,7 @@ const TicketListView = {
<option value="50" ${per_page === 50 ? 'selected' : ''}>50</option>
<option value="100" ${per_page === 100 ? 'selected' : ''}>100</option>
<option value="200" ${per_page === 200 ? 'selected' : ''}>200</option>
<option value="500" ${per_page === 500 ? 'selected' : ''}>500</option>
</select>
</div>
`;
+31
View File
@@ -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 {