0
0
Fork 0

improvements

This commit is contained in:
William Buezas 2024-03-22 18:33:25 -03:00
parent f1faf18523
commit 6f97ee1aeb
2 changed files with 41 additions and 25 deletions

View File

@ -91,3 +91,24 @@ export function toDateTimeFormat(date, showSeconds = false) {
second: showSeconds ? '2-digit' : undefined, second: showSeconds ? '2-digit' : undefined,
}); });
} }
/**
* Converts seconds to a formatted string representing hours and minutes (hh:mm).
* @param {number} seconds - The number of seconds to convert.
* @param {boolean} includeHSuffix - Optional parameter indicating whether to include "h." after the hour.
* @returns {string} A string representing the time in the format "hh:mm" with optional "h." suffix.
*/
export function secondsToHoursMinutes(seconds, includeHSuffix = true) {
if (!seconds) return includeHSuffix ? '00:00 h.' : '00:00';
const hours = Math.floor(seconds / 3600);
const remainingMinutes = seconds % 3600;
const minutes = Math.floor(remainingMinutes / 60);
const formattedHours = hours < 10 ? '0' + hours : hours;
const formattedMinutes = minutes < 10 ? '0' + minutes : minutes;
// Append "h." if includeHSuffix is true
const suffix = includeHSuffix ? ' h.' : '';
// Return formatted string
return formattedHours + ':' + formattedMinutes + suffix;
}

View File

