Skip to content

Commit

Permalink
fix: colleague timeclock showing "global" timeclock
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Oct 13, 2024
1 parent d2bc797 commit 7340334
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
43 changes: 30 additions & 13 deletions app/components/jobs/timeclock/TimeclockList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ const props = withDefaults(
defineProps<{
userId?: number;

Check warning on line 19 in app/components/jobs/timeclock/TimeclockList.vue

View workflow job for this annotation

GitHub Actions / node-tests

Prop 'userId' requires default value to be set
showStats?: boolean;
historicSubDays?: number;
forceHistoricView?: boolean;
}>(),
{
showStats: true,
historicSubDays: 7,
forceHistoricView: undefined,
},
);
Expand Down Expand Up @@ -51,17 +55,20 @@ function setFromProps(): void {
return;
}
query.users?.push({
userId: props.userId,
firstname: '',
lastname: '',
dateofbirth: '',
job: '',
jobGrade: 0,
});
query.users = [
{
userId: props.userId,
firstname: '',
lastname: '',
dateofbirth: '',
job: '',
jobGrade: 0,
},
];
}
watch(props, setFromProps);
setFromProps();
const futureDay = computed(() => addDays(query.from, 1));
const previousDay = computed(() => subDays(query.from, 1));
Expand All @@ -81,9 +88,17 @@ const {
() => listTimeclockEntries(),
);
const perDayView = computed(() => !canAccessAll.value || !(query.users !== undefined && query.users.length > 0));
const perDayView = computed(() => {
if (props.forceHistoricView !== undefined) {
return !props.forceHistoricView;
}
return !canAccessAll.value || !(query.users !== undefined && query.users.length > 0);
});
async function listTimeclockEntries(): Promise<ListTimeclockResponse> {
console.log('query', perDayView.value, query.users, query.from, query.to);
try {
const req: ListTimeclockRequest = {
pagination: {
Expand Down Expand Up @@ -155,14 +170,16 @@ function dayBackwards(): void {
}
// Update date to something reasonable when per day view is actived
watch(perDayView, () => {
if (canAccessAll && !perDayView.value) {
function setPerDayView(): void {
if (canAccessAll.value && !perDayView.value) {
const from = query.from;
const to = subDays(query.to ?? new Date(), 7);
const to = subDays(query.to ?? new Date(), props.historicSubDays);
query.from = to;
query.to = from;
}
});
}
watch(perDayView, setPerDayView);
setPerDayView();
const columns = computed(() =>
[
Expand Down
4 changes: 2 additions & 2 deletions app/components/partials/DatePickerPopover.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const open = ref(false);
<UButton
v-bind="button"
variant="outline"
color="gray"
color="black"
block
icon="i-mdi-calendar-month"
:label="modelValue ? format(modelValue, dateFormat) : dateFormat"
Expand Down Expand Up @@ -75,7 +75,7 @@ const open = ref(false);
<UButton
v-bind="button"
variant="outline"
color="gray"
color="black"
block
icon="i-mdi-calendar-month"
:label="modelValue ? format(modelValue, dateFormat) : dateFormat"
Expand Down
7 changes: 6 additions & 1 deletion app/pages/jobs/colleagues/[id]/timeclock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const route = useRoute('jobs-colleagues-id-timeclock');

<template>
<div class="flex flex-1 flex-col">
<TimeclockList :user-id="parseInt(route.params.id as string)" :show-stats="false" />
<TimeclockList
:user-id="parseInt(route.params.id as string)"
:show-stats="false"
force-historic-view
:historic-sub-days="14"
/>
</div>
</template>

0 comments on commit 7340334

Please sign in to comment.