Skip to content
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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions static/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ function createServiceWorkerReceiver() {
})
}

function downloadSettings(name, settings) { // eslint-disable-line no-unused-vars
var a = document.createElement('a')
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

a.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(settings))
a.setAttribute('download', name + '_' + moment().format('DD-MM-YYYY HH:mm'))
a.style.display = 'none'
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
}

function loadSettingsFile(file) { // eslint-disable-line no-unused-vars
var reader = new FileReader()
reader.onload = function () {
Object.assign(localStorage, JSON.parse(reader.result))
}
reader.readAsText(file.target.files[0])
window.location.reload()
}

function initMap() { // eslint-disable-line no-unused-vars
map = new google.maps.Map(document.getElementById('map'), {
center: {
Expand Down
2 changes: 2 additions & 0 deletions templates/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ <h3>Location Icon Marker</h3>
</div>
</div>
<div>
<center><button class="settings" onclick="downloadSettings('RocketMap', JSON.stringify(localStorage))"><i class="fa fa-upload fa-fw"></i>Export Settings</button></center>
<center><input id="settingsFileInput" type="file" style="display:none;" onchange="loadSettingsFile(event)"> <button class="settings" onclick="document.getElementById('settingsFileInput').click()"><i class="fa fa-download fa-fw"></i>Import Settings</button></center>
<center><button class="settings" onclick="confirm('Are you sure you want to reset settings to default values?') ? (localStorage.clear(), window.location.reload()) : false"><i class="fa fa-refresh fa-fw"></i>Reset Settings</button></center>
</div>
</nav>
Expand Down