From 95ef745504b3a5ec994295bfe3f5f8e525c54ed7 Mon Sep 17 00:00:00 2001 From: chris2fr Date: Sat, 24 Oct 2020 15:08:16 +0200 Subject: [PATCH] It Works !!!! --- app/app.js | 13 ++++++++----- components/import.js | 8 ++++---- scripts/storage.js | 25 ++++++++++++------------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/app.js b/app/app.js index 62cea6e..f539d19 100644 --- a/app/app.js +++ b/app/app.js @@ -127,14 +127,17 @@ var app = new Vue({ }, onVersionChange: function() { - // storage.setVersionedLocalStorage(this.currentVersion,"sections",this.$root.sections); - console.log(["version",this.currentVersion,this.$root.sections.meta.version]); + //Save previous state + 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"); - - console.log(["version",this.currentVersion,this.$root.sections.meta.version]); - + // console.log(["Root Sections",this.$root.sections]); storage.setLocalStorage(this.$root.sections); // Perhaps optimisation to come + + //console.log(["version",this.currentVersion,this.$root.sections.meta.version]); + }, /** diff --git a/components/import.js b/components/import.js index 3f77f83..f357505 100644 --- a/components/import.js +++ b/components/import.js @@ -48,10 +48,10 @@ var importComponent = { //console.log(version); this.$root.sections = storage.getVersionedLocalStorage(version,"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) { @@ -59,7 +59,7 @@ var importComponent = { var index = versions.indexOf(version); if (index > -1 && confirm("Are you sure you wish to delete " + version + "?")) { versions.splice(index, 1); - // storage.setVersionedLocalStorage(version,"sections",null) + storage.setVersionedLocalStorage(version,"sections",null); storage.setLocalStorage("versions",versions); this.$root.versions = versions; } diff --git a/scripts/storage.js b/scripts/storage.js index 215c915..fe0d608 100644 --- a/scripts/storage.js +++ b/scripts/storage.js @@ -41,8 +41,18 @@ var storage = { getLocalStorage: function(key) { - console.log(key); - return this.parseJSON2Native(localStorage.getItem(key)); + // console.log(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 @@ -57,15 +67,4 @@ var storage = { localStorage.removeItem(key); }, - parseJSON2Native: function(jsonValue) { - var value = null; - - if (jsonValue) - { - value = JSON.parse(jsonValue); - } - - return value; - } - } \ No newline at end of file