Skip to content

Commit c9d8c3a

Browse files
committed
fix API switching
1 parent 5b59626 commit c9d8c3a

File tree

1 file changed

+76
-25
lines changed

1 file changed

+76
-25
lines changed

js/tracker.js

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ function clean_refresh(text, force, history_step) {
366366
lhash_update(history_step);
367367

368368
clearTimeout(periodical);
369+
clearTimeout(periodical_focus);
369370
clearTimeout(periodical_receivers);
370371
clearTimeout(periodical_recoveries);
371372

@@ -888,6 +889,9 @@ function stopFollow(no_data_reset) {
888889
wvar.focus = "";
889890
}
890891

892+
//stop detailed data
893+
clearTimeout(periodical_focus);
894+
891895
// clear graph
892896
if(plot) plot = $.plot(plot_holder, {}, plot_options);
893897
updateGraph(null, true);
@@ -917,7 +921,8 @@ function followVehicle(vcallsign, noPan, force) {
917921
}
918922

919923
if(follow_vehicle != vcallsign || force) {
920-
refresh(vcallsign);
924+
clearTimeout(periodical_focus);
925+
refreshSingle(vcallsign, true);
921926
focusVehicle(vcallsign);
922927

923928
follow_vehicle = vcallsign;
@@ -1850,7 +1855,8 @@ function addPosition(position) {
18501855
listScroll.refresh();
18511856
listScroll.scrollToElement(_vehicle_idname);
18521857
followVehicle($(_vehicle_idname).attr('data-vcallsign'));
1853-
refresh(_vehicle_id);
1858+
clearTimeout(periodical_focus);
1859+
refreshSingle(_vehicle_id, true);
18541860
};
18551861

18561862
marker.shadow = marker_shadow;
@@ -2507,15 +2513,15 @@ function graphAddPosition(vcallsign, new_data) {
25072513
}
25082514

25092515
var ajax_positions = null;
2516+
var ajax_positions_single = null;
25102517
var ajax_inprogress = false;
2518+
var ajax_inprogress_single = false;
25112519

2512-
function refresh(serial) {
2520+
function refresh() {
25132521
if(ajax_inprogress) {
2514-
if (serial === undefined) {
2515-
clearTimeout(periodical);
2516-
periodical = setTimeout(refresh, 2000);
2517-
return;
2518-
}
2522+
clearTimeout(periodical);
2523+
periodical = setTimeout(refresh, 2000);
2524+
return;
25192525
}
25202526

25212527
ajax_inprogress = true;
@@ -2530,11 +2536,7 @@ function refresh(serial) {
25302536
var mode = wvar.mode.toLowerCase();
25312537
mode = (mode == "position") ? "latest" : mode.replace(/ /g,"");
25322538

2533-
if (serial === undefined) {
2534-
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=" + position_id + "&vehicles=" + encodeURIComponent(wvar.query);
2535-
} else {
2536-
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=0&vehicles=" + encodeURIComponent(serial);
2537-
}
2539+
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=" + position_id + "&vehicles=" + encodeURIComponent(wvar.query);
25382540

25392541
ajax_positions = $.ajax({
25402542
type: "GET",
@@ -2544,10 +2546,7 @@ function refresh(serial) {
25442546
success: function(response, textStatus) {
25452547
$("#stText").text("loading |");
25462548
response.fetch_timestamp = Date.now();
2547-
if (serial === undefined) {update(response);} else {
2548-
//vehicles[serial].kill();
2549-
update(response, true);
2550-
}
2549+
update(response);
25512550
$("#stText").text("");
25522551
$("#stTimer").attr("data-timestamp", response.fetch_timestamp);
25532552
},
@@ -2569,6 +2568,50 @@ function refresh(serial) {
25692568
});
25702569
}
25712570

2571+
function refreshSingle(serial, first) {
2572+
if(ajax_inprogress_single) {
2573+
clearTimeout(periodical_focus);
2574+
if (first) {
2575+
periodical_focus = setTimeout(refreshSingle, 2000, serial, first);
2576+
} else {
2577+
periodical_focus = setTimeout(refreshSingle, 2000, serial);
2578+
}
2579+
return;
2580+
}
2581+
2582+
if (first === undefined) {
2583+
first = false;
2584+
}
2585+
2586+
ajax_inprogress_single = true;
2587+
2588+
var mode = wvar.mode.toLowerCase();
2589+
mode = (mode == "position") ? "latest" : mode.replace(/ /g,"");
2590+
2591+
if (first){
2592+
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=0&vehicles=" + encodeURIComponent(serial);
2593+
} else {
2594+
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=" + position_id + "&vehicles=" + encodeURIComponent(serial);
2595+
}
2596+
2597+
ajax_positions_single = $.ajax({
2598+
type: "GET",
2599+
url: data_url,
2600+
data: data_str,
2601+
dataType: "json",
2602+
success: function(response, textStatus) {
2603+
response.fetch_timestamp = Date.now();
2604+
if (!first) {update(response, false);} else {
2605+
update(response, true);
2606+
}
2607+
},
2608+
complete: function(request, textStatus) {
2609+
clearTimeout(periodical_focus);
2610+
periodical_focus = setTimeout(refreshSingle, timer_seconds_focus * 1000, serial);
2611+
}
2612+
});
2613+
}
2614+
25722615
function refreshReceivers() {
25732616
// if options to hide receivers is selected do nothing
25742617
if(offline.get('opt_hide_receivers')) return;
@@ -2828,13 +2871,15 @@ function habitat_doc_step(hab_docs) {
28282871
}
28292872

28302873

2831-
var periodical, periodical_receivers, periodical_recoveries;
2874+
var periodical, periodical_focus, periodical_receivers, periodical_recoveries;
28322875
var periodical_predictions = null;
28332876
var timer_seconds = 5;
2877+
var timer_seconds_focus = 1;
28342878

28352879
function startAjax() {
28362880
// prevent insane clicks to start numerous requests
28372881
clearTimeout(periodical);
2882+
clearTimeout(periodical_focus);
28382883
clearTimeout(periodical_receivers);
28392884
clearTimeout(periodical_recoveries);
28402885
clearTimeout(periodical_predictions);
@@ -2853,6 +2898,8 @@ function stopAjax() {
28532898
clearTimeout(periodical);
28542899
if(ajax_positions) ajax_positions.abort();
28552900

2901+
clearTimeout(periodical_focus);
2902+
28562903
clearTimeout(periodical_predictions);
28572904
periodical_predictions = null;
28582905
if(ajax_predictions) ajax_predictions.abort();
@@ -3211,7 +3258,11 @@ function update(response, flag) {
32113258
// if no vehicles are found, this will remove the spinner and put a friendly message
32123259
$("#main .empty").html("<span>No vehicles :(</span>");
32133260

3214-
ajax_inprogress = false;
3261+
if (flag === undefined) {
3262+
ajax_inprogress = false;
3263+
} else {
3264+
ajax_inprogress_single = false;
3265+
}
32153266

32163267
return;
32173268
}
@@ -3273,11 +3324,7 @@ function update(response, flag) {
32733324
if(vehicle === undefined) return;
32743325

32753326
if(vehicle.updated) {
3276-
if (flag) {
3277-
updatePolyline(vcallsign, true);
3278-
} else {
3279-
updatePolyline(vcallsign);
3280-
}
3327+
updatePolyline(vcallsign, flag);
32813328

32823329
updateVehicleInfo(vcallsign, vehicle.curr_position);
32833330

@@ -3313,7 +3360,11 @@ function update(response, flag) {
33133360

33143361
if(periodical_predictions === null) refreshPredictions();
33153362

3316-
ajax_inprogress = false;
3363+
if (flag === undefined) {
3364+
ajax_inprogress = false;
3365+
} else {
3366+
ajax_inprogress_single = false;
3367+
}
33173368
}
33183369
};
33193370

0 commit comments

Comments
 (0)