setup device list and routing for device pages

This commit is contained in:
Jakob Ketterl 2021-02-19 00:03:25 +01:00
parent d65743f2ea
commit 872c7a4bfd
5 changed files with 54 additions and 22 deletions

View File

@ -13,10 +13,6 @@ html, body {
margin: 15px 15px 0;
}
.device {
margin-top: 20px;
}
.settings-section {
margin-top: 3em;
}
@ -84,4 +80,8 @@ table.bookmarks .frequency {
.wsjt-decoding-depths-table td:first-child {
padding-left: 0;
}
.sdr-device-list .list-group-item {
background: initial;
}

View File

@ -2,18 +2,18 @@
<html>
<head>
<title>OpenWebRX Settings</title>
<link rel="shortcut icon" type="image/x-icon" href="../static/favicon.ico" />
<link rel="stylesheet" href="../static/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../static/css/admin.css" />
<link rel="shortcut icon" type="image/x-icon" href="${assets_prefix}static/favicon.ico" />
<link rel="stylesheet" href="${assets_prefix}static/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${assets_prefix}static/css/admin.css" />
<script src="https://unpkg.com/location-picker/dist/location-picker.min.js"></script>
<script src="../compiled/settings.js"></script>
<script src="${assets_prefix}compiled/settings.js"></script>
<meta charset="utf-8">
</head>
<body>
${header}
<div class="container">
<div class="row">
<h1 class="col-12">${title}s</h1>
<h1 class="col-12">${title}</h1>
</div>
${content}
</div>

View File

@ -69,6 +69,7 @@ class SettingsFormController(AuthorizationMixin, WebpageController, metaclass=AB
variables = super().template_variables()
variables["content"] = self.render_sections()
variables["title"] = self.getTitle()
variables["assets_prefix"] = "../"
return variables
def parseFormData(self):

View File

@ -1,9 +1,10 @@
from owrx.controllers.admin import AuthorizationMixin
from owrx.controllers.template import WebpageController
from owrx.config import Config
from urllib.parse import quote, unquote
class SdrSettingsController(AuthorizationMixin, WebpageController):
class SdrDeviceListController(AuthorizationMixin, WebpageController):
def header_variables(self):
variables = super().header_variables()
variables["assets_prefix"] = "../"
@ -13,30 +14,59 @@ class SdrSettingsController(AuthorizationMixin, WebpageController):
variables = super().template_variables()
variables["content"] = self.render_devices()
variables["title"] = "SDR device settings"
variables["assets_prefix"] = "../"
return variables
def render_devices(self):
def render_device(device_id, config):
return """
<div class="card device bg-dark text-white">
<div class="card-header">
{device_name}
<li class="list-group-item">
<a href="{device_link}">
<h3>{device_name}</h3>
</a>
<div>
some more device info here
</div>
<div class="card-body">
sdr detail goes here
</div>
</div>
</li>
""".format(
device_name=config["name"]
device_name=config["name"],
device_link="{}/{}".format(self.request.path, quote(device_id)),
)
return """
<div class="col-12">
<ul class="row list-group list-group-flush sdr-device-list">
{devices}
</div>
</ul>
""".format(
devices="".join(render_device(key, value) for key, value in Config.get()["sdrs"].items())
)
def indexAction(self):
self.serve_template("settings/general.html", **self.template_variables())
class SdrDeviceController(AuthorizationMixin, WebpageController):
def get_device(self):
device_id = unquote(self.request.matches.group(1))
if device_id not in Config.get()["sdrs"]:
return None
return Config.get()["sdrs"][device_id]
def header_variables(self):
variables = super().header_variables()
variables["assets_prefix"] = "../../"
return variables
def template_variables(self, device):
variables = super().template_variables()
variables["title"] = device["name"]
variables["content"] = "TODO"
variables["assets_prefix"] = "../../"
return variables
def indexAction(self):
device = self.get_device()
if device is None:
self.send_response("device not found", code=404)
return
self.serve_template("settings/general.html", **self.template_variables(device))

View File

@ -6,7 +6,7 @@ from owrx.controllers.api import ApiController
from owrx.controllers.metrics import MetricsController
from owrx.controllers.settings import SettingsController
from owrx.controllers.settings.general import GeneralSettingsController
from owrx.controllers.settings.sdr import SdrSettingsController
from owrx.controllers.settings.sdr import SdrDeviceListController, SdrDeviceController
from owrx.controllers.settings.reporting import ReportingController
from owrx.controllers.settings.backgrounddecoding import BackgroundDecodingController
from owrx.controllers.settings.decoding import DecodingSettingsController
@ -115,7 +115,8 @@ class Router(object):
StaticRoute(
"/settings/general", GeneralSettingsController, method="POST", options={"action": "processFormData"}
),
StaticRoute("/settings/sdr", SdrSettingsController),
StaticRoute("/settings/sdr", SdrDeviceListController),
RegexRoute("/settings/sdr/(.+)", SdrDeviceController),
StaticRoute("/settings/bookmarks", BookmarksController),
StaticRoute("/settings/bookmarks", BookmarksController, method="POST", options={"action": "new"}),
RegexRoute("/settings/bookmarks/(.+)", BookmarksController, method="POST", options={"action": "update"}),