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>
<div id="notecontent"> <div id="notecontent">
<input id="datafile" type="file" onchange="loaddatafile(this)" hidden/>
<textarea id="md" spellcheck="false" oninput="datachanged()" onkeydown="editorkeydown()" onclick="clickeditor()"></textarea> <textarea id="md" spellcheck="false" oninput="datachanged()" onkeydown="editorkeydown()" onclick="clickeditor()"></textarea>
<div hidden id="preview"></div> <div hidden id="preview"></div>
</div> </div>

55
main.js
View File

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