move settings page to own vue component

This commit is contained in:
liamcottle 2024-08-02 18:44:41 +12:00
commit 1afc434d86
3 changed files with 165 additions and 104 deletions

View file

@ -551,6 +551,20 @@ class ReticulumMeshChat:
"config": self.get_config_dict(),
})
# update config
@routes.patch("/api/v1/config")
async def index(request):
# get request body as json
data = await request.json()
# update config
await self.update_config(data)
return web.json_response({
"config": self.get_config_dict(),
})
# get calls
@routes.get("/api/v1/calls")
async def index(request):
@ -1115,6 +1129,40 @@ class ReticulumMeshChat:
# tell websocket clients we just announced
await self.send_announced_to_websocket_clients()
async def update_config(self, data):
# update display name in config
if "display_name" in data and data["display_name"] != "":
self.config.display_name.set(data["display_name"])
# update auto announce interval
if "auto_announce_interval_seconds" in data:
# auto auto announce interval
auto_announce_interval_seconds = int(data["auto_announce_interval_seconds"])
self.config.auto_announce_interval_seconds.set(data["auto_announce_interval_seconds"])
# enable or disable auto announce based on interval
if auto_announce_interval_seconds > 0:
self.config.auto_announce_enabled.set(True)
else:
self.config.auto_announce_enabled.set(False)
if "auto_resend_failed_messages_when_announce_received" in data:
value = bool(data["auto_resend_failed_messages_when_announce_received"])
self.config.auto_resend_failed_messages_when_announce_received.set(value)
if "allow_auto_resending_failed_messages_with_attachments" in data:
value = bool(data["allow_auto_resending_failed_messages_with_attachments"])
self.config.allow_auto_resending_failed_messages_with_attachments.set(value)
if "show_suggested_community_interfaces" in data:
value = bool(data["show_suggested_community_interfaces"])
self.config.show_suggested_community_interfaces.set(value)
# send config to websocket clients
await self.send_config_to_websocket_clients()
# handle data received from websocket client
async def on_websocket_data_received(self, client, data):
@ -1124,40 +1172,11 @@ class ReticulumMeshChat:
# handle updating config
if _type == "config.set":
# send lxmf message to destination
# get config from websocket
config = data["config"]
# update display name in config
if "display_name" in config and config["display_name"] != "":
self.config.display_name.set(config["display_name"])
# update auto announce interval
if "auto_announce_interval_seconds" in config:
# auto auto announce interval
auto_announce_interval_seconds = int(config["auto_announce_interval_seconds"])
self.config.auto_announce_interval_seconds.set(config["auto_announce_interval_seconds"])
# enable or disable auto announce based on interval
if auto_announce_interval_seconds > 0:
self.config.auto_announce_enabled.set(True)
else:
self.config.auto_announce_enabled.set(False)
if "auto_resend_failed_messages_when_announce_received" in config:
value = bool(config["auto_resend_failed_messages_when_announce_received"])
self.config.auto_resend_failed_messages_when_announce_received.set(value)
if "allow_auto_resending_failed_messages_with_attachments" in config:
value = bool(config["allow_auto_resending_failed_messages_with_attachments"])
self.config.allow_auto_resending_failed_messages_with_attachments.set(value)
if "show_suggested_community_interfaces" in config:
value = bool(config["show_suggested_community_interfaces"])
self.config.show_suggested_community_interfaces.set(value)
# send config to websocket clients
await self.send_config_to_websocket_clients()
# update config
await self.update_config(config)
# handle downloading a file from a nomadnet node
elif _type == "nomadnet.file.download":
@ -1442,7 +1461,7 @@ class ReticulumMeshChat:
lxmf_message_state = "delivered"
elif lxmf_message.state == LXMF.LXMessage.FAILED:
lxmf_message_state = "failed"
return lxmf_message_state
# convert database announce to a dictionary
@ -2159,7 +2178,7 @@ def main():
# init app
reticulum_meshchat = ReticulumMeshChat(identity, args.storage_dir, args.reticulum_config_dir)
reticulum_meshchat.run(args.host, args.port, launch_browser=args.headless is False)
if __name__ == "__main__":
main()

