From b472b546f3af119e9772214686157bea1dcf6377 Mon Sep 17 00:00:00 2001 From: chris2fr Date: Mon, 19 Oct 2020 06:25:00 +0200 Subject: [PATCH 1/6] Cosmetic --- index.html | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/index.html b/index.html index e0d437c..9068a96 100644 --- a/index.html +++ b/index.html @@ -154,8 +154,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/scripts/storage.js b/scripts/storage.js index 2a01bd2..215c915 100644 --- a/scripts/storage.js +++ b/scripts/storage.js @@ -3,19 +3,61 @@ */ var storage = { + getCurrentVersion: function() + { + console.log("storage getCurrentVersion" + this.getLocalStorage('sections.meta.version')); + + return this.getLocalStorage('sections.meta.version'); + }, + + getAvailableVersions: function() + { + return storage.getLocalStorage("versions"); + }, + setLocalStorage: function(key, value) { var jsonValue = JSON.stringify(value); localStorage.setItem(key, jsonValue); }, + setVersionedLocalStorage: function(version, key, value) + { + var jsonValue = JSON.stringify(value); + key = "versions." + version + "." + key; + localStorage.setItem(key, jsonValue); + this.versions = []; + if (this.getLocalStorage("versions")) { + this.versions = this.getLocalStorage("versions"); + } + if (!this.versions.includes(version)) { + this.versions.push(version); + } + // versions.push(version); + // console.log([version, key, value, versions]); + this.setLocalStorage("versions",this.versions); + }, getLocalStorage: function(key) { - jsonValue = localStorage.getItem(key); - + console.log(key); + return this.parseJSON2Native(localStorage.getItem(key)); + }, + /* + * @TODO optimize + */ + getVersionedLocalStorage: function(version, key) + { + return this.getLocalStorage("versions." + version + "." + key); + }, + clearLocalStorage: function(key) + { + localStorage.removeItem(key); + }, + + parseJSON2Native: function(jsonValue) { var value = null; if (jsonValue) @@ -24,12 +66,6 @@ var storage = { } return value; - }, - - - - clearLocalStorage: function(key) - { - localStorage.removeItem(key); } + } \ No newline at end of file From 78158e7e67d951ab1523f4ac5e69449dea02489f Mon Sep 17 00:00:00 2001 From: chris2fr Date: Sat, 24 Oct 2020 13:34:38 +0200 Subject: [PATCH 4/6] Basic save function seems to work OK (somewhat alpha) --- app/app.js | 4 ++-- components/import.js | 49 ++++++++++++++++++++++++++++++++++++++++++-- index.html | 18 ++++++++++++---- scripts/storage.js | 2 +- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/app/app.js b/app/app.js index 76d84e1..8dc0a48 100644 --- a/app/app.js +++ b/app/app.js @@ -90,7 +90,7 @@ var app = new Vue({ this.loadFromStorage(); // Quick Fix storage.setVersionedLocalStorage(this.$root.sections.meta.version, "sections", this.$root.sections); - console.log([this.$root.sections.meta.version,this.$root.sections]); + // console.log([this.$root.sections.meta.version,this.$root.sections]); //if (!this.availableVersions.hasKey(this.$root.sections.meta.version)) // this.availableVersions.push(this.$root.sections.meta.version); // console.log([this.versions[0],storage.getVersionedLocalStorage(this.versions[0])]); @@ -167,7 +167,7 @@ var app = new Vue({ loadCountryCodes: function() { - console.log("loadCountryCodes(): data", countryCodes); + // console.log("loadCountryCodes(): data", countryCodes); this.countryCodes.push({ "code": "", diff --git a/components/import.js b/components/import.js index 72941ee..3f77f83 100644 --- a/components/import.js +++ b/components/import.js @@ -15,6 +15,7 @@ var importComponent = { data: function() { return { + item: {}, json: "" }; }, @@ -33,6 +34,8 @@ var importComponent = { storage.setLocalStorage("sections", this.$root.sections); + storage.setVersionedLocalStorage(this.$root.sections.meta.version, "sections", this.$root.sections); + router.push("section/basics"); }, @@ -42,8 +45,50 @@ var importComponent = { }, importVersion: function(version) { - this.sections = storage.getVersionedLocalStorage(version,"sections"); - router.push("section/basics"); + //console.log(version); + this.$root.sections = storage.getVersionedLocalStorage(version,"sections"); + storage.setLocalStorage("sections",this.$root.sections); + + // this.loadFromStorage(); + + // router.push("section/basics"); + }, + + deleteVersion: function(version) { + var versions = storage.getLocalStorage("versions"); + 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.setLocalStorage("versions",versions); + this.$root.versions = versions; + } + }, + + deleteClicked: function(index) + { + console.log(index); + var response = confirm("Are you sure you want to delete this position? " + index); + + if (response == true) + { + this.$root.versions.splice(index, 1); + } + }, + + + moveUpClicked: function(index) + { + console.log(index); + this.$root.moveArrayPosition(this.$root.versions, index, index - 1); + }, + + + moveDownClicked: function(index) + { + console.log(index); + this.$root.moveArrayPosition(this.$root.versions, index, index + 1); } + } }; \ No newline at end of file diff --git a/index.html b/index.html index 5dcd6c1..ee0b33a 100644 --- a/index.html +++ b/index.html @@ -1269,14 +1269,24 @@ diff --git a/scripts/storage.js b/scripts/storage.js index 215c915..cb933d4 100644 --- a/scripts/storage.js +++ b/scripts/storage.js @@ -41,7 +41,7 @@ var storage = { getLocalStorage: function(key) { - console.log(key); + // console.log(key); return this.parseJSON2Native(localStorage.getItem(key)); }, /* From 21894d77251ac6affe0e92a3ee55d0dfa7f21b60 Mon Sep 17 00:00:00 2001 From: chris2fr Date: Sat, 24 Oct 2020 14:40:34 +0200 Subject: [PATCH 5/6] Still Alpha Code, but WOrksish --- app/app.js | 17 ++++++++++++++--- index.html | 10 ++++++++-- scripts/storage.js | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/app.js b/app/app.js index 8dc0a48..62cea6e 100644 --- a/app/app.js +++ b/app/app.js @@ -58,7 +58,7 @@ var app = new Vue({ currentVersion: "", - availableVersions: [] + versions: [] }, created() @@ -66,6 +66,7 @@ var app = new Vue({ this.sections = models.newDefaultSections(); // this.versons = []; this.versions = storage.getLocalStorage("versions"); + this.currentVersion = ""; // console.log("this.sections=", this.sections); @@ -88,8 +89,9 @@ var app = new Vue({ { this.loadCountryCodes(); this.loadFromStorage(); + this.currentVersion = this.$root.sections.meta.version // Quick Fix - storage.setVersionedLocalStorage(this.$root.sections.meta.version, "sections", this.$root.sections); + storage.setVersionedLocalStorage(this.currentVersion, "sections", this.$root.sections); // console.log([this.$root.sections.meta.version,this.$root.sections]); //if (!this.availableVersions.hasKey(this.$root.sections.meta.version)) // this.availableVersions.push(this.$root.sections.meta.version); @@ -124,7 +126,16 @@ var app = new Vue({ this.activePage.fontAwesomeIconCss = component.fontAwesomeIcon; }, - + onVersionChange: function() { + // storage.setVersionedLocalStorage(this.currentVersion,"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]); + + storage.setLocalStorage(this.$root.sections); // Perhaps optimisation to come + }, /** * Reset and clear the details of the active page. diff --git a/index.html b/index.html index ee0b33a..f3d8402 100644 --- a/index.html +++ b/index.html @@ -47,8 +47,14 @@