Files
vac-optimizer/src/app/components/declaration-controls/declaration-controls.ts
T
nessarandClaude Fable 5.2 762b4be926 feat(declarations): record the leave balance a declared CP day was booked from (#379)
A declared CP day may carry the expiry date of the leave balance it was booked from. The planner attributes the day to the balance it names when its date lies within that balance's dates, and otherwise, as for every day that names none, to the matching balance usable on its date that expires first; an IF_THEN reserve then adds back only the days booked from a balance it counts. The field is optional in storage and in planning requests, on every calculation path, and days saved before this change load unchanged.

In declaration entry the CP chip becomes one chip per CP balance expiry date from two balances on, labelled with that date. With zero or one CP balance the controls and the clear-on-same-type behaviour are unchanged and the single balance is recorded automatically; with several, a CP day is cleared only by the chip of its own balance and replaced by another, and the drag preview follows the same rule.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0192He3CzBZP96zgTG9hCgLw
2026-11-30 02:18:59 +01:00

59 lines
2.1 KiB
TypeScript

import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';
import { MatButton } from '@angular/material/button';
import { MatIcon } from '@angular/material/icon';
import type { LeaveType } from '../../services/leave-planner.service';
import { TranslationService } from '../../services/translation-service';
import { UserInputService } from '../../services/user-input-service';
interface Chip {
type: LeaveType;
balance: string | null;
label: string;
}
/** Starts and ends declared non-working day entry, and chooses the type a calendar tap applies. */
@Component({
selector: 'app-declaration-controls',
imports: [MatButton, MatIcon],
templateUrl: './declaration-controls.html',
styleUrl: './declaration-controls.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
host: { '[class.is-active]': 'declarationEntry()' },
})
export class DeclarationControls {
private readonly userInput = inject(UserInputService);
protected readonly declarationEntry = this.userInput.declarationEntrySignal;
protected readonly declaredType = this.userInput.declaredTypeSignal;
protected readonly declaredBalance = this.userInput.declaredBalanceChoice;
protected readonly translationService = inject(TranslationService);
protected readonly tr = this.translationService.tr;
/** One CP chip per expiry date from two balances on; otherwise the single CP chip. */
protected readonly chips = computed<readonly Chip[]>(() => {
const dates = this.userInput.cpBalanceExpiryDates();
const cp: Chip[] =
dates.length > 1
? dates.map((balance) => ({
type: 'cp',
balance,
label: this.tr().bookedDays.cpUntil.replace(
'{date}',
this.translationService.formatPlanningDate(balance),
),
}))
: [{ type: 'cp', balance: null, label: 'CP' }];
return [
...cp,
...(['rtt', 'other'] as const).map((type) => ({
type,
balance: null,
label: this.translationService.getDayTypeLabel(type),
})),
];
});
protected choose(type: LeaveType, balance: string | null): void {
this.declaredType.set(type);
if (balance) this.userInput.declaredBalanceSignal.set(balance);
}
}