-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.html
More file actions
388 lines (349 loc) · 14.8 KB
/
Copy pathtask.html
File metadata and controls
388 lines (349 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Task Clienti - CRM Commercialista</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', sans-serif; background: #f5f7fa; }
.navbar {
background: #2c3e50;
color: white;
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
.nav-brand { font-size: 1.5rem; font-weight: bold; }
.nav-links a {
color: white;
text-decoration: none;
margin-left: 1.5rem;
padding: 0.5rem;
}
.nav-links a:hover, .nav-links a.active { border-bottom: 2px solid #3498db; }
.container { max-width: 1400px; margin: 2rem auto; padding: 0 2rem; }
h1 { color: #2c3e50; margin-bottom: 1.5rem; }
.filters {
background: white;
padding: 1rem;
border-radius: 10px;
margin-bottom: 2rem;
display: flex;
gap: 1rem;
flex-wrap: wrap;
align-items: center;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.filters select, .filters input {
padding: 0.5rem;
border: 1px solid #ddd;
border-radius: 5px;
}
.cliente-group {
background: white;
border-radius: 10px;
margin-bottom: 1.5rem;
overflow: hidden;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.cliente-header {
background: #2c3e50;
color: white;
padding: 1rem;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
}
.cliente-header:hover { background: #34495e; }
.task-list { padding: 1rem; }
.task-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem;
border-bottom: 1px solid #ecf0f1;
gap: 1rem;
flex-wrap: wrap;
}
.task-item:last-child { border-bottom: none; }
.task-info { flex: 2; min-width: 200px; }
.task-nome { font-weight: bold; display: flex; align-items: center; gap: 0.5rem; }
.task-scadenza { font-size: 0.8rem; color: #666; }
.task-progress { width: 150px; }
select.status-select {
padding: 0.4rem;
border-radius: 5px;
border: 1px solid #ddd;
font-size: 0.8rem;
}
.stato-badge {
display: inline-block;
padding: 0.25rem 0.5rem;
border-radius: 20px;
font-size: 0.7rem;
font-weight: bold;
}
.stato-da_iniziare { background: #95a5a6; color: white; }
.stato-in_corso { background: #f39c12; color: white; }
.stato-completato { background: #27ae60; color: white; }
.task-note { flex: 1; min-width: 150px; }
.task-note input {
width: 100%;
padding: 0.4rem;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 0.8rem;
}
.btn-save-task {
background: #3498db;
color: white;
border: none;
padding: 0.4rem 0.8rem;
border-radius: 5px;
cursor: pointer;
font-size: 0.8rem;
}
.btn-save-task:hover { background: #2980b9; }
.loading { text-align: center; padding: 2rem; color: #666; }
.toast {
position: fixed;
bottom: 20px;
right: 20px;
background: #27ae60;
color: white;
padding: 1rem;
border-radius: 5px;
z-index: 2000;
animation: fadeOut 3s forwards;
}
@keyframes fadeOut {
0% { opacity: 1; }
70% { opacity: 1; }
100% { opacity: 0; visibility: hidden; }
}
.progress-overall {
background: #ecf0f1;
border-radius: 10px;
height: 8px;
width: 100px;
overflow: hidden;
}
.progress-overall-fill {
background: #27ae60;
height: 100%;
width: 0%;
transition: width 0.3s;
}
</style>
</head>
<body>
<nav class="navbar">
<div class="nav-brand">📊 CRM Studio Commercialista</div>
<div class="nav-links">
<a href="dashboard.html">🏠 Dashboard</a>
<a href="clienti.html">👥 Clienti</a>
<a href="task.html" class="active">✅ Task Clienti</a>
<a href="lavorazioni.html">📈 Lavorazioni</a>
<a href="#" onclick="logout()">🚪 Esci</a>
</div>
</nav>
<main class="container">
<h1>✅ Task per Cliente</h1>
<div class="filters">
<label>🔍 Filtri:</label>
<select id="filtro-stato">
<option value="all">Tutti gli stati</option>
<option value="da_iniziare">Da iniziare</option>
<option value="in_corso">In corso</option>
<option value="completato">Completato</option>
</select>
<select id="filtro-anno">
<option value="2025">Anno 2025</option>
<option value="2026">Anno 2026</option>
</select>
<input type="text" id="filtro-cliente" placeholder="Cerca cliente..." style="flex:1">
</div>
<div id="task-container">
<div class="loading">⏳ Caricamento task...</div>
</div>
</main>
<script src="config.js"></script>
<script>
let clientiData = [];
let taskData = [];
let dirtyTasks = new Set();
if (!sessionStorage.getItem('logged')) {
window.location.href = 'index.html';
}
function showToast(message, isError = false) {
const toast = document.createElement('div');
toast.className = 'toast';
toast.style.background = isError ? '#e74c3c' : '#27ae60';
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 3000);
}
async function callAPI(action, data) {
try {
const response = await fetch(API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action, ...data })
});
return await response.json();
} catch (error) {
return { status: 'error', message: error.message };
}
}
function getTaskLabel(taskType) {
const task = CONFIG.taskTemplates.find(t => t.type === taskType);
return task ? task.label : taskType;
}
async function loadData() {
try {
const response = await fetch(`${API_URL}?t=${Date.now()}`);
const data = await response.json();
clientiData = data.clienti || [];
taskData = data.task_clienti || [];
renderTasks();
} catch (error) {
document.getElementById('task-container').innerHTML = '<div class="loading">❌ Errore caricamento task</div>';
}
}
function getStatoText(stato) {
const texts = {
'da_iniziare': '🔴 Da iniziare',
'in_corso': '🟡 In corso',
'completato': '✅ Completato'
};
return texts[stato] || stato;
}
function calcolaProgressoTasks(tasks) {
if (!tasks.length) return 0;
const completati = tasks.filter(t => t.stato === 'completato').length;
return Math.round((completati / tasks.length) * 100);
}
async function saveSingleTask(taskId) {
const task = taskData.find(t => t.id == taskId);
if (!task) return;
const result = await callAPI('updateTask', { task });
if (result.status === 'ok') {
showToast('✅ Task aggiornato');
} else {
showToast('❌ Errore salvataggio', true);
}
}
function updateTaskField(taskId, field, value) {
const task = taskData.find(t => t.id == taskId);
if (task) {
task[field] = value;
}
}
function renderTasks() {
const filtroStato = document.getElementById('filtro-stato').value;
const filtroAnno = document.getElementById('filtro-anno').value;
const filtroCliente = document.getElementById('filtro-cliente').value.toLowerCase();
const tasksByClient = {};
taskData.forEach(task => {
if (filtroAnno && task.anno_riferimento != filtroAnno) return;
if (filtroStato !== 'all' && task.stato !== filtroStato) return;
const cliente = clientiData.find(c => c.id == task.clienteId);
if (!cliente) return;
if (filtroCliente && !cliente.nome.toLowerCase().includes(filtroCliente)) return;
if (!tasksByClient[task.clienteId]) {
tasksByClient[task.clienteId] = {
cliente: cliente,
tasks: []
};
}
tasksByClient[task.clienteId].tasks.push(task);
});
const taskOrder = CONFIG.taskTemplates.map(t => t.type);
for (const clientId in tasksByClient) {
tasksByClient[clientId].tasks.sort((a, b) => {
return taskOrder.indexOf(a.task_type) - taskOrder.indexOf(b.task_type);
});
}
if (Object.keys(tasksByClient).length === 0) {
document.getElementById('task-container').innerHTML = '<div class="loading">📭 Nessun task trovato</div>';
return;
}
const html = Object.values(tasksByClient).map(group => {
const progresso = calcolaProgressoTasks(group.tasks);
return `
<div class="cliente-group">
<div class="cliente-header" onclick="toggleClient('client-${group.cliente.id}')">
<span>
<strong>${group.cliente.nome}</strong>
<span style="font-size:0.8rem; margin-left:1rem;">${group.tasks.length} task</span>
</span>
<div style="display:flex; align-items:center; gap:0.5rem;">
<span>${progresso}%</span>
<div class="progress-overall">
<div class="progress-overall-fill" style="width:${progresso}%"></div>
</div>
<span>▼</span>
</div>
</div>
<div class="task-list" id="client-${group.cliente.id}" style="display:block;">
${group.tasks.map(task => `
<div class="task-item" data-task-id="${task.id}">
<div class="task-info">
<div class="task-nome">
${getTaskLabel(task.task_type)}
${task.data_scadenza ? `<span class="task-scadenza">📅 Scade: ${new Date(task.data_scadenza).toLocaleDateString('it-IT')}</span>` : ''}
</div>
</div>
<div class="task-progress">
<select class="status-select" data-task-id="${task.id}" onchange="updateTaskField(${task.id}, 'stato', this.value); saveSingleTask(${task.id})">
<option value="da_iniziare" ${task.stato === 'da_iniziare' ? 'selected' : ''}>🔴 Da iniziare</option>
<option value="in_corso" ${task.stato === 'in_corso' ? 'selected' : ''}>🟡 In corso</option>
<option value="completato" ${task.stato === 'completato' ? 'selected' : ''}>✅ Completato</option>
</select>
</div>
<div class="task-note">
<input type="text" placeholder="Note..." value="${escapeHtml(task.note || '')}"
onchange="updateTaskField(${task.id}, 'note', this.value); saveSingleTask(${task.id})">
</div>
<button class="btn-save-task" onclick="saveSingleTask(${task.id})">💾 Salva</button>
</div>
`).join('')}
</div>
</div>
`;
}).join('');
document.getElementById('task-container').innerHTML = html;
}
function escapeHtml(str) {
if (!str) return '';
return str.replace(/[&<>]/g, function(m) {
if (m === '&') return '&';
if (m === '<') return '<';
if (m === '>') return '>';
return m;
});
}
function toggleClient(id) {
const element = document.getElementById(id);
if (element.style.display === 'none') {
element.style.display = 'block';
} else {
element.style.display = 'none';
}
}
function logout() {
sessionStorage.removeItem('logged');
window.location.href = 'index.html';
}
document.getElementById('filtro-stato').addEventListener('change', renderTasks);
document.getElementById('filtro-anno').addEventListener('change', renderTasks);
document.getElementById('filtro-cliente').addEventListener('input', renderTasks);
loadData();
</script>
</body>
</html>