2023-07-22 16:23:10 +00:00
$ ( function ( ) {
function SortByQrg ( a , b ) {
var a = a . frequency ;
var b = b . frequency ;
return ( ( a < b ) ? - 1 : ( ( a > b ) ? 1 : 0 ) ) ;
}
2023-07-23 09:29:04 +00:00
function fill _list ( band , de , maxAgeMinutes ) {
let dxurl = dxcluster _provider + "/spots/" + band + "/" + maxAgeMinutes + "/" + de ;
2023-07-22 16:23:10 +00:00
$ . ajax ( {
url : dxurl ,
cache : false ,
dataType : "json"
} ) . done ( function ( dxspots ) {
var table = $ ( '.spottable' ) . DataTable ( ) ;
table . page . len ( 50 ) ;
2023-07-23 08:55:45 +00:00
let oldtable = table . data ( ) ;
table . clear ( ) ;
2023-07-22 16:23:10 +00:00
if ( dxspots . length > 0 ) {
dxspots . sort ( SortByQrg ) ;
dxspots . forEach ( ( single ) => {
2023-07-23 06:12:11 +00:00
var data = [ ] ;
data [ 0 ] = [ ] ;
data [ 0 ] . push ( single . when _pretty ) ;
2023-07-23 18:02:04 +00:00
data [ 0 ] . push ( single . frequency + " kHz" ) ;
2023-07-23 06:12:11 +00:00
data [ 0 ] . push ( ( single . worked _call ? '<span class="text-success">' : '' ) + single . spotted + ( single . worked _call ? '</span>' : '' ) ) ;
data [ 0 ] . push ( single . dxcc _spotted . entity ) ;
2023-07-23 18:02:04 +00:00
data [ 0 ] . push ( single . spotter ) ;
2023-07-23 08:55:45 +00:00
if ( oldtable . length > 0 ) {
let update = false ;
oldtable . each ( function ( srow ) {
if ( JSON . stringify ( srow ) === JSON . stringify ( data [ 0 ] ) ) {
update = true ;
}
} ) ;
if ( ! update ) { // Sth. Fresh? So highlight
table . rows . add ( data ) . draw ( ) . nodes ( ) . to$ ( ) . addClass ( "fresh bg-info" ) ;
} else {
table . rows . add ( data ) . draw ( ) ;
}
} else {
table . rows . add ( data ) . draw ( ) ;
}
2023-07-22 16:23:10 +00:00
} ) ;
2023-07-23 08:55:45 +00:00
setTimeout ( function ( ) { // Remove Highlights within 15sec
$ ( ".fresh" ) . removeClass ( "bg-info" ) ;
} , 1000 ) ;
2023-07-22 16:23:10 +00:00
}
} ) ;
}
2023-07-23 11:40:47 +00:00
function highlight _current _qrg ( qrg ) {
var table = $ ( '.spottable' ) . DataTable ( ) ;
table . rows ( ) . every ( function ( ) {
var d = this . data ( ) ;
2023-07-23 18:02:04 +00:00
var distance = Math . abs ( parseInt ( d [ 1 ] . substring ( 0 , d [ 1 ] . length - 4 ) ) - qrg ) ;
2023-07-23 11:40:47 +00:00
if ( distance <= 20 ) {
distance ++ ;
alpha = ( . 5 / distance ) ;
this . nodes ( ) . to$ ( ) . css ( 'background-color' , 'rgba(0,0,255,' + alpha + ')' ) ;
} else {
this . nodes ( ) . to$ ( ) . css ( 'background-color' , '' ) ;
}
} ) ;
}
2023-07-23 08:55:45 +00:00
$ ( '.spottable' ) . DataTable ( ) . order ( [ 1 , 'asc' ] ) ;
$ ( '.spottable' ) . DataTable ( ) . clear ( ) ;
2023-07-24 09:57:03 +00:00
fill _list ( $ ( '#band option:selected' ) . val ( ) , $ ( '#decontSelect option:selected' ) . val ( ) , dxcluster _maxage ) ;
setInterval ( function ( ) { fill _list ( $ ( '#band option:selected' ) . val ( ) , $ ( '#decontSelect option:selected' ) . val ( ) , dxcluster _maxage ) ; } , 60000 ) ;
2023-07-23 09:29:04 +00:00
$ ( "#decontSelect" ) . on ( "change" , function ( ) {
$ ( '.spottable' ) . DataTable ( ) . clear ( ) ;
2023-07-24 09:57:03 +00:00
fill _list ( $ ( '#band option:selected' ) . val ( ) , $ ( '#decontSelect option:selected' ) . val ( ) , dxcluster _maxage ) ;
2023-07-23 09:29:04 +00:00
} ) ;
2023-07-22 16:23:10 +00:00
$ ( "#band" ) . on ( "change" , function ( ) {
2023-07-23 08:55:45 +00:00
$ ( '.spottable' ) . DataTable ( ) . order ( [ 1 , 'asc' ] ) ;
$ ( '.spottable' ) . DataTable ( ) . clear ( ) ;
2023-07-24 09:57:03 +00:00
fill _list ( $ ( '#band option:selected' ) . val ( ) , $ ( '#decontSelect option:selected' ) . val ( ) , dxcluster _maxage ) ;
2023-07-22 16:23:10 +00:00
} ) ;
2023-07-23 18:48:03 +00:00
$ ( "#spottertoggle" ) . on ( "click" , function ( ) {
if ( $ ( '.spottable' ) . DataTable ( ) . column ( 4 ) . visible ( ) ) {
$ ( '.spottable' ) . DataTable ( ) . column ( 4 ) . visible ( false ) ;
} else {
$ ( '.spottable' ) . DataTable ( ) . column ( 4 ) . visible ( true ) ;
}
} ) ;
2023-07-23 16:38:26 +00:00
$ ( "#menutoggle" ) . on ( "click" , function ( ) {
if ( $ ( '.navbar' ) . is ( ":hidden" ) ) {
$ ( '.navbar' ) . show ( ) ;
2023-07-23 16:46:16 +00:00
$ ( '#dxtabs' ) . show ( ) ;
$ ( '#dxtitle' ) . show ( ) ;
2023-07-23 16:38:26 +00:00
$ ( '#menutoggle_i' ) . removeClass ( 'fa-arrow-down' ) ;
$ ( '#menutoggle_i' ) . addClass ( 'fa-arrow-up' ) ;
} else {
$ ( '.navbar' ) . hide ( ) ;
2023-07-23 16:46:16 +00:00
$ ( '#dxtabs' ) . hide ( ) ;
$ ( '#dxtitle' ) . hide ( ) ;
2023-07-23 16:38:26 +00:00
$ ( '#menutoggle_i' ) . removeClass ( 'fa-arrow-up' ) ;
$ ( '#menutoggle_i' ) . addClass ( 'fa-arrow-down' ) ;
}
} ) ;
2023-07-22 16:23:10 +00:00
var updateFromCAT = function ( ) {
if ( $ ( 'select.radios option:selected' ) . val ( ) != '0' ) {
radioID = $ ( 'select.radios option:selected' ) . val ( ) ;
2023-07-23 11:40:47 +00:00
$ . getJSON ( base _url + "radio/json/" + radioID , function ( data ) {
2023-07-22 16:23:10 +00:00
if ( data . error ) {
if ( data . error == 'not_logged_in' ) {
$ ( ".radio_cat_state" ) . remove ( ) ;
if ( $ ( '.radio_login_error' ) . length == 0 ) {
$ ( '.messages' ) . prepend ( '<div class="alert alert-danger radio_login_error" role="alert"><i class="fas fa-broadcast-tower"></i> You\'re not logged it. Please <a href="' + base _url + '">login</a></div>' ) ;
}
}
// Put future Errorhandling here
} else {
if ( $ ( '.radio_login_error' ) . length != 0 ) {
$ ( ".radio_login_error" ) . remove ( ) ;
}
var band = frequencyToBand ( data . frequency ) ;
if ( band !== $ ( "#band" ) . val ( ) ) {
$ ( "#band" ) . val ( band ) ;
$ ( "#band" ) . trigger ( "change" ) ;
}
var minutes = Math . floor ( cat _timeout _interval / 60 ) ;
if ( data . updated _minutes _ago > minutes ) {
$ ( ".radio_cat_state" ) . remove ( ) ;
if ( $ ( '.radio_timeout_error' ) . length == 0 ) {
$ ( '.messages' ) . prepend ( '<div class="alert alert-danger radio_timeout_error" role="alert"><i class="fas fa-broadcast-tower"></i> Radio connection timed-out: ' + $ ( 'select.radios option:selected' ) . text ( ) + ' data is ' + data . updated _minutes _ago + ' minutes old.</div>' ) ;
} else {
$ ( '.radio_timeout_error' ) . html ( 'Radio connection timed-out: ' + $ ( 'select.radios option:selected' ) . text ( ) + ' data is ' + data . updated _minutes _ago + ' minutes old.' ) ;
}
} else {
$ ( ".radio_timeout_error" ) . remove ( ) ;
text = '<i class="fas fa-broadcast-tower"></i><span style="margin-left:10px;"></span><b>TX:</b> ' + ( Math . round ( parseInt ( data . frequency ) / 100 ) / 10000 ) . toFixed ( 4 ) + ' MHz' ;
2023-07-23 18:02:04 +00:00
highlight _current _qrg ( ( parseInt ( data . frequency ) ) / 1000 ) ;
2023-07-22 16:23:10 +00:00
if ( data . mode != null ) {
text = text + '<span style="margin-left:10px"></span>' + data . mode ;
}
if ( data . power != null && data . power != 0 ) {
text = text + '<span style="margin-left:10px"></span>' + data . power + ' W' ;
}
if ( ! $ ( '#radio_cat_state' ) . length ) {
$ ( '.messages' ) . prepend ( '<div aria-hidden="true"><div id="radio_cat_state" class="alert alert-success radio_cat_state" role="alert">' + text + '</div></div>' ) ;
} else {
$ ( '#radio_cat_state' ) . html ( text ) ;
}
}
}
} ) ;
}
} ;
2023-07-23 06:12:11 +00:00
$ . fn . dataTable . moment ( custom _date _format + ' HH:mm' ) ;
2023-07-22 16:23:10 +00:00
// Update frequency every three second
2023-07-23 11:40:47 +00:00
setInterval ( updateFromCAT , 3000 ) ;
2023-07-22 16:23:10 +00:00
// If a radios selected from drop down select radio update.
$ ( '.radios' ) . change ( updateFromCAT ) ;
} ) ;