added: sandbox vault with loading datafile

added: vault in title bar
This commit is contained in:
quenousimporte 2023-02-01 12:34:40 +01:00
parent 1793a5e50b
commit 712694bd28
2 changed files with 36 additions and 20 deletions

View File

@ -37,6 +37,7 @@
</div>
<div id="notecontent">
<input id="datafile" type="file" onchange="loaddatafile(this)" hidden/>
<textarea id="md" spellcheck="false" oninput="datachanged()" onkeydown="editorkeydown()" onclick="clickeditor()"></textarea>
<div hidden id="preview"></div>
</div>

55
main.js
View File

@ -35,6 +35,8 @@ var tags = null;
var currentvault = "";
var currenttag = "";
var vaults = ["local", "remote", "sandbox"];
var stat =
{
ses:
@ -228,8 +230,8 @@ var commands = [
action: downloadnotewithsubs
},
{
hint: "Download local data",
action: downloadlocal,
hint: "Download vault",
action: downloadvault,
shortcut: "ctrl+shift+S"
},
{
@ -275,7 +277,7 @@ var commands = [
shortcut: "ctrl+l"
},
{
hint: "Switch vault",
hint: "Change vault",
action: switchvault,
shortcut: "ctrl+shift+V"
},
@ -482,8 +484,17 @@ function addtagfilter()
function switchvault()
{
window.localStorage.setItem("vault", othervault());
init();
searchinlist(vaults)
.then(vault =>
{
window.localStorage.setItem("vault", vault);
init();
if (vault == "sandbox")
{
datafile.hidden = false;
}
});
}
function ancestors(note)
@ -804,14 +815,9 @@ function downloadnotes()
});
}
function downloadlocal()
function downloadvault()
{
var data =
{
local : JSON.parse(window.localStorage.getItem("local")),
remote : JSON.parse(window.localStorage.getItem("remote"))
};
download(timestamp() + " notes.json", JSON.stringify(data));
download("notes " + timestamp() + " " + currentvault + ".json", window.localStorage.getItem(currentvault));
}
function downloadnotewithsubs()
@ -961,23 +967,32 @@ function initsnippets()
}
}
function othervault()
{
return isremote() ? "local" : "remote";
}
function initvault()
{
currentvault = window.localStorage.getItem("vault") || "local";
}
function loaddatafile(filepath)
{
reader = new FileReader();
if (filepath.files && filepath.files[0])
{
reader.onload = function (e)
{
localdata = JSON.parse(e.target.result);
loadlast();
datafile.hidden = true;
};
reader.readAsText(filepath.files[0]);
}
return true;
}
function init()
{
loadsettings();
initvault();
commands.find(c => c.action == switchvault).hint = "Switch to " + othervault() + " vault";
window.onbeforeunload = checksaved;
window.onclick = focuseditor;
@ -1865,7 +1880,7 @@ function mainkeydownhandler()
function setwindowtitle()
{
document.title = "";
document.title = "[" + currentvault + "] -\xa0";
if (currenttag)
{
document.title += "[" + currenttag + "] -\xa0";