diff --git a/htdocs/lib/settings/Profiles.js b/htdocs/lib/settings/Profiles.js new file mode 100644 index 00000000..8b497611 --- /dev/null +++ b/htdocs/lib/settings/Profiles.js @@ -0,0 +1,23 @@ +$.fn.profiles = function() { + this.each(function() { + $(this).on('click', '.move-down', function(e) { + $.ajax(document.URL.replace(/\/profile\//, '/moveprofiledown/'), { + contentType: 'application/json', + method: 'GET' + }).done(function() { + document.location.reload(); + }); + return false; + }); + + $(this).on('click', '.move-up', function(e) { + $.ajax(document.URL.replace(/\/profile\//, '/moveprofileup/'), { + contentType: 'application/json', + method: 'GET' + }).done(function() { + document.location.reload(); + }); + return false; + }); + }); +} diff --git a/htdocs/settings.js b/htdocs/settings.js index c222bde0..b2c76b2c 100644 --- a/htdocs/settings.js +++ b/htdocs/settings.js @@ -10,4 +10,5 @@ $(function(){ $('.exponential-input').exponentialInput(); $('.device-log-messages').logMessages(); $('.client-list').clientList(); + $('.buttons').profiles(); }); diff --git a/owrx/controllers/assets.py b/owrx/controllers/assets.py index 055740f3..abd4a038 100644 --- a/owrx/controllers/assets.py +++ b/owrx/controllers/assets.py @@ -183,6 +183,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController): "lib/settings/ExponentialInput.js", "lib/settings/LogMessages.js", "lib/settings/ClientList.js", + "lib/settings/Profiles.js", "settings.js", ], } diff --git a/owrx/controllers/settings/sdr.py b/owrx/controllers/settings/sdr.py index 1f17b464..bab8d780 100644 --- a/owrx/controllers/settings/sdr.py +++ b/owrx/controllers/settings/sdr.py @@ -16,6 +16,10 @@ from owrx.log import HistoryHandler from abc import ABCMeta, abstractmethod from uuid import uuid4 +import logging + +logger = logging.getLogger(__name__) + class SdrDeviceBreadcrumb(SettingsBreadcrumb): def __init__(self): @@ -394,6 +398,8 @@ class SdrProfileController(SdrFormControllerWithModal): def render_remove_button(self): return """ + + """ @@ -413,6 +419,26 @@ class SdrProfileController(SdrFormControllerWithModal): config.store() return self.send_redirect("{}settings/sdr/{}".format(self.get_document_root(), quote(self.device_id))) + def moveProfileUp(self): + return self.moveProfile(self.profile_id, False) + + def moveProfileDown(self): + return self.moveProfile(self.profile_id, True) + + def moveProfile(self, id: str, moveDown: bool): + if id is None or id not in self.device["profiles"]: + return self.send_response("profile not found", code=404) + config = Config.get() + profiles = list(self.device["profiles"].keys()) + n = profiles.index(id) + if moveDown and n + 1 < len(profiles): + profiles = profiles[:n] + [profiles[n+1] , profiles[n]] + profiles[n+2:] + elif not moveDown and n > 0: + profiles = profiles[:n-1] + [profiles[n] , profiles[n-1]] + profiles[n+1:] + self.device["profiles"] = { x: self.device["profiles"][x] for x in profiles } + config.store() + return self.send_redirect("{}settings/sdr/{}".format(self.get_document_root(), quote(self.device_id))) + class NewProfileController(SdrProfileController): def __init__(self, handler, request, options): diff --git a/owrx/http.py b/owrx/http.py index 6ccd9c24..b6e32e4a 100644 --- a/owrx/http.py +++ b/owrx/http.py @@ -137,6 +137,16 @@ class Router(object): SdrProfileController, options={"action": "deleteProfile"}, ), + RegexRoute( + "^/settings/sdr/([^/]+)/moveprofileup/([^/]+)$", + SdrProfileController, + options={"action": "moveProfileUp"}, + ), + RegexRoute( + "^/settings/sdr/([^/]+)/moveprofiledown/([^/]+)$", + SdrProfileController, + options={"action": "moveProfileDown"}, + ), StaticRoute("/settings/bookmarks", BookmarksController), StaticRoute("/settings/bookmarks", BookmarksController, method="POST", options={"action": "new"}), RegexRoute("^/settings/bookmarks/(.+)$", BookmarksController, method="POST", options={"action": "update"}),