Skip to content

Commit

Permalink
COM-3856: can generate file
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysseferreira committed Jan 2, 2025
1 parent 03e7949 commit 50d4dd7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import groupBy from 'lodash/groupBy';
import useVuelidate from '@vuelidate/core';
import { required, requiredIf } from '@vuelidate/validators';
import AttendanceSheets from '@api/AttendanceSheets';
import { INTER_B2B, DD_MM_YYYY } from '@data/constants';
import { INTER_B2B, DD_MM_YYYY, GENERATION } from '@data/constants';
import { formatIdentity, sortStrings } from '@helpers/utils';
import CompaniDate from '@helpers/dates/companiDates';
import { NotifyPositive, NotifyNegative, NotifyWarning } from '@components/popup/notify';
Expand Down Expand Up @@ -177,6 +177,23 @@ export const useAttendanceSheets = (
}
};

const generateAttendanceSheet = async (attendanceSheetId) => {
try {
modalLoading.value = true;

await AttendanceSheets.update(attendanceSheetId, { method: GENERATION });

NotifyPositive('Feuille d\'émargement générée.');
await refreshAttendanceSheets();
} catch (e) {
console.error(e);
if (e.data.statusCode === 403) return NotifyNegative(e.data.message);
NotifyNegative('Erreur lors de la génération de la feuille d\'émargement.');
} finally {
modalLoading.value = false;
}
};

const validateAttendanceSheetDeletion = (attendanceSheet) => {
if (!canUpdate.value) return NotifyNegative('Impossible de supprimer la feuille d\'émargement.');

Expand Down Expand Up @@ -281,6 +298,7 @@ export const useAttendanceSheets = (
openAttendanceSheetEditionModal,
updateAttendanceSheet,
resetAttendanceSheetEditionModal,
generateAttendanceSheet,
// Validations
attendanceSheetValidations: v$,
};
Expand Down
22 changes: 20 additions & 2 deletions src/core/components/table/AttendanceTable/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@
<q-td :props="props" v-for="col in props.cols" :key="col.name" :data-label="col.label" :class="col.name"
:style="col.style">
<template v-if="col.name === 'actions'">
<div class="row no-wrap table-actions justify-end">
<div v-if="!props.row.file" class="justify-end overflow-hidden-nowrap flex">
<div v-if="!props.row.signatures.trainee" class="text-italic text-primary">En attente de signature</div>
<ni-primary-button v-else label="Générer" icon="add" :disabled="modalLoading"
@click="generateAttendanceSheet(props.row._id)" />
</div>
<div v-else class="row no-wrap table-actions justify-end">
<ni-button v-if="canUpdate && isSingleCourse" icon="edit" color="primary"
@click="openAttendanceSheetEditionModal(props.row)" :disable="disableSheetEdition(props.row)" />
<ni-button icon="file_download" color="primary" type="a" :href="get(props.row, 'file.link')"
Expand All @@ -108,6 +113,9 @@
@click="validateAttendanceSheetDeletion(props.row)" :disable="disableSheetDeletion(props.row)" />
</div>
</template>
<template v-else-if="col.name === 'trainee' && get(props.row, 'slots.length')">
{{ formatSingleAttendanceSheetName(col.value, props.row.slots) }}
</template>
<template v-else>
{{ col.value }}
<div v-if="get(props.row, 'trainee.external')" class="unsubscribed text-primary">Pas inscrit</div>
Expand Down Expand Up @@ -143,13 +151,14 @@ import { computed, toRefs, ref } from 'vue';
import { useRouter } from 'vue-router';
import pick from 'lodash/pick';
import get from 'lodash/get';
import { DEFAULT_AVATAR, TRAINING_ORGANISATION_MANAGER, VENDOR_ADMIN } from '@data/constants';
import { DEFAULT_AVATAR, TRAINING_ORGANISATION_MANAGER, VENDOR_ADMIN, DD_MM_YYYY } from '@data/constants';
import { defineAbilitiesFor, defineAbilitiesForCourse } from '@helpers/ability';
import { descendingSortBy } from '@helpers/dates/utils';
import { formatQuantity } from '@helpers/utils';
import CompaniDate from '@helpers/dates/companiDates';
import { multiply, subtract, divide } from '@helpers/numbers';
import Button from '@components/Button';
import PrimaryButton from '@components/PrimaryButton';
import SimpleTable from '@components/table/SimpleTable';
import AttendanceSheetAdditionModal from '@components/courses/AttendanceSheetAdditionModal';
import Indicator from '@components/courses/Indicator';
Expand All @@ -165,6 +174,7 @@ export default {
},
components: {
'ni-button': Button,
'ni-primary-button': PrimaryButton,
'ni-simple-table': SimpleTable,
'trainee-attendance-creation-modal': TraineeAttendanceCreationModal,
'attendance-sheet-addition-modal': AttendanceSheetAdditionModal,
Expand Down Expand Up @@ -290,6 +300,7 @@ export default {
resetAttendanceSheetEditionModal,
updateAttendanceSheet,
openAttendanceSheetEditionModal,
generateAttendanceSheet,
// Validations
attendanceSheetValidations,
} = useAttendanceSheets(course, isClientInterface, canUpdate, loggedUser, modalLoading);
Expand All @@ -299,6 +310,11 @@ export default {
if (index === course.value.trainees.length - 1) return 'last-subscribed-interline';
};
const formatSingleAttendanceSheetName = (traineeName, slots) => {
const dates = [...new Set(slots.map(slot => CompaniDate(slot.startDate).format(DD_MM_YYYY)))].join(', ');
return `${traineeName} - ${dates}`;
};
const created = async () => {
await Promise.all([
refreshAttendances({ course: course.value._id }),
Expand Down Expand Up @@ -367,6 +383,8 @@ export default {
updateAttendanceSheet,
formatQuantity,
openAttendanceSheetEditionModal,
generateAttendanceSheet,
formatSingleAttendanceSheetName,
// Validations
attendanceSheetValidations,
attendanceValidations,
Expand Down

0 comments on commit 50d4dd7

Please sign in to comment.