mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
using cp for plans
This commit is contained in:
43
frontend/src/components/Scheduler.tsx
Normal file
43
frontend/src/components/Scheduler.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
// src/components/Scheduler.tsx
|
||||
import React from 'react';
|
||||
import { useScheduling } from '../hooks/useScheduling';
|
||||
|
||||
interface Props {
|
||||
scheduleRequest: ScheduleRequest;
|
||||
}
|
||||
|
||||
export const Scheduler: React.FC<Props> = ({ scheduleRequest }) => {
|
||||
const { generateSchedule, loading, error, result } = useScheduling();
|
||||
|
||||
const handleGenerateSchedule = async () => {
|
||||
try {
|
||||
await generateSchedule(scheduleRequest);
|
||||
} catch (err) {
|
||||
// Error handling
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button
|
||||
onClick={handleGenerateSchedule}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Generating Schedule...' : 'Generate Optimal Schedule'}
|
||||
</button>
|
||||
|
||||
{loading && (
|
||||
<div>
|
||||
<progress max="100" value="70" />
|
||||
<p>Optimizing schedule... (max 2 minutes)</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && <div className="error">{error}</div>}
|
||||
|
||||
{result && (
|
||||
<ScheduleResultView result={result} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
37
frontend/src/hooks/useScheduling.ts
Normal file
37
frontend/src/hooks/useScheduling.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// frontend/src/services/scheduling/scheduling.ts
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { ScheduleRequest, ScheduleResult } from '../types/scheduling';
|
||||
|
||||
export const useScheduling = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [result, setResult] = useState<ScheduleResult | null>(null);
|
||||
|
||||
const generateSchedule = useCallback(async (request: ScheduleRequest) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/scheduling/generate-schedule', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(request)
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Scheduling request failed');
|
||||
|
||||
const data: ScheduleResult = await response.json();
|
||||
setResult(data);
|
||||
return data;
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return { generateSchedule, loading, error, result };
|
||||
};
|
||||
@@ -5,7 +5,7 @@ import { useAuth } from '../../contexts/AuthContext';
|
||||
import { shiftPlanService } from '../../services/shiftPlanService';
|
||||
import { employeeService } from '../../services/employeeService';
|
||||
import { shiftAssignmentService, ShiftAssignmentService } from '../../services/shiftAssignmentService';
|
||||
import { IntelligentShiftScheduler, SchedulingResult, AssignmentResult } from '../../services/scheduling';
|
||||
import { IntelligentShiftScheduler, SchedulingResult, AssignmentResult } from '../../hooks/useScheduling';
|
||||
import { ShiftPlan, TimeSlot, ScheduledShift } from '../../models/ShiftPlan';
|
||||
import { Employee, EmployeeAvailability } from '../../models/Employee';
|
||||
import { useNotification } from '../../contexts/NotificationContext';
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
// frontend/src/services/scheduling.ts/scheduling.ts
|
||||
|
||||
import { Employee, EmployeeAvailability } from '../models/Employee';
|
||||
import { ScheduledShift, ShiftPlan } from '../models/ShiftPlan';
|
||||
import { shiftAssignmentService } from './shiftAssignmentService';
|
||||
@@ -2,7 +2,7 @@
|
||||
import { ShiftPlan, ScheduledShift } from '../models/ShiftPlan';
|
||||
import { Employee, EmployeeAvailability } from '../models/Employee';
|
||||
import { authService } from './authService';
|
||||
import { IntelligentShiftScheduler, AssignmentResult, WeeklyPattern } from './scheduling';
|
||||
import { IntelligentShiftScheduler, AssignmentResult, WeeklyPattern } from '../hooks/useScheduling';
|
||||
import { isScheduledShift } from '../models/helpers';
|
||||
|
||||
const API_BASE_URL = 'http://localhost:3002/api/scheduled-shifts';
|
||||
|
||||
Reference in New Issue
Block a user