display existing bookmarks in table

This commit is contained in:
Jakob Ketterl 2021-02-13 18:35:15 +01:00
parent 3e4ba42aab
commit 3b60e0b737
4 changed files with 46 additions and 4 deletions

View File

@ -54,3 +54,7 @@ h1 {
padding: 20px;
font-size: 1.2rem;
}
table.bookmarks .frequency {
text-align: right;
}

View File

@ -14,6 +14,6 @@ ${header}
<div class="row">
<h1 class="col-12">Bookmarks</h1>
</div>
make me pretty!
${bookmarks}
</div>
</body>

View File

@ -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]

View File

@ -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 """
<table class="table bookmarks">
<tr>
<th>Name</th>
<th class="frequency">Frequency</th>
<th>Modulation</th>
</tr>
{bookmarks}
</table>
""".format(
bookmarks="".join(self.render_bookmark(idx, b) for idx, b in enumerate(bookmarks.getBookmarks()))
)
def render_bookmark(self, idx: int, bookmark: Bookmark):
return """
<tr data-index="{index}">
<td>{name}</td>
<td class="frequency">{frequency}</td>
<td>{modulation}</td>
</tr>
""".format(
index=idx,
name=bookmark.getName(),
frequency=bookmark.getFrequency(),
modulation=bookmark.getModulation(),
)
def indexAction(self):
self.serve_template("settings/bookmarks.html", **self.template_variables())