This commit is contained in:
William Buezas 2024-03-20 10:31:42 -03:00
parent 7ff8bc642e
commit 522b01b293
3 changed files with 201 additions and 81 deletions

View File

@ -0,0 +1,106 @@
<script setup>
import { reactive, ref, computed, onBeforeMount } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router';
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
import FormModelPopup from './FormModelPopup.vue';
import VnInputTime from 'components/common/VnInputTime.vue';
const $props = defineProps({
entryId: {
type: Number,
default: null,
},
dated: {
type: Date,
default: true,
},
});
const emit = defineEmits(['onDataSaved']);
const route = useRoute();
const { t } = useI18n();
let workerHourEntry = reactive({});
const entryDirections = [
{ code: 'in', description: t('Entrada') },
{ code: 'middle', description: t('Intermedio') },
{ code: 'out', description: t('Salida') },
];
const closeButton = ref(null);
const onDataSaved = () => {
emit('onDataSaved');
closeForm();
};
const closeForm = () => {
if (closeButton.value) closeButton.value.click();
};
const isEditMode = computed(() => !!$props.entryId);
const title = computed(() => (isEditMode.value ? t('Edit entry') : t('Add time')));
const urlCreate = computed(() =>
isEditMode.value
? `WorkerTimeControls/${$props.entryId}/updateTimeEntry`
: `WorkerTimeControls/${route.params.id}/addTimeEntry`
);
onBeforeMount(() => {
workerHourEntry = isEditMode.value
? {}
: {
timed: new Date($props.dated),
workerFk: route.params.id,
};
});
</script>
<template>
<FormModelPopup
:form-initial-data="workerHourEntry"
:observe-form-changes="false"
:default-actions="false"
:title="title"
:url-create="urlCreate"
@on-data-saved="onDataSaved()"
>
<template #form-inputs="{ data }">
<VnInputTime
v-if="!isEditMode"
:label="t('Hour')"
v-model="data.timed"
autofocus
:required="true"
:is-clearable="false"
/>
<VnSelectFilter
:label="t('Type')"
v-model="data.direction"
:options="entryDirections"
option-value="code"
option-label="description"
hide-selected
:required="true"
/>
<pre>{{ workerHourEntry }}</pre>
</template>
</FormModelPopup>
</template>
<i18n>
es:
Add time: Añadir hora
Edit entry: Editar entrada
Hour: Hora
Type: Tipo
Entrada: Entrada
Intermedio: Intermedio
Salida: Salida
</i18n>

View File

