It Works !!!!

This commit is contained in:
chris2fr 2020-10-24 15:08:16 +02:00
parent 21894d7725
commit 95ef745504
3 changed files with 24 additions and 22 deletions

View File

@ -127,14 +127,17 @@ var app = new Vue({
}, },
onVersionChange: function() { onVersionChange: function() {
// storage.setVersionedLocalStorage(this.currentVersion,"sections",this.$root.sections); //Save previous state
console.log(["version",this.currentVersion,this.$root.sections.meta.version]); storage.setVersionedLocalStorage(this.$root.sections.meta.version,"sections",this.$root.sections);
// console.log(["version",this.currentVersion,this.$root.sections.meta.version]);
this.$root.sections = storage.getVersionedLocalStorage(this.currentVersion,"sections"); this.$root.sections = storage.getVersionedLocalStorage(this.currentVersion,"sections");
// console.log(["Root Sections",this.$root.sections]);
console.log(["version",this.currentVersion,this.$root.sections.meta.version]);
storage.setLocalStorage(this.$root.sections); // Perhaps optimisation to come storage.setLocalStorage(this.$root.sections); // Perhaps optimisation to come
//console.log(["version",this.currentVersion,this.$root.sections.meta.version]);
}, },
/** /**

View File

@ -48,10 +48,10 @@ var importComponent = {
//console.log(version); //console.log(version);
this.$root.sections = storage.getVersionedLocalStorage(version,"sections"); this.$root.sections = storage.getVersionedLocalStorage(version,"sections");
storage.setLocalStorage("sections",this.$root.sections); storage.setLocalStorage("sections",this.$root.sections);
this.$root.currentVersion = version;
this.$root.loadFromStorage();
// this.loadFromStorage(); router.push("section/basics");
// router.push("section/basics");
}, },
deleteVersion: function(version) { deleteVersion: function(version) {
@ -59,7 +59,7 @@ var importComponent = {
var index = versions.indexOf(version); var index = versions.indexOf(version);
if (index > -1 && confirm("Are you sure you wish to delete " + version + "?")) { if (index > -1 && confirm("Are you sure you wish to delete " + version + "?")) {
versions.splice(index, 1); versions.splice(index, 1);
// storage.setVersionedLocalStorage(version,"sections",null) storage.setVersionedLocalStorage(version,"sections",null);
storage.setLocalStorage("versions",versions); storage.setLocalStorage("versions",versions);
this.$root.versions = versions; this.$root.versions = versions;
} }

View File

@ -41,8 +41,18 @@ var storage = {
getLocalStorage: function(key) getLocalStorage: function(key)
{ {
console.log(key); // console.log(key);
return this.parseJSON2Native(localStorage.getItem(key));
var value = null;
if (key)
{
value = JSON.parse(localStorage.getItem(key));
}
// console.log(value);
return value;
//return this.parseJSON2Native(localStorage.getItem(key));
}, },
/* /*
* @TODO optimize * @TODO optimize
@ -57,15 +67,4 @@ var storage = {
localStorage.removeItem(key); localStorage.removeItem(key);
}, },
parseJSON2Native: function(jsonValue) {
var value = null;
if (jsonValue)
{
value = JSON.parse(jsonValue);
}
return value;
}
} }