diff --git a/SPECIFICATION.md b/SPECIFICATION.md index 1ffcd736..21eed34c 100644 --- a/SPECIFICATION.md +++ b/SPECIFICATION.md @@ -1013,7 +1013,11 @@ days; a country does not get its regions' days. - **Out again:** the page downloads the shown list in the same format, and `occ absence:export-holidays [--year] [--region]` prints it. -Everyone can read the list. HR always edits it, and HR or an admin can let every +Everyone can read the list. The page opens on the viewer's own days (their code, its +country and `*`) when they have a region code, and says which those are; without one it +links to the profile to set it. HR, who keep the list for every region, open on all +regions with the rule itself. Days already past in the shown year are muted. +HR always edits the list, and HR or an admin can let every employee (§2.2) add, edit and delete single holidays, so HR does not become a bottleneck. That switch lives in the *Public holidays* section of the Settings page (§12); the *Public holidays* page only tells HR who may edit and links there. Importing a whole list diff --git a/src/utils/regions.spec.ts b/src/utils/regions.spec.ts index 02524aef..676b1505 100644 --- a/src/utils/regions.spec.ts +++ b/src/utils/regions.spec.ts @@ -3,9 +3,12 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ import { describe, expect, it, vi } from 'vitest' -import { regionCountryName, regionFlag } from './regions.ts' +import { holidayAppliesTo, holidaySources, regionCountryName, regionFlag } from './regions.ts' -vi.mock('@nextcloud/l10n', () => ({ getLanguage: () => 'en' })) +vi.mock('@nextcloud/l10n', () => ({ + getLanguage: () => 'en', + t: (_app: string, text: string, vars: Record) => text.replace(/\{(\w+)\}/g, (_match: string, key: string) => vars[key] ?? ''), +})) describe('regionFlag', () => { it('shows the country of a code', () => { @@ -31,3 +34,31 @@ describe('regionCountryName', () => { expect(regionCountryName('QQ')).toBe('') }) }) + +describe('holidayAppliesTo', () => { + it('takes the days of the code, of its country and of everywhere', () => { + expect(holidayAppliesTo('DE-BY', 'DE-BY')).toBe(true) + expect(holidayAppliesTo('DE', 'DE-BY')).toBe(true) + expect(holidayAppliesTo('*', 'DE-BY')).toBe(true) + }) + + it('leaves out other regions, even of the same country', () => { + expect(holidayAppliesTo('DE-BE', 'DE-BY')).toBe(false) + expect(holidayAppliesTo('FR', 'DE-BY')).toBe(false) + expect(holidayAppliesTo('DE-BY', 'DE')).toBe(false) + }) +}) + +describe('holidaySources', () => { + it('names the region and its country', () => { + expect(holidaySources('DE-BY')).toBe('You get the holidays of DE-BY, of Germany and those for everyone.') + }) + + it('names only the country for a code without a region', () => { + expect(holidaySources('FR')).toBe('You get the holidays of France and those for everyone.') + }) + + it('says nothing without a code', () => { + expect(holidaySources('')).toBe('') + }) +}) diff --git a/src/utils/regions.ts b/src/utils/regions.ts index 6e0f9df9..b9523446 100644 --- a/src/utils/regions.ts +++ b/src/utils/regions.ts @@ -2,7 +2,7 @@ * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { getLanguage } from '@nextcloud/l10n' +import { getLanguage, t } from '@nextcloud/l10n' /** Holidays entered for this code apply to everyone (§7.2) */ export const EVERYWHERE = '*' @@ -48,3 +48,31 @@ export function regionCountryName(code: string | null | undefined): string { const name = new Intl.DisplayNames([getLanguage().replace('_', '-'), 'en'], { type: 'region', fallback: 'none' }).of(country) return name ?? '' } + +/** + * Whether a holiday entered for `region` applies to someone with `code` (§7.2): + * the days of the code, of its country and of everywhere. + * + * @param region the region code of the holiday + * @param code the person's region code, uppercase such as `DE-BY` + */ +export function holidayAppliesTo(region: string, code: string): boolean { + return region === EVERYWHERE || region === code || region === countryOf(code) +} + +/** + * Where the holidays of someone with this region code come from, in one sentence. + * + * @param code their region code, '' when they set none + * @return '' without a code + */ +export function holidaySources(code: string): string { + const country = countryOf(code) + if (!country) { + return '' + } + const countryName = regionCountryName(code) || country + return code === country + ? t('absence', 'You get the holidays of {country} and those for everyone.', { country: countryName }, undefined, { escape: false, sanitize: false }) + : t('absence', 'You get the holidays of {region}, of {country} and those for everyone.', { region: code, country: countryName }, undefined, { escape: false, sanitize: false }) +} diff --git a/src/views/HolidaysView.vue b/src/views/HolidaysView.vue index bc005243..c5b7fdc0 100644 --- a/src/views/HolidaysView.vue +++ b/src/views/HolidaysView.vue @@ -47,12 +47,23 @@ -

- {{ t('absence', 'People get the days of their region code, of its country, and the days entered for * (everywhere). DE-BY gets DE-BY, DE and * days.') }} - -

+

+

{{ session.holidaysEveryoneEdits ? t('absence', 'Who may edit: everyone.') : t('absence', 'Who may edit: HR only.') }} @@ -73,7 +84,7 @@ - + {{ formatDate(holiday.date) }} {{ regionName(holiday.region) }} @@ -267,16 +278,22 @@ import api from '../services/api.ts' import { useSessionStore } from '../stores/session.ts' import { formatDate, toIso } from '../utils/dates.ts' import { serverMessage } from '../utils/errors.ts' +import { formatRegionCode } from '../utils/holidays.ts' import { latestOnly } from '../utils/latest.ts' import { locale } from '../utils/locale.ts' -import { EVERYWHERE, regionFlag } from '../utils/regions.ts' +import { EVERYWHERE, holidayAppliesTo, holidaySources, regionFlag } from '../utils/regions.ts' const sessionStore = useSessionStore() -/** An entry of the region filter: `id` is the region code, '' for all of them */ +/** + * An entry of the region filter. `code` is a region code, '' for all of them; + * `mine` shows every day that applies to the viewer's code, not only its own. + */ interface RegionOption { id: string label: string + code: string + mine: boolean } /** The add and edit form: `id` is null for a new holiday */ @@ -289,13 +306,24 @@ interface HolidayForm { } const currentYear = new Date().getFullYear() -const all: RegionOption = { id: '', label: t('absence', 'All regions') } +const all: RegionOption = { id: '', label: t('absence', 'All regions'), code: '', mine: false } +const today = toIso(new Date()) const loading = ref(true) const holidays = shallowRef([]) const year = ref(currentYear) const years = [currentYear - 1, currentYear, currentYear + 1, currentYear + 2] -const region = shallowRef(all) +const session = computed(() => sessionStore.session) + +/** The viewer's region code such as `DE-BY`, '' when they set none */ +const ownCode = computed(() => formatRegionCode(session.value.holidayCountry ?? '', session.value.holidayRegion ?? '')) + +const mine = computed(() => (ownCode.value + ? { id: 'mine', label: t('absence', 'Your holidays ({code})', { code: ownCode.value }), code: ownCode.value, mine: true } + : null)) + +// HR keeps the list for every region; everyone else opens on their own days +const region = shallowRef((!session.value.isHr && mine.value) || all) const form = ref(null) const saving = ref(false) // The holiday whose deletion waits for a confirmation @@ -314,16 +342,21 @@ const example = JSON.stringify([ // Changing the year twice quickly: only the year picked last may land. const startLoad = latestOnly() -const session = computed(() => sessionStore.session) - const canEdit = computed(() => sessionStore.session.canEditHolidays) const regionOptions = computed(() => { const codes = [...new Set(holidays.value.map((h) => h.region))].sort() - return [all, ...codes.map((code) => ({ id: code, label: `${regionFlag(code)} ${regionName(code)}`.trim() }))] + const own = mine.value ? [mine.value] : [] + return [all, ...own, ...codes.map((code) => ({ id: code, label: `${regionFlag(code)} ${regionName(code)}`.trim(), code, mine: false }))] }) -const shown = computed(() => (region.value.id === '' ? holidays.value : holidays.value.filter((h) => h.region === region.value.id))) +const shown = computed(() => { + const { code, mine: applying } = region.value + if (code === '') { + return holidays.value + } + return holidays.value.filter((h) => (applying ? holidayAppliesTo(h.region, code) : h.region === code)) +}) watch(year, () => { load() @@ -372,7 +405,7 @@ async function load(): Promise { function edit(holiday: Holiday | null): void { form.value = holiday ? { id: holiday.id, date: new Date(holiday.date + 'T00:00:00'), region: holiday.region, label: holiday.label, recurring: holiday.recurring } - : { id: null, date: new Date(`${year.value}-01-01T00:00:00`), region: region.value.id, label: '', recurring: false } + : { id: null, date: new Date(`${year.value}-01-01T00:00:00`), region: region.value.code, label: '', recurring: false } } /** @@ -532,7 +565,7 @@ function download(): void { const list = shown.value.map(({ date, region, label, recurring }) => ({ date, region, label, recurring })) const link = document.createElement('a') link.href = URL.createObjectURL(new Blob([JSON.stringify(list, null, '\t')], { type: 'application/json' })) - link.download = `holidays-${year.value}${region.value.id ? '-' + region.value.id : ''}.json` + link.download = `holidays-${year.value}${region.value.code ? '-' + region.value.code : ''}.json` link.click() URL.revokeObjectURL(link.href) } @@ -550,12 +583,17 @@ function download(): void { font-weight: 600; } + &__intro a, + &__who a { + text-decoration: underline; + } + &__who { margin-block-end: calc(2 * var(--default-grid-baseline)); + } - a { - text-decoration: underline; - } + &__past td { + color: var(--color-text-maxcontrast); } &__byline,