repeat last month option added in tue UI
This commit is contained in:
@ -60,6 +60,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
var autoFill = common.parseBool(req.query.autoFill);
|
||||
var forDay = common.parseBool(req.query.forDay);
|
||||
var type = parseInt(req.query.type) || 0;
|
||||
var repeat = common.parseBool(req.query.repeat);
|
||||
if (type == 2) {
|
||||
// var result = await GenerateOptimalSchedule(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);
|
||||
};
|
||||
|
||||
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
|
||||
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 publishersWithChangedPref = [];
|
||||
@ -287,25 +288,27 @@ async function GenerateSchedule(axios, date, copyFromPreviousMonth = false, auto
|
||||
|
||||
//---------------------------------------------------
|
||||
// // COMMENT TO DISABLE COPY FROM LAST MONTH
|
||||
// if (availability && copyFromPreviousMonth && !publishersThisWeek.includes(publisher.id)) {
|
||||
// const transportCount = shiftAssignments.filter(a => a.isWithTransport).length;
|
||||
// const isWithTransport = availability.isWithTransportIn || availability.isWithTransportOut;
|
||||
if (doRepeatLast) {
|
||||
if (availability && copyFromPreviousMonth && !publishersThisWeek.includes(publisher.id)) {
|
||||
const transportCount = shiftAssignments.filter(a => a.isWithTransport).length;
|
||||
const isWithTransport = availability.isWithTransportIn || availability.isWithTransportOut;
|
||||
|
||||
// if (!isWithTransport || transportCount < 2) {
|
||||
// shiftAssignments.push({
|
||||
// publisherId: publisher.id,
|
||||
// isConfirmed: true,
|
||||
// isBySystem: true,
|
||||
// isWithTransport: isWithTransport
|
||||
// });
|
||||
// publishersThisWeek.push(publisher.id);
|
||||
// updateRegistry(publisher.id, day, weekNr);
|
||||
// publisher.currentMonthAssignments += 1;
|
||||
// }
|
||||
// else {
|
||||
// console.log(" " + publisher.firstName + " " + publisher.lastName + " skipped (transport already assigned)");
|
||||
// }
|
||||
// }
|
||||
if (!isWithTransport || transportCount < 2) {
|
||||
shiftAssignments.push({
|
||||
publisherId: publisher.id,
|
||||
isConfirmed: true,
|
||||
isBySystem: true,
|
||||
isWithTransport: isWithTransport
|
||||
});
|
||||
publishersThisWeek.push(publisher.id);
|
||||
updateRegistry(publisher.id, day, weekNr);
|
||||
publisher.currentMonthAssignments += 1;
|
||||
}
|
||||
else {
|
||||
console.log(" " + publisher.firstName + " " + publisher.lastName + " skipped (transport already assigned)");
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
const handleCheckboxChange = (event) => {
|
||||
setFilterShowWithoutAssignments(!filterShowWithoutAssignments); // Toggle the checkbox state
|
||||
};
|
||||
const [repeatEnabled, setRepeatEnabled] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
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) => {
|
||||
try {
|
||||
setActiveButton(buttonId);
|
||||
const endpoint = `/api/shiftgenerate?action=generate&date=${common.getISODateOnly(value)}©FromPreviousMonth=${copyFromPrevious}&autoFill=${autoFill}&forDay=${forDay}&type=${type}`;
|
||||
const endpoint = `/api/shiftgenerate?action=generate&date=${common.getISODateOnly(value)}©FromPreviousMonth=${copyFromPrevious}&autoFill=${autoFill}&forDay=${forDay}&type=${type}&repeat=${repeatEnabled}`;
|
||||
const { shifts } = await axiosInstance.get(endpoint);
|
||||
toast.success('Готово!', { autoClose: 1000 });
|
||||
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)}>
|
||||
{isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)}
|
||||
Генерирай смени </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)}>
|
||||
{isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)}
|
||||
Генерирай смени 2 <span className="text-yellow-500 ml-1 text-xs">✨</span></button>
|
||||
<button className="block w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center justify-between"
|
||||
onClick={() => generateShifts("genDay", true, true, null, 1)}>
|
||||
<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)}>
|
||||
{isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)}
|
||||
|
Reference in New Issue
Block a user