From 90d3381529f6dbf33cddd8436112a908f70d30d5 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Thu, 27 Jun 2024 23:35:13 -0400 Subject: [PATCH] Bookmark descriptions now operational. --- htdocs/index.html | 4 ++++ htdocs/lib/BookmarkBar.js | 12 +++-------- htdocs/lib/BookmarkDialog.js | 6 +++--- htdocs/lib/Utils.js | 2 +- htdocs/lib/settings/BookmarkTable.js | 22 ++++++++++++++----- owrx/bookmarks.py | 5 +++++ owrx/controllers/settings/bookmarks.py | 6 +++++- owrx/eibi.py | 30 +++++++++++++++----------- owrx/repeaters.py | 21 +++++++++++++++--- 9 files changed, 74 insertions(+), 34 deletions(-) diff --git a/htdocs/index.html b/htdocs/index.html index fed38b00..411d07c4 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -381,6 +381,10 @@ +
+ + +
Cancel
Ok
diff --git a/htdocs/lib/BookmarkBar.js b/htdocs/lib/BookmarkBar.js index 5a904077..cb3e3a73 100644 --- a/htdocs/lib/BookmarkBar.js +++ b/htdocs/lib/BookmarkBar.js @@ -17,15 +17,6 @@ function BookmarkBar() { stopScanner(); }); -// me.$container.on('contextmenu', '.bookmark', function(e){ -// e.stopPropagation(); -// var $bookmark = $(e.target).closest('.bookmark'); -// var b = $bookmark.data(); -// if (!b || !b.description) return false; -// divlog(b.description, false); -// return false; -// }); - me.$container.on('click', '.action[data-action=edit]', function(e){ e.stopPropagation(); var $bookmark = $(e.target).closest('.bookmark'); @@ -103,6 +94,9 @@ BookmarkBar.prototype.render = function(){ '
' + b.name + '
' + '
' ); + if (b.description) { + $bookmark.prop('title', b.description); + } $bookmark.data(b); return $bookmark; }); diff --git a/htdocs/lib/BookmarkDialog.js b/htdocs/lib/BookmarkDialog.js index 4a0a1841..c2d94c26 100644 --- a/htdocs/lib/BookmarkDialog.js +++ b/htdocs/lib/BookmarkDialog.js @@ -11,7 +11,7 @@ $.fn.bookmarkDialog = function() { }, setValues: function(bookmark) { var $form = $el.find('form'); - ['name', 'frequency', 'modulation'].forEach(function(key){ + ['name', 'frequency', 'modulation', 'description'].forEach(function(key){ $form.find('#' + key).val(bookmark[key]); }); $el.data('id', bookmark.id || false); @@ -20,7 +20,7 @@ $.fn.bookmarkDialog = function() { getValues: function() { var bookmark = {}; var valid = true; - ['name', 'frequency', 'modulation'].forEach(function(key){ + ['name', 'frequency', 'modulation', 'description'].forEach(function(key){ var $input = $el.find('#' + key); valid = valid && $input[0].checkValidity(); bookmark[key] = $input.val(); @@ -33,4 +33,4 @@ $.fn.bookmarkDialog = function() { return bookmark; } } -} \ No newline at end of file +} diff --git a/htdocs/lib/Utils.js b/htdocs/lib/Utils.js index af6056a2..27aef7b0 100644 --- a/htdocs/lib/Utils.js +++ b/htdocs/lib/Utils.js @@ -42,7 +42,7 @@ Utils.setIcaoUrl = function(url) { // Escape HTML code Utils.htmlEscape = function(input) { - return $('
').text(input).html() + return $('
').text(input).html(); }; // Print frequency (in Hz) in a nice way diff --git a/htdocs/lib/settings/BookmarkTable.js b/htdocs/lib/settings/BookmarkTable.js index 48f48f19..ac60356e 100644 --- a/htdocs/lib/settings/BookmarkTable.js +++ b/htdocs/lib/settings/BookmarkTable.js @@ -4,7 +4,7 @@ function Editor(table) { Editor.prototype.getInputHtml = function() { return ''; -} +}; Editor.prototype.render = function(el) { this.input = $(this.getInputHtml()); @@ -62,7 +62,7 @@ NameEditor.prototype = new Editor(); NameEditor.prototype.getInputHtml = function() { return ''; -} +}; function FrequencyEditor(table) { Editor.call(this, table); @@ -122,7 +122,7 @@ FrequencyEditor.prototype.setupEvents = function() { me.expInput.val(FrequencyEditor.suffixes[c]); } }); -} +}; FrequencyEditor.prototype.getValue = function() { var frequency = parseFloat(this.freqInput.val()); @@ -160,7 +160,7 @@ var renderFrequency = function(freq) { suffix = suffix[0] == 'K' ? 'k' : suffix[0]; var expString = suffix[0] + 'Hz'; return frequency + ' ' + expString; -} +}; FrequencyEditor.prototype.getHtml = function() { return renderFrequency(this.getValue()); @@ -186,11 +186,22 @@ ModulationEditor.prototype.getHtml = function() { return $option.html(); }; +function DescriptionEditor(table) { + Editor.call(this, table); +} + +DescriptionEditor.prototype = new Editor(); + +DescriptionEditor.prototype.getInputHtml = function() { + return ''; +}; + $.fn.bookmarktable = function() { var editors = { name: NameEditor, frequency: FrequencyEditor, - modulation: ModulationEditor + modulation: ModulationEditor, + description: DescriptionEditor }; $.each(this, function(){ @@ -386,6 +397,7 @@ $.fn.bookmarktable = function() { '' + bookmark.name + '' + '' + renderFrequency(bookmark.frequency) +'' + '' + modulation_name + '' + + '' + bookmark.description + '' + '' + '' + '' + diff --git a/owrx/bookmarks.py b/owrx/bookmarks.py index 9aafe449..191090ce 100644 --- a/owrx/bookmarks.py +++ b/owrx/bookmarks.py @@ -14,6 +14,7 @@ class Bookmark(object): self.name = j["name"] self.frequency = j["frequency"] self.modulation = j["modulation"] + self.description = j["description"] if "description" in j else "" self.srcFile = srcFile def getName(self): @@ -25,6 +26,9 @@ class Bookmark(object): def getModulation(self): return self.modulation + def getDescription(self): + return self.description + def getSrcFile(self): return self.srcFile @@ -33,6 +37,7 @@ class Bookmark(object): "name": self.getName(), "frequency": self.getFrequency(), "modulation": self.getModulation(), + "description": self.getDescription(), } diff --git a/owrx/controllers/settings/bookmarks.py b/owrx/controllers/settings/bookmarks.py index 9cd39e7e..41f69776 100644 --- a/owrx/controllers/settings/bookmarks.py +++ b/owrx/controllers/settings/bookmarks.py @@ -35,6 +35,7 @@ class BookmarksController(AuthorizationMixin, BreadcrumbMixin, WebpageController Name Frequency Modulation + Description Actions {bookmarks} @@ -69,6 +70,7 @@ class BookmarksController(AuthorizationMixin, BreadcrumbMixin, WebpageController {name} {rendered_frequency} {modulation_name} + {description} @@ -81,6 +83,7 @@ class BookmarksController(AuthorizationMixin, BreadcrumbMixin, WebpageController rendered_frequency=render_frequency(bookmark.getFrequency()), modulation=bookmark.getModulation() if mode is None else mode.modulation, modulation_name=bookmark.getModulation() if mode is None else mode.name, + description=bookmark.getDescription(), ) def _findBookmark(self, bookmark_id): @@ -98,7 +101,7 @@ class BookmarksController(AuthorizationMixin, BreadcrumbMixin, WebpageController return try: data = json.loads(self.get_body().decode("utf-8")) - for key in ["name", "frequency", "modulation"]: + for key in ["name", "frequency", "modulation", "description"]: if key in data: value = data[key] if key == "frequency": @@ -120,6 +123,7 @@ class BookmarksController(AuthorizationMixin, BreadcrumbMixin, WebpageController "name": bookmark_data["name"], "frequency": int(bookmark_data["frequency"]), "modulation": bookmark_data["modulation"], + "description": bookmark_data["description"], } bookmark = Bookmark(data) bookmarks.addBookmark(bookmark) diff --git a/owrx/eibi.py b/owrx/eibi.py index 766ec070..6a14e31c 100644 --- a/owrx/eibi.py +++ b/owrx/eibi.py @@ -68,23 +68,29 @@ class EIBI(object): @staticmethod def getDescription(b): - description = "" + description = [] # Describe target region if "tgt" in b: - description += "Targeting " + b["tgt"] + "." - # Describe transmitter locations - if "src" in b and b["src"] in EIBI_Locations: - description += ( - (" " if len(description) > 0 else "") + - "Transmitting from " + - ", ".join([x["name"] for x in EIBI_Locations[b["src"]]]) - ) + target = b["tgt"] # Add country name if ITU code present if "itu" in b and b["itu"] in EIBI_Countries: - description += ", " + EIBI_Countries[b["itu"]] - description += "." + source = EIBI_Countries[b["itu"]] + else: + source = target + description += [( + "Broadcasting to " + target + + ((" from " + source) if source != target else "") + + "." + )] + # Describe transmitter locations + if "src" in b and b["src"] in EIBI_Locations: + description += [( + "Transmitting from " + + ", ".join([x["name"] for x in EIBI_Locations[b["src"]]]) + + "." + )] # Done - return description + return " ".join(description) def __init__(self): self.patternCSV = re.compile(r"^([\d\.]+);(\d\d\d\d)-(\d\d\d\d);(\S*);(\S+);(.*);(.*);(.*);(.*);(\d+);(.*);(.*)$") diff --git a/owrx/repeaters.py b/owrx/repeaters.py index 38da2135..a1d50a14 100644 --- a/owrx/repeaters.py +++ b/owrx/repeaters.py @@ -69,6 +69,20 @@ class Repeaters(object): else: return "nfm" + # Compose textual description of an entry + @staticmethod + def getDescription(entry): + description = [] + # Add information from the entry to the description + if "status" in entry: + description += [entry["status"] + "."] + if "updated" in entry: + description += ["Last updated " + entry["updated"] + "."] + if "comment" in entry: + description += [entry["comment"]] + # Done + return " ".join(description) + def __init__(self): self.refreshPeriod = 60*60*24 self.lock = threading.Lock() @@ -231,9 +245,10 @@ class Repeaters(object): # Return bookmarks for all found entries logger.info("Created {0} bookmarks for {1}-{2}kHz within {3}km.".format(len(result), f1//1000, f2//1000, rangeKm)) return [ Bookmark({ - "name" : result[f][0]["name"], - "modulation" : result[f][0]["mode"], - "frequency" : result[f][0]["freq"] + "name" : result[f][0]["name"], + "modulation" : result[f][0]["mode"], + "frequency" : result[f][0]["freq"], + "description" : Repeaters.getDescription(result[f][0]) }, srcFile = "RepeaterBook") for f in result.keys() ] #