New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds buttons to the menu to export / import the settings #2545
base: develop
Are you sure you want to change the base?
Conversation
static/js/map.js
Outdated
@@ -153,6 +153,32 @@ function createServiceWorkerReceiver() { | |||
}) | |||
} | |||
|
|||
function download(name, settings) { // eslint-disable-line no-unused-vars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
download
-> downloadSettings
static/js/map.js
Outdated
a.click() | ||
document.body.removeChild(a) | ||
} | ||
function upload(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upload
-> loadSettings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And add a linebreak between this function and the one before.)
static/js/map.js
Outdated
console.log(fr.result) | ||
upload(fr.result) | ||
} | ||
fr.readAsText(t.files[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use file.target.files[0]
.
(And remove the declaration of t
.)
templates/map.html
Outdated
@@ -461,6 +461,8 @@ <h3>Location Icon Marker</h3> | |||
</div> | |||
</div> | |||
<div> | |||
<center><button class="settings" onclick="download('RocketMap', JSON.stringify(JSON.stringify(localStorage)))"><i class="fa fa-upload fa-fw"></i>Export Settings</button></center> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of the double JSON.stringify()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need two JSON.stringify()'s to get the quotes escaped (for loadSettings(e)
).
templates/map.html
Outdated
@@ -461,6 +461,8 @@ <h3>Location Icon Marker</h3> | |||
</div> | |||
</div> | |||
<div> | |||
<center><button class="settings" onclick="downloadSettings('RocketMap', JSON.stringify(JSON.stringify(localStorage)))"><i class="fa fa-upload fa-fw"></i>Export Settings</button></center> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double JSON.stringify(JSON.stringify(
? Is the double quoting necessary to make it downloadable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not necessary to download it, but to deal with the data during import. This code works fine for me. But maybe I have a cleaner solution. I have to test it.
static/js/map.js
Outdated
function openSettingsFile(file) { // eslint-disable-line no-unused-vars | ||
var fr = new FileReader() | ||
fr.onload = function () { | ||
console.log(fr.result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove debug.
static/js/map.js
Outdated
} | ||
|
||
function openSettingsFile(file) { // eslint-disable-line no-unused-vars | ||
var fr = new FileReader() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use more descriptive variable names.
static/js/map.js
Outdated
} | ||
|
||
function loadSettings(e) { | ||
var t = JSON.parse(JSON.parse(e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, related to my question about the double stringify.
- use Object.assign instead of Object.keys().forEach - loadSettings() no longer necessary - double quoting no longer necessary
@sebastienvercammen |
7844410
to
b81bb26
Compare
static/js/map.js
Outdated
@@ -153,6 +153,25 @@ function createServiceWorkerReceiver() { | |||
}) | |||
} | |||
|
|||
function downloadSettings(name, settings) { // eslint-disable-line no-unused-vars | |||
var a = document.createElement('a') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one needs a readabillity update -> more descriptive variable name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Description
Adds buttons to the menu to export / import the settings.
Motivation and Context
Because the settings are stored in "Local Storage", they can be lost. Not anymore! You can export the settings for a later import.
By default, the file will have the following name: "RocketMap_DD-MM-YYYY HH:mm.txt".
How Has This Been Tested?
I use it on my own server.
Screenshots (if appropriate):
Types of changes
Checklist: