Merge commit '5b42a854862417d17b7736aefd8da6d336a592d5'

This commit is contained in:
Dobromir Popov
2024-11-04 22:17:24 +02:00
2 changed files with 41 additions and 24 deletions

View File

@ -60,6 +60,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
var autoFill = common.parseBool(req.query.autoFill); var autoFill = common.parseBool(req.query.autoFill);
var forDay = common.parseBool(req.query.forDay); var forDay = common.parseBool(req.query.forDay);
var type = parseInt(req.query.type) || 0; var type = parseInt(req.query.type) || 0;
var repeat = common.parseBool(req.query.repeat);
if (type == 2) { if (type == 2) {
// var result = await GenerateOptimalSchedule(axios, date, copyFromPreviousMonth, autoFill, forDay, type); // var result = await GenerateOptimalSchedule(axios, date, copyFromPreviousMonth, autoFill, forDay, type);
var result = await GenerateScheduleNew(axios, date, copyFromPreviousMonth, autoFill, forDay, type); var result = await GenerateScheduleNew(axios, date, copyFromPreviousMonth, autoFill, forDay, type);
@ -76,7 +77,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
originalConsoleLog.apply(console, arguments); originalConsoleLog.apply(console, arguments);
}; };
var result = await GenerateSchedule(axios, date, copyFromPreviousMonth, autoFill, forDay, type); var result = await GenerateSchedule(axios, date, copyFromPreviousMonth, autoFill, forDay, type, undefined, repeat);
// Restore the original console.log // Restore the original console.log
console.log = originalConsoleLog; console.log = originalConsoleLog;
@ -183,7 +184,7 @@ function updatePublishersWithCurrentCounts(publishers) {
} }
async function GenerateSchedule(axios, date, copyFromPreviousMonth = false, autoFill = false, forDay, algType = 0, until) { async function GenerateSchedule(axios, date, copyFromPreviousMonth = false, autoFill = false, forDay, algType = 0, until, doRepeatLast = true) {
let missingPublishers = []; let missingPublishers = [];
let publishersWithChangedPref = []; let publishersWithChangedPref = [];
@ -287,25 +288,27 @@ async function GenerateSchedule(axios, date, copyFromPreviousMonth = false, auto
//--------------------------------------------------- //---------------------------------------------------
// // COMMENT TO DISABLE COPY FROM LAST MONTH // // COMMENT TO DISABLE COPY FROM LAST MONTH
// if (availability && copyFromPreviousMonth && !publishersThisWeek.includes(publisher.id)) { if (doRepeatLast) {
// const transportCount = shiftAssignments.filter(a => a.isWithTransport).length; if (availability && copyFromPreviousMonth && !publishersThisWeek.includes(publisher.id)) {
// const isWithTransport = availability.isWithTransportIn || availability.isWithTransportOut; const transportCount = shiftAssignments.filter(a => a.isWithTransport).length;
const isWithTransport = availability.isWithTransportIn || availability.isWithTransportOut;
// if (!isWithTransport || transportCount < 2) { if (!isWithTransport || transportCount < 2) {
// shiftAssignments.push({ shiftAssignments.push({
// publisherId: publisher.id, publisherId: publisher.id,
// isConfirmed: true, isConfirmed: true,
// isBySystem: true, isBySystem: true,
// isWithTransport: isWithTransport isWithTransport: isWithTransport
// }); });
// publishersThisWeek.push(publisher.id); publishersThisWeek.push(publisher.id);
// updateRegistry(publisher.id, day, weekNr); updateRegistry(publisher.id, day, weekNr);
// publisher.currentMonthAssignments += 1; publisher.currentMonthAssignments += 1;
// } }
// else { else {
// console.log(" " + publisher.firstName + " " + publisher.lastName + " skipped (transport already assigned)"); console.log(" " + publisher.firstName + " " + publisher.lastName + " skipped (transport already assigned)");
// } }
// } }
}
//--------------------------------------------------- //---------------------------------------------------
} }

View File

@ -86,6 +86,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
const handleCheckboxChange = (event) => { const handleCheckboxChange = (event) => {
setFilterShowWithoutAssignments(!filterShowWithoutAssignments); // Toggle the checkbox state setFilterShowWithoutAssignments(!filterShowWithoutAssignments); // Toggle the checkbox state
}; };
const [repeatEnabled, setRepeatEnabled] = useState(true);
useEffect(() => { useEffect(() => {
console.log("checkbox checked: " + filterShowWithoutAssignments); console.log("checkbox checked: " + filterShowWithoutAssignments);
@ -445,7 +446,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
const generateShifts = async (buttonId, copyFromPrevious = false, autoFill = false, forDay?: Boolean | null, type = 0) => { const generateShifts = async (buttonId, copyFromPrevious = false, autoFill = false, forDay?: Boolean | null, type = 0) => {
try { try {
setActiveButton(buttonId); setActiveButton(buttonId);
const endpoint = `/api/shiftgenerate?action=generate&date=${common.getISODateOnly(value)}&copyFromPreviousMonth=${copyFromPrevious}&autoFill=${autoFill}&forDay=${forDay}&type=${type}`; const endpoint = `/api/shiftgenerate?action=generate&date=${common.getISODateOnly(value)}&copyFromPreviousMonth=${copyFromPrevious}&autoFill=${autoFill}&forDay=${forDay}&type=${type}&repeat=${repeatEnabled}`;
const { shifts } = await axiosInstance.get(endpoint); const { shifts } = await axiosInstance.get(endpoint);
toast.success('Готово!', { autoClose: 1000 }); toast.success('Готово!', { autoClose: 1000 });
setIsMenuOpen(false); setIsMenuOpen(false);
@ -728,9 +729,22 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
<button className="block w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center" onClick={() => generateShifts("genDay", true, true, null, 0)}> <button className="block w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center" onClick={() => generateShifts("genDay", true, true, null, 0)}>
{isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)} {isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)}
Генерирай смени </button> Генерирай смени </button>
<button className="block w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center" onClick={() => generateShifts("genDay", true, true, null, 1)}> <button className="block w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center justify-between"
{isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)} onClick={() => generateShifts("genDay", true, true, null, 1)}>
Генерирай смени 2 <span className="text-yellow-500 ml-1 text-xs"></span></button> <div className="flex items-center">
{isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)}
Генерирай<span className="text-yellow-500 ml-1 text-xs"></span>
</div>
<div className="flex items-center" onClick={(e) => e.stopPropagation()}>
<input
type="checkbox"
checked={repeatEnabled}
onChange={(e) => setRepeatEnabled(e.target.checked)}
className="mr-2 form-checkbox h-4 w-4 text-blue-600 transition duration-150 ease-in-out"
/>
<span className="text-sm text-gray-600">повт.</span>
</div>
</button>
{/* ✧✨ */} {/* ✧✨ */}
{/* <button className="block w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center" onClick={() => generateShifts("genDay", true, true, null, 2)}> {/* <button className="block w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center" onClick={() => generateShifts("genDay", true, true, null, 2)}>
{isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)} {isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)}