""".format(
+ device_id=device_id,
device_name=config["name"] if config["name"] else "[Unnamed device]",
device_link="{}settings/sdr/{}".format(self.get_document_root(), quote(device_id)),
state=state_info,
@@ -107,6 +108,26 @@ class SdrDeviceListController(AuthorizationMixin, BreadcrumbMixin, WebpageContro
def indexAction(self):
self.serve_template("settings/general.html", **self.template_variables())
+ def moveDevice(self):
+ try:
+ data = json.loads(self.get_body().decode("utf-8"))
+ if "device_id" not in data or "index" not in data:
+ self.send_response("{}", content_type="application/json", code=400)
+ return
+ device_id = data["device_id"]
+ index = data["index"]
+ config = Config.get()
+ devices = config["sdrs"]
+ device = next(d for d in devices if d["id"] == device_id)
+ devices.remove(device)
+ devices.insert(index, device)
+ config.store()
+ self.send_response("{}", content_type="application/json", code=203)
+ except json.JSONDecodeError:
+ self.send_response("{}", content_type="application/json", code=400)
+ except StopIteration:
+ self.send_response("{}", content_type="application/json", code=404)
+
class SdrFormController(SettingsFormController, metaclass=ABCMeta):
def __init__(self, handler, request, options):
diff --git a/owrx/http.py b/owrx/http.py
index 9781033b..5fcfa2c2 100644
--- a/owrx/http.py
+++ b/owrx/http.py
@@ -104,6 +104,12 @@ class Router(object):
"/settings/general", GeneralSettingsController, method="POST", options={"action": "processFormData"}
),
StaticRoute("/settings/sdr", SdrDeviceListController),
+ StaticRoute(
+ "/settings/sdr/movedevice",
+ SdrDeviceListController,
+ method="POST",
+ options={"action": "moveDevice"}
+ ),
StaticRoute("/settings/newsdr", NewSdrDeviceController),
StaticRoute(
"/settings/newsdr", NewSdrDeviceController, method="POST", options={"action": "processFormData"}