@ -22,7 +22,7 @@ const $props = defineProps({
}, },
}); });
const emit = defineEmits(['onHourEntryDeleted']); const emit = defineEmits(['onHourEntryDeleted', 'showWorkerTimeForm']);
const { t } = useI18n(); const { t } = useI18n();
const { notify } = useNotify(); const { notify } = useNotify();
@ -57,6 +57,16 @@ const deleteHourEntry = async () => {
console.error('Error deleting hour entry'); console.error('Error deleting hour entry');
} }
}; };
const getChipFormattedHour = (date) => {
//TODO:: Ver si se puede hacer una funcion reutilizable o complementar a utils de dates
const newDate = new Date(date);
const hour = newDate.getHours();
const min = newDate.getMinutes();
return `${hour < 10 ? '0' + hour : hour}:${min < 10 ? '0' + min : min}`;
};
const showWorkerTimeForm = () => emit('showWorkerTimeForm');
</script> </script>
<template> <template>
@ -64,16 +74,18 @@ const deleteHourEntry = async () => {
<QIcon class="direction-icon" :name="directionIconName" size="sm"> <QIcon class="direction-icon" :name="directionIconName" size="sm">
<QTooltip>{{ directionIconTooltip }}</QTooltip> <QTooltip>{{ directionIconTooltip }}</QTooltip>
</QIcon> </QIcon>
<QBadge rounded class="chip"> <QBadge rounded class="chip" @click="showWorkerTimeForm()">
<QIcon name="edit" size="sm" class="fill-icon"> <QIcon name="edit" size="sm" class="fill-icon">
<QTooltip>{{ t('Edit') }}</QTooltip></QIcon <QTooltip>{{ t('Edit') }}</QTooltip></QIcon
> >
<span class="q-px-sm text-subtitle2 text-weight-regular">{{ hour }}</span> <span class="q-px-sm text-subtitle2 text-weight-regular">{{
getChipFormattedHour(hour)
}}</span>
<QIcon <QIcon
name="cancel" name="cancel"
class="remove-icon" class="remove-icon"
size="sm" size="sm"
@click=" @click.stop="
openConfirmationModal( openConfirmationModal(
t('This time entry will be deleted'), t('This time entry will be deleted'),
t('Are you sure you want to delete this entry?'), t('Are you sure you want to delete this entry?'),

View File

@ -1,10 +1,12 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { onMounted, ref, computed, onBeforeMount, nextTick } from 'vue'; import { onMounted, ref, computed, onBeforeMount, nextTick, reactive } from 'vue';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
import WorkerTimeHourChip from 'components/WorkerTimeHourChip.vue'; import WorkerTimeHourChip from 'components/WorkerTimeHourChip.vue';
import WorkerTimeForm from 'components/WorkerTimeForm.vue';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
import axios from 'axios'; import axios from 'axios';
import { useRole } from 'src/composables/useRole'; import { useRole } from 'src/composables/useRole';
@ -13,12 +15,6 @@ import { useStateStore } from 'stores/useStateStore';
import { useState } from 'src/composables/useState'; import { useState } from 'src/composables/useState';
import { dashIfEmpty } from 'src/filters'; import { dashIfEmpty } from 'src/filters';
// const entryDirections = [
// { code: 'in', description: t('Entrada') },
// { code: 'middle', description: t('Intermedio') },
// { code: 'out', description: t('Salida') },
// ];
const route = useRoute(); const route = useRoute();
const { t } = useI18n(); const { t } = useI18n();
const { notify } = useNotify(); const { notify } = useNotify();
@ -47,6 +43,7 @@ const columns = computed(() => {
}); });
}); });
const workerTimeFormDialogRef = ref(null);
const workerHoursRef = ref(null); const workerHoursRef = ref(null);
const calendarRef = ref(null); const calendarRef = ref(null);
const selectedDate = ref(null); const selectedDate = ref(null);
@ -60,6 +57,10 @@ const reason = ref(null);
const canResend = ref(null); const canResend = ref(null);
const weekTotalHours = ref(null); const weekTotalHours = ref(null);
const workerTimeControlMails = ref(null); const workerTimeControlMails = ref(null);
const workerTimeFormProps = reactive({
dated: null,
formType: null,
});
onMounted(() => setDate(Date.vnNew())); onMounted(() => setDate(Date.vnNew()));
@ -71,14 +72,6 @@ const getHeaderFormattedDate = (date) => {
return `${day} ${monthName}`; return `${day} ${monthName}`;
}; };
const getChipFormattedHour = (date) => {
//TODO:: Ver si se puede hacer una funcion reutilizable o complementar a utils de dates
const newDate = new Date(date);
const hour = newDate.getHours();
const min = newDate.getMinutes();
return `${hour < 10 ? '0' + hour : hour}:${min < 10 ? '0' + min : min}`;
};
const formatHours = (timestamp = 0) => { const formatHours = (timestamp = 0) => {
//TODO:: Ver si se puede hacer una funcion reutilizable o complementar a utils de dates //TODO:: Ver si se puede hacer una funcion reutilizable o complementar a utils de dates
let hour = Math.floor(timestamp / 3600); let hour = Math.floor(timestamp / 3600);
@ -380,7 +373,7 @@ const getFinishTime = () => {
} }
}; };
const onHourEntryDeleted = async () => { const updateData = async () => {
await fetchHours(); await fetchHours();
await getMailStates(selectedDate.value); await getMailStates(selectedDate.value);
}; };
@ -400,6 +393,16 @@ const getMailStates = async (date) => {
// await repaint(); // await repaint();
}; };
const showWorkerTimeForm = (propValue, formType) => {
console.log('workerTimeFormDialogRef:: ', workerTimeFormDialogRef.value);
if (formType === 'edit') {
workerTimeFormProps.entryId = propValue;
} else {
workerTimeFormProps.dated = propValue;
}
workerTimeFormDialogRef.value.show();
};
onBeforeMount(() => { onBeforeMount(() => {
weekdayStore.initStore(); weekdayStore.initStore();
console.log('asdasdasd:: ', weekdayStore); console.log('asdasdasd:: ', weekdayStore);
@ -455,10 +458,9 @@ onMounted(async () => {
<pre>date range: {{ selectedCalendarDates }}</pre> <pre>date range: {{ selectedCalendarDates }}</pre>
</QDrawer> </QDrawer>
<QPage class="column items-center q-pa-md"> <QPage class="column items-center q-pa-md">
<QCard class="full-width"> <QTable :columns="columns" :rows="['']" hide-bottom class="full-width">
<QTable :columns="columns" :rows="['']" hide-bottom>
<template #header="props"> <template #header="props">
<QTr :props="props"> <QTr :props="props" no-hover>
<QTh <QTh
v-for="col in props.cols" v-for="col in props.cols"
:key="col.name" :key="col.name"
@ -473,28 +475,29 @@ onMounted(async () => {
</QTr> </QTr>
</template> </template>
<template #body="props"> <template #body="props">
<QTr> <QTr no-hover>
<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 0 20px 0 !important"
> >
<div <div class="full-height">
v-for="(hour, index) in day.dayData?.hours"
:key="index"
:props="props"
class="hour-chip"
>
<WorkerTimeHourChip <WorkerTimeHourChip
:hour="getChipFormattedHour(hour.timed)" v-for="(hour, ind) in day.dayData?.hours"
:key="ind"
:hour="hour.timed"
:direction="hour.direction" :direction="hour.direction"
:id="hour.id" :id="hour.id"
@on-hour-entry-deleted="onHourEntryDeleted()" @on-hour-entry-deleted="updateData()"
@show-worker-time-form="
showWorkerTimeForm(hour.id, 'edit')
"
class="hour-chip"
/> />
</div> </div>
</QTd> </QTd>
</QTr> </QTr>
<QTr> <QTr no-hover>
<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">
@ -505,6 +508,7 @@ onMounted(async () => {
color="primary" color="primary"
class="fill-icon cursor-pointer" class="fill-icon cursor-pointer"
size="sm" size="sm"
@click="showWorkerTimeForm(day.dayData?.dated, 'create')"
> >
<QTooltip>{{ t('Add time') }}</QTooltip> <QTooltip>{{ t('Add time') }}</QTooltip>
</QIcon> </QIcon>
@ -513,9 +517,10 @@ onMounted(async () => {
</QTr> </QTr>
</template> </template>
</QTable> </QTable>
</QCard> <QDialog ref="workerTimeFormDialogRef">
<WorkerTimeForm v-bind="workerTimeFormProps" @on-data-saved="updateData()" />
</QDialog>
<pre>{{ columns }}</pre> <pre>{{ columns }}</pre>
<!-- <pre>{{ weekDays }}</pre> -->
</QPage> </QPage>
</template> </template>
@ -550,9 +555,6 @@ onMounted(async () => {
<i18n> <i18n>
es: es:
Entrada: Entrada
Intermedio: Intermedio
Salida: Salida
Hours: Horas Hours: Horas
Total semana: Total semana Total semana: Total semana
Termina a las: Termina a las Termina a las: Termina a las