1
0
Fork 0

Add custom sorter for frequencies on transmitters list

Signed-off-by: Pierros Papadeas <pierros@papadeas.gr>
spacecruft
Pierros Papadeas 2020-07-12 14:28:46 +03:00
parent a0d398f129
commit 980ef8abe2
2 changed files with 11 additions and 21 deletions

View File

@ -3,31 +3,20 @@ function ppb_to_freq(freq, drift) {
return Math.round(freq_obs);
}
function format_freq(frequency) {
if (isNaN(frequency) || frequency == ''){
return 'None';
} else if (frequency < 1000) {
// Frequency is in Hz range
return frequency.toFixed(3) + ' Hz';
} else if (frequency < 1000000) {
return (frequency/1000).toFixed(3) + ' kHz';
} else {
return (frequency/1000000).toFixed(3) + ' MHz';
}
/* eslint-disable no-unused-vars */
/* Disabling eslint for the following function since it is called by the Bootstrap Table library */
function freqSorter(a, b) {
var aa = a.split(' ', 1);
var bb = b.split(' ', 1);
return aa - bb;
}
/* eslint-enable no-unused-vars */
$(document).ready(function() {
$('#transmitters-table').bootstrapTable();
$('#transmitters-table').css('opacity','1');
$( '#transmitters-table' ).on('pre-body.bs.table', function() {
$('.frequency').each(function() {
var to_format = $(this).html();
$(this).html(format_freq(to_format));
});
});
// Calculate the drifted frequencies
$('.drifted').each(function() {
var drifted = ppb_to_freq($(this).data('freq_or'),$(this).data('drift'));

View File

@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load tags %}
{% block title %} - Transmitters List{% endblock %}
@ -24,7 +25,7 @@
data-sortable="true"
data-filter-control="select">Type</th>
<th data-sortable="true">Description</th>
<th data-sortable="true">Downlink</th>
<th data-sortable="true" data-sorter="freqSorter">Downlink</th>
<th data-sortable="true" data-visible="false">Downlink Drift</th>
<th data-sortable="true" data-visible="false">Uplink</th>
<th data-sortable="true" data-visible="false">Uplink Drift</th>
@ -50,13 +51,13 @@
</td>
<td>{{ trans.type }}</td>
<td>{{ trans.description }}</td>
<td class="frequency">{{ trans.downlink_low }}</td>
<td class="frequency">{{ trans.downlink_low | frq }}</td>
<td>{{ trans.downlink_drift }}</td>
<td class="frequency">{{ trans.uplink }}</td>
<td>{{ trans.uplink_drift }}</td>
<td>{{ trans.invert }}</td>
<td>{{ trans.downlink_mode }}</td>
<td>{{ trans.baud }}</td>
<td>{{ trans.baud | floatformat }}</td>
<td>{{ trans.service }}</td>
<td>{{ trans.status }}</td>
</tr>