From 8df885b727b15bb25b3c9b42744e1c0a8a248811 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sun, 10 May 2020 17:27:46 +0200 Subject: [PATCH] download receiver details via rest api --- htdocs/lib/Header.js | 8 ++++++++ owrx/connection.py | 12 ++---------- owrx/controllers/api.py | 11 ++--------- owrx/details.py | 21 +++++++++++++++++++++ 4 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 owrx/details.py diff --git a/htdocs/lib/Header.js b/htdocs/lib/Header.js index d1c6a30..cced6b6 100644 --- a/htdocs/lib/Header.js +++ b/htdocs/lib/Header.js @@ -6,6 +6,7 @@ function Header(el) { }); this.init_rx_photo(); + this.download_details(); }; Header.prototype.setDetails = function(details) { @@ -57,6 +58,13 @@ Header.prototype.toggle_rx_photo = function(ev) { } }; +Header.prototype.download_details = function() { + var self = this; + $.ajax('api/receiverdetails').done(function(data){ + self.setDetails(data); + }); +}; + $.fn.header = function() { if (!this.data('header')) { this.data('header', new Header(this)); diff --git a/owrx/connection.py b/owrx/connection.py index 14620fe..e8f5172 100644 --- a/owrx/connection.py +++ b/owrx/connection.py @@ -1,4 +1,5 @@ from owrx.config import Config +from owrx.details import ReceiverDetails from owrx.dsp import DspManager from owrx.cpu import CpuUsageThread from owrx.sdr import SdrService @@ -9,7 +10,6 @@ from owrx.version import openwebrx_version from owrx.bands import Bandplan from owrx.bookmarks import Bookmarks from owrx.map import Map -from owrx.locator import Locator from owrx.property import PropertyStack from owrx.modes import Modes, DigitalMode from multiprocessing import Queue @@ -68,18 +68,10 @@ class OpenWebRxClient(Client, metaclass=ABCMeta): def __init__(self, conn): super().__init__(conn) - receiver_details = Config.get().filter( - "receiver_name", - "receiver_location", - "receiver_asl", - "receiver_gps", - "photo_title", - "photo_desc", - ) + receiver_details = ReceiverDetails() def send_receiver_info(*args): receiver_info = receiver_details.__dict__() - receiver_info["locator"] = Locator.fromCoordinates(receiver_info["receiver_gps"]) self.write_receiver_details(receiver_info) # TODO unsubscribe diff --git a/owrx/controllers/api.py b/owrx/controllers/api.py index 60bb74f..4dcde14 100644 --- a/owrx/controllers/api.py +++ b/owrx/controllers/api.py @@ -1,6 +1,6 @@ from . import Controller from owrx.feature import FeatureDetector -from owrx.config import Config +from owrx.details import ReceiverDetails import json @@ -10,13 +10,6 @@ class ApiController(Controller): self.send_response(data, content_type="application/json") def receiverDetails(self): - receiver_details = Config.get().filter( - "receiver_name", - "receiver_location", - "receiver_asl", - "receiver_gps", - "photo_title", - "photo_desc", - ) + receiver_details = ReceiverDetails() data = json.dumps(receiver_details.__dict__()) self.send_response(data, content_type="application/json") diff --git a/owrx/details.py b/owrx/details.py new file mode 100644 index 0000000..5bc7253 --- /dev/null +++ b/owrx/details.py @@ -0,0 +1,21 @@ +from owrx.config import Config +from owrx.locator import Locator +from owrx.property import PropertyFilter + + +class ReceiverDetails(PropertyFilter): + def __init__(self): + super().__init__( + Config.get(), + "receiver_name", + "receiver_location", + "receiver_asl", + "receiver_gps", + "photo_title", + "photo_desc", + ) + + def __dict__(self): + receiver_info = super().__dict__() + receiver_info["locator"] = Locator.fromCoordinates(receiver_info["receiver_gps"]) + return receiver_info