Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1739,9 +1739,13 @@ NcContent(app-name="absence")
(filter form + CSV buttons), plus entitlement / leave-type / holiday management.
- **Profile** (`#/profile`, `#/profile/:uid`) — the first entry of the navigation. The person's
vacation balance and next leave (HR edits the vacation days there with the entitlement
editor of the Employees list, §13), their region code (editable by the person, with the
change dialog of §7.2), the number of public holidays this year and the next ones, the
contract (§6.4: read-only, editable by HR), sick days this year (HR only when sick
editor of the Employees list, §13): on one's own profile the ring and a link to *My
leave* for the details, on someone else's the ring with its ledger. Their region code
(editable by the person: *Save* first shows the change dialog of §7.2), the number of
public holidays this year and the next ones with a link to the list, the
contract (§6.4: read-only, editable by HR; the "Since" line of today's working pattern is
left out when it began on the start date, and the note says who sees it, "you, your
manager and HR" on one's own profile), sick days this year (HR only when sick
leave is a confidential type, §5.7), and the history of
changes (the person and HR only). The person, their manager and HR may open it
(`GET /api/profiles/{uid}`), the same rule as balances. An account that does not
Expand Down
4 changes: 2 additions & 2 deletions src/components/RegionCodeField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
:modelValue="code"
:label="t('absence', 'My region code')"
:error="code !== '' && !codeValid"
:helperText="code !== '' && !codeValid ? t('absence', 'Use a country like DE or a region like DE-BY') : ''"
:helperText="code !== '' && !codeValid ? t('absence', 'Use a country like DE or a region like DE-BY') : t('absence', 'Sets your public holidays')"
@update:modelValue="code = String($event)" />
<NcButton :disabled="saving || !codeValid || code === savedCode" @click="save">
{{ t('absence', 'Change') }}
{{ t('absence', 'Save') }}
</NcButton>
</div>
<p v-if="knownCodes.length" class="region-code__hint">
Expand Down
16 changes: 15 additions & 1 deletion src/utils/contract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { describe, expect, it } from 'vitest'
import { contractDiff, describePeriod, weekdaysOn } from './contract.ts'
import { contractDiff, describePeriod, patternSince, weekdaysOn } from './contract.ts'

const fullTime = { from: '2024-03-01', weekdays: [1, 2, 3, 4, 5], percent: 100 }
const fourDays = { from: '2026-07-01', weekdays: [1, 2, 3, 4], percent: 80 }
Expand Down Expand Up @@ -43,3 +43,17 @@ describe('contractDiff', () => {
expect(contractDiff([], [fullTime])).toEqual({ removed: [], added: [fullTime], kept: [] })
})
})

describe('patternSince', () => {
it('dates a pattern that began after the start', () => {
expect(patternSince(fourDays.from, fullTime.from)).toBe('2026-07-01')
})

it('leaves the date out when the pattern began on the start date', () => {
expect(patternSince(fullTime.from, '2024-03-01')).toBeNull()
})

it('dates the pattern when there is no start date', () => {
expect(patternSince(fullTime.from, null)).toBe('2024-03-01')
})
})
11 changes: 11 additions & 0 deletions src/utils/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,14 @@ export function contractDiff<T extends PeriodPattern>(before: T[], after: T[]):
const added = after.filter((period) => !before.some((other) => same(period, other)))
return { removed, added, kept: removed.length ? [] : before.slice(-1) }
}

/**
* The date since which today's working pattern runs, for a read-only contract.
*
* @param from the start of the period in force today
* @param start the start date of the contract, null when HR entered none
* @return null when the pattern began on the start date, which has a line of its own
*/
export function patternSince(from: string, start: string | null): string | null {
return from === start ? null : from
}
37 changes: 31 additions & 6 deletions src/views/ProfileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@
<div v-else-if="profile" class="profile__grid">
<section class="profile__card">
<h3>{{ t('absence', 'Vacation {year}', { year: profile.holidays.year }) }}</h3>
<BalanceCard v-for="row in balances" :key="row.typeId" :row="row" />
<div v-if="profile.self" class="profile__balance">
<BalanceRing v-for="row in balances" :key="row.typeId" :row="row" />
<RouterLink class="profile__link" :to="{ name: 'my' }">
{{ t('absence', 'Details in My leave') }}
</RouterLink>
</div>
<template v-else>
<BalanceCard v-for="row in balances" :key="row.typeId" :row="row" />
</template>
<NcButton
v-if="profile.canEditContract && balances.length"
class="profile__edit"
Expand Down Expand Up @@ -96,9 +104,9 @@
<p v-if="profile.holidays.upcoming.length" class="profile__note">
{{ t('absence', 'Next: {days}', { days: profile.holidays.upcoming.map((day) => `${day.label}, ${formatDate(day.date)}`).join(' · ') }, undefined, { escape: false, sanitize: false }) }}
</p>
<router-link :to="{ name: 'holidays' }">
<RouterLink class="profile__link" :to="{ name: 'holidays' }">
{{ t('absence', 'See the list') }}
</router-link>
</RouterLink>
</section>

<section class="profile__card profile__card--wide">
Expand All @@ -116,8 +124,8 @@
· {{ t('absence', '{percent}%', { percent: current.percent }) }}
</template>
</p>
<p class="profile__note">
{{ t('absence', 'Since {date}', { date: formatDate(current.from) }) }}
<p v-if="since" class="profile__note">
{{ t('absence', 'Since {date}', { date: formatDate(since) }) }}
</p>
</template>
<p v-else class="profile__note">
Expand All @@ -130,7 +138,7 @@
</p>
</template>
<p class="profile__note">
{{ t('absence', 'Set by HR. Visible to this person, their manager and HR.') }}
{{ profile.self ? t('absence', 'Set by HR. Visible to you, your manager and HR.') : t('absence', 'Set by HR. Visible to this person, their manager and HR.') }}
</p>
</section>

Expand Down Expand Up @@ -169,12 +177,14 @@ import NcButton from '@nextcloud/vue/components/NcButton'
import NcEmptyContent from '@nextcloud/vue/components/NcEmptyContent'
import Pencil from 'vue-material-design-icons/Pencil.vue'
import BalanceCard from '../components/BalanceCard.vue'
import BalanceRing from '../components/BalanceRing.vue'
import ContractEditor from '../components/ContractEditor.vue'
import EntitlementDialog from '../components/EntitlementDialog.vue'
import RegionCodeField from '../components/RegionCodeField.vue'
import SkeletonList from '../components/SkeletonList.vue'
import api from '../services/api.ts'
import { useSessionStore } from '../stores/session.ts'
import { patternSince } from '../utils/contract.ts'
import { formatDate, formatRange, toIso } from '../utils/dates.ts'
import { displayNameOf } from '../utils/displayName.ts'
import { isForbidden, serverMessage } from '../utils/errors.ts'
Expand Down Expand Up @@ -219,6 +229,9 @@ const current = computed<ContractPeriod | null>(() => {
return [...profile.value.contract.periods].reverse().find((period) => period.from <= today) ?? null
})

/** When today's working pattern began, null when that is the start date */
const since = computed(() => (current.value && profile.value ? patternSince(current.value.from, profile.value.contract.start) : null))

watch(profileUid, () => {
// The row belongs to the previous person: saving it would write to this one
editingDays.value = null
Expand Down Expand Up @@ -370,6 +383,18 @@ function onContractSaved(): void {
margin: 12px 0 4px;
}

&__balance {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: calc(4 * var(--default-grid-baseline));
}

&__link {
color: var(--color-primary-element);
font-weight: 600;
}

&__edit {
margin-top: 8px;
}
Expand Down
Loading