Skip to content
Snippets Groups Projects
Commit 7c6070cc authored by Leonardo Alain Surdez's avatar Leonardo Alain Surdez
Browse files

[Merge] branch 'feature/exportCsv' into 'master'

[Feat] Export in CSV all the visible application.

See merge request !26
parents f3fe75c8 a80945bb
No related branches found
No related tags found
1 merge request!26[Feat] Export in CSV all the visible application.
<template>
<div id="applications-view">
<h1>Postulations</h1>
<h1>Postulations
<v-btn round color="primary" @click="exportApplications">Exporter en CSV</v-btn>
</h1>
<div>
<applicationsFilters />
<v-card-title v-if="hasSelected && $store.getters['moduleUser/userIsResponsible']">
......@@ -238,6 +240,84 @@ export default {
return [...items].sort(descending ? compareFunction : compareFunctionReversed);
},
exportApplications() {
const currentDate = this.getFormattedDate(new Date());
const filterInfo = this.getFilterInfo(); // Fonction à définir pour récupérer les informations du filtre
const filterText = filterInfo ? `_${filterInfo}` : ''; // Ajoutez le filtre au nom du fichier si des informations sont disponibles
const filename = `${currentDate}_CanAp_Export_${filterText}.csv`;
const allApplications = this.$store.getters['moduleApplications/getFilteredApplications'];
const applicationsData = allApplications.map(item => {
return {
'Lien': window.location.origin + '/gest/' + this.$router.resolve('application/' + item.applicant_id).href,
'Nom': item.applicant_name || '',
'Prénom': item.applicant_fsname || '',
'Formation': item.job_full_value || '',
'Lieu': item.location_site || '',
'Maturité': item.applicant_maturity ? 'Oui' : 'Non',
'Adresse': this.formatArray([item.applicant_address_street, item.applicant_address_npa]) || '',
'Email': item.applicant_mail || '',
'Date naissance': item.applicant_birthdate || '',
'Majeur': item.applicant_has_majority ? 'Oui' : 'Non',
'Nationalité': item.applicant_nationality || '',
'Origine': item.applicant_origin || '',
'Langues': this.generateLanguagesString(item),
'Fin de scolarité': item.applicant_scolarity_end || '',
'Date postulation': this.formatDate(item.applicant_application_date) || '',
};
});
const csvContent = this.convertToCSV(applicationsData);
const blob = new Blob([csvContent], { type: 'text/csv' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = filename;
link.click();
},
getFormattedDate(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const formattedDate = `${year}${month}${day}${hours}${minutes}`;
return formattedDate;
},
getFilterInfo() {
const filterProperty = this.$store.state.moduleApplications.filters.filterProperty;
const searchFilter = this.$store.state.moduleApplications.filters.search;
const selectedJobFilter = this.$store.state.moduleApplications.filters.selectedJob;
const selectedFilter = searchFilter || selectedJobFilter;
const sanitizedFilter = selectedFilter ? selectedFilter.replace(/\s/g, '_') : '';
const filterInfo = sanitizedFilter;
return filterInfo;
},
formatArray(value) {
return Array.isArray(value) && value.length > 0 ? value.join(', ') : value || '';
},
formatDate(date) {
return date ? new Date(date).toLocaleString('fr-CH') : '';
},
generateLanguagesString(item) {
const languageMappings = [
{ key: 'applicant_speaks_french', value: 'FR' },
{ key: 'applicant_speaks_english', value: 'EN' },
{ key: 'applicant_speaks_german', value: 'DE' },
{ key: 'applicant_speaks_other', value: 'Autre' },
];
return languageMappings
.filter(mapping => item[mapping.key])
.map(mapping => mapping.value)
.join(', ');
},
convertToCSV(data) {
const header = Object.keys(data[0]).join(',') + '\n';
const rows = data.map(row => Object.values(row).map(col => '"' + col + '"').join(',') + '\n');
return header + rows.join('');
},
},
components: {
ApplicationsFilters,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment