From 2d142e45ed3c6452c4a2328fc4a37e52a5041fb5 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Tue, 30 Mar 2021 18:19:23 +0200 Subject: [PATCH] implement dialog to import personal bookmarks --- htdocs/css/admin.css | 6 +- htdocs/lib/BookmarkBar.js | 18 ------ htdocs/lib/BookmarkLocalStorage.js | 17 ++++++ htdocs/lib/settings/BookmarkTable.js | 77 ++++++++++++++++++++------ htdocs/settings/bookmarks.html | 21 +++++++ owrx/controllers/assets.py | 2 + owrx/controllers/settings/bookmarks.py | 4 +- 7 files changed, 108 insertions(+), 37 deletions(-) create mode 100644 htdocs/lib/BookmarkLocalStorage.js diff --git a/htdocs/css/admin.css b/htdocs/css/admin.css index fc2bfe6..88d8da8 100644 --- a/htdocs/css/admin.css +++ b/htdocs/css/admin.css @@ -80,7 +80,7 @@ h1 { padding-right: 15px; } -.bookmarks table .frequency { +.bookmarks table .frequency, .bookmark-list table .frequency { text-align: right; } @@ -90,6 +90,10 @@ h1 { display: initial; } +.bookmark-list table .form-check-input { + margin-left: 0; +} + .actions { margin: 1rem 0; } diff --git a/htdocs/lib/BookmarkBar.js b/htdocs/lib/BookmarkBar.js index 35e8919..2284ca5 100644 --- a/htdocs/lib/BookmarkBar.js +++ b/htdocs/lib/BookmarkBar.js @@ -145,21 +145,3 @@ BookmarkBar.prototype.getDemodulatorPanel = function() { BookmarkBar.prototype.getDemodulator = function() { return this.getDemodulatorPanel().getDemodulator(); }; - -BookmarkLocalStorage = function(){ -}; - -BookmarkLocalStorage.prototype.getBookmarks = function(){ - return JSON.parse(window.localStorage.getItem("bookmarks")) || []; -}; - -BookmarkLocalStorage.prototype.setBookmarks = function(bookmarks){ - window.localStorage.setItem("bookmarks", JSON.stringify(bookmarks)); -}; - -BookmarkLocalStorage.prototype.deleteBookmark = function(data) { - if (data.id) data = data.id; - var bookmarks = this.getBookmarks(); - bookmarks = bookmarks.filter(function(b) { return b.id !== data; }); - this.setBookmarks(bookmarks); -}; diff --git a/htdocs/lib/BookmarkLocalStorage.js b/htdocs/lib/BookmarkLocalStorage.js new file mode 100644 index 0000000..edb4992 --- /dev/null +++ b/htdocs/lib/BookmarkLocalStorage.js @@ -0,0 +1,17 @@ +BookmarkLocalStorage = function(){ +}; + +BookmarkLocalStorage.prototype.getBookmarks = function(){ + return JSON.parse(window.localStorage.getItem("bookmarks")) || []; +}; + +BookmarkLocalStorage.prototype.setBookmarks = function(bookmarks){ + window.localStorage.setItem("bookmarks", JSON.stringify(bookmarks)); +}; + +BookmarkLocalStorage.prototype.deleteBookmark = function(data) { + if (data.id) data = data.id; + var bookmarks = this.getBookmarks(); + bookmarks = bookmarks.filter(function(b) { return b.id !== data; }); + this.setBookmarks(bookmarks); +}; diff --git a/htdocs/lib/settings/BookmarkTable.js b/htdocs/lib/settings/BookmarkTable.js index c01f3dc..136a66f 100644 --- a/htdocs/lib/settings/BookmarkTable.js +++ b/htdocs/lib/settings/BookmarkTable.js @@ -66,14 +66,16 @@ NameEditor.prototype.getInputHtml = function() { function FrequencyEditor(table) { Editor.call(this, table); - this.suffixes = { - 'K': 3, - 'M': 6, - 'G': 9, - 'T': 12 - }; } +FrequencyEditor.suffixes = { + '': 0, + 'K': 3, + 'M': 6, + 'G': 9, + 'T': 12 +}; + FrequencyEditor.prototype = new Editor(); FrequencyEditor.prototype.getInputHtml = function() { @@ -81,8 +83,7 @@ FrequencyEditor.prototype.getInputHtml = function() { '' + '
' + '' + + '' + b.name + '' + + '' + renderFrequency(b.frequency) + '' + + '' + modulation + '' + + '' + ); + row.data('bookmark', b); + return row; + })); + $importModal.find('.bookmark-list').html($list); + } else { + $importModal.find('.bookmark-list').html('No personal bookmarks found in this browser'); + } + $importModal.modal('show'); + }); }); }; diff --git a/htdocs/settings/bookmarks.html b/htdocs/settings/bookmarks.html index 1a25d23..f5013a5 100644 --- a/htdocs/settings/bookmarks.html +++ b/htdocs/settings/bookmarks.html @@ -20,6 +20,7 @@ ${header}
${bookmarks}
+
@@ -43,4 +44,24 @@ ${header}
+ \ No newline at end of file diff --git a/owrx/controllers/assets.py b/owrx/controllers/assets.py index ef1cad4..cda5924 100644 --- a/owrx/controllers/assets.py +++ b/owrx/controllers/assets.py @@ -125,6 +125,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController): "lib/Header.js", "lib/Demodulator.js", "lib/DemodulatorPanel.js", + "lib/BookmarkLocalStorage.js", "lib/BookmarkBar.js", "lib/BookmarkDialog.js", "lib/AudioEngine.js", @@ -148,6 +149,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController): "lib/Header.js", "lib/settings/MapInput.js", "lib/settings/ImageUpload.js", + "lib/BookmarkLocalStorage.js", "lib/settings/BookmarkTable.js", "lib/settings/WsjtDecodingDepthsInput.js", "lib/settings/WaterfallDropdown.js", diff --git a/owrx/controllers/settings/bookmarks.py b/owrx/controllers/settings/bookmarks.py index 38de38a..1778589 100644 --- a/owrx/controllers/settings/bookmarks.py +++ b/owrx/controllers/settings/bookmarks.py @@ -43,7 +43,9 @@ class BookmarksController(AuthorizationMixin, WebpageController): 9: "G", 12: "T", } - exp = int(math.log10(freq) / 3) * 3 + exp = 0 + if freq > 0: + exp = int(math.log10(freq) / 3) * 3 num = freq suffix = "" if exp in suffixes: