From ced02bc60020eddaf6bdaa309648ac19af33261f Mon Sep 17 00:00:00 2001 From: luktinghin Date: Fri, 1 Dec 2023 00:11:52 +0800 Subject: [PATCH 01/12] Export/Import Function --- index.html | 43 ++++++++++++++--------- main.js | 101 ++++++++++++++++++++++++++++++++++++++++++++--------- styles.css | 27 ++++++++++++++ 3 files changed, 137 insertions(+), 34 deletions(-) diff --git a/index.html b/index.html index 15cc066..06ae750 100644 --- a/index.html +++ b/index.html @@ -1,15 +1,6 @@ - - - @@ -64,7 +55,7 @@ - + SimTIVA | Free TIVA Simulation App to Simulate Target-Controlled Infusion | Simple TCI Calculator @@ -448,16 +439,34 @@

SimTIVA is a computer simulation program to simulate delivery of total intra diff --git a/main.js b/main.js index 7d23b23..0a01bd0 100644 --- a/main.js +++ b/main.js @@ -7635,13 +7635,24 @@ function toLoadTransition() { } function toPageOneFromLoad() { - setTimeout(function(){setmodal("modalInitial")},200); - document.getElementById("modalLoad").classList.remove("fadein"); - document.getElementById("modalLoadcontent").classList.remove("open"); - document.getElementById("rescuebuttons").style.display="block"; - if (manageFileListState == 1) { - manageFileList(); - } + setTimeout(function(){ + setmodal("modalInitial"); + document.getElementById("modalLoadDescription").innerHTML = "Select a SIM-FILE to load:"; + document.getElementById("modalLoadDescription").style.display = "none"; + document.getElementById("fileselection").style.display = "none"; + document.getElementById("loadfile_container").style.display = "none"; + document.getElementById("modalLoadHugeButtons").style.display = "block"; + document.getElementById("modalLoadImportButtons").style.display = "none"; + document.getElementById("modalLoadNormalButtons").style.display = "none"; + document.getElementById("loadfile_container").innerHTML = ""; + },200); + document.getElementById("modalLoad").classList.remove("fadein"); + document.getElementById("modalLoadcontent").classList.remove("open"); + document.getElementById("rescuebuttons").style.display="block"; + + if (manageFileListState == 1) { + manageFileList(); + } } function displayDisclaimer() { @@ -7969,13 +7980,21 @@ function confirmretrospective() { hideallmodal(); } -function init_rescue(input_uid) { +function init_rescue(input_uid,external_flag) { + hideallmodal(); document.getElementById("card_cpt0").classList.add("hide"); document.getElementById("card_cet0").classList.add("hide"); document.getElementById("card_infusion0").classList.add("hide"); document.getElementById("status").innerHTML = ""; - parseobject(input_uid); + if (external_flag) { + tempFileIndex = importDataArray.findIndex((elem) => elem[0]==input_uid); + if (tempFileIndex != -1) { + parseobject(null,true,importDataArray[tempFileIndex][1]); + } + } else { + parseobject(input_uid); + } var timestamp_lastdatadate = new Date(input_uid*1000 + time_in_s*1000); var timestamp_lastdatatime = timestamp_lastdatadate.toLocaleDateString() + " " + timestamp_lastdatadate.toLocaleTimeString(); setTimeout(function() { @@ -9316,13 +9335,43 @@ function loadobject(input_uid) { } function load() { + toLoadTransition(); +} + + +function loadSourceExt() { + document.getElementById("modalLoadHugeButtons").style.display = "none"; + document.getElementById("modalLoadImportButtons").style.display = "block"; + document.getElementById("fileselection").style.display = "block"; + document.getElementById("modalLoadDescription").style.display = "inline-block"; + document.getElementById("modalLoadDescription").innerHTML = "Load from external .CSV file:"; + document.getElementById("loadfile_container").classList.add("compress"); + document.getElementById("loadfile_container").style.display = "block"; + document.getElementById("loadfile_container").innerHTML = + ` +
After loading, the database of external sim-files will appear here.
+ ` + //document.getElementById("loadfile_container").style.display = "block"; + //importDialog(); +} + +function loadSourceLocal() { if ((localStorage.getItem("keys") == null) || (JSON.parse(localStorage.getItem("keys")).length == 0)) { displayWarning("No saved data", "No previously saved sim-file data.") } else { generateFileKeys(); - toLoadTransition(); document.getElementById("rescuebuttons").style.display = "none"; + document.getElementById("modalLoadHugeButtons").style.display = "none"; + document.getElementById("fileselection").style.display = "none"; + document.getElementById("modalLoadNormalButtons").style.display = "block"; + document.getElementById("modalLoadDescription").style.display = "inline-block"; + document.getElementById("loadfile_container").classList.remove("compress"); + document.getElementById("loadfile_container").style.display = "block"; + + importDataArray.length = 0; + } + } function rescue() { @@ -9347,10 +9396,25 @@ function generateFileKeys() { } function renderImportList() { - let El1 = document.getElementById("filecontent"); + let El1 = document.getElementById("loadfile_container"); for (impcountr = 0; impcountr=0; i--) { tempObject = loadobject(inputkeysarray[i]); @@ -9718,7 +9782,7 @@ let importDataArray = new Array(); function previewFile() { - const content = document.getElementById("filecontent"); + const content = document.getElementById("loadfile_container"); const [file] = document.getElementById("myFile").files; const reader = new FileReader(); @@ -9731,6 +9795,8 @@ function previewFile() { //iterate through CSV file let parseArrayRaw = reader.result.split("\n"); let impcount; + //pop importDataArray + importDataArray.length = 0; for (impcount = 1; impcount Date: Fri, 1 Dec 2023 00:18:48 +0800 Subject: [PATCH 02/12] Minor Update main.js --- main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/main.js b/main.js index 0a01bd0..a996695 100644 --- a/main.js +++ b/main.js @@ -9340,6 +9340,7 @@ function load() { function loadSourceExt() { + document.getElementById("rescuebuttons").style.display = "none"; document.getElementById("modalLoadHugeButtons").style.display = "none"; document.getElementById("modalLoadImportButtons").style.display = "block"; document.getElementById("fileselection").style.display = "block"; From d41f0c74055193e4ce62e86766f6a9249b4b454a Mon Sep 17 00:00:00 2001 From: luktinghin Date: Sat, 2 Dec 2023 15:46:43 +0800 Subject: [PATCH 03/12] Export/Import function --- index.html | 15 ++++---- main.js | 107 +++++++++++++++++++++++++++++++++-------------------- styles.css | 8 +++- 3 files changed, 82 insertions(+), 48 deletions(-) diff --git a/index.html b/index.html index 1bc6348..648715d 100644 --- a/index.html +++ b/index.html @@ -451,13 +451,14 @@

SimTIVA is a computer simulation program to simulate delivery of total intra
Select source: - LOAD FROM EXTERNAL -
Choose this option if you have previously exported a SimTIVA database .csv file
-
-
- LOAD LOCAL SIMFILES -
This option will load sim-files automatically saved on your device
+ IMPORT FROM EXTERNAL +
This will import a previously saved SimTIVA database file (.csv)
+
+ LOAD LOCAL SIMFILE +
This will load sim-files saved on device. You can also manage & export local sim-files.
+ +
Load Selection @@ -466,7 +467,7 @@

SimTIVA is a computer simulation program to simulate delivery of total intra

diff --git a/main.js b/main.js index 3d9420b..5fde6ea 100644 --- a/main.js +++ b/main.js @@ -7637,6 +7637,7 @@ function toLoadTransition() { function toPageOneFromLoad() { setTimeout(function(){ setmodal("modalInitial"); + //reset styles document.getElementById("modalLoadDescription").innerHTML = "Select a SIM-FILE to load:"; document.getElementById("modalLoadDescription").style.display = "none"; document.getElementById("fileselection").style.display = "none"; @@ -7645,6 +7646,9 @@ function toPageOneFromLoad() { document.getElementById("modalLoadImportButtons").style.display = "none"; document.getElementById("modalLoadNormalButtons").style.display = "none"; document.getElementById("loadfile_container").innerHTML = ""; + document.getElementById("btn_load_import").classList.add("disabled"); + document.getElementById("loadfile_container").classList.remove("compress"); + document.getElementById("loadfile_container").classList.remove("collapse"); },200); document.getElementById("modalLoad").classList.remove("fadein"); document.getElementById("modalLoadcontent").classList.remove("open"); @@ -7674,7 +7678,7 @@ function ptolwarning() { } function displayloadabout() { - text = "The sim-files are saved automatically when simulation is running. To save with a file name for easier access later on, simply type a file name in the share/save popup module. All the data in the sim-files are stored locally on your device via the local-storage API and will never be accessed or stored by our server in any way."; + text = "The sim-files are saved automatically when simulation is running. To save with a file name for easier access later on, simply type a file name in the share/save popup module. All the data in the sim-files are stored locally on your device via the local-storage API and will never be accessed or stored by our server in any way.

Exporting sim-file database
You may export local sim-files by clicking 'Manage' -> 'Export all'. This will generate a .CSV (comma-seperated values) file which you may access with a spreadsheet program or with SimTIVA.

Importing database (.CSV)
You may import a previously exported database file by choosing this option in the 'Load' menu. The database will be loaded and the sim-files stored in the database can be accessed."; displayWarning("About Sim-Files", text); } @@ -7983,6 +7987,8 @@ function confirmretrospective() { function init_rescue(input_uid,external_flag) { hideallmodal(); + hidemodal("modalInitial"); + hidemodal("modalLoad"); document.getElementById("card_cpt0").classList.add("hide"); document.getElementById("card_cet0").classList.add("hide"); document.getElementById("card_infusion0").classList.add("hide"); @@ -9345,8 +9351,9 @@ function loadSourceExt() { document.getElementById("modalLoadImportButtons").style.display = "block"; document.getElementById("fileselection").style.display = "block"; document.getElementById("modalLoadDescription").style.display = "inline-block"; - document.getElementById("modalLoadDescription").innerHTML = "Load from external .CSV file:"; - document.getElementById("loadfile_container").classList.add("compress"); + document.getElementById("modalLoadDescription").innerHTML = "Import from external .CSV file:"; + document.getElementById("loadfile_container").classList.add("collapse"); + document.getElementById("loadfile_container").classList.remove("compress"); document.getElementById("loadfile_container").style.display = "block"; document.getElementById("loadfile_container").innerHTML = ` @@ -9366,6 +9373,7 @@ function loadSourceLocal() { document.getElementById("fileselection").style.display = "none"; document.getElementById("modalLoadNormalButtons").style.display = "block"; document.getElementById("modalLoadDescription").style.display = "inline-block"; + document.getElementById("loadfile_container").classList.remove("collapse"); document.getElementById("loadfile_container").classList.remove("compress"); document.getElementById("loadfile_container").style.display = "block"; @@ -9398,7 +9406,7 @@ function generateFileKeys() { function renderImportList() { let El1 = document.getElementById("loadfile_container"); - for (impcountr = 0; impcountr
-

- `); -} - let importDataArray = new Array(); function previewFile() { @@ -9790,45 +9791,71 @@ function previewFile() { reader.addEventListener( "load", () => { - errorCount = 0; //crosschecking code to see whether file type is correct - //... - //iterate through CSV file - let parseArrayRaw = reader.result.split("\n"); - let impcount; - //pop importDataArray - importDataArray.length = 0; - for (impcount = 1; impcount"; + console.log(errorMessage); + } + if (errorMessage != "") { + let tempRaw = reader.result.split("\n"); //last record is 2nd last line. last line is an empty line. + + if (tempRaw != undefined) { + if (reader.result.slice(0,26) != "UID,Timestamp,Duration,Nam") { + errorMessage += "Cannot read file. Does not seem to be a SimTIVA .csv database file." + "
"; + } else { + //preview first record and see if it's fine + let parseArrayComma = parseArrayRaw[1].split(","); + let parseArrayURL = parseArrayComma[parseArrayComma.length-1]; + if (parseArrayURL.slice(0,19) != "https://simtiva.app") { + errorMessage += "Wrong weblink reference. Possible corrupted database."; + } + } } else { - errorCount += 1; + errorMessage += "Cannot read file. Does not seem to be a SimTIVA .csv database file."; } - console.log(obj); - console.log(errorCount); } - impcount -= 1; - alert("Total " + impcount + " records retrieved.\n" + - importDataArray.length + " records read successfully.\n" + - errorCount + " records failed to load."); - document.getElementById("loadfile_container").classList.remove("compress"); - document.getElementById("loadfile_container").innerHTML = ''; - renderImportList(); - - //console.log("read successfully"); - //console.log(parseArrayObj); - + console.log(errorMessage); + if (errorMessage != "") { + displayWarning("Failed import",errorMessage); + } else { + errorCount = 0; + + //iterate through CSV file + let parseArrayRaw = reader.result.split("\n"); + let impcount; + //pop importDataArray + importDataArray.length = 0; + for (impcount = 1; impcount" + + importDataArray.length + " records read successfully.
" + + errorCount + " records failed to load."); + document.getElementById("btn_load_import").classList.remove("disabled"); + document.getElementById("loadfile_container").classList.remove("collapse"); + document.getElementById("loadfile_container").classList.add("compress"); + document.getElementById("loadfile_container").innerHTML = ''; + renderImportList(); + } }, false, ); if (file) { reader.readAsText(file); + reader.fileName = file.name; } } diff --git a/styles.css b/styles.css index d656ebe..794af35 100644 --- a/styles.css +++ b/styles.css @@ -1584,6 +1584,7 @@ a.button.disabled:hover, a.button.disabled:active { color:rgb(190,190,190); background-color:rgb(240,240,240); cursor:not-allowed; + pointer-events: none; } a.button.tinybutton { @@ -4279,9 +4280,10 @@ body.dark #progressbar { overflow-y: auto; height: 60dvh; display: none; + /*transition: all ease 1s;*/ } -#loadfile_container.compress { +#loadfile_container.collapse { height: 200px; padding-top: 70px; width: 70%; @@ -4289,6 +4291,10 @@ body.dark #progressbar { margin-right: auto; } +#loadfile_container.compress { + height: 50dvh; +} + #filecontent { height: 55dvh; overflow: auto; From 71143a86fc16f2140a6d4fa7efa001d03cbef666 Mon Sep 17 00:00:00 2001 From: luktinghin Date: Sat, 2 Dec 2023 15:50:05 +0800 Subject: [PATCH 04/12] minor update --- main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 5fde6ea..1d545cf 100644 --- a/main.js +++ b/main.js @@ -9350,7 +9350,7 @@ function loadSourceExt() { document.getElementById("modalLoadHugeButtons").style.display = "none"; document.getElementById("modalLoadImportButtons").style.display = "block"; document.getElementById("fileselection").style.display = "block"; - document.getElementById("modalLoadDescription").style.display = "inline-block"; + document.getElementById("modalLoadDescription").style.display = "inline"; document.getElementById("modalLoadDescription").innerHTML = "Import from external .CSV file:"; document.getElementById("loadfile_container").classList.add("collapse"); document.getElementById("loadfile_container").classList.remove("compress"); @@ -9372,7 +9372,7 @@ function loadSourceLocal() { document.getElementById("modalLoadHugeButtons").style.display = "none"; document.getElementById("fileselection").style.display = "none"; document.getElementById("modalLoadNormalButtons").style.display = "block"; - document.getElementById("modalLoadDescription").style.display = "inline-block"; + document.getElementById("modalLoadDescription").style.display = "inline"; document.getElementById("loadfile_container").classList.remove("collapse"); document.getElementById("loadfile_container").classList.remove("compress"); document.getElementById("loadfile_container").style.display = "block"; From f97a50e2dbb65eac7e2c527bc8c1fff340286be8 Mon Sep 17 00:00:00 2001 From: luktinghin Date: Sat, 2 Dec 2023 15:55:57 +0800 Subject: [PATCH 05/12] Update style --- styles.css | 1 + 1 file changed, 1 insertion(+) diff --git a/styles.css b/styles.css index 794af35..d44862b 100644 --- a/styles.css +++ b/styles.css @@ -146,6 +146,7 @@ body { margin: 0px; background:#7B8092; overscroll-behavior-y: contain; + touch-action: pan-y, pan-x; } From 5b02520dbf5d9bd1f17cc4fbeca3cc755b268296 Mon Sep 17 00:00:00 2001 From: luktinghin Date: Sat, 2 Dec 2023 15:59:05 +0800 Subject: [PATCH 06/12] minor update --- index.html | 2 +- styles.css | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/index.html b/index.html index 648715d..3579a2c 100644 --- a/index.html +++ b/index.html @@ -443,7 +443,7 @@

SimTIVA is a computer simulation program to simulate delivery of total intra