add button to export single interface

This commit is contained in:
liamcottle
2025-01-02 00:05:51 +13:00
parent fabb6d5ca3
commit b19ee171eb
3 changed files with 59 additions and 6 deletions

View File

@@ -590,13 +590,29 @@ class ReticulumMeshChat:
})
# export interfaces
@routes.get("/api/v1/reticulum/interfaces/export")
@routes.post("/api/v1/reticulum/interfaces/export")
async def export_interfaces(request):
try:
# get request data
selected_interface_names = None
try:
data = await request.json()
selected_interface_names = data.get('selected_interface_names')
except:
# request data was not json, but we don't care
pass
# format interfaces for export
output = []
for interface_name, interface in self.reticulum.config["interfaces"].items():
# skip interface if not selected
if selected_interface_names is not None and selected_interface_names != "":
if interface_name not in selected_interface_names:
continue
# add interface to output
output.append(f"[[{interface_name}]]")
for key, value in interface.items():
output.append(f" {key} = {value}")

View File

@@ -115,6 +115,17 @@
</button>
</div>
<!-- export interface button -->
<div class="my-auto mr-1">
<button @click="exportInterface" type="button" class="cursor-pointer">
<span class="flex text-gray-700 bg-gray-100 hover:bg-gray-200 p-2 dark:bg-zinc-600 dark:text-white dark:hover:bg-zinc-700 dark:focus-visible:outline-zinc-500 rounded-full ">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" />
</svg>
</span>
</button>
</div>
<!-- delete interface button -->
<div class="my-auto mr-2">
<button @click="deleteInterface" type="button" class="cursor-pointer">
@@ -175,6 +186,9 @@ export default {
editInterface() {
this.$emit("edit");
},
exportInterface() {
this.$emit("export");
},
deleteInterface() {
this.$emit("delete");
},

View File

@@ -1,6 +1,7 @@
<template>
<div class="flex flex-col flex-1 overflow-hidden min-w-full sm:min-w-[500px] dark:bg-zinc-950">
<div class="overflow-y-auto p-2 space-y-2">
<!-- warning - keeping orange-500 for warning visibility in both modes -->
<div class="flex bg-orange-500 p-2 text-sm font-semibold leading-6 text-white rounded shadow">
<div class="my-auto">
@@ -59,6 +60,7 @@
@enable="enableInterface(iface._name)"
@disable="disableInterface(iface._name)"
@edit="editInterface(iface._name)"
@export="exportInterface(iface._name)"
@delete="deleteInterface(iface._name)"/>
<!-- disabled interfaces -->
@@ -69,7 +71,9 @@
@enable="enableInterface(iface._name)"
@disable="disableInterface(iface._name)"
@edit="editInterface(iface._name)"
@export="exportInterface(iface._name)"
@delete="deleteInterface(iface._name)"/>
</div>
</div>
@@ -253,19 +257,38 @@ export default {
try {
// fetch exported interfaces
const response = await window.axios.get('/api/v1/reticulum/interfaces/export', {
responseType: 'blob'
});
const response = await window.axios.post('/api/v1/reticulum/interfaces/export');
// download file to browser
const blob = new Blob([response.data]);
DownloadUtils.downloadFile("meshchat_interfaces", blob);
DownloadUtils.downloadFile("meshchat_interfaces", new Blob([response.data], {
type: "application/octet-stream",
}));
} catch(e) {
DialogUtils.alert("Failed to export interfaces");
console.error(e);
}
},
async exportInterface(interfaceName) {
try {
// fetch exported interfaces
const response = await window.axios.post('/api/v1/reticulum/interfaces/export', {
selected_interface_names: [
interfaceName,
],
});
// download file to browser
DownloadUtils.downloadFile(interfaceName, new Blob([response.data], {
type: "application/octet-stream",
}));
} catch(e) {
DialogUtils.alert("Failed to export interface");
console.error(e);
}
},
showImportInterfacesModal() {
this.$refs["import-interfaces-modal"].show();
},