View file

@ -106,7 +106,7 @@
<!-- settings -->
<li>
<button @click="showSettingsTab" type="button" :class="[ tab === 'settings' ? 'bg-blue-100 text-blue-800 group:text-blue-800 hover:bg-blue-100' : '']" class="w-full text-gray-800 hover:bg-gray-100 group flex gap-x-3 rounded-r-full p-2 mr-2 text-sm leading-6 font-semibold focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600">
<button @click="tab = 'settings'" type="button" :class="[ tab === 'settings' ? 'bg-blue-100 text-blue-800 group:text-blue-800 hover:bg-blue-100' : '']" class="w-full text-gray-800 hover:bg-gray-100 group flex gap-x-3 rounded-r-full p-2 mr-2 text-sm leading-6 font-semibold focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600">
<span class="my-auto">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.325.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z" />
@ -1214,55 +1214,7 @@
</div>
<!-- settings tab -->
<div v-if="tab === 'settings'" class="overflow-y-auto space-y-2 p-2">
<!-- failed messages -->
<div class="bg-white rounded shadow">
<div class="flex border-b border-gray-300 text-gray-700 p-2 font-semibold">Failed Messages</div>
<div class="divide-y text-gray-900">
<div class="p-2">
<div class="flex items-start">
<div class="flex items-center h-5">
<input v-model="config.auto_resend_failed_messages_when_announce_received" @change="onAutoResendFailedMessagesWhenAnnounceReceivedChange" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300">
</div>
<label class="ml-2 text-sm font-medium text-gray-900">Auto resend</label>
</div>
<div class="text-sm text-gray-700">When enabled, failed messages will auto resend when an announce is received from the intended destination.</div>
</div>
<div class="p-2">
<div class="flex items-start">
<div class="flex items-center h-5">
<input v-model="config.allow_auto_resending_failed_messages_with_attachments" @change="onAllowAutoResendingFailedMessagesWithAttachmentsChange" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300">
</div>
<label class="ml-2 text-sm font-medium text-gray-900">Allow resending with attachments</label>
</div>
<div class="text-sm text-gray-700">When enabled, failed messages that have attachments are allowed to auto resend.</div>
</div>
</div>
</div>
<!-- interfaces -->
<div class="bg-white rounded shadow">
<div class="flex border-b border-gray-300 text-gray-700 p-2 font-semibold">Interfaces</div>
<div class="divide-y text-gray-900">
<div class="p-2">
<div class="flex items-start">
<div class="flex items-center h-5">
<input v-model="config.show_suggested_community_interfaces" @change="onShowSuggestedCommunityInterfacesChange" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300">
</div>
<label class="ml-2 text-sm font-medium text-gray-900">Show Community Interfaces</label>
</div>
<div class="text-sm text-gray-700">When enabled, community interfaces will be shown on the Add Interface page.</div>
</div>
</div>
</div>
</div>
<SettingsPage v-if="tab === 'settings'"/>
<!-- about tab -->
<div v-if="tab === 'about'" class="overflow-y-auto space-y-2 p-2">
@ -1344,8 +1296,13 @@
</template>
<script>
import SettingsPage from "./settings/SettingsPage.vue";
export default {
name: 'App',
components: {
SettingsPage,
},
data() {
return {
@ -1923,21 +1880,6 @@ export default {
"auto_announce_interval_seconds": this.config.auto_announce_interval_seconds,
});
},
async onAutoResendFailedMessagesWhenAnnounceReceivedChange() {
await this.updateConfig({
"auto_resend_failed_messages_when_announce_received": this.config.auto_resend_failed_messages_when_announce_received,
});
},
async onAllowAutoResendingFailedMessagesWithAttachmentsChange() {
await this.updateConfig({
"allow_auto_resending_failed_messages_with_attachments": this.config.allow_auto_resending_failed_messages_with_attachments,
});
},
async onShowSuggestedCommunityInterfacesChange() {
await this.updateConfig({
"show_suggested_community_interfaces": this.config.show_suggested_community_interfaces,
});
},
async startNewLXMFConversation() {
// ask for destination address
@ -2897,10 +2839,6 @@ export default {
await this.getConversations();
},
showSettingsTab() {
this.tab = "settings";
this.getConfig();
},
showAboutTab() {
this.tab = "about";
this.getAppInfo();

View file

@ -0,0 +1,104 @@
<template>
<div class="overflow-y-auto space-y-2 p-2">
<!-- failed messages -->
<div class="bg-white rounded shadow">
<div class="flex border-b border-gray-300 text-gray-700 p-2 font-semibold">Failed Messages</div>
<div class="divide-y text-gray-900">
<div class="p-2">
<div class="flex items-start">
<div class="flex items-center h-5">
<input v-model="config.auto_resend_failed_messages_when_announce_received" @change="onAutoResendFailedMessagesWhenAnnounceReceivedChange" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300">
</div>
<label class="ml-2 text-sm font-medium text-gray-900">Auto resend</label>
</div>
<div class="text-sm text-gray-700">When enabled, failed messages will auto resend when an announce is received from the intended destination.</div>
</div>
<div class="p-2">
<div class="flex items-start">
<div class="flex items-center h-5">
<input v-model="config.allow_auto_resending_failed_messages_with_attachments" @change="onAllowAutoResendingFailedMessagesWithAttachmentsChange" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300">
</div>
<label class="ml-2 text-sm font-medium text-gray-900">Allow resending with attachments</label>
</div>
<div class="text-sm text-gray-700">When enabled, failed messages that have attachments are allowed to auto resend.</div>
</div>
</div>
</div>
<!-- interfaces -->
<div class="bg-white rounded shadow">
<div class="flex border-b border-gray-300 text-gray-700 p-2 font-semibold">Interfaces</div>
<div class="divide-y text-gray-900">
<div class="p-2">
<div class="flex items-start">
<div class="flex items-center h-5">
<input v-model="config.show_suggested_community_interfaces" @change="onShowSuggestedCommunityInterfacesChange" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300">
</div>
<label class="ml-2 text-sm font-medium text-gray-900">Show Community Interfaces</label>
</div>
<div class="text-sm text-gray-700">When enabled, community interfaces will be shown on the Add Interface page.</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'SettingsPage',
data() {
return {
config: {
auto_resend_failed_messages_when_announce_received: null,
allow_auto_resending_failed_messages_with_attachments: null,
show_suggested_community_interfaces: null,
},
};
},
mounted() {
this.getConfig();
},
methods: {
async getConfig() {
try {
const response = await window.axios.get("/api/v1/config");
this.config = response.data.config;
} catch(e) {
// do nothing if failed to load config
console.log(e);
}
},
async updateConfig(config) {
try {
const response = await window.axios.patch("/api/v1/config", config);
this.config = response.data.config;
} catch(e) {
alert("Failed to save config!");
console.log(e);
}
},
async onAutoResendFailedMessagesWhenAnnounceReceivedChange() {
await this.updateConfig({
"auto_resend_failed_messages_when_announce_received": this.config.auto_resend_failed_messages_when_announce_received,
});
},
async onAllowAutoResendingFailedMessagesWithAttachmentsChange() {
await this.updateConfig({
"allow_auto_resending_failed_messages_with_attachments": this.config.allow_auto_resending_failed_messages_with_attachments,
});
},
async onShowSuggestedCommunityInterfacesChange() {
await this.updateConfig({
"show_suggested_community_interfaces": this.config.show_suggested_community_interfaces,
});
},
},
}
</script>