From: Marc Foley Date: Wed, 12 Mar 2025 09:53:17 +0000 (+0000) Subject: tags.html: save and load a previous session X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9189%2Fhead;p=thirdparty%2Fgoogle%2Ffonts.git tags.html: save and load a previous session --- diff --git a/.ci/tags.html b/.ci/tags.html index 34b484572..f85336ab3 100644 --- a/.ci/tags.html +++ b/.ci/tags.html @@ -20,6 +20,7 @@
File @@ -338,7 +339,6 @@ function axesCombos(axes) { this.loadFonts(); this.loadCSV(); this.loadFamilyPangrams(); - }, mounted() { const urlParams = new URLSearchParams(window.location.search); @@ -394,6 +394,15 @@ function axesCombos(axes) { } }, methods: { + saveSession() { + localStorage.setItem("tagData", this.tagsToCSV()); + }, + lastSession() { + if (localStorage.getItem("tagData")) { + this.tags = this.parseCSV(localStorage.getItem("tagData")); + } + this.history.push("Last session loaded"); + }, async getFamilyData() { let dat = await fetch("family_data.json").then(response => response.json()).then(data => { let results = []; @@ -460,6 +469,7 @@ function axesCombos(axes) { edited(family) { this.isEdited = true; this.history.push(`* ${family.name},${family.category},${family.Weight}`); + this.saveSession(); }, parseUnicode(str) { let ranges = str.split(","); @@ -553,6 +563,7 @@ function axesCombos(axes) { this.tags.push(newFamily); this.history.push(`+ ${newFamily.displayName},${newFamily.category},${newFamily.score}`); } + this.saveSession(); }, copyFamily() { this.isEdited = true; @@ -566,6 +577,7 @@ function axesCombos(axes) { this.tags.push(newTag); this.history.push(`+ ${newTag.Family},${newTag["Group/Tag"]},${newTag.Weight}`); }) + this.saveSession(); }, AddPlaceHolderTags() { this.isEdited = true; @@ -591,6 +603,7 @@ function axesCombos(axes) { let tagKey = `${Family.name},${Family.category}`; this.seen.delete(tagKey); this.history.push(`- ${Family.displayName},${Family.category},${Family.score}`); + this.saveSession(); }, tagsToCSV() { this.RemovePlaceHolderTags(); @@ -652,17 +665,22 @@ function axesCombos(axes) { return response.text() }) .then(csvText => { - const lines = csvText.split("\r\n") - lines.forEach((line) => { - if (line === "") { - return; - } - let family = FontTag.fromCsv(line); - this.categories.add(family.category); - this.tags.push(family); - }); + this.tags = this.parseCSV(csvText); csvText = "Family,Group/Tag,Weight\r\n" + csvText; }) + }, + parseCSV(text) { + const lines = text.split("\r\n"); + let res = []; + lines.forEach((line) => { + if (line === "") { + return; + } + let family = FontTag.fromCsv(line); + this.categories.add(family.category); + res.push(family); + }); + return res; } } } // methods