feat: contatore tempo allocato, pagina miei ticket, unione ticket (da db)
This commit is contained in:
@@ -8,6 +8,7 @@ const TicketListView = {
|
||||
sortBy: 'create_time',
|
||||
sortDir: 'DESC',
|
||||
selectedIds: new Set(),
|
||||
selectedOrder: [],
|
||||
searchTimeout: null,
|
||||
|
||||
async render() {
|
||||
@@ -19,17 +20,23 @@ const TicketListView = {
|
||||
await App.ensureLookups();
|
||||
|
||||
// Build query params
|
||||
const isMyTickets = window.location.hash.startsWith('#/tickets/my');
|
||||
if (isMyTickets) {
|
||||
const activeAgentId = localStorage.getItem('activeAgentId') || '1';
|
||||
Filters.state.user_id = activeAgentId;
|
||||
}
|
||||
|
||||
const params = Filters.toQueryParams();
|
||||
params.set('page', this.currentPage);
|
||||
params.set('per_page', this.perPage);
|
||||
params.set('sort_by', this.sortBy);
|
||||
params.set('sort_dir', this.sortDir);
|
||||
|
||||
|
||||
const searchInput = document.getElementById('global-search');
|
||||
if (searchInput && searchInput.value.trim()) {
|
||||
params.set('search', searchInput.value.trim());
|
||||
}
|
||||
|
||||
|
||||
const data = await App.api(`/api/tickets?${params.toString()}`);
|
||||
|
||||
this.renderContent(container, data);
|
||||
@@ -79,6 +86,7 @@ const TicketListView = {
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-primary btn-sm" id="batch-apply">Applica</button>
|
||||
<button class="btn btn-primary btn-sm" id="batch-merge" disabled style="background: var(--accent-secondary); border-color: var(--accent-secondary); margin-left: 8px;">Unisci Selezionati</button>
|
||||
<button class="btn btn-ghost btn-xs" id="batch-cancel">Annulla</button>
|
||||
</div>
|
||||
|
||||
@@ -95,18 +103,20 @@ const TicketListView = {
|
||||
<th class="sortable ${this.sortBy === 'priority' ? (this.sortDir === 'ASC' ? 'sort-asc' : 'sort-desc') : ''}" data-sort="priority">Priorità</th>
|
||||
<th class="sortable ${this.sortBy === 'queue' ? (this.sortDir === 'ASC' ? 'sort-asc' : 'sort-desc') : ''}" data-sort="queue">Coda</th>
|
||||
<th>Owner</th>
|
||||
<th>Cliente</th>
|
||||
<th class="sortable ${this.sortBy === 'create_time' ? (this.sortDir === 'ASC' ? 'sort-asc' : 'sort-desc') : ''}" data-sort="create_time">Creato</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${tickets.length > 0 ? tickets.map(t => `
|
||||
<tr data-ticket-id="${t.id}" class="${this.selectedIds.has(String(t.id)) ? 'selected' : ''}" style="cursor:pointer;">
|
||||
<tr data-ticket-id="${t.id}" class="${this.selectedIds.has(String(t.id)) ? 'selected' : ''} ${this.selectedOrder[0] === String(t.id) ? 'first-selected' : ''}" style="cursor:pointer;">
|
||||
<td><span class="ticket-tn"><a href="#/tickets/${t.id}" class="ticket-tn-link" onclick="event.stopPropagation()">${t.tn}</a></span></td>
|
||||
<td class="ticket-title-cell"><a href="#/tickets/${t.id}" class="ticket-title-link" onclick="event.stopPropagation()">${App.escapeHtml(t.title || '(senza titolo)')}</a></td>
|
||||
<td><span class="badge badge-state" data-state-type="${(t.state_type || '').toLowerCase()}">${t.state_name}</span></td>
|
||||
<td><span class="badge badge-priority" data-priority="${App.priorityIndex(t.priority_name)}">${App.priorityIndex(t.priority_name)}</span></td>
|
||||
<td><span class="badge badge-queue">${t.queue_name}</span></td>
|
||||
<td style="color:var(--text-secondary);font-size:0.82rem;">${t.owner_first || ''} ${t.owner_last || ''}</td>
|
||||
<td style="color:var(--text-secondary);font-size:0.82rem;">${t.customer_first ? `${t.customer_first} ${t.customer_last}` : (t.customer_user_id || '—')}</td>
|
||||
<td style="color:var(--text-tertiary);font-size:0.78rem;">${App.formatDateTime(t.create_time)}</td>
|
||||
</tr>
|
||||
`).join('') : `
|
||||
@@ -163,6 +173,7 @@ const TicketListView = {
|
||||
Filters.bindEvents(() => {
|
||||
this.currentPage = 1;
|
||||
this.selectedIds.clear();
|
||||
this.selectedOrder = [];
|
||||
this.render();
|
||||
});
|
||||
|
||||
@@ -192,11 +203,27 @@ const TicketListView = {
|
||||
const id = String(row.dataset.ticketId);
|
||||
if (this.selectedIds.has(id)) {
|
||||
this.selectedIds.delete(id);
|
||||
row.classList.remove('selected');
|
||||
this.selectedOrder = this.selectedOrder.filter(x => x !== id);
|
||||
} else {
|
||||
this.selectedIds.add(id);
|
||||
row.classList.add('selected');
|
||||
this.selectedOrder.push(id);
|
||||
}
|
||||
|
||||
// Update classes on all rows
|
||||
document.querySelectorAll('.ticket-table tbody tr[data-ticket-id]').forEach(tr => {
|
||||
const trId = String(tr.dataset.ticketId);
|
||||
if (this.selectedIds.has(trId)) {
|
||||
tr.classList.add('selected');
|
||||
} else {
|
||||
tr.classList.remove('selected');
|
||||
}
|
||||
if (this.selectedOrder[0] === trId) {
|
||||
tr.classList.add('first-selected');
|
||||
} else {
|
||||
tr.classList.remove('first-selected');
|
||||
}
|
||||
});
|
||||
|
||||
this.updateBatchBar();
|
||||
});
|
||||
});
|
||||
@@ -207,15 +234,35 @@ const TicketListView = {
|
||||
batchApply.addEventListener('click', () => this.applyBatch());
|
||||
}
|
||||
|
||||
// Batch merge (Issue #7)
|
||||
const batchMerge = document.getElementById('batch-merge');
|
||||
if (batchMerge) {
|
||||
batchMerge.addEventListener('click', () => this.mergeBatch());
|
||||
}
|
||||
|
||||
// Batch select all visible
|
||||
const batchSelectAll = document.getElementById('batch-select-all');
|
||||
if (batchSelectAll) {
|
||||
batchSelectAll.addEventListener('click', () => {
|
||||
document.querySelectorAll('.ticket-table tbody tr[data-ticket-id]').forEach(row => {
|
||||
const id = String(row.dataset.ticketId);
|
||||
this.selectedIds.add(id);
|
||||
row.classList.add('selected');
|
||||
if (!this.selectedIds.has(id)) {
|
||||
this.selectedIds.add(id);
|
||||
this.selectedOrder.push(id);
|
||||
}
|
||||
});
|
||||
|
||||
// Update classes
|
||||
document.querySelectorAll('.ticket-table tbody tr[data-ticket-id]').forEach(tr => {
|
||||
const trId = String(tr.dataset.ticketId);
|
||||
tr.classList.add('selected');
|
||||
if (this.selectedOrder[0] === trId) {
|
||||
tr.classList.add('first-selected');
|
||||
} else {
|
||||
tr.classList.remove('first-selected');
|
||||
}
|
||||
});
|
||||
|
||||
this.updateBatchBar();
|
||||
});
|
||||
}
|
||||
@@ -225,8 +272,10 @@ const TicketListView = {
|
||||
if (batchCancel) {
|
||||
batchCancel.addEventListener('click', () => {
|
||||
this.selectedIds.clear();
|
||||
this.selectedOrder = [];
|
||||
document.querySelectorAll('.ticket-table tbody tr').forEach(tr => {
|
||||
tr.classList.remove('selected');
|
||||
tr.classList.remove('first-selected');
|
||||
});
|
||||
this.updateBatchBar();
|
||||
});
|
||||
@@ -237,6 +286,7 @@ const TicketListView = {
|
||||
btn.addEventListener('click', () => {
|
||||
this.currentPage = parseInt(btn.dataset.page);
|
||||
this.selectedIds.clear();
|
||||
this.selectedOrder = [];
|
||||
this.render();
|
||||
});
|
||||
});
|
||||
@@ -247,6 +297,16 @@ const TicketListView = {
|
||||
if (count) {
|
||||
count.textContent = `${this.selectedIds.size} selezionat${this.selectedIds.size === 1 ? 'o' : 'i'}`;
|
||||
}
|
||||
|
||||
// Enable/disable merge button
|
||||
const mergeBtn = document.getElementById('batch-merge');
|
||||
if (mergeBtn) {
|
||||
if (this.selectedIds.size >= 2) {
|
||||
mergeBtn.disabled = false;
|
||||
} else {
|
||||
mergeBtn.disabled = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async applyBatch() {
|
||||
@@ -276,9 +336,59 @@ const TicketListView = {
|
||||
});
|
||||
Toast.success(res.message || `${this.selectedIds.size} ticket aggiornati`);
|
||||
this.selectedIds.clear();
|
||||
this.selectedOrder = [];
|
||||
this.render();
|
||||
} catch (err) {
|
||||
Toast.error('Errore aggiornamento batch: ' + err.message);
|
||||
}
|
||||
},
|
||||
|
||||
async mergeBatch() {
|
||||
if (this.selectedOrder.length < 2) return;
|
||||
|
||||
const targetId = this.selectedOrder[0];
|
||||
const sourceIds = this.selectedOrder.slice(1);
|
||||
|
||||
// Get target ticket number
|
||||
const targetRow = document.querySelector(`.ticket-table tbody tr[data-ticket-id="${targetId}"]`);
|
||||
const targetTn = targetRow ? targetRow.querySelector('.ticket-tn-link').textContent.trim() : targetId;
|
||||
|
||||
// Collect source ticket numbers
|
||||
const sourceTns = [];
|
||||
sourceIds.forEach(id => {
|
||||
const row = document.querySelector(`.ticket-table tbody tr[data-ticket-id="${id}"]`);
|
||||
if (row) {
|
||||
sourceTns.push(row.querySelector('.ticket-tn-link').textContent.trim());
|
||||
} else {
|
||||
sourceTns.push(`#${id}`);
|
||||
}
|
||||
});
|
||||
|
||||
const confirmed = confirm(`Sei sicuro di voler unire i ticket ${sourceTns.join(', ')} nel ticket principale #${targetTn}? Questa azione sposterà tutti gli articoli e tempi consultivati.`);
|
||||
if (!confirmed) return;
|
||||
|
||||
try {
|
||||
const mergeBtn = document.getElementById('batch-merge');
|
||||
if (mergeBtn) {
|
||||
mergeBtn.disabled = true;
|
||||
mergeBtn.textContent = 'Unione in corso...';
|
||||
}
|
||||
|
||||
const res = await App.api('/api/tickets/merge', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
targetId: parseInt(targetId),
|
||||
sourceIds: sourceIds.map(x => parseInt(x))
|
||||
})
|
||||
});
|
||||
|
||||
Toast.success(res.message || 'Ticket uniti con successo');
|
||||
this.selectedIds.clear();
|
||||
this.selectedOrder = [];
|
||||
this.render();
|
||||
} catch (err) {
|
||||
Toast.error('Errore durante l\'unione: ' + err.message);
|
||||
this.updateBatchBar();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user