mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
Compare commits
1 Commits
v1.0.20
...
feature/ex
| Author | SHA1 | Date | |
|---|---|---|---|
| 59e326fae3 |
@@ -592,26 +592,6 @@ async function getShiftPlanById(planId: string): Promise<any> {
|
|||||||
`, [planId]);
|
`, [planId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load employees without role column + join with employee_roles
|
|
||||||
const employees = await db.all<any>(`
|
|
||||||
SELECT
|
|
||||||
e.id,
|
|
||||||
e.firstname,
|
|
||||||
e.lastname,
|
|
||||||
e.email,
|
|
||||||
e.employee_type,
|
|
||||||
e.contract_type,
|
|
||||||
e.can_work_alone,
|
|
||||||
e.is_trainee,
|
|
||||||
e.is_active as isActive,
|
|
||||||
GROUP_CONCAT(er.role) as roles
|
|
||||||
FROM employees e
|
|
||||||
LEFT JOIN employee_roles er ON e.id = er.employee_id
|
|
||||||
WHERE e.is_active = 1
|
|
||||||
GROUP BY e.id
|
|
||||||
ORDER BY e.firstname, e.lastname
|
|
||||||
`, []);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...plan,
|
...plan,
|
||||||
isTemplate: plan.is_template === 1,
|
isTemplate: plan.is_template === 1,
|
||||||
@@ -649,19 +629,6 @@ async function getShiftPlanById(planId: string): Promise<any> {
|
|||||||
requiredEmployees: shift.required_employees,
|
requiredEmployees: shift.required_employees,
|
||||||
assignedEmployees: JSON.parse(shift.assigned_employees || '[]'),
|
assignedEmployees: JSON.parse(shift.assigned_employees || '[]'),
|
||||||
timeSlotName: shift.time_slot_name
|
timeSlotName: shift.time_slot_name
|
||||||
})),
|
|
||||||
// Include employees with proper role handling
|
|
||||||
employees: employees.map(emp => ({
|
|
||||||
id: emp.id,
|
|
||||||
firstname: emp.firstname,
|
|
||||||
lastname: emp.lastname,
|
|
||||||
email: emp.email,
|
|
||||||
employeeType: emp.employee_type,
|
|
||||||
contractType: emp.contract_type,
|
|
||||||
canWorkAlone: emp.can_work_alone === 1,
|
|
||||||
isTrainee: emp.is_trainee === 1,
|
|
||||||
isActive: emp.isActive === 1,
|
|
||||||
roles: emp.roles ? emp.roles.split(',') : [] // Convert comma-separated roles to array
|
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -965,247 +932,4 @@ export const clearAssignments = async (req: Request, res: Response): Promise<voi
|
|||||||
console.error('❌ Error clearing assignments:', error);
|
console.error('❌ Error clearing assignments:', error);
|
||||||
res.status(500).json({ error: 'Internal server error' });
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const exportShiftPlanToExcel = async (req: Request, res: Response): Promise<void> => {
|
|
||||||
try {
|
|
||||||
const { id } = req.params;
|
|
||||||
|
|
||||||
console.log('📊 Starting Excel export for plan:', id);
|
|
||||||
|
|
||||||
// Check if plan exists
|
|
||||||
const plan = await getShiftPlanById(id);
|
|
||||||
if (!plan) {
|
|
||||||
res.status(404).json({ error: 'Shift plan not found' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plan.status !== 'published') {
|
|
||||||
res.status(400).json({ error: 'Can only export published shift plans' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For now, return a simple CSV as placeholder
|
|
||||||
// In a real implementation, you would use a library like exceljs or xlsx
|
|
||||||
|
|
||||||
const csvData = generateCSVFromPlan(plan);
|
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="Schichtplan_${plan.name}_${new Date().toISOString().split('T')[0]}.xlsx"`);
|
|
||||||
|
|
||||||
// For now, return CSV as placeholder - replace with actual Excel generation
|
|
||||||
res.setHeader('Content-Type', 'text/csv');
|
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="Schichtplan_${plan.name}_${new Date().toISOString().split('T')[0]}.csv"`);
|
|
||||||
res.send(csvData);
|
|
||||||
|
|
||||||
console.log('✅ Excel export completed for plan:', id);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ Error exporting to Excel:', error);
|
|
||||||
res.status(500).json({ error: 'Internal server error during Excel export' });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const exportShiftPlanToPDF = async (req: Request, res: Response): Promise<void> => {
|
|
||||||
try {
|
|
||||||
const { id } = req.params;
|
|
||||||
|
|
||||||
console.log('📄 Starting PDF export for plan:', id);
|
|
||||||
|
|
||||||
// Check if plan exists
|
|
||||||
const plan = await getShiftPlanById(id);
|
|
||||||
if (!plan) {
|
|
||||||
res.status(404).json({ error: 'Shift plan not found' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plan.status !== 'published') {
|
|
||||||
res.status(400).json({ error: 'Can only export published shift plans' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For now, return a simple HTML as placeholder
|
|
||||||
// In a real implementation, you would use a library like pdfkit, puppeteer, or html-pdf
|
|
||||||
|
|
||||||
const pdfData = generateHTMLFromPlan(plan);
|
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'application/pdf');
|
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="Schichtplan_${plan.name}_${new Date().toISOString().split('T')[0]}.pdf"`);
|
|
||||||
|
|
||||||
// For now, return HTML as placeholder - replace with actual PDF generation
|
|
||||||
res.setHeader('Content-Type', 'text/html');
|
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="Schichtplan_${plan.name}_${new Date().toISOString().split('T')[0]}.html"`);
|
|
||||||
res.send(pdfData);
|
|
||||||
|
|
||||||
console.log('✅ PDF export completed for plan:', id);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ Error exporting to PDF:', error);
|
|
||||||
res.status(500).json({ error: 'Internal server error during PDF export' });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper function to generate CSV data
|
|
||||||
function generateCSVFromPlan(plan: any): string {
|
|
||||||
const headers = ['Datum', 'Tag', 'Schicht', 'Zeit', 'Zugewiesene Mitarbeiter', 'Benötigte Mitarbeiter'];
|
|
||||||
const rows: string[] = [headers.join(';')];
|
|
||||||
|
|
||||||
// Group scheduled shifts by date for better organization
|
|
||||||
const shiftsByDate = new Map();
|
|
||||||
|
|
||||||
plan.scheduledShifts?.forEach((scheduledShift: any) => {
|
|
||||||
const date = scheduledShift.date;
|
|
||||||
if (!shiftsByDate.has(date)) {
|
|
||||||
shiftsByDate.set(date, []);
|
|
||||||
}
|
|
||||||
shiftsByDate.get(date).push(scheduledShift);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sort dates chronologically
|
|
||||||
const sortedDates = Array.from(shiftsByDate.keys()).sort();
|
|
||||||
|
|
||||||
sortedDates.forEach(date => {
|
|
||||||
const dateShifts = shiftsByDate.get(date);
|
|
||||||
const dateObj = new Date(date);
|
|
||||||
const dayName = getGermanDayName(dateObj.getDay());
|
|
||||||
|
|
||||||
dateShifts.forEach((scheduledShift: any) => {
|
|
||||||
const timeSlot = plan.timeSlots?.find((ts: any) => ts.id === scheduledShift.timeSlotId);
|
|
||||||
const employeeNames = scheduledShift.assignedEmployees.map((empId: string) => {
|
|
||||||
const employee = plan.employees?.find((emp: any) => emp.id === empId);
|
|
||||||
return employee ? `${employee.firstname} ${employee.lastname}` : 'Unbekannt';
|
|
||||||
}).join(', ');
|
|
||||||
|
|
||||||
const row = [
|
|
||||||
date,
|
|
||||||
dayName,
|
|
||||||
timeSlot?.name || 'Unbekannt',
|
|
||||||
timeSlot ? `${timeSlot.startTime} - ${timeSlot.endTime}` : '',
|
|
||||||
employeeNames || 'Keine Zuweisungen',
|
|
||||||
scheduledShift.requiredEmployees || 2
|
|
||||||
].map(field => `"${field}"`).join(';');
|
|
||||||
|
|
||||||
rows.push(row);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add plan summary
|
|
||||||
rows.push('');
|
|
||||||
rows.push('Plan Zusammenfassung');
|
|
||||||
rows.push(`"Plan Name";"${plan.name}"`);
|
|
||||||
rows.push(`"Zeitraum";"${plan.startDate} bis ${plan.endDate}"`);
|
|
||||||
rows.push(`"Status";"${plan.status}"`);
|
|
||||||
rows.push(`"Erstellt von";"${plan.created_by_name || 'Unbekannt'}"`);
|
|
||||||
rows.push(`"Erstellt am";"${plan.createdAt}"`);
|
|
||||||
rows.push(`"Anzahl Schichten";"${plan.scheduledShifts?.length || 0}"`);
|
|
||||||
|
|
||||||
return rows.join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to generate HTML data
|
|
||||||
function generateHTMLFromPlan(plan: any): string {
|
|
||||||
const shiftsByDate = new Map();
|
|
||||||
|
|
||||||
plan.scheduledShifts?.forEach((scheduledShift: any) => {
|
|
||||||
const date = scheduledShift.date;
|
|
||||||
if (!shiftsByDate.has(date)) {
|
|
||||||
shiftsByDate.set(date, []);
|
|
||||||
}
|
|
||||||
shiftsByDate.get(date).push(scheduledShift);
|
|
||||||
});
|
|
||||||
|
|
||||||
const sortedDates = Array.from(shiftsByDate.keys()).sort();
|
|
||||||
|
|
||||||
let html = `
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Schichtplan: ${plan.name}</title>
|
|
||||||
<style>
|
|
||||||
body { font-family: Arial, sans-serif; margin: 20px; }
|
|
||||||
h1 { color: #2c3e50; }
|
|
||||||
h2 { color: #34495e; margin-top: 30px; }
|
|
||||||
table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
|
|
||||||
th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
|
|
||||||
th { background-color: #f2f2f2; font-weight: bold; }
|
|
||||||
tr:nth-child(even) { background-color: #f9f9f9; }
|
|
||||||
.summary { background-color: #e8f4fd; padding: 15px; border-radius: 5px; margin-bottom: 20px; }
|
|
||||||
.date-section { margin-bottom: 30px; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Schichtplan: ${plan.name}</h1>
|
|
||||||
|
|
||||||
<div class="summary">
|
|
||||||
<h2>Plan Informationen</h2>
|
|
||||||
<p><strong>Zeitraum:</strong> ${plan.startDate} bis ${plan.endDate}</p>
|
|
||||||
<p><strong>Status:</strong> ${plan.status}</p>
|
|
||||||
<p><strong>Erstellt von:</strong> ${plan.created_by_name || 'Unbekannt'}</p>
|
|
||||||
<p><strong>Erstellt am:</strong> ${plan.createdAt}</p>
|
|
||||||
<p><strong>Anzahl Schichten:</strong> ${plan.scheduledShifts?.length || 0}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h2>Schichtzuweisungen</h2>
|
|
||||||
`;
|
|
||||||
|
|
||||||
sortedDates.forEach(date => {
|
|
||||||
const dateShifts = shiftsByDate.get(date);
|
|
||||||
const dateObj = new Date(date);
|
|
||||||
const dayName = getGermanDayName(dateObj.getDay());
|
|
||||||
|
|
||||||
html += `
|
|
||||||
<div class="date-section">
|
|
||||||
<h3>${date} (${dayName})</h3>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Schicht</th>
|
|
||||||
<th>Zeit</th>
|
|
||||||
<th>Zugewiesene Mitarbeiter</th>
|
|
||||||
<th>Benötigte Mitarbeiter</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
`;
|
|
||||||
|
|
||||||
dateShifts.forEach((scheduledShift: any) => {
|
|
||||||
const timeSlot = plan.timeSlots?.find((ts: any) => ts.id === scheduledShift.timeSlotId);
|
|
||||||
const employeeNames = scheduledShift.assignedEmployees.map((empId: string) => {
|
|
||||||
const employee = plan.employees?.find((emp: any) => emp.id === empId);
|
|
||||||
return employee ? `${employee.firstname} ${employee.lastname}` : 'Unbekannt';
|
|
||||||
}).join(', ') || 'Keine Zuweisungen';
|
|
||||||
|
|
||||||
html += `
|
|
||||||
<tr>
|
|
||||||
<td>${timeSlot?.name || 'Unbekannt'}</td>
|
|
||||||
<td>${timeSlot ? `${timeSlot.startTime} - ${timeSlot.endTime}` : ''}</td>
|
|
||||||
<td>${employeeNames}</td>
|
|
||||||
<td>${scheduledShift.requiredEmployees || 2}</td>
|
|
||||||
</tr>
|
|
||||||
`;
|
|
||||||
});
|
|
||||||
|
|
||||||
html += `
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
});
|
|
||||||
|
|
||||||
html += `
|
|
||||||
<div style="margin-top: 40px; font-size: 12px; color: #666; text-align: center;">
|
|
||||||
Erstellt am: ${new Date().toLocaleString('de-DE')}
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`;
|
|
||||||
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to get German day names
|
|
||||||
function getGermanDayName(dayIndex: number): string {
|
|
||||||
const days = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];
|
|
||||||
return days[dayIndex];
|
|
||||||
}
|
|
||||||
@@ -7,9 +7,7 @@ import {
|
|||||||
updateShiftPlan,
|
updateShiftPlan,
|
||||||
deleteShiftPlan,
|
deleteShiftPlan,
|
||||||
createFromPreset,
|
createFromPreset,
|
||||||
clearAssignments,
|
clearAssignments
|
||||||
exportShiftPlanToExcel,
|
|
||||||
exportShiftPlanToPDF
|
|
||||||
} from '../controllers/shiftPlanController.js';
|
} from '../controllers/shiftPlanController.js';
|
||||||
import {
|
import {
|
||||||
validateShiftPlan,
|
validateShiftPlan,
|
||||||
@@ -32,7 +30,4 @@ router.put('/:id', validateId, validateShiftPlanUpdate, handleValidationErrors,
|
|||||||
router.delete('/:id', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), deleteShiftPlan);
|
router.delete('/:id', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), deleteShiftPlan);
|
||||||
router.post('/:id/clear-assignments', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), clearAssignments);
|
router.post('/:id/clear-assignments', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), clearAssignments);
|
||||||
|
|
||||||
router.get('/:id/export/excel', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), exportShiftPlanToExcel);
|
|
||||||
router.get('/:id/export/pdf', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), exportShiftPlanToPDF);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -19,6 +19,8 @@ export const designTokens = {
|
|||||||
9: '#cda8f0',
|
9: '#cda8f0',
|
||||||
10: '#ebd7fa',
|
10: '#ebd7fa',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
manager: '#CC0000',
|
||||||
|
|
||||||
// Semantic Colors
|
// Semantic Colors
|
||||||
primary: '#51258f',
|
primary: '#51258f',
|
||||||
|
|||||||
@@ -896,9 +896,6 @@ const ShiftPlanView: React.FC = () => {
|
|||||||
<div style={{ fontSize: '14px', color: '#666' }}>
|
<div style={{ fontSize: '14px', color: '#666' }}>
|
||||||
{formatTime(timeSlot.startTime)} - {formatTime(timeSlot.endTime)}
|
{formatTime(timeSlot.startTime)} - {formatTime(timeSlot.endTime)}
|
||||||
</div>
|
</div>
|
||||||
<div style={{ fontSize: '11px', color: '#999', marginTop: '4px' }}>
|
|
||||||
ID: {timeSlot.id.substring(0, 8)}...
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
{days.map(weekday => {
|
{days.map(weekday => {
|
||||||
const shift = timeSlot.shiftsByDay[weekday.id];
|
const shift = timeSlot.shiftsByDay[weekday.id];
|
||||||
@@ -922,7 +919,55 @@ const ShiftPlanView: React.FC = () => {
|
|||||||
const isValidShift = shift.timeSlotId === timeSlot.id && shift.dayOfWeek === weekday.id;
|
const isValidShift = shift.timeSlotId === timeSlot.id && shift.dayOfWeek === weekday.id;
|
||||||
|
|
||||||
let assignedEmployees: string[] = [];
|
let assignedEmployees: string[] = [];
|
||||||
let displayText = '';
|
let displayContent: React.ReactNode = null;
|
||||||
|
|
||||||
|
// Helper function to create employee boxes
|
||||||
|
const createEmployeeBoxes = (employeeIds: string[]) => {
|
||||||
|
return employeeIds.map(empId => {
|
||||||
|
const employee = employees.find(emp => emp.id === empId);
|
||||||
|
if (!employee) return null;
|
||||||
|
|
||||||
|
// Determine background color based on employee role
|
||||||
|
let backgroundColor = '#642ab5'; // Default: non-trainee personnel (purple)
|
||||||
|
|
||||||
|
if (employee.isTrainee) {
|
||||||
|
backgroundColor = '#cda8f0'; // Trainee
|
||||||
|
} else if (employee.roles?.includes('manager')) {
|
||||||
|
backgroundColor = '#CC0000'; // Manager
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={empId}
|
||||||
|
style={{
|
||||||
|
backgroundColor,
|
||||||
|
color: 'white',
|
||||||
|
padding: '4px 8px',
|
||||||
|
borderRadius: '4px',
|
||||||
|
marginBottom: '2px',
|
||||||
|
fontSize: '12px',
|
||||||
|
textAlign: 'center',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis'
|
||||||
|
}}
|
||||||
|
title={`${employee.firstname} ${employee.lastname}${employee.isTrainee ? ' (Trainee)' : ''}`}
|
||||||
|
>
|
||||||
|
{employee.firstname} {employee.lastname}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}).filter(Boolean);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function to get fallback content
|
||||||
|
const getFallbackContent = () => {
|
||||||
|
const shiftsForSlot = shiftPlan?.shifts?.filter(s =>
|
||||||
|
s.dayOfWeek === weekday.id &&
|
||||||
|
s.timeSlotId === timeSlot.id
|
||||||
|
) || [];
|
||||||
|
const totalRequired = shiftsForSlot.reduce((sum, s) => sum + s.requiredEmployees, 0);
|
||||||
|
return totalRequired === 0 ? '-' : `0/${totalRequired}`;
|
||||||
|
};
|
||||||
|
|
||||||
if (shiftPlan?.status === 'published') {
|
if (shiftPlan?.status === 'published') {
|
||||||
// For published plans, use actual assignments from scheduled shifts
|
// For published plans, use actual assignments from scheduled shifts
|
||||||
@@ -935,15 +980,21 @@ const ShiftPlanView: React.FC = () => {
|
|||||||
if (scheduledShift) {
|
if (scheduledShift) {
|
||||||
assignedEmployees = scheduledShift.assignedEmployees || [];
|
assignedEmployees = scheduledShift.assignedEmployees || [];
|
||||||
|
|
||||||
// DEBUG: Log if we're still seeing old data
|
// Log if we're still seeing old data
|
||||||
if (assignedEmployees.length > 0) {
|
if (assignedEmployees.length > 0) {
|
||||||
console.warn(`⚠️ Found non-empty assignments for ${weekday.name} ${timeSlot.name}:`, assignedEmployees);
|
console.warn(`⚠️ Found non-empty assignments for ${weekday.name} ${timeSlot.name}:`, assignedEmployees);
|
||||||
}
|
}
|
||||||
|
|
||||||
displayText = assignedEmployees.map(empId => {
|
const employeeBoxes = createEmployeeBoxes(assignedEmployees);
|
||||||
const employee = employees.find(emp => emp.id === empId);
|
displayContent = employeeBoxes.length > 0 ? (
|
||||||
return employee ? `${employee.firstname} ${employee.lastname}` : 'Unbekannt';
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '2px' }}>
|
||||||
}).join(', ');
|
{employeeBoxes}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div style={{ color: '#666', fontStyle: 'italic' }}>
|
||||||
|
{getFallbackContent()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else if (assignmentResult) {
|
} else if (assignmentResult) {
|
||||||
// For draft with preview, use assignment result
|
// For draft with preview, use assignment result
|
||||||
@@ -955,30 +1006,26 @@ const ShiftPlanView: React.FC = () => {
|
|||||||
|
|
||||||
if (scheduledShift) {
|
if (scheduledShift) {
|
||||||
assignedEmployees = getAssignmentsForScheduledShift(scheduledShift);
|
assignedEmployees = getAssignmentsForScheduledShift(scheduledShift);
|
||||||
displayText = assignedEmployees.map(empId => {
|
const employeeBoxes = createEmployeeBoxes(assignedEmployees);
|
||||||
const employee = employees.find(emp => emp.id === empId);
|
displayContent = employeeBoxes.length > 0 ? (
|
||||||
return employee ? `${employee.firstname} ${employee.lastname}` : 'Unbekannt';
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '2px' }}>
|
||||||
}).join(', ');
|
{employeeBoxes}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div style={{ color: '#666', fontStyle: 'italic' }}>
|
||||||
|
{getFallbackContent()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no assignments yet, show empty or required count
|
// If no display content set yet, use fallback
|
||||||
if (!displayText) {
|
if (!displayContent) {
|
||||||
const shiftsForSlot = shiftPlan?.shifts?.filter(s =>
|
displayContent = (
|
||||||
s.dayOfWeek === weekday.id &&
|
<div style={{ color: '#666', fontStyle: 'italic' }}>
|
||||||
s.timeSlotId === timeSlot.id
|
{getFallbackContent()}
|
||||||
) || [];
|
</div>
|
||||||
|
);
|
||||||
const totalRequired = shiftsForSlot.reduce((sum, s) =>
|
|
||||||
sum + s.requiredEmployees, 0);
|
|
||||||
|
|
||||||
// Show "0/2" instead of just "0" to indicate it's empty
|
|
||||||
displayText = `0/${totalRequired}`;
|
|
||||||
|
|
||||||
// Optional: Show empty state more clearly
|
|
||||||
if (totalRequired === 0) {
|
|
||||||
displayText = '-';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -1013,7 +1060,7 @@ const ShiftPlanView: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{displayText}
|
{displayContent}
|
||||||
|
|
||||||
{/* Shift debug info - SAME AS AVAILABILITYMANAGER */}
|
{/* Shift debug info - SAME AS AVAILABILITYMANAGER */}
|
||||||
<div style={{
|
<div style={{
|
||||||
@@ -1023,8 +1070,6 @@ const ShiftPlanView: React.FC = () => {
|
|||||||
textAlign: 'left',
|
textAlign: 'left',
|
||||||
fontFamily: 'monospace'
|
fontFamily: 'monospace'
|
||||||
}}>
|
}}>
|
||||||
<div>Shift: {shift.id.substring(0, 6)}...</div>
|
|
||||||
<div>Day: {shift.dayOfWeek}</div>
|
|
||||||
{!isValidShift && (
|
{!isValidShift && (
|
||||||
<div style={{ color: '#e74c3c', fontWeight: 'bold' }}>
|
<div style={{ color: '#e74c3c', fontWeight: 'bold' }}>
|
||||||
VALIDATION ERROR
|
VALIDATION ERROR
|
||||||
@@ -1039,7 +1084,6 @@ const ShiftPlanView: React.FC = () => {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1123,7 +1167,7 @@ const ShiftPlanView: React.FC = () => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Your existing "Zuweisungen neu berechnen" button */}
|
{/* "Zuweisungen neu berechnen" button */}
|
||||||
{shiftPlan.status === 'published' && hasRole(['admin', 'maintenance']) && (
|
{shiftPlan.status === 'published' && hasRole(['admin', 'maintenance']) && (
|
||||||
<button
|
<button
|
||||||
onClick={handleRecreateAssignments}
|
onClick={handleRecreateAssignments}
|
||||||
@@ -1405,7 +1449,7 @@ const ShiftPlanView: React.FC = () => {
|
|||||||
Abbrechen
|
Abbrechen
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* KORRIGIERTER BUTTON MIT TYPESCRIPT-FIX */}
|
{/* BUTTON zum publishen */}
|
||||||
<button
|
<button
|
||||||
onClick={handlePublish}
|
onClick={handlePublish}
|
||||||
disabled={publishing || !canPublishAssignment()}
|
disabled={publishing || !canPublishAssignment()}
|
||||||
|
|||||||
Reference in New Issue
Block a user