From 3b60e0b7373f7b842bd5f95d052b686fe963c645 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 13 Feb 2021 18:35:15 +0100 Subject: [PATCH] display existing bookmarks in table --- htdocs/css/admin.css | 4 ++++ htdocs/settings/bookmarks.html | 2 +- owrx/bookmarks.py | 9 ++++++--- owrx/controllers/bookmarks.py | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/htdocs/css/admin.css b/htdocs/css/admin.css index 167159e..3890b80 100644 --- a/htdocs/css/admin.css +++ b/htdocs/css/admin.css @@ -54,3 +54,7 @@ h1 { padding: 20px; font-size: 1.2rem; } + +table.bookmarks .frequency { + text-align: right; +} \ No newline at end of file diff --git a/htdocs/settings/bookmarks.html b/htdocs/settings/bookmarks.html index 1d7970c..e666986 100644 --- a/htdocs/settings/bookmarks.html +++ b/htdocs/settings/bookmarks.html @@ -14,6 +14,6 @@ ${header}

Bookmarks

- make me pretty! + ${bookmarks} \ No newline at end of file diff --git a/owrx/bookmarks.py b/owrx/bookmarks.py index 651daf7..fe74365 100644 --- a/owrx/bookmarks.py +++ b/owrx/bookmarks.py @@ -78,7 +78,10 @@ class Bookmarks(object): return [] return [] - def getBookmarks(self, range): + def getBookmarks(self, range=None): self._refresh() - (lo, hi) = range - return [b for b in self.bookmarks if lo <= b.getFrequency() <= hi] + if range is None: + return self.bookmarks + else: + (lo, hi) = range + return [b for b in self.bookmarks if lo <= b.getFrequency() <= hi] diff --git a/owrx/controllers/bookmarks.py b/owrx/controllers/bookmarks.py index 51d45cc..9720827 100644 --- a/owrx/controllers/bookmarks.py +++ b/owrx/controllers/bookmarks.py @@ -1,5 +1,6 @@ from owrx.controllers.template import WebpageController from owrx.controllers.admin import AuthorizationMixin +from owrx.bookmarks import Bookmark, Bookmarks class BookmarksController(AuthorizationMixin, WebpageController): @@ -8,5 +9,39 @@ class BookmarksController(AuthorizationMixin, WebpageController): variables["assets_prefix"] = "../" return variables + def template_variables(self): + variables = super().template_variables() + variables["bookmarks"] = self.render_table() + return variables + + def render_table(self): + bookmarks = Bookmarks.getSharedInstance() + return """ + + + + + + + {bookmarks} +
NameFrequencyModulation
+ """.format( + bookmarks="".join(self.render_bookmark(idx, b) for idx, b in enumerate(bookmarks.getBookmarks())) + ) + + def render_bookmark(self, idx: int, bookmark: Bookmark): + return """ + + {name} + {frequency} + {modulation} + + """.format( + index=idx, + name=bookmark.getName(), + frequency=bookmark.getFrequency(), + modulation=bookmark.getModulation(), + ) + def indexAction(self): self.serve_template("settings/bookmarks.html", **self.template_variables())