Aggiunte stored procedure più utili le altre pfff

This commit is contained in:
2026-07-05 18:48:29 +02:00
parent 457c3eacf6
commit 4f41b50d37
10 changed files with 1578 additions and 156 deletions
+61 -3
View File
@@ -57,6 +57,12 @@ const App = {
// Init active agent selector
this.initAgentSelector();
// Bind refresh lookups button
const refreshBtn = document.getElementById('refresh-lookups-btn');
if (refreshBtn) {
refreshBtn.addEventListener('click', () => this.refreshLookups());
}
// Initial route
if (!window.location.hash || window.location.hash === '#/') {
window.location.hash = '#/dashboard';
@@ -67,7 +73,8 @@ const App = {
/** Route based on current hash */
route() {
const hash = window.location.hash || '#/dashboard';
const fullHash = window.location.hash || '#/dashboard';
const hash = fullHash.split('?')[0];
const titleEl = document.getElementById('page-title');
// Update active nav link
@@ -90,6 +97,11 @@ const App = {
titleEl.textContent = 'Nuovo Ticket';
TicketCreateView.render();
} else if (hash === '#/tickets/bulk') {
document.getElementById('nav-bulk-tickets')?.classList.add('active');
titleEl.textContent = 'Apertura Massiva Ticket';
TicketBulkView.render();
} else if (hash.match(/^#\/tickets\/(\d+)$/)) {
const id = hash.match(/^#\/tickets\/(\d+)$/)[1];
document.getElementById('nav-tickets')?.classList.add('active');
@@ -124,8 +136,22 @@ const App = {
},
/** Ensure lookup data is loaded (cached) */
async ensureLookups() {
if (this.lookupsLoaded) return;
async ensureLookups(forceRefresh = false) {
if (this.lookupsLoaded && !forceRefresh) return;
// Check localStorage cache first if not forcing refresh
if (!forceRefresh) {
const cached = localStorage.getItem('otrs_lookups');
if (cached) {
try {
this.lookups = JSON.parse(cached);
this.lookupsLoaded = true;
return;
} catch (e) {
console.warn('Failed to parse cached lookups, reloading...', e);
}
}
}
try {
const [queues, states, priorities, users, types] = await Promise.all([
@@ -137,6 +163,7 @@ const App = {
]);
this.lookups = { queues, states, priorities, users, types };
localStorage.setItem('otrs_lookups', JSON.stringify(this.lookups));
this.lookupsLoaded = true;
} catch (err) {
console.error('Failed to load lookups:', err);
@@ -144,6 +171,37 @@ const App = {
}
},
/** Force refresh of lookups */
async refreshLookups() {
const btn = document.getElementById('refresh-lookups-btn');
const origHtml = btn ? btn.innerHTML : '';
if (btn) {
btn.disabled = true;
btn.innerHTML = '<div class="spinner" style="width:16px;height:16px;border-width:2px;margin:0;"></div>';
}
try {
await this.ensureLookups(true);
await this.initAgentSelector();
Toast.success('Dati locali (code, utenti, ecc.) aggiornati con successo!');
// If we are on a view that needs lookups, we can re-render it
const hash = window.location.hash;
if (hash === '#/tickets/bulk') {
TicketBulkView.render();
} else if (hash === '#/tickets/new') {
TicketCreateView.render();
}
} catch (err) {
Toast.error('Errore durante l\'aggiornamento: ' + err.message);
} finally {
if (btn) {
btn.disabled = false;
btn.innerHTML = origHtml;
}
}
},
/** Check database connection */
async checkConnection() {
const dot = document.getElementById('connection-status');