destinguish between pubs without availabilities (orange) and with changed availabilities (red) in calendar dash

This commit is contained in:
Dobromir Popov
2024-03-02 19:10:29 +02:00
parent 27a0c2cbb4
commit 6c6f8f41d0
6 changed files with 122 additions and 45 deletions

View File

@ -156,37 +156,43 @@ function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, a
// Determine border styles // Determine border styles
let borderStyles = ''; let borderStyles = '';
//if there is no publisherInfo - draw red border - publisher is no longer available for the day! if (selectedPublisher && selectedPublisher.id === ass.publisher.id) {
if (!publisherInfo.availabilities || publisherInfo.availabilities.length == 0) { borderStyles += 'border-2 border-blue-300'; // Bottom border for selected publishers
borderStyles = 'border-2 border-red-500 ';
} }
else { else {
//pub is not available for that shift assignment. if (publisherInfo.availabilityCount == 0) //user has never the form
if (publisherInfo.availabilities?.length === 0 || {
publisherInfo.availabilities?.every(avail => avail.isFromPreviousAssignment)) { borderStyles = 'border-2 border-orange-300 ';
borderStyles += 'border-l-3 border-r-3 border-orange-500 '; // Top border for manual publishers
}
// checkig if the publisher is available for this assignment
if (publisherInfo.availabilities?.some(av =>
av.startTime <= ass.startTime &&
av.endTime >= ass.endTime)) {
borderStyles += 'border-t-2 border-red-500 '; // Left border for specific availability conditions
} }
else
//if there is no publisherInfo - draw red border - publisher is no longer available for the day!
if (!publisherInfo.availabilities || publisherInfo.availabilities.length == 0) {
borderStyles = 'border-2 border-red-500 ';
}
else {
// checkig if the publisher is available for this assignment
if (publisherInfo.availabilities?.some(av =>
av.startTime <= shift.startTime &&
av.endTime >= shift.endTime)) {
borderStyles += 'border-l-2 border-blue-500 '; // Left border for specific availability conditions
}
if (publisherInfo.hasUpToDateAvailabilities) {
//add green right border
borderStyles += 'border-r-2 border-green-300';
}
//the pub is the same time as last month
// if (publisherInfo.availabilities?.some(av =>
// (!av.dayOfMonth || av.isFromPreviousMonth) &&
// av.startTime <= ass.startTime &&
// av.endTime >= ass.endTime)) {
// borderStyles += 'border-t-2 border-yellow-500 '; // Left border for specific availability conditions
// }
}
//the pub is the same time as last month
// if (publisherInfo.availabilities?.some(av =>
// (!av.dayOfMonth || av.isFromPreviousMonth) &&
// av.startTime <= ass.startTime &&
// av.endTime >= ass.endTime)) {
// borderStyles += 'border-t-2 border-yellow-500 '; // Left border for specific availability conditions
// }
if (selectedPublisher && selectedPublisher.id === ass.publisher.id) {
borderStyles += 'border-2 border-blue-300'; // Bottom border for selected publishers
}
if (publisherInfo.hasUpToDateAvailabilities) {
//add green right border
borderStyles += 'border-r-2 border-green-300';
}
} }
return ( return (
<div key={index} <div key={index}

View File

@ -3,6 +3,7 @@ import { NextApiRequest, NextApiResponse } from 'next'
import { DayOfWeek } from '@prisma/client'; import { DayOfWeek } from '@prisma/client';
const common = require('../../src/helpers/common'); const common = require('../../src/helpers/common');
const data = require('../../src/helpers/data'); const data = require('../../src/helpers/data');
const subq = require('../../prisma/bl/subqueries');
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
@ -168,6 +169,19 @@ export default async function handler(req, res) {
let startOfDay = new Date(date.getFullYear(), date.getMonth(), date.getDate()); let startOfDay = new Date(date.getFullYear(), date.getMonth(), date.getDate());
let endOfDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999); let endOfDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
const pubAvCount = await prisma.publisher.findMany({
select: {
id: true,
firstName: true,
lastName: true,
_count: {
select: {
availabilities: true,
}
}
}
});
let shiftsForDate = await prisma.shift.findMany({ let shiftsForDate = await prisma.shift.findMany({
where: { where: {
startTime: { startTime: {
@ -178,12 +192,19 @@ export default async function handler(req, res) {
include: { include: {
assignments: { assignments: {
include: { include: {
publisher: true, publisher: subq.publisherSelect
}, },
}, },
}, },
}); });
shiftsForDate.forEach(shift => {
shift.assignments.forEach(assignment => {
assignment.publisher.availabilityCount = pubAvCount.find(pub => pub.id === assignment.publisher.id)?._count?.availabilities || 0;
});
}
);
console.log("shiftsForDate(" + date + ") - " + shiftsForDate.length + " : " + JSON.stringify(shiftsForDate.map(shift => shift.id))); console.log("shiftsForDate(" + date + ") - " + shiftsForDate.length + " : " + JSON.stringify(shiftsForDate.map(shift => shift.id)));
res.status(200).json(shiftsForDate); res.status(200).json(shiftsForDate);
@ -587,7 +608,7 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
//if pub has up-to-date availabilities (with dayOfMonth) for the current month //if pub has up-to-date availabilities (with dayOfMonth) for the current month
pub.hasUpToDateAvailabilities = pub.availabilities?.some(avail => { pub.hasUpToDateAvailabilities = pub.availabilities?.some(avail => {
return avail.dayOfMonth != null && avail.startTime >= currentMonthStart && avail.startTime <= currentMonthEnd; return avail.dayOfMonth != null && avail.startTime >= currentMonthStart; // && avail.startTime <= currentMonthEnd;
}); });
}); });

View File

@ -187,7 +187,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
// Finally, sort by (currentMonthAssignments - previousMonthAssignments). // Finally, sort by (currentMonthAssignments - previousMonthAssignments).
return (a.currentMonthAssignments - a.previousMonthAssignments) - (b.currentMonthAssignments - b.previousMonthAssignments); return (a.currentMonthAssignments - a.previousMonthAssignments) - (b.currentMonthAssignments - b.previousMonthAssignments);
}); });
setAvailablePubs(sortedPubs); // Assuming availablePubs is a state managed by useState setAvailablePubs(sortedPubs);
}; };
const handleSelectedPublisher = (publisher) => { const handleSelectedPublisher = (publisher) => {

46
prisma/bl/subqueries.js Normal file
View File

@ -0,0 +1,46 @@
export const publisherSelectWithAvCount = {
select: {
id: true,
firstName: true,
lastName: true,
email: true,
phone: true,
desiredShiftsPerMonth: true,
},
include: {
_count: {
select: {
availability: {
where: {
isactive: true
}
}
}
}
}
}
export const publisherSelect = {
select: {
id: true,
firstName: true,
lastName: true,
email: true,
phone: true,
desiredShiftsPerMonth: true,
},
}
// availability: {
// select: {
// id: true,
// startTime: true,
// endTime: true,
// dayOfMonth: true,
// dayofweek: true,
// isactive: true,
// count: 'Availability_count'
// }
// }

View File

@ -0,0 +1,8 @@
-- AlterTable
--ALTER TABLE `Availability` ADD COLUMN `dateOfEntry` DATETIME(3) NULL;
-- AlterTable
ALTER TABLE `Publisher` ADD COLUMN `alwaysAsFamily` BOOLEAN NULL DEFAULT false;
-- AlterTable
ALTER TABLE `Shift` ADD COLUMN `isPublished` BOOLEAN NOT NULL DEFAULT false;

View File

@ -103,16 +103,14 @@ model Publisher {
isMale Boolean @default(true) isMale Boolean @default(true)
isNameForeign Boolean @default(false) isNameForeign Boolean @default(false)
familyHeadId String? // Optional familyHeadId for each family member familyHeadId String? // Optional familyHeadId for each family member
familyHead Publisher? @relation("FamilyMember", fields: [familyHeadId], references: [id]) familyHead Publisher? @relation("FamilyMember", fields: [familyHeadId], references: [id])
familyMembers Publisher[] @relation("FamilyMember") familyMembers Publisher[] @relation("FamilyMember")
//alwaysAsFamily Boolean? @default(false) // New field to indicate if the publisher always wants to be assigned with the family alwaysAsFamily Boolean? @default(false) //NEW v1.0.1 // New field to indicate if the publisher always wants to be assigned with the family
type PublisherType @default(Publisher) type PublisherType @default(Publisher)
town String? town String?
comments String? comments String?
reports Report[] reports Report[]
@@map("Publisher")
} }
model Availability { model Availability {
@ -131,12 +129,10 @@ model Availability {
isWithTransportOut Boolean @default(false) isWithTransportOut Boolean @default(false)
isFromPreviousAssignment Boolean @default(false) isFromPreviousAssignment Boolean @default(false)
isFromPreviousMonth Boolean @default(false) isFromPreviousMonth Boolean @default(false)
repeatWeekly Boolean? // New field to indicate weekly repetition repeatWeekly Boolean? // New field to indicate weekly repetition // until now dayofweek was used for repetition when dayOfMonth is null
repeatFrequency Int? // New field to indicate repetition frequency repeatFrequency Int? // New field to indicate repetition frequency
endDate DateTime? // New field for the end date of repetition endDate DateTime? // New field for the end date of repetition
//dateOfEntry DateTime //dateOfEntry DateTime? //NEW v1.0.1 trade storage for intuintivity
@@map("Availability")
} }
model CartEvent { model CartEvent {
@ -169,7 +165,7 @@ model Shift {
//date DateTime //date DateTime
reportId Int? @unique reportId Int? @unique
Report Report? @relation(fields: [reportId], references: [id]) Report Report? @relation(fields: [reportId], references: [id])
//isPublished Boolean @default(false) isPublished Boolean @default(false) //NEW v1.0.1
@@map("Shift") @@map("Shift")
} }