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:
+10
-1
@@ -1,4 +1,4 @@
|
||||
import { MODES, PK_MODELS, CLINICAL_THRESHOLDS, generateSimulationData, processTimelineEvents } from './pkCore.js';
|
||||
import { MODES, PK_MODELS, CLINICAL_THRESHOLDS, APP_VERSION, generateSimulationData, processTimelineEvents } from './pkCore.js';
|
||||
import { adjustChartYScale } from './chartManager.js';
|
||||
import { initCalculatorUI } from './calculator.js';
|
||||
import { exportSimulationToCSV } from './csvExport.js';
|
||||
@@ -8,6 +8,13 @@ let currentMode = MODES.ESKETAMINE;
|
||||
let pkChart = null;
|
||||
let currentSimulationData = null;
|
||||
|
||||
function updateVersionDisplay() {
|
||||
const versionEl = document.querySelector('[data-i18n="app.version"]');
|
||||
if (versionEl) {
|
||||
versionEl.textContent = t('app.version', { version: APP_VERSION });
|
||||
}
|
||||
}
|
||||
|
||||
const timelineInputs = Array.from({ length: 61 }, (_, i) => ({
|
||||
time: i * 5,
|
||||
bolusMg: 0,
|
||||
@@ -16,12 +23,14 @@ const timelineInputs = Array.from({ length: 61 }, (_, i) => ({
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
await initI18n();
|
||||
updateVersionDisplay();
|
||||
|
||||
const selectLang = document.getElementById('selectLang');
|
||||
if (selectLang) {
|
||||
selectLang.value = getCurrentLang();
|
||||
selectLang.addEventListener('change', async (e) => {
|
||||
await initI18n(e.target.value);
|
||||
updateVersionDisplay();
|
||||
renderTimelineGrid();
|
||||
updateSimulation();
|
||||
});
|
||||
|
||||
+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);
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Version unique de l'application (Centralisée)
|
||||
*/
|
||||
export const APP_VERSION = '0.16.0';
|
||||
|
||||
export const MODES = {
|
||||
ESKETAMINE: 'ESKETAMINE',
|
||||
RACEMIQUE: 'RACEMIQUE'
|
||||
|
||||
Reference in New Issue
Block a user