Fix export to sheets

This commit is contained in:
RedstonewolfX 2024-07-13 00:27:19 -04:00
parent c80c291805
commit 9dec435ecf

View File

@ -528,6 +528,7 @@ export function downloadLog(keyword: string) {
* Saves a log to your device. * Saves a log to your device.
* @param i The index of the log you want to save. * @param i The index of the log you want to save.
*/ */
export const SheetsMode = new Utils.BooleanHolder(false)
export function downloadLogByID(i: integer) { export function downloadLogByID(i: integer) {
console.log(i) console.log(i)
var d = JSON.parse(localStorage.getItem(logs[i][1])) var d = JSON.parse(localStorage.getItem(logs[i][1]))
@ -543,7 +544,9 @@ export function downloadLogByID(i: integer) {
export function downloadLogByIDToSheet(i: integer) { export function downloadLogByIDToSheet(i: integer) {
console.log(i) console.log(i)
var d = JSON.parse(localStorage.getItem(logs[i][1])) var d = JSON.parse(localStorage.getItem(logs[i][1]))
const blob = new Blob([ printDRPD("", "", d as DRPD).split("\n").join("CHAR(10)") ], {type: "text/json"}); SheetsMode.value = true;
const blob = new Blob([ printDRPD("", "", d as DRPD) ], {type: "text/json"});
SheetsMode.value = false;
const link = document.createElement("a"); const link = document.createElement("a");
link.href = window.URL.createObjectURL(blob); link.href = window.URL.createObjectURL(blob);
var date: string = (d as DRPD).date var date: string = (d as DRPD).date
@ -1074,19 +1077,23 @@ function printWave(inData: string, indent: string, wave: Wave): string {
inData += ",\n" + indent + " \"double\": " + wave.double + "" inData += ",\n" + indent + " \"double\": " + wave.double + ""
var isFirst = true var isFirst = true
if (wave.actions.length > 0) { if (wave.actions.length > 0) {
inData += ",\n" + indent + " \"actions\": [" if (SheetsMode.value) {
for (var i = 0; i < wave.actions.length; i++) { inData += ",\n" + indent + " \"actions\": [" + wave.actions.join("CHAR(10)") + "]"
if (wave.actions[i] != undefined) { } else {
if (isFirst) { inData += ",\n" + indent + " \"actions\": ["
isFirst = false; for (var i = 0; i < wave.actions.length; i++) {
} else { if (wave.actions[i] != undefined) {
inData += "," if (isFirst) {
isFirst = false;
} else {
inData += ","
}
inData += "\n " + indent + "\"" + wave.actions[i] + "\""
} }
inData += "\n " + indent + "\"" + wave.actions[i] + "\""
} }
if (!isFirst) inData += "\n"
inData += indent + " ]"
} }
if (!isFirst) inData += "\n"
inData += indent + " ]"
} else { } else {
inData += ",\n" + indent + " \"actions\": []" inData += ",\n" + indent + " \"actions\": []"
} }