implement "add profile" sequence

This commit is contained in:
Jakob Ketterl 2021-03-03 22:33:37 +01:00
parent 400ed3541d
commit 8671f98c14
2 changed files with 60 additions and 8 deletions

View File

@ -65,9 +65,12 @@ class SdrDeviceListController(AuthorizationMixin, WebpageController):
<div>{num_profiles} profile(s)</div> <div>{num_profiles} profile(s)</div>
{additional_info} {additional_info}
</div> </div>
<ul class="col-6 list-group list-group-flush sdr-profile-list"> <div class="col-6">
<ul class="list-group list-group-flush sdr-profile-list">
{profiles} {profiles}
</ul> </ul>
<a href="{newprofile_link}" class="btn btn-success">Add profile...</a>
</div>
</div> </div>
</li> </li>
""".format( """.format(
@ -77,6 +80,7 @@ class SdrDeviceListController(AuthorizationMixin, WebpageController):
num_profiles=len(config["profiles"]), num_profiles=len(config["profiles"]),
additional_info=additional_info, additional_info=additional_info,
profiles="".join(render_profile(device_id, p_id, p) for p_id, p in config["profiles"].items()), profiles="".join(render_profile(device_id, p_id, p) for p_id, p in config["profiles"].items()),
newprofile_link="{}settings/sdr/{}/newprofile".format(self.get_document_root(), quote(device_id)),
) )
return """ return """
@ -114,6 +118,8 @@ class SdrFormController(SettingsFormController, metaclass=ABCMeta):
return None, None return None, None
return device_id, config["sdrs"][device_id] return device_id, config["sdrs"][device_id]
class SdrFormControllerWithModal(SdrFormController, metaclass=ABCMeta):
def buildModal(self): def buildModal(self):
return """ return """
<div class="modal" id="deleteModal" tabindex="-1" role="dialog"> <div class="modal" id="deleteModal" tabindex="-1" role="dialog">
@ -149,7 +155,7 @@ class SdrFormController(SettingsFormController, metaclass=ABCMeta):
pass pass
class SdrDeviceController(SdrFormController): class SdrDeviceController(SdrFormControllerWithModal):
def getData(self): def getData(self):
return self.device return self.device
@ -220,15 +226,17 @@ class NewSdrDeviceController(SettingsFormController):
# need to overwrite the existing key in the config since the layering won't capture the changes otherwise # need to overwrite the existing key in the config since the layering won't capture the changes otherwise
config = Config.get() config = Config.get()
sdrs = config["sdrs"] sdrs = config["sdrs"]
if self.stack["id"] in sdrs:
raise ValueError("device {} already exists!".format(self.stack["id"]))
sdrs[self.stack["id"]] = self.data_layer sdrs[self.stack["id"]] = self.data_layer
config["sdrs"] = sdrs config["sdrs"] = sdrs
super().store() super().store()
def getSuccessfulRedirect(self): def getSuccessfulRedirect(self):
return "{}settings/sdr/{}".format(self.get_document_root(), self.stack["id"]) return "{}settings/sdr/{}".format(self.get_document_root(), quote(self.stack["id"]))
class SdrProfileController(SdrFormController): class SdrProfileController(SdrFormControllerWithModal):
def __init__(self, handler, request, options): def __init__(self, handler, request, options):
super().__init__(handler, request, options) super().__init__(handler, request, options)
self.profile_id, self.profile = self._get_profile() self.profile_id, self.profile = self._get_profile()
@ -282,3 +290,39 @@ class SdrProfileController(SdrFormController):
return "{}settings/{}/deleteprofile/{}".format( return "{}settings/{}/deleteprofile/{}".format(
self.get_document_root(), quote(self.device_id), quote(self.profile_id) self.get_document_root(), quote(self.device_id), quote(self.profile_id)
) )
class NewProfileController(SdrFormController):
def __init__(self, handler, request, options):
super().__init__(handler, request, options)
id_layer = PropertyLayer(id="")
self.data_layer = PropertyLayer(name="")
self.stack = PropertyStack()
self.stack.addLayer(0, id_layer)
self.stack.addLayer(1, self.data_layer)
def getSections(self):
return [
Section(
"New profile settings",
TextInput("name", "Profile name"),
TextInput("id", "Profile ID"),
)
]
def getTitle(self):
return "New profile"
def store(self):
if self.stack["id"] in self.device["profiles"]:
raise ValueError("Profile {} already exists!".format(self.stack["id"]))
self.device["profiles"][self.stack["id"]] = self.data_layer
super().store()
def getData(self):
return self.stack
def getSuccessfulRedirect(self):
return "{}settings/sdr/{}/profile/{}".format(
self.get_document_root(), quote(self.device_id), quote(self.stack["id"])
)

View File

@ -11,6 +11,7 @@ from owrx.controllers.settings.sdr import (
SdrDeviceController, SdrDeviceController,
SdrProfileController, SdrProfileController,
NewSdrDeviceController, NewSdrDeviceController,
NewProfileController,
) )
from owrx.controllers.settings.reporting import ReportingController from owrx.controllers.settings.reporting import ReportingController
from owrx.controllers.settings.backgrounddecoding import BackgroundDecodingController from owrx.controllers.settings.backgrounddecoding import BackgroundDecodingController
@ -129,6 +130,13 @@ class Router(object):
RegexRoute( RegexRoute(
"^/settings/sdr/([^/]+)$", SdrDeviceController, method="POST", options={"action": "processFormData"} "^/settings/sdr/([^/]+)$", SdrDeviceController, method="POST", options={"action": "processFormData"}
), ),
RegexRoute("^/settings/sdr/([^/]+)/newprofile$", NewProfileController),
RegexRoute(
"^/settings/sdr/([^/]+)/newprofile$",
NewProfileController,
method="POST",
options={"action": "processFormData"},
),
RegexRoute("^/settings/sdr/([^/]+)/profile/([^/]+)$", SdrProfileController), RegexRoute("^/settings/sdr/([^/]+)/profile/([^/]+)$", SdrProfileController),
RegexRoute( RegexRoute(
"^/settings/sdr/([^/]+)/profile/([^/]+)$", "^/settings/sdr/([^/]+)/profile/([^/]+)$",