download and uplpoad grid preset

pull/916/head
DJ2LS 2025-03-17 10:57:28 +01:00
parent 9dafa2901f
commit 0c12da0343
3 changed files with 99 additions and 0 deletions

View File

@ -352,10 +352,81 @@ function savePreset() {
console.log("Saved grid preset");
}
function downloadPreset() {
let data = settingsStore.local.grid_layout;
// Remove leading and trailing double quotes if they exist
if (data.startsWith('"') && data.endsWith('"')) {
data = data.slice(1, -1);
}
// Create a Blob from the processed data
const blob = new Blob([data], { type: "application/json" });
const url = URL.createObjectURL(blob);
// Create a temporary anchor element to trigger the download
const a = document.createElement("a");
a.href = url;
a.download = "FreeDATA_GUI_preset.freedata";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
console.log("Downloaded preset as FreeDATA_preset.gui");
}
function uploadPreset() {
// Create a hidden file input element
const input = document.createElement('input');
input.type = 'file';
input.accept = '.freedata';
// Listen for when a file is selected
input.addEventListener('change', function(event) {
const file = event.target.files[0];
if (!file) {
console.log("No file selected, using custom preset.");
restoreGridLayoutFromConfig();
return;
}
const reader = new FileReader();
reader.onload = function(e) {
try {
const content = e.target.result;
// Store the file content into the settingsStore
clearAllItems()
settingsStore.local.grid_preset = content;
loadPreset();
console.log("Preset uploaded and stored.");
} catch (err) {
console.error("Error processing the preset", err);
}
};
reader.onerror = function() {
console.error("Error reading file, using custom preset.");
};
// Start reading the file as text
reader.readAsText(file);
});
// Trigger the file dialog
input.click();
}
function loadPreset() {
clearAllItems();
settingsStore.local.grid_layout = settingsStore.local.grid_preset;
restoreGridLayoutFromConfig();
saveLocalSettingsToConfig();
console.log("Restored grid preset");
}
@ -374,6 +445,7 @@ function onChange(event, changeItems) {
function restoreGridLayoutFromConfig() {
if (items.value.length === 0) {
const savedGrid = JSON.parse(settingsStore.local.grid_layout || "[]");
console.log(savedGrid)
savedGrid.forEach(([x, y, w, h, id]) => {
const widget = gridWidgets.find((gw) => gw.id === id);
if (widget) {
@ -770,6 +842,25 @@ onMounted(() => {
>
{{ $t('grid.savepreset') }}
</button>
<hr/>
<button
class="btn btn-sm btn-outline-secondary"
type="button"
@click="downloadPreset"
:title="$t('grid.downloadpreset_help')"
>
{{ $t('grid.downloadpreset') }}<i class="ms-1 bi bi-download"></i>
</button>
<button
class="ms-2 btn btn-sm btn-outline-secondary"
type="button"
@click="uploadPreset"
:title="$t('grid.uploadpreset_help')"
>
{{ $t('grid.uploadpreset') }}<i class="ms-1 bi bi-upload"></i>
</button>
</div>
</div>

View File

@ -76,6 +76,10 @@
"radiocontrol": "Transceiversteuerung/Status",
"statistics": "Statistik",
"other": "Diverses",
"uploadpreset": "Preset Hochladen",
"uploadpreset_help": "Lade eine Preset Datei hoch. ",
"downloadpreset": "Preset Herunterladen",
"downloadpreset_help": "Lade eine Preset-Date herunter um sie zu speichern und zu teilen",
"components": {
"tune": "Tune",
"stop_help": "Sitzung abbrechen und Aussendung beenden",

View File

@ -76,6 +76,10 @@
"radiocontrol": "Radio control/Status",
"statistics": "Statistics",
"other": "Other",
"uploadpreset": "Upload Preset",
"uploadpreset_help": "Upload a preset file",
"downloadpreset": "Download Preset",
"downloadpreset_help": "Download preset file for sharing or saving",
"components": {
"tune": "Tune",
"stop_help": "Abort session and stop transmissions",