mirror of
https://github.com/gauvainboiche/ketapk.git
synced 2026-09-02 11:13:11 +02:00
fix: Deploying version dynamically + adding Tauri project files
This commit is contained in:
+12
-21
@@ -1,8 +1,6 @@
|
||||
import { t } from './i18n.js';
|
||||
import { APP_VERSION } from './pkCore.js';
|
||||
|
||||
/**
|
||||
* Formate la date au format strict : YYYY_DD_MM_HH_MM_SS
|
||||
*/
|
||||
function getFormattedTimestamp() {
|
||||
const now = new Date();
|
||||
const YYYY = now.getFullYear();
|
||||
@@ -14,27 +12,20 @@ function getFormattedTimestamp() {
|
||||
return `${YYYY}_${DD}_${MM}_${HH}_${Min}_${SS}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforme le nom saisi en slug propre (ex: "DUPONT Jean" -> "dupont_jean")
|
||||
*/
|
||||
function slugify(text) {
|
||||
if (!text) return '';
|
||||
return text
|
||||
.toString()
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.normalize("NFD").replace(/[\u0300-\u036f]/g, "") // Enlève les accents
|
||||
.replace(/[^a-z0-9]+/g, "_") // Remplace les caractères spéciaux par _
|
||||
.replace(/^_+|_+$/g, ""); // Nettoie les _ aux bornes
|
||||
.normalize("NFD").replace(/[\u0300-\u036f]/g, "")
|
||||
.replace(/[^a-z0-9]+/g, "_")
|
||||
.replace(/^_+|_+$/g, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Exporte les données de simulation au format CSV
|
||||
*/
|
||||
export async function exportSimulationToCSV(simulationData, patientInfo) {
|
||||
if (!simulationData || !simulationData.timeline) return;
|
||||
|
||||
// \uFEFF (BOM UTF-8) pour qu'Excel ouvre le CSV directement avec les accents
|
||||
let csvContent = "\uFEFF";
|
||||
|
||||
// Métadonnées du rapport
|
||||
@@ -43,9 +34,12 @@ export async function exportSimulationToCSV(simulationData, patientInfo) {
|
||||
csvContent += `${t('patient.name_label') || 'Patient'}:,${patientInfo.name}\n`;
|
||||
}
|
||||
csvContent += `${t('csv.weight')}:,${patientInfo.weight}\n`;
|
||||
csvContent += `${t('csv.unit')}:,${patientInfo.infusionUnit}\n\n`;
|
||||
csvContent += `${t('csv.unit')}:,${patientInfo.infusionUnit}\n`;
|
||||
|
||||
// Ligne de Traçabilité de Version
|
||||
csvContent += `${t('csv.version') || 'Version'}:,v${APP_VERSION}\n\n`;
|
||||
|
||||
// En-têtes du tableau selon la langue active
|
||||
// En-têtes du tableau
|
||||
const headers = [
|
||||
t('csv.col_time'),
|
||||
t('csv.col_bolus'),
|
||||
@@ -56,7 +50,7 @@ export async function exportSimulationToCSV(simulationData, patientInfo) {
|
||||
];
|
||||
csvContent += headers.join(",") + "\n";
|
||||
|
||||
// Lignes de données (0 à 300 min)
|
||||
// Lignes de données
|
||||
simulationData.timeline.forEach((item, index) => {
|
||||
const dominoCp = (simulationData.domino && simulationData.domino[index]) ? Math.round(simulationData.domino[index].cp) : "N/A";
|
||||
const clementsCp = (simulationData.clements && simulationData.clements[index]) ? Math.round(simulationData.clements[index].cp) : "N/A";
|
||||
@@ -73,14 +67,12 @@ export async function exportSimulationToCSV(simulationData, patientInfo) {
|
||||
csvContent += row.join(",") + "\n";
|
||||
});
|
||||
|
||||
// Construction du nom de fichier : ketapk_YYYY_DD_MM_HH_MM_SS.csv ou ketapk_nom_prenom_YYYY_DD_MM_HH_MM_SS.csv
|
||||
const timestamp = getFormattedTimestamp();
|
||||
const slugName = slugify(patientInfo.name);
|
||||
const fileName = slugName
|
||||
? `ketapk_${slugName}_${timestamp}.csv`
|
||||
: `ketapk_${timestamp}.csv`;
|
||||
|
||||
// 1. Solution principale : API Native File System (Parfait sous WebView2 / Tauri Desktop)
|
||||
if (window.showSaveFilePicker) {
|
||||
try {
|
||||
const handle = await window.showSaveFilePicker({
|
||||
@@ -95,12 +87,11 @@ export async function exportSimulationToCSV(simulationData, patientInfo) {
|
||||
await writable.close();
|
||||
return;
|
||||
} catch (err) {
|
||||
if (err.name === 'AbortError') return; // Annulation utilisateur
|
||||
console.warn('Fallback vers Data URI suite à l’erreur native :', err);
|
||||
if (err.name === 'AbortError') return;
|
||||
console.warn('Fallback vers Data URI :', err);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fallback Data URI (Compatibilité web directe sans passer par Blob)
|
||||
const encodedUri = "data:text/csv;charset=utf-8," + encodeURIComponent(csvContent);
|
||||
const link = document.createElement("a");
|
||||
link.setAttribute("href", encodedUri);
|
||||
|
||||
Reference in New Issue
Block a user