destinguish between pubs without availabilities (orange) and with changed availabilities (red) in calendar dash
This commit is contained in:
@ -156,37 +156,43 @@ function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, a
|
||||
|
||||
// Determine border styles
|
||||
let borderStyles = '';
|
||||
//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 ';
|
||||
if (selectedPublisher && selectedPublisher.id === ass.publisher.id) {
|
||||
borderStyles += 'border-2 border-blue-300'; // Bottom border for selected publishers
|
||||
}
|
||||
else {
|
||||
//pub is not available for that shift assignment.
|
||||
if (publisherInfo.availabilities?.length === 0 ||
|
||||
publisherInfo.availabilities?.every(avail => avail.isFromPreviousAssignment)) {
|
||||
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
|
||||
if (publisherInfo.availabilityCount == 0) //user has never the form
|
||||
{
|
||||
borderStyles = 'border-2 border-orange-300 ';
|
||||
}
|
||||
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 (
|
||||
<div key={index}
|
||||
|
@ -3,6 +3,7 @@ import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { DayOfWeek } from '@prisma/client';
|
||||
const common = require('../../src/helpers/common');
|
||||
const data = require('../../src/helpers/data');
|
||||
const subq = require('../../prisma/bl/subqueries');
|
||||
|
||||
import fs from 'fs';
|
||||
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 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({
|
||||
where: {
|
||||
startTime: {
|
||||
@ -178,12 +192,19 @@ export default async function handler(req, res) {
|
||||
include: {
|
||||
assignments: {
|
||||
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)));
|
||||
|
||||
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
|
||||
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;
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -187,7 +187,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
// Finally, sort by (currentMonthAssignments - 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) => {
|
||||
|
46
prisma/bl/subqueries.js
Normal file
46
prisma/bl/subqueries.js
Normal 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'
|
||||
// }
|
||||
// }
|
@ -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;
|
@ -103,16 +103,14 @@ model Publisher {
|
||||
isMale Boolean @default(true)
|
||||
isNameForeign Boolean @default(false)
|
||||
|
||||
familyHeadId String? // Optional familyHeadId for each family member
|
||||
familyHead Publisher? @relation("FamilyMember", fields: [familyHeadId], references: [id])
|
||||
familyMembers Publisher[] @relation("FamilyMember")
|
||||
//alwaysAsFamily Boolean? @default(false) // New field to indicate if the publisher always wants to be assigned with the family
|
||||
type PublisherType @default(Publisher)
|
||||
town String?
|
||||
comments String?
|
||||
reports Report[]
|
||||
|
||||
@@map("Publisher")
|
||||
familyHeadId String? // Optional familyHeadId for each family member
|
||||
familyHead Publisher? @relation("FamilyMember", fields: [familyHeadId], references: [id])
|
||||
familyMembers Publisher[] @relation("FamilyMember")
|
||||
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)
|
||||
town String?
|
||||
comments String?
|
||||
reports Report[]
|
||||
}
|
||||
|
||||
model Availability {
|
||||
@ -131,12 +129,10 @@ model Availability {
|
||||
isWithTransportOut Boolean @default(false)
|
||||
isFromPreviousAssignment 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
|
||||
endDate DateTime? // New field for the end date of repetition
|
||||
//dateOfEntry DateTime
|
||||
|
||||
@@map("Availability")
|
||||
//dateOfEntry DateTime? //NEW v1.0.1 trade storage for intuintivity
|
||||
}
|
||||
|
||||
model CartEvent {
|
||||
@ -169,7 +165,7 @@ model Shift {
|
||||
//date DateTime
|
||||
reportId Int? @unique
|
||||
Report Report? @relation(fields: [reportId], references: [id])
|
||||
//isPublished Boolean @default(false)
|
||||
isPublished Boolean @default(false) //NEW v1.0.1
|
||||
|
||||
@@map("Shift")
|
||||
}
|
||||
|
Reference in New Issue
Block a user