Adding code to move profiles around.
This commit is contained in:
parent
cbc97e1dd2
commit
976860dd17
|
|
@ -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;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -10,4 +10,5 @@ $(function(){
|
|||
$('.exponential-input').exponentialInput();
|
||||
$('.device-log-messages').logMessages();
|
||||
$('.client-list').clientList();
|
||||
$('.buttons').profiles();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 """
|
||||
<button type="button" class="btn btn-success move-up">Move up</button>
|
||||
<button type="button" class="btn btn-success move-down">Move down</button>
|
||||
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">Remove profile...</button>
|
||||
"""
|
||||
|
||||
|
|
@ -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):
|
||||
|
|
|
|||
10
owrx/http.py
10
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"}),
|
||||
|
|
|
|||
Loading…
Reference in New Issue