feat: AI assistant (HartBOT), demand filling, budget-per-role, project favorites, and UX improvements

AI Assistant (HartBOT):
- Chat panel with inline layout, session persistence, message history (up-arrow recall)
- OpenAI function calling with 20+ tools (search, navigate, create/cancel allocations, update status)
- RBAC-aware tool filtering, fuzzy search with word-level matching
- Navigation actions (router.push) and data invalidation after mutations
- Country/metro city/org unit/role filtering on resource search

Demand Filling Enhancements:
- Two-phase fill modal: plan multiple resources, then confirm & assign all at once
- Availability preview per resource (available/partial/conflict days, existing bookings)
- Coverage bar showing demand hours distribution across assigned resources
- Fill demand from project detail page (new Assign button per demand)
- Fixed: filled demands no longer shown on timeline, demand bars no longer overlap

Budget per Role:
- DemandRequirement.budgetCents field (schema + API + UI)
- Project wizard step 3: budget input per role with allocation summary bar
- Project detail: allocated vs booked budget per demand
- Fill demand modal: role budget display with cost estimates
- AllocationModal: budget field for demand editing

Project Favorites:
- User.favoriteProjectIds (JSONB) with toggle API
- Star button on projects list and detail page (optimistic updates)
- "My Projects" dashboard widget (favorites + responsible person projects)

Project Management:
- Edit project from detail page (ProjectModal integration)
- Edit demands from detail page (AllocationModal integration)
- Admin-only project deletion (cascades assignments + demands)
- Create user accounts from admin panel

Timeline Fixes:
- Country multi-select filter with backend support
- URL param sync for same-page navigation (AI assistant integration)
- Demand lane stacking (no more overlapping bars)
- Single-day booking resize handles (always visible, min 6px)
- Single-day resize allowed (start === end)
- "All Clients" toggle (select all / deselect all)

Other Fixes:
- crypto.randomUUID fallback for non-secure contexts
- Chat message limit raised (200 max, client sends last 40)
- Status dropdown portal (no longer clipped by table overflow)
- Cents display restored in budget views (2 decimal places)
- Allocations grouped view with project sub-groups (collapsed by default)
- Server-side resource search for project wizard (no 500 limit)

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-03-16 15:31:48 +01:00
parent f5551e33c7
commit b0e55786c3
44 changed files with 4516 additions and 609 deletions
+129
View File
@@ -82,6 +82,7 @@ function toDemandRequirementUpdateInput(input: AllocationEntryUpdateInput) {
...(input.role !== undefined ? { role: input.role } : {}),
...(input.roleId !== undefined ? { roleId: input.roleId } : {}),
...(input.headcount !== undefined ? { headcount: input.headcount } : {}),
...(input.budgetCents !== undefined ? { budgetCents: input.budgetCents } : {}),
...(input.status !== undefined ? { status: input.status } : {}),
...(input.metadata !== undefined ? { metadata: input.metadata } : {}),
};
@@ -298,6 +299,134 @@ export const allocationRouter = createTRPCRouter({
);
}),
/**
* Check a resource's availability for a date range.
* Returns working days, existing allocations, conflict days, and available capacity.
*/
checkResourceAvailability: protectedProcedure
.input(z.object({
resourceId: z.string(),
startDate: z.coerce.date(),
endDate: z.coerce.date(),
hoursPerDay: z.number().min(0.5).max(24).default(8),
}))
.query(async ({ ctx, input }) => {
const resource = await ctx.db.resource.findUnique({
where: { id: input.resourceId },
select: {
id: true, displayName: true, eid: true, fte: true,
country: { select: { dailyWorkingHours: true } },
},
});
if (!resource) throw new TRPCError({ code: "NOT_FOUND", message: "Resource not found" });
const dailyCapacity = (resource.country?.dailyWorkingHours ?? 8) * (resource.fte ?? 1);
// Get existing assignments in the date range
const existingAssignments = await ctx.db.assignment.findMany({
where: {
resourceId: input.resourceId,
status: { not: "CANCELLED" },
startDate: { lte: input.endDate },
endDate: { gte: input.startDate },
},
select: {
id: true, startDate: true, endDate: true, hoursPerDay: true, status: true,
project: { select: { name: true, shortCode: true } },
},
orderBy: { startDate: "asc" },
});
// Get vacations in the date range
const vacations = await ctx.db.vacation.findMany({
where: {
resourceId: input.resourceId,
status: "APPROVED",
startDate: { lte: input.endDate },
endDate: { gte: input.startDate },
},
select: { startDate: true, endDate: true, isHalfDay: true },
});
// Calculate day-by-day availability
let totalWorkingDays = 0;
let availableDays = 0;
let conflictDays = 0;
let partialDays = 0;
let totalAvailableHours = 0;
const requestedHpd = input.hoursPerDay;
const d = new Date(input.startDate);
const end = new Date(input.endDate);
while (d <= end) {
const dow = d.getDay();
if (dow !== 0 && dow !== 6) {
totalWorkingDays++;
// Check vacation
const isVacation = vacations.some((v) => {
const vs = new Date(v.startDate); vs.setHours(0, 0, 0, 0);
const ve = new Date(v.endDate); ve.setHours(0, 0, 0, 0);
const dc = new Date(d); dc.setHours(0, 0, 0, 0);
return dc >= vs && dc <= ve;
});
if (isVacation) {
conflictDays++;
d.setDate(d.getDate() + 1);
continue;
}
// Sum existing hours on this day
let bookedHours = 0;
for (const a of existingAssignments) {
const as2 = new Date(a.startDate); as2.setHours(0, 0, 0, 0);
const ae = new Date(a.endDate); ae.setHours(0, 0, 0, 0);
const dc = new Date(d); dc.setHours(0, 0, 0, 0);
if (dc >= as2 && dc <= ae) {
bookedHours += a.hoursPerDay;
}
}
const remainingCapacity = Math.max(0, dailyCapacity - bookedHours);
if (remainingCapacity >= requestedHpd) {
availableDays++;
totalAvailableHours += requestedHpd;
} else if (remainingCapacity > 0) {
partialDays++;
totalAvailableHours += remainingCapacity;
} else {
conflictDays++;
}
}
d.setDate(d.getDate() + 1);
}
const totalRequestedHours = totalWorkingDays * requestedHpd;
return {
resource: { id: resource.id, name: resource.displayName, eid: resource.eid },
dailyCapacity,
totalWorkingDays,
availableDays,
partialDays,
conflictDays,
totalAvailableHours: Math.round(totalAvailableHours * 10) / 10,
totalRequestedHours,
coveragePercent: totalRequestedHours > 0
? Math.round((totalAvailableHours / totalRequestedHours) * 100)
: 0,
existingAssignments: existingAssignments.map((a) => ({
project: a.project.name,
code: a.project.shortCode,
hoursPerDay: a.hoursPerDay,
start: a.startDate.toISOString().slice(0, 10),
end: a.endDate.toISOString().slice(0, 10),
status: a.status,
})),
};
}),
createDemandRequirement: managerProcedure
.input(CreateDemandRequirementSchema)
.mutation(async ({ ctx, input }) => {