Bookmark descriptions now operational.

This commit is contained in:
Marat Fayzullin 2024-06-27 23:35:13 -04:00
parent 0ca80d7fef
commit 90d3381529
9 changed files with 74 additions and 34 deletions

View File

@ -381,6 +381,10 @@
<label for="modulation">Modulation:</label>
<select name="modulation" id="modulation"></select>
</div>
<div class="form-field">
<label for="name">Description:</label>
<input type="text" id="description" name="description">
</div>
<div class="buttons">
<div class="openwebrx-button" data-action="cancel">Cancel</div>
<div class="openwebrx-button" data-action="submit">Ok</div>

View File

@ -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(){
'<div class="bookmark-content">' + b.name + '</div>' +
'</div>'
);
if (b.description) {
$bookmark.prop('title', b.description);
}
$bookmark.data(b);
return $bookmark;
});

View File

@ -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();

View File

@ -42,7 +42,7 @@ Utils.setIcaoUrl = function(url) {
// Escape HTML code
Utils.htmlEscape = function(input) {
return $('<div/>').text(input).html()
return $('<div/>').text(input).html();
};
// Print frequency (in Hz) in a nice way

View File

@ -4,7 +4,7 @@ function Editor(table) {
Editor.prototype.getInputHtml = function() {
return '<input>';
}
};
Editor.prototype.render = function(el) {
this.input = $(this.getInputHtml());
@ -62,7 +62,7 @@ NameEditor.prototype = new Editor();
NameEditor.prototype.getInputHtml = function() {
return '<input class="form-control form-control-sm" type="text">';
}
};
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 '<input class="form-control form-control-sm" type="text">';
};
$.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() {
'<td data-editor="name" data-value="' + bookmark.name + '">' + bookmark.name + '</td>' +
'<td data-editor="frequency" data-value="' + bookmark.frequency + '" class="frequency">' + renderFrequency(bookmark.frequency) +'</td>' +
'<td data-editor="modulation" data-value="' + bookmark.modulation + '">' + modulation_name + '</td>' +
'<td data-editor="description" data-value="' + bookmark.description + '">' + bookmark.description + '</td>' +
'<td>' +
'<button type="button" class="btn btn-sm btn-danger bookmark-delete">delete</button>' +
'</td>' +

View File

@ -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(),
}

View File

@ -35,6 +35,7 @@ class BookmarksController(AuthorizationMixin, BreadcrumbMixin, WebpageController
<th>Name</th>
<th class="frequency">Frequency</th>
<th>Modulation</th>
<th>Description</th>
<th>Actions</th>
</tr>
{bookmarks}
@ -69,6 +70,7 @@ class BookmarksController(AuthorizationMixin, BreadcrumbMixin, WebpageController
<td data-editor="name" data-value="{name}">{name}</td>
<td data-editor="frequency" data-value="{frequency}" class="frequency">{rendered_frequency}</td>
<td data-editor="modulation" data-value="{modulation}">{modulation_name}</td>
<td data-editor="description" data-value="{description}">{description}</td>
<td>
<button type="button" class="btn btn-sm btn-danger bookmark-delete">delete</button>
</td>
@ -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)

View File

@ -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+);(.*);(.*)$")

View File

@ -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()
@ -233,7 +247,8 @@ class Repeaters(object):
return [ Bookmark({
"name" : result[f][0]["name"],
"modulation" : result[f][0]["mode"],
"frequency" : result[f][0]["freq"]
"frequency" : result[f][0]["freq"],
"description" : Repeaters.getDescription(result[f][0])
}, srcFile = "RepeaterBook") for f in result.keys() ]
#