feat: enhance user input component with new styling and functionality
- Added informational styling to warning cards in user input component. - Improved remaining days details and history display with new computed properties. - Updated user input service to manage planning outcomes and traces more effectively. - Enhanced leave planner service to classify remaining balances with detailed reasons. - Expanded translation service to support new balance reasoning and suggestions. - Updated translations for multiple languages to reflect new features and terminology.
This commit is contained in:
1 parent
9851edf906
commit
3dc601982a
15 files changed
+679
-141
No files matched your search
@@ -1,4 +1,11 @@
|
||||
import { Component, computed, inject, ChangeDetectionStrategy } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
computed,
|
||||
effect,
|
||||
inject,
|
||||
signal,
|
||||
ChangeDetectionStrategy,
|
||||
} from '@angular/core';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { UserInputService } from '../../services/user-input-service';
|
||||
import { RulesPanel } from '../rules-panel/rules-panel';
|
||||
@@ -11,6 +18,7 @@ import type { LeaveType } from '../../services/leave-planner.service';
|
||||
import { TranslationService } from '../../services/translation-service';
|
||||
import { CalendarSettingsService } from '../../services/calendar-settings-service';
|
||||
import { PlanningDurationService } from '../../services/planning-duration.service';
|
||||
import { addPlanningDays } from '../../services/planning-date';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-input',
|
||||
@@ -50,47 +58,151 @@ export class UserInput {
|
||||
return this.translationService.tr;
|
||||
}
|
||||
|
||||
protected remainingDays = computed(() => {
|
||||
const remaining = this.userInputService.remainingVacationDaysSignal();
|
||||
return remaining.reduce((acc, day) => acc + day.numberOfDays, 0);
|
||||
});
|
||||
protected readonly trace = this.userInputService.planningTraceSignal;
|
||||
protected readonly traceResolved = this.userInputService.traceResolvedSignal;
|
||||
protected readonly historyBalanceId = signal<string | null>(null);
|
||||
protected readonly historyPage = signal(0);
|
||||
protected readonly remainingDays = computed(() =>
|
||||
(this.userInputService.displayedPlanSignal()?.remainingBalances ?? []).reduce(
|
||||
(total, balance) => total + balance.quantity,
|
||||
0,
|
||||
),
|
||||
);
|
||||
protected readonly hasAtRiskDays = computed(() =>
|
||||
this.userInputService
|
||||
.displayedPlanSignal()
|
||||
?.remainingBalances.some((balance) => balance.classification !== 'deferred'),
|
||||
);
|
||||
|
||||
protected remainingDaysDetails = computed(() => {
|
||||
const remaining = this.userInputService.remainingVacationDaysSignal();
|
||||
return remaining
|
||||
.filter((day) => day.numberOfDays > 0)
|
||||
.map((day) => {
|
||||
const typeName = this.translationService.getDayTypeLabel(day.type);
|
||||
const expiryDate = day.expiryDate.toLocaleDateString(
|
||||
this.translationService.locale(),
|
||||
{
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
year: 'numeric',
|
||||
},
|
||||
);
|
||||
const expiresLabel = this.tr().userInput.expires;
|
||||
const classification = day.classification
|
||||
? this.getClassificationLabel(day.classification)
|
||||
: '';
|
||||
const reason = day.classification ? this.getReasonLabel(day.classification) : '';
|
||||
const explanation = classification ? `${classification}: ${reason}; ` : '';
|
||||
return `${day.numberOfDays} ${typeName} (${explanation}${expiresLabel} ${expiryDate})`;
|
||||
});
|
||||
const plan = this.userInputService.displayedPlanSignal();
|
||||
if (!plan) return [];
|
||||
const incomplete =
|
||||
this.userInputService.planningOutcomeSignal()?.kind === 'PlanningIncomplete';
|
||||
const copy = this.tr().userInput;
|
||||
return plan.remainingBalances.map((balance) => {
|
||||
const code =
|
||||
incomplete && ['preserved', 'not-established'].includes(balance.reason.code)
|
||||
? 'calculation-incomplete'
|
||||
: balance.reason.code;
|
||||
return {
|
||||
id: balance.id,
|
||||
title: `${balance.quantity} ${balance.quantity > 1 ? copy.daysSuffix : copy.daySuffix} ${this.translationService.getDayTypeLabel(balance.type)}`,
|
||||
reason: this.translationService.getRemainingBalanceReason(
|
||||
balance,
|
||||
plan,
|
||||
incomplete,
|
||||
),
|
||||
validity: copy.remainingValidity
|
||||
.replace(
|
||||
'{available}',
|
||||
this.translationService.formatPlanningDate(balance.availableFrom),
|
||||
)
|
||||
.replace(
|
||||
'{expiry}',
|
||||
this.translationService.formatPlanningDate(balance.expiryDate),
|
||||
),
|
||||
horizon: copy.remainingHorizon
|
||||
.replace(
|
||||
'{start}',
|
||||
this.translationService.formatPlanningDate(plan.horizon.start),
|
||||
)
|
||||
.replace(
|
||||
'{end}',
|
||||
this.translationService.formatPlanningDate(
|
||||
addPlanningDays(plan.horizon.end, -1),
|
||||
),
|
||||
),
|
||||
earnedFrom: balance.sourceRuleId
|
||||
? copy.remainingEarnedFrom.replace(
|
||||
'{rule}',
|
||||
this.ruleName(balance.sourceRuleId),
|
||||
)
|
||||
: '',
|
||||
suggestion: copy.remainingSuggestions[code],
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
private getClassificationLabel(classification: NonNullable<VacDay['classification']>): string {
|
||||
const labels = this.tr().userInput.remainingClassification;
|
||||
if (classification === 'unavoidable-expiry') return labels.unavoidableExpiry;
|
||||
if (classification === 'at-risk') return labels.atRisk;
|
||||
return labels.deferred;
|
||||
protected readonly remainingHistory = computed(() => {
|
||||
const id = this.historyBalanceId();
|
||||
if (!id) return [];
|
||||
return (
|
||||
this.trace()?.phases.flatMap((phase) =>
|
||||
phase.decisions.flatMap((decision) =>
|
||||
decision.candidates
|
||||
.filter((candidate) => candidate.placement?.balanceId === id)
|
||||
.map((candidate) => ({ candidate, phase: phase.name })),
|
||||
),
|
||||
) ?? []
|
||||
);
|
||||
});
|
||||
protected readonly historyPageCount = computed(() =>
|
||||
Math.ceil(this.remainingHistory().length / 20),
|
||||
);
|
||||
protected readonly visibleHistory = computed(() =>
|
||||
this.remainingHistory()
|
||||
.slice(this.historyPage() * 20, (this.historyPage() + 1) * 20)
|
||||
.map(({ candidate, phase }) => ({
|
||||
date: (candidate.dates ?? (candidate.date ? [candidate.date] : []))
|
||||
.map((date) => this.translationService.formatPlanningDate(date))
|
||||
.join(', '),
|
||||
phase: this.tr().planning.explanation.stages[phase] ?? this.criterionLabel(phase),
|
||||
status: this.tr().planning.traceStatuses[candidate.status],
|
||||
reason: candidate.reason
|
||||
? (this.tr().userInput.remainingCandidateReasons[candidate.reason.code] ??
|
||||
this.tr().planning.explanation.unavailable[candidate.reason.code] ??
|
||||
this.tr().userInput.remainingCandidateReasons['unknown'])
|
||||
: '',
|
||||
criteria: (candidate.technicalComparison ?? []).flatMap((value) => {
|
||||
const label = this.criterionLabel(value.name);
|
||||
return label
|
||||
? [
|
||||
{
|
||||
text: `${label} : ${value.before} → ${value.after}`,
|
||||
decisive: value.name === candidate.firstDecisiveComparator,
|
||||
},
|
||||
]
|
||||
: [];
|
||||
}),
|
||||
})),
|
||||
);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
this.userInputService.planningOutcomeSignal();
|
||||
this.historyBalanceId.set(null);
|
||||
this.historyPage.set(0);
|
||||
});
|
||||
}
|
||||
|
||||
private getReasonLabel(classification: NonNullable<VacDay['classification']>): string {
|
||||
const labels = this.tr().userInput.remainingReason;
|
||||
if (classification === 'unavoidable-expiry') return labels.unavoidableExpiry;
|
||||
if (classification === 'at-risk') return labels.atRisk;
|
||||
return labels.deferred;
|
||||
private ruleName(id: string): string {
|
||||
return (
|
||||
this.userInputService.planningSnapshotSignal()?.rules.find((rule) => rule.id === id)
|
||||
?.name ?? id
|
||||
);
|
||||
}
|
||||
|
||||
private criterionLabel(name: string): string | undefined {
|
||||
const id = name.replace(/^protected:/, '');
|
||||
const key =
|
||||
id === 'obligations'
|
||||
? 'obligation-validity'
|
||||
: id.startsWith('preference:')
|
||||
? 'preference'
|
||||
: id;
|
||||
return this.tr().planning.explanation.objectives[key]?.label.replace(
|
||||
'{rule}',
|
||||
this.ruleName(id.slice('preference:'.length)),
|
||||
);
|
||||
}
|
||||
|
||||
protected toggleRemainingHistory(id: string, event: Event): void {
|
||||
const open = (event.currentTarget as HTMLDetailsElement).open;
|
||||
if (open && id !== this.historyBalanceId()) {
|
||||
this.historyPage.set(0);
|
||||
this.historyBalanceId.set(id);
|
||||
} else if (!open && id === this.historyBalanceId()) this.historyBalanceId.set(null);
|
||||
}
|
||||
|
||||
protected hasRemainingDays = computed(() => this.remainingDays() > 0);
|
||||
|
||||
Reference in new issue
Block a user