@ -17,10 +17,10 @@ import { useState } from 'src/composables/useState';
import { dashIfEmpty } from 'src/filters'; import { dashIfEmpty } from 'src/filters';
import { useVnConfirm } from 'composables/useVnConfirm'; import { useVnConfirm } from 'composables/useVnConfirm';
import { useArrayData } from 'composables/useArrayData'; import { useArrayData } from 'composables/useArrayData';
import { toTimeFormat } from 'filters/date.js'; import { toTimeFormat, secondsToHoursMinutes } from 'filters/date.js';
const route = useRoute(); const route = useRoute();
const { t } = useI18n(); const { t, locale } = useI18n();
const { notify } = useNotify(); const { notify } = useNotify();
const { hasAny } = useRole(); const { hasAny } = useRole();
const _state = useState(); const _state = useState();
@ -75,16 +75,13 @@ const columns = computed(() => {
const getHeaderFormattedDate = (date) => { const getHeaderFormattedDate = (date) => {
const newDate = new Date(date); const newDate = new Date(date);
const day = String(newDate.getDate()).padStart(2, '0'); const day = String(newDate.getDate()).padStart(2, '0');
const monthName = newDate.toLocaleString('es-ES', { month: 'long' }); const monthName = newDate.toLocaleString(locale.value, { month: 'long' });
return `${day} ${monthName}`; return `${day} ${monthName}`;
}; };
const formatHours = (hour = 0) => { const formattedWeekTotalHours = computed(() =>
const _hour = toTimeFormat(hour); secondsToHoursMinutes(weekTotalHours.value)
return _hour ? `${_hour} h.` : '00:00 h.'; );
};
const formattedWeekTotalHours = computed(() => formatHours(weekTotalHours.value));
const defaultDate = computed(() => { const defaultDate = computed(() => {
const date = Date.vnNew(); const date = Date.vnNew();
@ -211,7 +208,6 @@ const getWorkedHours = async (from, to) => {
weekDay.workedHours = workDay.workedHours; weekDay.workedHours = workDay.workedHours;
} }
} }
weekTotalHours.value = _weekTotalHours; weekTotalHours.value = _weekTotalHours;
}; };
@ -358,7 +354,7 @@ const getFinishTime = () => {
const finishTimeStamp = const finishTimeStamp =
lastKnownTime && remainingTime ? lastKnownTime + remainingTime : null; lastKnownTime && remainingTime ? lastKnownTime + remainingTime : null;
if (finishTimeStamp) return formatHours(finishTimeStamp); if (finishTimeStamp) return toTimeFormat(finishTimeStamp) + ' h.';
} }
}; };
@ -466,7 +462,7 @@ onMounted(async () => {
<div> <div>
<QBtnGroup push class="q-gutter-x-sm" flat> <QBtnGroup push class="q-gutter-x-sm" flat>
<QBtn <QBtn
v-if="isHimSelf" v-if="isHimSelf && state"
:label="t('Satisfied')" :label="t('Satisfied')"
color="primary" color="primary"
type="submit" type="submit"
@ -474,7 +470,7 @@ onMounted(async () => {
@click="isSatisfied()" @click="isSatisfied()"
/> />
<QBtn <QBtn
v-if="isHimSelf" v-if="isHimSelf && state"
:label="t('Not satisfied')" :label="t('Not satisfied')"
color="primary" color="primary"
type="submit" type="submit"
@ -482,7 +478,7 @@ onMounted(async () => {
@click="showReasonForm()" @click="showReasonForm()"
/> />
<QBtn <QBtn
v-if="reason && (isHimSelf || isHr)" v-if="reason && state && (isHimSelf || isHr)"
:label="t('Reason')" :label="t('Reason')"
color="primary" color="primary"
type="submit" type="submit"
@ -501,10 +497,10 @@ onMounted(async () => {
) )
" "
> >
<QTooltip <QTooltip>
>{{ state ? t('Resend') : t('globals.send') }} {{ state ? t('Resend') : t('globals.send') }}
{{ t('email of this week to the user') }}</QTooltip {{ t('email of this week to the user') }}
> </QTooltip>
</QBtn> </QBtn>
</QBtnGroup> </QBtnGroup>
</div> </div>
@ -541,7 +537,6 @@ onMounted(async () => {
dense dense
:default-year-month="defaultDate" :default-year-month="defaultDate"
/> />
<pre>date range: {{ selectedCalendarDates }}</pre>
</QDrawer> </QDrawer>
<QPage class="column items-center q-pa-md"> <QPage class="column items-center q-pa-md">
<QTable :columns="columns" :rows="['']" hide-bottom class="full-width"> <QTable :columns="columns" :rows="['']" hide-bottom class="full-width">
@ -557,12 +552,12 @@ onMounted(async () => {
<div class="column-title-container"> <div class="column-title-container">
<span class="text-primary">{{ t(col.label) }}</span> <span class="text-primary">{{ t(col.label) }}</span>
<span>{{ col.formattedDate }}</span> <span>{{ col.formattedDate }}</span>
<span <QBadge
v-if="col.dayData?.event" v-if="col.dayData?.event"
:style="`color: ${col.dayData.event.color}`" :style="`background-color: ${col.dayData.event.color}`"
> >
{{ col.dayData.event.name }} {{ col.dayData.event.name }}
</span> </QBadge>
</div> </div>
</QTh> </QTh>
</QTr> </QTr>
@ -572,7 +567,7 @@ onMounted(async () => {
<QTd <QTd
v-for="(day, index) in props.cols" v-for="(day, index) in props.cols"
:key="index" :key="index"
style="padding: 20px 0 20px 0 !important" style="padding: 20px 16px !important"
> >
<div class="full-height"> <div class="full-height">
<WorkerTimeHourChip <WorkerTimeHourChip
@ -594,7 +589,7 @@ onMounted(async () => {
<QTd v-for="(day, index) in props.cols" :key="index"> <QTd v-for="(day, index) in props.cols" :key="index">
<div class="column items-center justify-center"> <div class="column items-center justify-center">
<span class="q-mb-md text-sm text-body1"> <span class="q-mb-md text-sm text-body1">
{{ formatHours(day.dayData?.workedHours) }} {{ secondsToHoursMinutes(day.dayData?.workedHours) }}
</span> </span>
<QIcon <QIcon
name="add_circle" name="add_circle"