Compare commits

..

7 Commits

4 changed files with 843 additions and 595 deletions

View File

@@ -27,8 +27,7 @@
"helmet": "8.1.0", "helmet": "8.1.0",
"express-validator": "7.3.0", "express-validator": "7.3.0",
"exceljs": "4.4.0", "exceljs": "4.4.0",
"pdfkit": "0.12.3", "playwright": "^1.37.0"
"@types/pdfkit": "^0.12.3"
}, },
"devDependencies": { "devDependencies": {
"@types/bcryptjs": "^2.4.2", "@types/bcryptjs": "^2.4.2",

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
// frontend/src/pages/ShiftPlans/ShiftPlanView.tsx // frontend/src/pages/ShiftPlans/ShiftPlanView.tsx
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { useParams, useNavigate } from 'react-router-dom'; import { useParams, useNavigate } from 'react-router-dom';
import { useAuth } from '../../contexts/AuthContext'; import { useAuth } from '../../contexts/AuthContext';
import { shiftPlanService } from '../../services/shiftPlanService'; import { shiftPlanService } from '../../services/shiftPlanService';
@@ -56,6 +56,9 @@ const ShiftPlanView: React.FC = () => {
const [showAssignmentPreview, setShowAssignmentPreview] = useState(false); const [showAssignmentPreview, setShowAssignmentPreview] = useState(false);
const [recreating, setRecreating] = useState(false); const [recreating, setRecreating] = useState(false);
const [exporting, setExporting] = useState(false); const [exporting, setExporting] = useState(false);
const [exportType, setExportType] = useState<'pdf' | 'excel' | null>(null);
const [dropdownWidth, setDropdownWidth] = useState(0);
const dropdownRef = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
loadShiftPlanData(); loadShiftPlanData();
@@ -121,6 +124,12 @@ const ShiftPlanView: React.FC = () => {
} }
}, [availabilities]); }, [availabilities]);
useEffect(() => {
if (dropdownRef.current) {
setDropdownWidth(dropdownRef.current.offsetWidth);
}
}, [exportType]);
// Create a data structure that maps days to their shifts with time slot info - SAME AS AVAILABILITYMANAGER // Create a data structure that maps days to their shifts with time slot info - SAME AS AVAILABILITYMANAGER
const getTimetableData = () => { const getTimetableData = () => {
if (!shiftPlan || !shiftPlan.shifts || !shiftPlan.timeSlots) { if (!shiftPlan || !shiftPlan.shifts || !shiftPlan.timeSlots) {
@@ -242,60 +251,33 @@ const ShiftPlanView: React.FC = () => {
}; };
}; };
const handleExportExcel = async () => { const handleExport = async () => {
if (!shiftPlan) return; if (!shiftPlan || !exportType) return;
try { try {
setExporting(true); setExporting(true);
// Call the export service let blob: Blob;
const blob = await shiftPlanService.exportShiftPlanToExcel(shiftPlan.id); if (exportType === 'excel') {
blob = await shiftPlanService.exportShiftPlanToExcel(shiftPlan.id);
// Use file-saver to download the file saveAs(blob, `Schichtplan_${shiftPlan.name}_${new Date().toISOString().split('T')[0]}.xlsx`);
saveAs(blob, `Schichtplan_${shiftPlan.name}_${new Date().toISOString().split('T')[0]}.xlsx`); } else {
blob = await shiftPlanService.exportShiftPlanToPDF(shiftPlan.id);
saveAs(blob, `Schichtplan_${shiftPlan.name}_${new Date().toISOString().split('T')[0]}.pdf`);
}
showNotification({ showNotification({
type: 'success', type: 'success',
title: 'Export erfolgreich', title: 'Export erfolgreich',
message: 'Der Schichtplan wurde als Excel-Datei exportiert.' message: `Der Schichtplan wurde als ${exportType === 'excel' ? 'Excel' : 'PDF'} exportiert.`
}); });
} catch (error) { } catch (error) {
console.error('Error exporting to Excel:', error); console.error(`Error exporting to ${exportType}:`, error);
showNotification({ showNotification({
type: 'error', type: 'error',
title: 'Export fehlgeschlagen', title: 'Export fehlgeschlagen',
message: 'Der Excel-Export konnte nicht durchgeführt werden.' message: `Der ${exportType === 'excel' ? 'Excel' : 'PDF'}-Export konnte nicht durchgeführt werden.`
});
} finally {
setExporting(false);
}
};
const handleExportPDF = async () => {
if (!shiftPlan) return;
try {
setExporting(true);
// Call the PDF export service
const blob = await shiftPlanService.exportShiftPlanToPDF(shiftPlan.id);
// Use file-saver to download the file
saveAs(blob, `Schichtplan_${shiftPlan.name}_${new Date().toISOString().split('T')[0]}.pdf`);
showNotification({
type: 'success',
title: 'Export erfolgreich',
message: 'Der Schichtplan wurde als PDF exportiert.'
});
} catch (error) {
console.error('Error exporting to PDF:', error);
showNotification({
type: 'error',
title: 'Export fehlgeschlagen',
message: 'Der PDF-Export konnte nicht durchgeführt werden.'
}); });
} finally { } finally {
setExporting(false); setExporting(false);
@@ -679,7 +661,7 @@ const ShiftPlanView: React.FC = () => {
const matchingScheduledShifts = scheduledShifts.filter(scheduled => { const matchingScheduledShifts = scheduledShifts.filter(scheduled => {
const dayOfWeek = getDayOfWeek(scheduled.date); const dayOfWeek = getDayOfWeek(scheduled.date);
return dayOfWeek === shiftPattern.dayOfWeek && return dayOfWeek === shiftPattern.dayOfWeek &&
scheduled.timeSlotId === shiftPattern.timeSlotId; scheduled.timeSlotId === shiftPattern.timeSlotId;
}); });
console.log(`📅 Shift Pattern: ${shiftPattern.id}`); console.log(`📅 Shift Pattern: ${shiftPattern.id}`);
@@ -932,7 +914,7 @@ const ShiftPlanView: React.FC = () => {
if (employee.isTrainee) { if (employee.isTrainee) {
backgroundColor = '#cda8f0'; // Trainee backgroundColor = '#cda8f0'; // Trainee
} else if (employee.roles?.includes('manager')) { } else if (employee.employeeType === 'manager') {
backgroundColor = '#CC0000'; // Manager backgroundColor = '#CC0000'; // Manager
} }
@@ -974,7 +956,7 @@ const ShiftPlanView: React.FC = () => {
const scheduledShift = scheduledShifts.find(scheduled => { const scheduledShift = scheduledShifts.find(scheduled => {
const scheduledDayOfWeek = getDayOfWeek(scheduled.date); const scheduledDayOfWeek = getDayOfWeek(scheduled.date);
return scheduledDayOfWeek === weekday.id && return scheduledDayOfWeek === weekday.id &&
scheduled.timeSlotId === timeSlot.id; scheduled.timeSlotId === timeSlot.id;
}); });
if (scheduledShift) { if (scheduledShift) {
@@ -1001,7 +983,7 @@ const ShiftPlanView: React.FC = () => {
const scheduledShift = scheduledShifts.find(scheduled => { const scheduledShift = scheduledShifts.find(scheduled => {
const scheduledDayOfWeek = getDayOfWeek(scheduled.date); const scheduledDayOfWeek = getDayOfWeek(scheduled.date);
return scheduledDayOfWeek === weekday.id && return scheduledDayOfWeek === weekday.id &&
scheduled.timeSlotId === timeSlot.id; scheduled.timeSlotId === timeSlot.id;
}); });
if (scheduledShift) { if (scheduledShift) {
@@ -1054,7 +1036,7 @@ const ShiftPlanView: React.FC = () => {
alignItems: 'center', alignItems: 'center',
justifyContent: 'center' justifyContent: 'center'
}} }}
title={`Shift Validierung: timeSlotId=${shift.timeSlotId}, dayOfWeek=${shift.dayOfWeek}`} title={`Shift Validierung: timeSlotId=${shift.timeSlotId}, dayOfWeek=${shift.dayOfWeek}`}
> >
</div> </div>
@@ -1124,49 +1106,7 @@ const ShiftPlanView: React.FC = () => {
{shiftPlan.status === 'published' ? 'Veröffentlicht' : 'Entwurf'} {shiftPlan.status === 'published' ? 'Veröffentlicht' : 'Entwurf'}
</div> </div>
</div> </div>
<div style={{ display: 'flex', gap: '10px', alignItems: 'center' }}> <div style={{ display: 'flex', gap: '10px', alignItems: 'center' }}>
{shiftPlan.status === 'published' && hasRole(['admin', 'maintenance']) && (
<>
<button
onClick={handleExportExcel}
disabled={exporting}
style={{
padding: '10px 20px',
backgroundColor: '#27ae60',
color: 'white',
border: 'none',
borderRadius: '4px',
cursor: exporting ? 'not-allowed' : 'pointer',
fontWeight: 'bold',
display: 'flex',
alignItems: 'center',
gap: '8px'
}}
>
{exporting ? '🔄' : '📊'} {exporting ? 'Exportiert...' : 'Excel Export'}
</button>
<button
onClick={handleExportPDF}
disabled={exporting}
style={{
padding: '10px 20px',
backgroundColor: '#e74c3c',
color: 'white',
border: 'none',
borderRadius: '4px',
cursor: exporting ? 'not-allowed' : 'pointer',
fontWeight: 'bold',
display: 'flex',
alignItems: 'center',
gap: '8px'
}}
>
{exporting ? '🔄' : '📄'} {exporting ? 'Exportiert...' : 'PDF Export'}
</button>
</>
)}
{/* "Zuweisungen neu berechnen" button */} {/* "Zuweisungen neu berechnen" button */}
{shiftPlan.status === 'published' && hasRole(['admin', 'maintenance']) && ( {shiftPlan.status === 'published' && hasRole(['admin', 'maintenance']) && (
<button <button
@@ -1492,6 +1432,65 @@ const ShiftPlanView: React.FC = () => {
{renderTimetable()} {renderTimetable()}
{shiftPlan.status === 'published' && hasRole(['admin', 'maintenance']) && (
<div style={{
display: 'flex',
alignItems: 'center',
position: 'relative',
marginLeft: '10px'
}}>
{/* Export Dropdown */}
<div
ref={dropdownRef}
style={{
transform: exportType ? `translateX(-${dropdownWidth}px)` : 'translateX(0)',
transition: 'transform 0.3s ease-in-out',
position: exportType ? 'absolute' : 'relative',
right: exportType ? `-${dropdownWidth}px` : '0'
}}
>
<select
value={exportType || ''}
onChange={(e) => setExportType(e.target.value as 'pdf' | 'excel' | null)}
style={{
padding: '10px 20px',
backgroundColor: 'white',
border: '1px solid #ddd',
borderRadius: '4px',
cursor: 'pointer',
minWidth: '120px'
}}
>
<option value="">Export</option>
<option value="pdf">PDF</option>
<option value="excel">Excel</option>
</select>
</div>
{/* Export Button */}
{exportType && (
<button
onClick={handleExport}
disabled={exporting}
style={{
padding: '10px 20px',
backgroundColor: '#51258f',
color: 'white',
border: 'none',
borderRadius: '4px',
cursor: exporting ? 'not-allowed' : 'pointer',
fontWeight: 'bold',
marginLeft: '10px',
opacity: exporting ? 0.7 : 1,
transition: 'opacity 0.2s ease'
}}
>
{exporting ? '🔄 Exportiert...' : 'EXPORT'}
</button>
)}
</div>
)}
{/* Summary */} {/* Summary */}
{days.length > 0 && ( {days.length > 0 && (
<div style={{ <div style={{
@@ -1506,8 +1505,8 @@ const ShiftPlanView: React.FC = () => {
shiftPlan.status === 'published' shiftPlan.status === 'published'
? 'Angezeigt werden die aktuell zugewiesenen Mitarbeiter' ? 'Angezeigt werden die aktuell zugewiesenen Mitarbeiter'
: assignmentResult : assignmentResult
? 'Angezeigt werden die vorgeschlagenen Mitarbeiter für eine exemplarische Woche' ? 'Angezeigt werden die vorgeschlagenen Mitarbeiter für eine exemplarische Woche'
: 'Angezeigt wird "zugewiesene/benötigte Mitarbeiter" pro Schicht und Wochentag' : 'Angezeigt wird "zugewiesene/benötigte Mitarbeiter" pro Schicht und Wochentag'
} }
</div> </div>
)} )}