Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COM-3842: add slot in modal attendance sheet #2086

Merged
merged 7 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions .github/workflows/endToEnd.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- run: cd api && yarn install
env:
DETACHMENT_ALLOWED_COMPANY_IDS : ${{ secrets.DETACHMENT_ALLOWED_COMPANY_IDS }}
SINGLE_COURSES_SUBPROGRAM_IDS : ${{ secrets.SINGLE_COURSES_SUBPROGRAM_IDS }}
- uses: actions/checkout@v3
with:
path: 'webapp'
Expand All @@ -53,3 +54,4 @@ jobs:
API_HOSTNAME: ${{ secrets.API_HOSTNAME }}
TOKEN_SECRET: ${{ secrets.TOKEN_SECRET }}
DETACHMENT_ALLOWED_COMPANY_IDS : ${{ secrets.DETACHMENT_ALLOWED_COMPANY_IDS }}
SINGLE_COURSES_SUBPROGRAM_IDS : ${{ secrets.SINGLE_COURSES_SUBPROGRAM_IDS }}
1 change: 1 addition & 0 deletions quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ module.exports = configure(ctx => ({
GA_TRACKING_ID: process.env.GA_TRACKING_ID,
BULB_LINK: process.env.BULB_LINK,
DETACHMENT_ALLOWED_COMPANY_IDS: process.env.DETACHMENT_ALLOWED_COMPANY_IDS,
SINGLE_COURSES_SUBPROGRAM_IDS: process.env.SINGLE_COURSES_SUBPROGRAM_IDS,
},
},
devServer: { open: true },
Expand Down
23 changes: 21 additions & 2 deletions src/core/components/courses/AttendanceSheetAdditionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<ni-input in-modal caption="Feuille d'émargement" type="file" @blur="validations.file.$touch" last required-field
:model-value="newAttendanceSheet.file" @update:model-value="update($event, 'file')"
:extensions="[DOC_EXTENSIONS, IMAGE_EXTENSIONS]" :error="validations.file.$error" />
<ni-option-group v-if="slotOptions.length" :model-value="newAttendanceSheet.slots" in-modal required-field
:options="slotOptions" :error="validations.slots.$error" type="checkbox" inline
@update:model-value="update($event, 'slots')"
caption="Sélectionner les créneaux auxquels a été présent·e le/la participant·e" />
<template #footer>
<ni-button class="full-width modal-btn bg-primary" label="Ajouter la feuille d'émargement" :loading="loading"
icon-right="add" @click="submit" color="white" />
Expand All @@ -25,8 +29,10 @@ import Modal from '@components/modal/Modal';
import Select from '@components/form/Select';
import Input from '@components/form/Input';
import Button from '@components/Button';
import { INTER_B2B, DOC_EXTENSIONS, IMAGE_EXTENSIONS, DD_MM_YYYY } from '@data/constants';
import OptionGroup from '@components/form/OptionGroup';
import { INTER_B2B, DOC_EXTENSIONS, IMAGE_EXTENSIONS, DD_MM_YYYY, HH_MM } from '@data/constants';
import { formatAndSortIdentityOptions } from '@helpers/utils';
import { ascendingSortBy } from '@helpers/dates/utils';
import CompaniDate from '@helpers/dates/companiDates';

export default {
Expand All @@ -36,17 +42,19 @@ export default {
'ni-modal': Modal,
'ni-input': Input,
'ni-button': Button,
'ni-option-group': OptionGroup,
},
props: {
modelValue: { type: Boolean, default: false },
newAttendanceSheet: { type: Object, default: () => ({}) },
course: { type: Object, default: () => ({}) },
validations: { type: Object, default: () => ({}) },
loading: { type: Boolean, default: false },
slots: { type: Array, default: () => [] },
},
emits: ['hide', 'update:model-value', 'update:new-attendance-sheet', 'submit'],
setup (props, { emit }) {
const { newAttendanceSheet, course } = toRefs(props);
const { newAttendanceSheet, course, slots } = toRefs(props);

const traineeOptions = computed(() => formatAndSortIdentityOptions(course.value.trainees));

Expand All @@ -58,6 +66,16 @@ export default {
return [...dateOptionsSet].map(date => ({ value: date, label: CompaniDate(date).format(DD_MM_YYYY) }));
});

const slotOptions = computed(() => (
[...slots.value]
.sort(ascendingSortBy('startDate'))
.map(s => ({
label: `${CompaniDate(s.startDate).format(`${DD_MM_YYYY} ${HH_MM}`)}
- ${CompaniDate(s.endDate).format(HH_MM)}`,
value: s._id,
}))
));

const hide = () => emit('hide');

const input = event => emit('update:model-value', event);
Expand All @@ -74,6 +92,7 @@ export default {
// Computed
traineeOptions,
dateOptions,
slotOptions,
// Methods
hide,
input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { formatIdentity, sortStrings } from '@helpers/utils';
import CompaniDate from '@helpers/dates/companiDates';
import { NotifyPositive, NotifyNegative, NotifyWarning } from '@components/popup/notify';

const SINGLE_COURSES_SUBPROGRAM_IDS = process.env.SINGLE_COURSES_SUBPROGRAM_IDS.split(';');

export const useAttendanceSheets = (
course,
isClientInterface,
Expand Down Expand Up @@ -38,11 +40,14 @@ export const useAttendanceSheets = (
{ name: 'actions', label: '', align: 'left' },
]);

const isSingleCourse = computed(() => SINGLE_COURSES_SUBPROGRAM_IDS.includes(course.value.subProgram._id));

const attendanceSheetRules = computed(() => ({
newAttendanceSheet: {
file: { required },
trainee: { required: requiredIf(course.value.type === INTER_B2B) },
date: { required: requiredIf(course.value.type !== INTER_B2B) },
slots: { required: requiredIf(isSingleCourse.value) },
},
}));

Expand Down Expand Up @@ -78,6 +83,12 @@ export const useAttendanceSheets = (
return attendanceSheets.value;
});

const notLinkedSlotOptions = computed(() => {
if (!isSingleCourse.value) return [];

return course.value.slots.filter(s => attendanceSheets.value.every(as => !get(as, 'slots', []).includes(s._id)));
manonpalin marked this conversation as resolved.
Show resolved Hide resolved
});

const disableSheetDeletion = attendanceSheet => !attendanceSheet.file.link || !!course.value.archivedAt;

const refreshAttendanceSheets = async () => {
Expand Down Expand Up @@ -105,10 +116,15 @@ export const useAttendanceSheets = (
if (course.value.archivedAt) {
return NotifyWarning('Vous ne pouvez pas ajouter de feuilles d\'émargement à une formation archivée.');
}
if (isSingleCourse.value && !notLinkedSlotOptions.value.length) {
return NotifyWarning('Tous les créneaux sont déjà rattachés à une feuille d\'émargement.');
}
manonpalin marked this conversation as resolved.
Show resolved Hide resolved
if (!course.value.companies.length) {
return NotifyWarning('Au moins une structure doit être rattachée à la formation.');
}

if (isSingleCourse.value) newAttendanceSheet.value.slots = [];
Dezau1995 marked this conversation as resolved.
Show resolved Hide resolved
manonpalin marked this conversation as resolved.
Show resolved Hide resolved

attendanceSheetAdditionModal.value = true;
};

Expand All @@ -118,12 +134,14 @@ export const useAttendanceSheets = (
};

const formatPayload = () => {
const { course: newAttendanceSheetCourse, file, trainee, date } = newAttendanceSheet.value;
const { course: newAttendanceSheetCourse, file, trainee, date, slots } = newAttendanceSheet.value;
const form = new FormData();
course.value.type === INTER_B2B ? form.append('trainee', trainee) : form.append('date', date);
form.append('course', newAttendanceSheetCourse);
form.append('file', file);

if (isSingleCourse.value) slots.forEach(slot => form.append('slots', slot));

return form;
};

Expand Down Expand Up @@ -186,6 +204,7 @@ export const useAttendanceSheets = (
// Computed
attendanceSheetVisibleColumns,
formattedAttendanceSheets,
notLinkedSlotOptions,
// Methods
disableSheetDeletion,
refreshAttendanceSheets,
Expand Down
4 changes: 3 additions & 1 deletion src/core/components/table/AttendanceTable/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

<attendance-sheet-addition-modal v-model="attendanceSheetAdditionModal" @hide="resetAttendanceSheetAdditionModal"
@submit="addAttendanceSheet" v-model:new-attendance-sheet="newAttendanceSheet" :loading="modalLoading"
:validations="attendanceSheetValidations.newAttendanceSheet" :course="course" />
:validations="attendanceSheetValidations.newAttendanceSheet" :course="course" :slots="notLinkedSlotOptions" />
</div>
</template>

Expand Down Expand Up @@ -264,6 +264,7 @@ export default {
// Computed
attendanceSheetVisibleColumns,
formattedAttendanceSheets,
notLinkedSlotOptions,
// Methods
disableSheetDeletion,
refreshAttendanceSheets,
Expand Down Expand Up @@ -320,6 +321,7 @@ export default {
presentTraineesCount,
absenceRate,
realAbsenceRate,
notLinkedSlotOptions,
// Methods
get,
attendanceCheckboxValue,
Expand Down
Loading