mirror of
https://github.com/jketterl/openwebrx.git
synced 2025-12-06 07:12:09 +01:00
implement device drag & drop frontend
This commit is contained in:
parent
d5ccaf1b9c
commit
c711916a0b
|
|
@ -22,4 +22,16 @@ $(function(){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
$('.sdr-device-list').draggableList({
|
||||||
|
dataType: 'application/x-sdr-device',
|
||||||
|
itemSelector: '.sdr-device',
|
||||||
|
idProperty: 'device-id',
|
||||||
|
performMove: function(deviceId, index) {
|
||||||
|
return $.ajax(document.location.href + '/movedevice', {
|
||||||
|
data: JSON.stringify({device_id: deviceId, index: index}),
|
||||||
|
contentType: 'application/json',
|
||||||
|
method: 'POST'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
@ -73,7 +73,7 @@ class SdrDeviceListController(AuthorizationMixin, BreadcrumbMixin, WebpageContro
|
||||||
)
|
)
|
||||||
|
|
||||||
return """
|
return """
|
||||||
<li class="list-group-item">
|
<li class="list-group-item sdr-device" data-device-id="{device_id}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<a href="{device_link}">
|
<a href="{device_link}">
|
||||||
|
|
@ -87,6 +87,7 @@ class SdrDeviceListController(AuthorizationMixin, BreadcrumbMixin, WebpageContro
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
""".format(
|
""".format(
|
||||||
|
device_id=device_id,
|
||||||
device_name=config["name"] if config["name"] else "[Unnamed device]",
|
device_name=config["name"] if config["name"] else "[Unnamed device]",
|
||||||
device_link="{}settings/sdr/{}".format(self.get_document_root(), quote(device_id)),
|
device_link="{}settings/sdr/{}".format(self.get_document_root(), quote(device_id)),
|
||||||
state=state_info,
|
state=state_info,
|
||||||
|
|
@ -107,6 +108,26 @@ class SdrDeviceListController(AuthorizationMixin, BreadcrumbMixin, WebpageContro
|
||||||
def indexAction(self):
|
def indexAction(self):
|
||||||
self.serve_template("settings/general.html", **self.template_variables())
|
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):
|
class SdrFormController(SettingsFormController, metaclass=ABCMeta):
|
||||||
def __init__(self, handler, request, options):
|
def __init__(self, handler, request, options):
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,12 @@ class Router(object):
|
||||||
"/settings/general", GeneralSettingsController, method="POST", options={"action": "processFormData"}
|
"/settings/general", GeneralSettingsController, method="POST", options={"action": "processFormData"}
|
||||||
),
|
),
|
||||||
StaticRoute("/settings/sdr", SdrDeviceListController),
|
StaticRoute("/settings/sdr", SdrDeviceListController),
|
||||||
|
StaticRoute(
|
||||||
|
"/settings/sdr/movedevice",
|
||||||
|
SdrDeviceListController,
|
||||||
|
method="POST",
|
||||||
|
options={"action": "moveDevice"}
|
||||||
|
),
|
||||||
StaticRoute("/settings/newsdr", NewSdrDeviceController),
|
StaticRoute("/settings/newsdr", NewSdrDeviceController),
|
||||||
StaticRoute(
|
StaticRoute(
|
||||||
"/settings/newsdr", NewSdrDeviceController, method="POST", options={"action": "processFormData"}
|
"/settings/newsdr", NewSdrDeviceController, method="POST", options={"action": "processFormData"}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue