sam00 / index.html
valsi's picture
Add 3 files
6be0485 verified
Raw History Blame Contribute Delete
49.1 kB
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diario di Lavoro - Gestione Squadre</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<style>
.table-seat {
transition: all 0.3s ease;
}
.table-seat:hover {
transform: scale(1.05);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.table-surface {
background: linear-gradient(135deg, #f5f7fa 0%, #e4e8eb 100%);
}
.draggable-item {
cursor: grab;
transition: all 0.2s ease;
}
.draggable-item:active {
cursor: grabbing;
}
.draggable-item:hover {
background-color: #f0f4ff;
}
.rotate-text {
writing-mode: vertical-rl;
text-orientation: mixed;
transform: rotate(180deg);
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<header class="mb-8">
<div class="flex justify-between items-center">
<div>
<h1 class="text-3xl font-bold text-indigo-800">Diario di Lavoro</h1>
<div id="current-date" class="text-gray-600 mt-1"></div>
</div>
<div class="flex space-x-4">
<button id="prev-day" class="bg-gray-200 hover:bg-gray-300 px-4 py-2 rounded-lg">
<i class="fas fa-arrow-left"></i>
</button>
<button id="next-day" class="bg-gray-200 hover:bg-gray-300 px-4 py-2 rounded-lg">
<i class="fas fa-arrow-right"></i>
</button>
<button id="save-btn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg">
<i class="fas fa-save mr-2"></i>Salva
</button>
</div>
</div>
<div class="mt-4 flex flex-wrap gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Turno</label>
<select id="shift-select" class="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
<option value="morning">Mattina</option>
<option value="afternoon">Pomeriggio</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Data</label>
<input type="date" id="date-input" class="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Importa da Excel</label>
<input type="file" id="file-input" accept=".xlsx, .xls" class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-semibold file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100">
</div>
<div class="flex items-end">
<button id="export-btn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg">
<i class="fas fa-file-export mr-2"></i>Esporta Excel
</button>
</div>
</div>
</header>
<!-- Main Content -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Left Panel - Team Members -->
<div class="lg:col-span-1 bg-white p-6 rounded-xl shadow-sm">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold text-gray-800">Persone Disponibili</h2>
<button id="add-person-btn" class="text-indigo-600 hover:text-indigo-800">
<i class="fas fa-plus-circle mr-1"></i> Aggiungi
</button>
</div>
<div class="mb-6">
<div class="flex items-center mb-2">
<input type="text" id="search-person" placeholder="Cerca persona..." class="flex-1 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
<button id="search-btn" class="ml-2 bg-indigo-100 text-indigo-700 p-2 rounded-md">
<i class="fas fa-search"></i>
</button>
</div>
<div id="people-list" class="space-y-2 max-h-96 overflow-y-auto">
<!-- People will be loaded here -->
</div>
</div>
<div class="border-t pt-4">
<h3 class="text-lg font-medium text-gray-800 mb-3">Mansioni Predefinite</h3>
<div id="tasks-list" class="grid grid-cols-2 gap-2">
<!-- Tasks will be loaded here -->
</div>
<div class="mt-3">
<button id="add-task-btn" class="text-sm text-indigo-600 hover:text-indigo-800">
<i class="fas fa-plus mr-1"></i> Aggiungi Mansione
</button>
</div>
</div>
</div>
<!-- Center Panel - Work Table -->
<div class="lg:col-span-2">
<div class="bg-white p-6 rounded-xl shadow-sm mb-6">
<h2 class="text-xl font-semibold text-gray-800 mb-6">Tavolo di Lavoro</h2>
<div class="relative">
<!-- Table Surface -->
<div class="table-surface rounded-lg mx-auto w-full h-64 md:h-80 flex items-center justify-center relative">
<!-- Table shape -->
<div class="absolute inset-0 flex items-center justify-center">
<div class="w-3/4 h-3/4 border-4 border-indigo-200 rounded-lg bg-white shadow-inner"></div>
</div>
<!-- Seats around the table -->
<!-- Top side (3 seats) -->
<div class="absolute top-0 left-0 right-0 flex justify-center space-x-8 md:space-x-16 px-4">
<div class="table-seat seat" data-position="top-left" data-side="top">
<div class="bg-white p-3 rounded-lg shadow-md border border-gray-200 w-24 h-24 flex flex-col items-center justify-center">
<select class="person-select mb-2 w-full text-sm border-gray-300 rounded">
<option value="">Seleziona persona</option>
</select>
<select class="task-select w-full text-sm border-gray-300 rounded">
<option value="">Seleziona mansione</option>
</select>
</div>
</div>
<div class="table-seat seat" data-position="top-center" data-side="top">
<div class="bg-white p-3 rounded-lg shadow-md border border-gray-200 w-24 h-24 flex flex-col items-center justify-center">
<select class="person-select mb-2 w-full text-sm border-gray-300 rounded">
<option value="">Seleziona persona</option>
</select>
<select class="task-select w-full text-sm border-gray-300 rounded">
<option value="">Seleziona mansione</option>
</select>
</div>
</div>
<div class="table-seat seat" data-position="top-right" data-side="top">
<div class="bg-white p-3 rounded-lg shadow-md border border-gray-200 w-24 h-24 flex flex-col items-center justify-center">
<select class="person-select mb-2 w-full text-sm border-gray-300 rounded">
<option value="">Seleziona persona</option>
</select>
<select class="task-select w-full text-sm border-gray-300 rounded">
<option value="">Seleziona mansione</option>
</select>
</div>
</div>
</div>
<!-- Bottom side (3 seats) -->
<div class="absolute bottom-0 left-0 right-0 flex justify-center space-x-8 md:space-x-16 px-4">
<div class="table-seat seat" data-position="bottom-left" data-side="bottom">
<div class="bg-white p-3 rounded-lg shadow-md border border-gray-200 w-24 h-24 flex flex-col items-center justify-center">
<select class="person-select mb-2 w-full text-sm border-gray-300 rounded">
<option value="">Seleziona persona</option>
</select>
<select class="task-select w-full text-sm border-gray-300 rounded">
<option value="">Seleziona mansione</option>
</select>
</div>
</div>
<div class="table-seat seat" data-position="bottom-center" data-side="bottom">
<div class="bg-white p-3 rounded-lg shadow-md border border-gray-200 w-24 h-24 flex flex-col items-center justify-center">
<select class="person-select mb-2 w-full text-sm border-gray-300 rounded">
<option value="">Seleziona persona</option>
</select>
<select class="task-select w-full text-sm border-gray-300 rounded">
<option value="">Seleziona mansione</option>
</select>
</div>
</div>
<div class="table-seat seat" data-position="bottom-right" data-side="bottom">
<div class="bg-white p-3 rounded-lg shadow-md border border-gray-200 w-24 h-24 flex flex-col items-center justify-center">
<select class="person-select mb-2 w-full text-sm border-gray-300 rounded">
<option value="">Seleziona persona</option>
</select>
<select class="task-select w-full text-sm border-gray-300 rounded">
<option value="">Seleziona mansione</option>
</select>
</div>
</div>
</div>
<!-- Your position (center of the table) -->
<div class="absolute inset-0 flex items-center justify-center">
<div class="bg-indigo-100 border-2 border-indigo-300 rounded-full w-16 h-16 flex items-center justify-center shadow-md">
<span class="text-indigo-800 font-medium">TU</span>
</div>
</div>
</div>
</div>
</div>
<!-- Other Tables Assignments -->
<div class="bg-white p-6 rounded-xl shadow-sm">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold text-gray-800">Altri Tavoli</h2>
<button id="add-other-table-btn" class="text-indigo-600 hover:text-indigo-800">
<i class="fas fa-plus-circle mr-1"></i> Aggiungi Tavolo
</button>
</div>
<div id="other-tables-container">
<!-- Other tables assignments will be added here -->
<div class="other-table mb-4 p-4 border border-gray-200 rounded-lg">
<div class="flex justify-between items-center mb-2">
<h3 class="font-medium text-gray-700">Tavolo 1</h3>
<button class="remove-table-btn text-red-500 hover:text-red-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Persona</label>
<select class="other-person-select w-full border-gray-300 rounded">
<option value="">Seleziona persona</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Mansione</label>
<select class="other-task-select w-full border-gray-300 rounded">
<option value="">Seleziona mansione</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Notes Section -->
<div class="mt-8 bg-white p-6 rounded-xl shadow-sm">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Note e Osservazioni</h2>
<textarea id="notes" class="w-full h-32 border border-gray-300 rounded-lg p-3 focus:border-indigo-500 focus:ring-indigo-500" placeholder="Aggiungi qui note importanti, osservazioni o cambiamenti..."></textarea>
</div>
</div>
<!-- Modals -->
<!-- Add Person Modal -->
<div id="add-person-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg p-6 w-full max-w-md">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-medium text-gray-900">Aggiungi Nuova Persona</h3>
<button id="close-person-modal" class="text-gray-400 hover:text-gray-500">
<i class="fas fa-times"></i>
</button>
</div>
<div class="space-y-4">
<div>
<label for="new-person-name" class="block text-sm font-medium text-gray-700 mb-1">Nome e Cognome</label>
<input type="text" id="new-person-name" class="w-full border border-gray-300 rounded-md px-3 py-2">
</div>
<div>
<label for="new-person-code" class="block text-sm font-medium text-gray-700 mb-1">Codice Identificativo (opzionale)</label>
<input type="text" id="new-person-code" class="w-full border border-gray-300 rounded-md px-3 py-2">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Turni Disponibili</label>
<div class="space-y-2">
<label class="inline-flex items-center">
<input type="checkbox" class="form-checkbox text-indigo-600" checked>
<span class="ml-2">Mattina</span>
</label>
<label class="inline-flex items-center">
<input type="checkbox" class="form-checkbox text-indigo-600" checked>
<span class="ml-2">Pomeriggio</span>
</label>
</div>
</div>
</div>
<div class="mt-6 flex justify-end space-x-3">
<button id="cancel-add-person" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">Annulla</button>
<button id="confirm-add-person" class="px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700">Aggiungi</button>
</div>
</div>
</div>
<!-- Add Task Modal -->
<div id="add-task-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg p-6 w-full max-w-md">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-medium text-gray-900">Aggiungi Nuova Mansione</h3>
<button id="close-task-modal" class="text-gray-400 hover:text-gray-500">
<i class="fas fa-times"></i>
</button>
</div>
<div class="space-y-4">
<div>
<label for="new-task-name" class="block text-sm font-medium text-gray-700 mb-1">Nome Mansione</label>
<input type="text" id="new-task-name" class="w-full border border-gray-300 rounded-md px-3 py-2">
</div>
<div>
<label for="new-task-code" class="block text-sm font-medium text-gray-700 mb-1">Codice (opzionale)</label>
<input type="text" id="new-task-code" class="w-full border border-gray-300 rounded-md px-3 py-2">
</div>
<div>
<label for="new-task-desc" class="block text-sm font-medium text-gray-700 mb-1">Descrizione (opzionale)</label>
<textarea id="new-task-desc" class="w-full border border-gray-300 rounded-md px-3 py-2 h-20"></textarea>
</div>
</div>
<div class="mt-6 flex justify-end space-x-3">
<button id="cancel-add-task" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">Annulla</button>
<button id="confirm-add-task" class="px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700">Aggiungi</button>
</div>
</div>
</div>
<script>
// Sample data
const samplePeople = [
{ id: 1, name: "Mario Rossi", code: "MR", shifts: ["morning", "afternoon"] },
{ id: 2, name: "Luigi Bianchi", code: "LB", shifts: ["morning"] },
{ id: 3, name: "Anna Verdi", code: "AV", shifts: ["afternoon"] },
{ id: 4, name: "Giulia Neri", code: "GN", shifts: ["morning", "afternoon"] },
{ id: 5, name: "Paolo Gialli", code: "PG", shifts: ["morning"] },
{ id: 6, name: "Laura Blu", code: "LB", shifts: ["afternoon"] },
{ id: 7, name: "Marco Viola", code: "MV", shifts: ["morning", "afternoon"] },
{ id: 8, name: "Sara Rosa", code: "SR", shifts: ["morning"] },
{ id: 9, name: "Andrea Celeste", code: "AC", shifts: ["afternoon"] },
{ id: 10, name: "Elena Arancione", code: "EA", shifts: ["morning", "afternoon"] }
];
const sampleTasks = [
{ id: 1, name: "Assemblaggio", code: "ASS", description: "Assemblaggio componenti principali" },
{ id: 2, name: "Controllo Qualità", code: "CQ", description: "Controllo qualità prodotto finito" },
{ id: 3, name: "Imballaggio", code: "IMB", description: "Preparazione imballaggio per spedizione" },
{ id: 4, name: "Logistica", code: "LOG", description: "Gestione movimentazione materiali" },
{ id: 5, name: "Manutenzione", code: "MAN", description: "Manutenzione ordinaria macchinari" }
];
// Initialize app data
let appData = {
currentDate: new Date(),
people: [...samplePeople],
tasks: [...sampleTasks],
assignments: {
morning: {
table: {
"top-left": { person: null, task: null },
"top-center": { person: null, task: null },
"top-right": { person: null, task: null },
"bottom-left": { person: null, task: null },
"bottom-center": { person: null, task: null },
"bottom-right": { person: null, task: null }
},
otherTables: []
},
afternoon: {
table: {
"top-left": { person: null, task: null },
"top-center": { person: null, task: null },
"top-right": { person: null, task: null },
"bottom-left": { person: null, task: null },
"bottom-center": { person: null, task: null },
"bottom-right": { person: null, task: null }
},
otherTables: []
}
},
notes: ""
};
// DOM Elements
const currentDateElement = document.getElementById('current-date');
const dateInput = document.getElementById('date-input');
const shiftSelect = document.getElementById('shift-select');
const peopleList = document.getElementById('people-list');
const tasksList = document.getElementById('tasks-list');
const notesTextarea = document.getElementById('notes');
const otherTablesContainer = document.getElementById('other-tables-container');
const searchPersonInput = document.getElementById('search-person');
const searchBtn = document.getElementById('search-btn');
const prevDayBtn = document.getElementById('prev-day');
const nextDayBtn = document.getElementById('next-day');
const saveBtn = document.getElementById('save-btn');
const exportBtn = document.getElementById('export-btn');
const fileInput = document.getElementById('file-input');
const addPersonBtn = document.getElementById('add-person-btn');
const addTaskBtn = document.getElementById('add-task-btn');
const addOtherTableBtn = document.getElementById('add-other-table-btn');
// Modal elements
const addPersonModal = document.getElementById('add-person-modal');
const closePersonModal = document.getElementById('close-person-modal');
const cancelAddPerson = document.getElementById('cancel-add-person');
const confirmAddPerson = document.getElementById('confirm-add-person');
const newPersonName = document.getElementById('new-person-name');
const newPersonCode = document.getElementById('new-person-code');
const addTaskModal = document.getElementById('add-task-modal');
const closeTaskModal = document.getElementById('close-task-modal');
const cancelAddTask = document.getElementById('cancel-add-task');
const confirmAddTask = document.getElementById('confirm-add-task');
const newTaskName = document.getElementById('new-task-name');
const newTaskCode = document.getElementById('new-task-code');
const newTaskDesc = document.getElementById('new-task-desc');
// Initialize the app
function init() {
updateDateDisplay();
renderPeopleList();
renderTasksList();
loadAssignments();
setupEventListeners();
}
// Update date display
function updateDateDisplay() {
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
currentDateElement.textContent = appData.currentDate.toLocaleDateString('it-IT', options);
dateInput.valueAsDate = appData.currentDate;
}
// Render people list
function renderPeopleList(filter = '') {
peopleList.innerHTML = '';
const filteredPeople = appData.people.filter(person =>
person.name.toLowerCase().includes(filter.toLowerCase()) ||
(person.code && person.code.toLowerCase().includes(filter.toLowerCase()))
);
filteredPeople.forEach(person => {
const personElement = document.createElement('div');
personElement.className = 'draggable-item bg-gray-50 p-3 rounded-lg border border-gray-200 flex justify-between items-center';
personElement.dataset.personId = person.id;
personElement.draggable = true;
personElement.innerHTML = `
<div>
<span class="font-medium">${person.name}</span>
${person.code ? `<span class="text-xs bg-gray-200 px-2 py-1 rounded ml-2">${person.code}</span>` : ''}
</div>
<div class="flex space-x-2">
${person.shifts.includes('morning') ? '<span class="text-xs bg-yellow-100 text-yellow-800 px-2 py-1 rounded">M</span>' : ''}
${person.shifts.includes('afternoon') ? '<span class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded">P</span>' : ''}
</div>
`;
personElement.addEventListener('dragstart', handleDragStart);
peopleList.appendChild(personElement);
});
}
// Render tasks list
function renderTasksList() {
tasksList.innerHTML = '';
appData.tasks.forEach(task => {
const taskElement = document.createElement('div');
taskElement.className = 'draggable-item bg-gray-50 p-2 rounded border border-gray-200 text-sm';
taskElement.dataset.taskId = task.id;
taskElement.draggable = true;
taskElement.innerHTML = `
<div class="font-medium">${task.name}</div>
${task.code ? `<div class="text-xs text-gray-500">${task.code}</div>` : ''}
`;
taskElement.addEventListener('dragstart', handleDragStart);
tasksList.appendChild(taskElement);
});
}
// Load assignments for current shift
function loadAssignments() {
const currentShift = shiftSelect.value;
const assignments = appData.assignments[currentShift];
// Load main table assignments
Object.keys(assignments.table).forEach(position => {
const seat = document.querySelector(`.seat[data-position="${position}"]`);
const personSelect = seat.querySelector('.person-select');
const taskSelect = seat.querySelector('.task-select');
// Clear and populate person select
personSelect.innerHTML = '<option value="">Seleziona persona</option>';
appData.people.forEach(person => {
if (person.shifts.includes(currentShift)) {
const option = document.createElement('option');
option.value = person.id;
option.textContent = person.name;
if (assignments.table[position].person === person.id) {
option.selected = true;
}
personSelect.appendChild(option);
}
});
// Add temporary person if exists
if (assignments.table[position].person && !appData.people.some(p => p.id === assignments.table[position].person)) {
const option = document.createElement('option');
option.value = assignments.table[position].person;
option.textContent = `[EXT] ${assignments.table[position].person}`;
option.selected = true;
personSelect.appendChild(option);
}
// Clear and populate task select
taskSelect.innerHTML = '<option value="">Seleziona mansione</option>';
appData.tasks.forEach(task => {
const option = document.createElement('option');
option.value = task.id;
option.textContent = task.name;
if (assignments.table[position].task === task.id) {
option.selected = true;
}
taskSelect.appendChild(option);
});
// Add temporary task if exists
if (assignments.table[position].task && !appData.tasks.some(t => t.id === assignments.table[position].task)) {
const option = document.createElement('option');
option.value = assignments.table[position].task;
option.textContent = `[EXT] ${assignments.table[position].task}`;
option.selected = true;
taskSelect.appendChild(option);
}
});
// Load other tables assignments
otherTablesContainer.innerHTML = '';
assignments.otherTables.forEach((table, index) => {
addOtherTable(table.person, table.task, index);
});
// Load notes
notesTextarea.value = appData.notes;
}
// Save assignments for current shift
function saveAssignments() {
const currentShift = shiftSelect.value;
const assignments = appData.assignments[currentShift];
// Save main table assignments
document.querySelectorAll('.seat').forEach(seat => {
const position = seat.dataset.position;
const personSelect = seat.querySelector('.person-select');
const taskSelect = seat.querySelector('.task-select');
assignments.table[position] = {
person: personSelect.value ? parseInt(personSelect.value) : null,
task: taskSelect.value ? parseInt(taskSelect.value) : null
};
});
// Save other tables assignments
assignments.otherTables = [];
document.querySelectorAll('.other-table').forEach(table => {
const personSelect = table.querySelector('.other-person-select');
const taskSelect = table.querySelector('.other-task-select');
assignments.otherTables.push({
person: personSelect.value ? parseInt(personSelect.value) : null,
task: taskSelect.value ? parseInt(taskSelect.value) : null
});
});
// Save notes
appData.notes = notesTextarea.value;
// Show save confirmation
const saveNotification = document.createElement('div');
saveNotification.className = 'fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg';
saveNotification.textContent = 'Dati salvati con successo!';
document.body.appendChild(saveNotification);
setTimeout(() => {
saveNotification.classList.add('opacity-0', 'transition-opacity', 'duration-500');
setTimeout(() => saveNotification.remove(), 500);
}, 2000);
}
// Add other table assignment
function addOtherTable(personId = null, taskId = null, index = null) {
const tableDiv = document.createElement('div');
tableDiv.className = 'other-table mb-4 p-4 border border-gray-200 rounded-lg';
const tableId = index !== null ? index : Date.now();
tableDiv.dataset.tableId = tableId;
tableDiv.innerHTML = `
<div class="flex justify-between items-center mb-2">
<h3 class="font-medium text-gray-700">Tavolo ${tableId + 1}</h3>
<button class="remove-table-btn text-red-500 hover:text-red-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Persona</label>
<select class="other-person-select w-full border-gray-300 rounded">
<option value="">Seleziona persona</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Mansione</label>
<select class="other-task-select w-full border-gray-300 rounded">
<option value="">Seleziona mansione</option>
</select>
</div>
</div>
`;
// Populate person select
const personSelect = tableDiv.querySelector('.other-person-select');
appData.people.forEach(person => {
if (person.shifts.includes(shiftSelect.value)) {
const option = document.createElement('option');
option.value = person.id;
option.textContent = person.name;
if (personId === person.id) {
option.selected = true;
}
personSelect.appendChild(option);
}
});
// Add temporary person if exists
if (personId && !appData.people.some(p => p.id === personId)) {
const option = document.createElement('option');
option.value = personId;
option.textContent = `[EXT] ${personId}`;
option.selected = true;
personSelect.appendChild(option);
}
// Populate task select
const taskSelect = tableDiv.querySelector('.other-task-select');
appData.tasks.forEach(task => {
const option = document.createElement('option');
option.value = task.id;
option.textContent = task.name;
if (taskId === task.id) {
option.selected = true;
}
option.dataset.taskId = task.id;
taskSelect.appendChild(option);
});
// Add temporary task if exists
if (taskId && !appData.tasks.some(t => t.id === taskId)) {
const option = document.createElement('option');
option.value = taskId;
option.textContent = `[EXT] ${taskId}`;
option.selected = true;
taskSelect.appendChild(option);
}
// Add remove event
tableDiv.querySelector('.remove-table-btn').addEventListener('click', () => {
tableDiv.remove();
});
otherTablesContainer.appendChild(tableDiv);
}
// Handle drag and drop
function handleDragStart(e) {
e.dataTransfer.setData('text/plain', e.target.dataset.personId || e.target.dataset.taskId);
e.dataTransfer.effectAllowed = 'copy';
// Set drag image
const dragImage = e.target.cloneNode(true);
dragImage.style.width = `${e.target.offsetWidth}px`;
dragImage.style.height = `${e.target.offsetHeight}px`;
dragImage.style.position = 'absolute';
dragImage.style.top = '-9999px';
document.body.appendChild(dragImage);
e.dataTransfer.setDragImage(dragImage, e.target.offsetWidth / 2, e.target.offsetHeight / 2);
setTimeout(() => document.body.removeChild(dragImage), 0);
}
// Setup event listeners
function setupEventListeners() {
// Date navigation
prevDayBtn.addEventListener('click', () => {
appData.currentDate.setDate(appData.currentDate.getDate() - 1);
updateDateDisplay();
});
nextDayBtn.addEventListener('click', () => {
appData.currentDate.setDate(appData.currentDate.getDate() + 1);
updateDateDisplay();
});
dateInput.addEventListener('change', () => {
appData.currentDate = new Date(dateInput.value);
updateDateDisplay();
});
// Shift change
shiftSelect.addEventListener('change', loadAssignments);
// Save button
saveBtn.addEventListener('click', saveAssignments);
// Export to Excel
exportBtn.addEventListener('click', exportToExcel);
// Import from Excel
fileInput.addEventListener('change', importFromExcel);
// Search
searchBtn.addEventListener('click', () => {
renderPeopleList(searchPersonInput.value);
});
searchPersonInput.addEventListener('keyup', (e) => {
if (e.key === 'Enter') {
renderPeopleList(searchPersonInput.value);
}
});
// Add person
addPersonBtn.addEventListener('click', () => {
newPersonName.value = '';
newPersonCode.value = '';
addPersonModal.classList.remove('hidden');
});
closePersonModal.addEventListener('click', () => {
addPersonModal.classList.add('hidden');
});
cancelAddPerson.addEventListener('click', () => {
addPersonModal.classList.add('hidden');
});
confirmAddPerson.addEventListener('click', () => {
const name = newPersonName.value.trim();
if (name) {
const newId = appData.people.length > 0 ? Math.max(...appData.people.map(p => p.id)) + 1 : 1;
const newPerson = {
id: newId,
name: name,
code: newPersonCode.value.trim() || null,
shifts: ['morning', 'afternoon'] // Default to both shifts
};
appData.people.push(newPerson);
renderPeopleList();
addPersonModal.classList.add('hidden');
}
});
// Add task
addTaskBtn.addEventListener('click', () => {
newTaskName.value = '';
newTaskCode.value = '';
newTaskDesc.value = '';
addTaskModal.classList.remove('hidden');
});
closeTaskModal.addEventListener('click', () => {
addTaskModal.classList.add('hidden');
});
cancelAddTask.addEventListener('click', () => {
addTaskModal.classList.add('hidden');
});
confirmAddTask.addEventListener('click', () => {
const name = newTaskName.value.trim();
if (name) {
const newId = appData.tasks.length > 0 ? Math.max(...appData.tasks.map(t => t.id)) + 1 : 1;
const newTask = {
id: newId,
name: name,
code: newTaskCode.value.trim() || null,
description: newTaskDesc.value.trim() || null
};
appData.tasks.push(newTask);
renderTasksList();
addTaskModal.classList.add('hidden');
}
});
// Add other table
addOtherTableBtn.addEventListener('click', () => {
addOtherTable();
});
// Setup drag and drop for seats
document.querySelectorAll('.seat').forEach(seat => {
seat.addEventListener('dragover', (e) => {
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
seat.classList.add('ring-2', 'ring-indigo-500');
});
seat.addEventListener('dragleave', () => {
seat.classList.remove('ring-2', 'ring-indigo-500');
});
seat.addEventListener('drop', (e) => {
e.preventDefault();
seat.classList.remove('ring-2', 'ring-indigo-500');
const id = e.dataTransfer.getData('text/plain');
const isPerson = appData.people.some(p => p.id == id);
const isTask = appData.tasks.some(t => t.id == id);
if (isPerson) {
const select = seat.querySelector('.person-select');
select.value = id;
select.dispatchEvent(new Event('change'));
} else if (isTask) {
const select = seat.querySelector('.task-select');
select.value = id;
select.dispatchEvent(new Event('change'));
}
});
});
}
// Export to Excel
function exportToExcel() {
const currentShift = shiftSelect.value;
const assignments = appData.assignments[currentShift];
// Prepare data
const data = [
["Diario di Lavoro", "", "", "", ""],
["Data:", appData.currentDate.toLocaleDateString('it-IT'), "", "", ""],
["Giorno:", appData.currentDate.toLocaleDateString('it-IT', { weekday: 'long' }), "", "", ""],
["Turno:", currentShift === 'morning' ? 'Mattina' : 'Pomeriggio', "", "", ""],
["", "", "", "", ""],
["Tavolo Principale", "", "", "", ""],
["Posizione", "Persona", "Mansione", "", ""]
];
// Add main table assignments
Object.keys(assignments.table).forEach(position => {
const person = assignments.table[position].person
? (appData.people.find(p => p.id === assignments.table[position].person)?.name || `[EXT] ${assignments.table[position].person}`)
: '';
const task = assignments.table[position].task
? (appData.tasks.find(t => t.id === assignments.table[position].task)?.name || `[EXT] ${assignments.table[position].task}`)
: '';
data.push([position, person, task, "", ""]);
});
// Add other tables
data.push(["", "", "", "", ""]);
data.push(["Altri Tavoli", "", "", "", ""]);
data.push(["Tavolo", "Persona", "Mansione", "", ""]);
assignments.otherTables.forEach((table, index) => {
const person = table.person
? (appData.people.find(p => p.id === table.person)?.name || `[EXT] ${table.person}`)
: '';
const task = table.task
? (appData.tasks.find(t => t.id === table.task)?.name || `[EXT] ${table.task}`)
: '';
data.push([`Tavolo ${index + 1}`, person, task, "", ""]);
});
// Add notes
data.push(["", "", "", "", ""]);
data.push(["Note e Osservazioni", "", "", "", ""]);
data.push([appData.notes, "", "", "", ""]);
// Create workbook
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, "Diario");
// Generate file
const fileName = `Diario_Lavoro_${appData.currentDate.toISOString().split('T')[0]}_${currentShift}.xlsx`;
XLSX.writeFile(wb, fileName);
}
// Import from Excel
function importFromExcel(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
// Process the first sheet
const firstSheet = workbook.Sheets[workbook.SheetNames[0]];
const jsonData = XLSX.utils.sheet_to_json(firstSheet, { header: 1 });
// Here you would parse the Excel data and update appData
// This is a simplified example - you would need to implement proper parsing
console.log("Importing data:", jsonData);
// Reset file input
fileInput.value = '';
// Show import notification
const importNotification = document.createElement('div');
importNotification.className = 'fixed bottom-4 right-4 bg-blue-500 text-white px-4 py-2 rounded-lg shadow-lg';
importNotification.textContent = 'Dati importati con successo!';
document.body.appendChild(importNotification);
setTimeout(() => {
importNotification.classList.add('opacity-0', 'transition-opacity', 'duration-500');
setTimeout(() => importNotification.remove(), 500);
}, 2000);
};
reader.readAsArrayBuffer(file);
}
// Initialize the app
document.addEventListener('DOMContentLoaded', init);
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=valsi/sam00" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>