feat: aggiunto campo di testo per nota nell'area della modifica rapida di un ticket (nota rapida)

This commit is contained in:
VVER440 committed 2026-08-20 00:05:34 +02:00
1 parent 35888400ed
commit ba23635c7d
3 files changed
+87 -28

No files matched your search

+24 -1
View File
@@ -1355,7 +1355,30 @@ body {
box-shadow: 0 0 0 3px var(--accent-primary-glow); box-shadow: 0 0 0 3px var(--accent-primary-glow);
} }
.quick-edit-select.changed { .quick-edit-field.full-width {
grid-column: 1 / -1;
}
.quick-edit-textarea {
padding: 8px 12px;
background: var(--bg-tertiary);
border: 1px solid var(--border-subtle);
border-radius: var(--radius-md);
color: var(--text-primary);
font-family: inherit;
font-size: 0.85rem;
outline: none;
resize: vertical;
min-height: 60px;
transition: all var(--transition-fast);
}
.quick-edit-textarea:focus {
border-color: var(--accent-primary);
box-shadow: 0 0 0 3px var(--accent-primary-glow);
}
.quick-edit-textarea.changed {
border-color: var(--success); border-color: var(--success);
box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
} }
+26 -1
View File
@@ -238,7 +238,11 @@ const TicketDetailView = {
<label class="quick-edit-label">Tempo (minuti)</label> <label class="quick-edit-label">Tempo (minuti)</label>
<input type="number" step="any" min="0" class="form-input" id="qe-time-unit" placeholder="minuti" style="padding: 6px 12px; height: 32px; font-size: 0.85rem;" /> <input type="number" step="any" min="0" class="form-input" id="qe-time-unit" placeholder="minuti" style="padding: 6px 12px; height: 32px; font-size: 0.85rem;" />
</div> </div>
<div style="margin-top:var(--space-md);display:flex;gap:var(--space-sm);justify-content:flex-end;"> <div class="quick-edit-field full-width">
<label class="quick-edit-label">Nota / Commento</label>
<textarea class="quick-edit-textarea" id="qe-note" placeholder="Inserisci una nota..."></textarea>
</div>
<div style="margin-top:var(--space-md);display:flex;gap:var(--space-sm);justify-content:flex-end;grid-column:1 / -1;">
<button class="btn btn-ghost btn-sm" id="qe-reset">Reset</button> <button class="btn btn-ghost btn-sm" id="qe-reset">Reset</button>
<button class="btn btn-primary btn-sm" id="qe-save" disabled>Salva Modifiche</button> <button class="btn btn-primary btn-sm" id="qe-save" disabled>Salva Modifiche</button>
</div> </div>
@@ -588,6 +592,7 @@ const TicketDetailView = {
const saveBtn = document.getElementById('qe-save'); const saveBtn = document.getElementById('qe-save');
const resetBtn = document.getElementById('qe-reset'); const resetBtn = document.getElementById('qe-reset');
const timeUnitInput = document.getElementById('qe-time-unit'); const timeUnitInput = document.getElementById('qe-time-unit');
const noteInput = document.getElementById('qe-note');
const checkChanges = () => { const checkChanges = () => {
let hasChanges = false; let hasChanges = false;
@@ -610,6 +615,14 @@ const TicketDetailView = {
hasChanges = true; hasChanges = true;
} }
const noteText = noteInput ? noteInput.value.trim() : '';
if (noteInput) {
noteInput.classList.toggle('changed', noteText.length > 0);
}
if (noteText.length > 0) {
hasChanges = true;
}
saveBtn.disabled = !hasChanges; saveBtn.disabled = !hasChanges;
}; };
@@ -618,6 +631,10 @@ const TicketDetailView = {
timeUnitInput.addEventListener('input', checkChanges); timeUnitInput.addEventListener('input', checkChanges);
timeUnitInput.addEventListener('change', checkChanges); timeUnitInput.addEventListener('change', checkChanges);
} }
if (noteInput) {
noteInput.addEventListener('input', checkChanges);
noteInput.addEventListener('change', checkChanges);
}
// Queue Autocomplete inside Quick Edit // Queue Autocomplete inside Quick Edit
const queueSearchInput = document.getElementById('qe-queue-search'); const queueSearchInput = document.getElementById('qe-queue-search');
@@ -763,6 +780,10 @@ const TicketDetailView = {
if (timeUnitInput) { if (timeUnitInput) {
timeUnitInput.value = ''; timeUnitInput.value = '';
} }
if (noteInput) {
noteInput.value = '';
noteInput.classList.remove('changed');
}
saveBtn.disabled = true; saveBtn.disabled = true;
}); });
@@ -803,6 +824,10 @@ const TicketDetailView = {
} }
} }
if (noteInput && noteInput.value.trim()) {
updates.note = noteInput.value.trim();
}
if (Object.keys(updates).length === 0) return; if (Object.keys(updates).length === 0) return;
try { try {
+37 -26
View File
@@ -744,9 +744,11 @@ router.post('/', async (req, res) => {
// ============================================================ // ============================================================
router.patch('/:id', async (req, res) => { router.patch('/:id', async (req, res) => {
const { id } = req.params; const { id } = req.params;
const updates = req.body; // { ticket_state_id, ticket_priority_id, queue_id, user_id, type_id, title } const updates = req.body; // { ticket_state_id, ticket_priority_id, queue_id, user_id, type_id, title, note }
const operatorId = parseInt(req.headers['x-agent-id'], 10) || 1; const operatorId = parseInt(req.headers['x-agent-id'], 10) || 1;
const timeUnit = parseFloat(updates.time_unit); const timeUnit = parseFloat(updates.time_unit);
const noteText = typeof updates.note === 'string' ? updates.note.trim() : (typeof updates.note_text === 'string' ? updates.note_text.trim() : '');
const hasNote = noteText.length > 0;
// Fetch current ticket first (needed for both REST dummy fields and database fallback) // Fetch current ticket first (needed for both REST dummy fields and database fallback)
let current; let current;
@@ -780,8 +782,8 @@ router.patch('/:id', async (req, res) => {
if (updates.customer_id !== undefined) ticketFields.CustomerID = updates.customer_id; if (updates.customer_id !== undefined) ticketFields.CustomerID = updates.customer_id;
if (updates.customer_user_id !== undefined) ticketFields.CustomerUser = updates.customer_user_id; if (updates.customer_user_id !== undefined) ticketFields.CustomerUser = updates.customer_user_id;
// If ticketFields is empty but we have a timeUnit to log, we must supply a dummy field (e.g. StateID) so the Ticket parameter is not empty // If ticketFields is empty but we have a note or timeUnit to log, supply a dummy field (StateID) so Ticket is not empty
if (Object.keys(ticketFields).length === 0 && !isNaN(timeUnit) && timeUnit > 0) { if (Object.keys(ticketFields).length === 0 && (hasNote || (!isNaN(timeUnit) && timeUnit > 0))) {
ticketFields.StateID = current.ticket_state_id; ticketFields.StateID = current.ticket_state_id;
} }
@@ -802,20 +804,25 @@ router.patch('/:id', async (req, res) => {
} }
} }
if (Object.keys(ticketFields).length > 0 || (!isNaN(timeUnit) && timeUnit > 0)) { if (Object.keys(ticketFields).length > 0 || hasNote || (!isNaN(timeUnit) && timeUnit > 0)) {
const reqBody = { const reqBody = {
Ticket: ticketFields Ticket: ticketFields
}; };
if (!isNaN(timeUnit) && timeUnit > 0) { if (hasNote || (!isNaN(timeUnit) && timeUnit > 0)) {
reqBody.Article = { const noteSubject = hasNote ? noteText : 'Consuntivazione';
const noteBody = hasNote ? noteText : 'Consuntivazione';
const articleObj = {
CommunicationChannel: 'Internal', CommunicationChannel: 'Internal',
SenderType: 'agent', SenderType: 'agent',
Subject: 'Consuntivazione', Subject: noteSubject,
Body: 'Consuntivazione', Body: noteBody,
ContentType: 'text/html; charset=utf8', ContentType: 'text/html; charset=utf8'
TimeUnit: timeUnit,
TimeUnits: timeUnit
}; };
if (!isNaN(timeUnit) && timeUnit > 0) {
articleObj.TimeUnit = timeUnit;
articleObj.TimeUnits = timeUnit;
}
reqBody.Article = articleObj;
} }
const result = await otrsRequest('PATCH', `/Ticket/${id}`, reqBody); const result = await otrsRequest('PATCH', `/Ticket/${id}`, reqBody);
@@ -876,7 +883,7 @@ router.patch('/:id', async (req, res) => {
const timeUnitVal = parseFloat(updates.time_unit); const timeUnitVal = parseFloat(updates.time_unit);
const hasTimeUnit = !isNaN(timeUnitVal) && timeUnitVal > 0; const hasTimeUnit = !isNaN(timeUnitVal) && timeUnitVal > 0;
if (setClauses.length === 0 && !hasTimeUnit) { if (setClauses.length === 0 && !hasTimeUnit && !hasNote) {
await client.query('ROLLBACK'); await client.query('ROLLBACK');
return res.json({ message: 'No changes detected' }); return res.json({ message: 'No changes detected' });
} }
@@ -893,7 +900,7 @@ router.patch('/:id', async (req, res) => {
setParams setParams
); );
} else { } else {
// If there are no fields modified but we have a time_unit, we still update change_time/change_by // If there are no fields modified but we have a note or time_unit, we still update change_time/change_by
await client.query( await client.query(
`UPDATE ticket SET change_time = NOW(), change_by = $1 WHERE id = $2`, `UPDATE ticket SET change_time = NOW(), change_by = $1 WHERE id = $2`,
[operatorId, id] [operatorId, id]
@@ -955,8 +962,8 @@ router.patch('/:id', async (req, res) => {
} }
} }
// If time_unit is provided, insert a system note article and log the time // If note or time_unit is provided, insert a system note article and log the time
if (hasTimeUnit) { if (hasNote || hasTimeUnit) {
// Get sender type for "agent" // Get sender type for "agent"
const senderResult = await client.query( const senderResult = await client.query(
`SELECT id FROM article_sender_type WHERE name = 'agent'` `SELECT id FROM article_sender_type WHERE name = 'agent'`
@@ -984,8 +991,10 @@ router.patch('/:id', async (req, res) => {
const articleId = articleResult.rows[0].id; const articleId = articleResult.rows[0].id;
const now = new Date(); const now = new Date();
const contentPath = `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')}`; const contentPath = `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')}`;
const noteBody = 'Consuntivazione'; const noteSubject = hasNote ? noteText : 'Consuntivazione';
const htmlBody = `<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">${noteBody}</body></html>`; const noteBodyRaw = hasNote ? noteText : 'Consuntivazione';
const safeBody = noteBodyRaw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br/>');
const htmlBody = `<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">${safeBody}</body></html>`;
const binaryBody = Buffer.from(htmlBody, 'utf-8'); const binaryBody = Buffer.from(htmlBody, 'utf-8');
const contentSize = Buffer.byteLength(htmlBody, 'utf-8'); const contentSize = Buffer.byteLength(htmlBody, 'utf-8');
const base64Body = binaryBody.toString('base64'); const base64Body = binaryBody.toString('base64');
@@ -1005,7 +1014,7 @@ router.patch('/:id', async (req, res) => {
'text/html; charset=utf-8', EXTRACT(EPOCH FROM NOW())::INTEGER, $5, 'text/html; charset=utf-8', EXTRACT(EPOCH FROM NOW())::INTEGER, $5,
NOW(), $6, NOW(), $6 NOW(), $6, NOW(), $6
)`, )`,
[articleId, fromHeader, 'Consuntivazione', htmlBody, contentPath, operatorId] [articleId, fromHeader, noteSubject, htmlBody, contentPath, operatorId]
); );
// Create article_data_mime_attachment for OTRS CE HTML rendering // Create article_data_mime_attachment for OTRS CE HTML rendering
@@ -1020,14 +1029,16 @@ router.patch('/:id', async (req, res) => {
[articleId, String(contentSize), base64Body, operatorId] [articleId, String(contentSize), base64Body, operatorId]
); );
// Log the time in time_accounting // Log the time in time_accounting if provided
await client.query( if (hasTimeUnit) {
`INSERT INTO time_accounting ( await client.query(
ticket_id, article_id, time_unit, `INSERT INTO time_accounting (
create_time, create_by, change_time, change_by ticket_id, article_id, time_unit,
) VALUES ($1, $2, $3, NOW(), $4, NOW(), $4)`, create_time, create_by, change_time, change_by
[id, articleId, timeUnitVal, operatorId] ) VALUES ($1, $2, $3, NOW(), $4, NOW(), $4)`,
); [id, articleId, timeUnitVal, operatorId]
);
}
} }
await client.query('COMMIT'); await client.query('COMMIT');