Skip to content

Commit 71a706c

Browse files
authored
Merge pull request projecthorus#41 from LukePrior/testing
Tidy up some code
2 parents 0dedb5b + 1104054 commit 71a706c

File tree

1 file changed

+11
-91
lines changed

1 file changed

+11
-91
lines changed

js/tracker.js

Lines changed: 11 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,29 +2724,22 @@ function refresh() {
27242724
periodical = setTimeout(refresh, 2000);
27252725
return;
27262726
}
2727-
2727+
27282728
if (ajax_inprogress_old != wvar.query) {
2729-
document.getElementById("timeperiod").disabled = false;
2729+
document.getElementById("timeperiod").disabled = false;
27302730
}
27312731

27322732
ajax_inprogress = true;
27332733

27342734
$("#stText").text("checking |");
27352735

2736-
if(/[a-z0-9]{32}/ig.exec(wvar.query)) {
2737-
initHabitat();
2738-
return;
2739-
}
2740-
27412736
var mode = wvar.mode.toLowerCase();
27422737
mode = (mode == "position") ? "latest" : mode.replace(/ /g,"");
27432738

2744-
if (wvar.query) {
2745-
if (sondePrefix.indexOf(wvar.query) > -1) {
2746-
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=" + position_id + "&vehicles=";
2747-
} else {
2748-
var data_str = "mode=3days&type=positions&format=json&max_positions=" + max_positions + "&position_id=0&vehicles=" + encodeURIComponent(wvar.query);
2749-
}
2739+
if (wvar.query && sondePrefix.indexOf(wvar.query) > -1) {
2740+
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=0";
2741+
} else if (wvar.query) {
2742+
var data_str = "mode=3days&type=positions&format=json&max_positions=" + max_positions + "&position_id=0&vehicles=" + encodeURIComponent(wvar.query);
27502743
} else {
27512744
var data_str = "mode="+mode+"&type=positions&format=json&max_positions=" + max_positions + "&position_id=" + position_id + "&vehicles=" + encodeURIComponent(wvar.query);
27522745
}
@@ -2759,17 +2752,13 @@ function refresh() {
27592752
success: function(response, textStatus) {
27602753
$("#stText").text("loading |");
27612754
response.fetch_timestamp = Date.now();
2762-
if (sondePrefix.indexOf(wvar.query) > -1) {
2763-
ajax_inprogress_old = "none";
2764-
update(response);
2765-
} else if (wvar.query != null) {
2755+
if (wvar.query && sondePrefix.indexOf(wvar.query) == -1) {
27662756
if (JSON.stringify(response).indexOf(wvar.query) == -1) {
27672757
//check using new API
27682758
ajax_inprogress = false;
27692759
refreshSingleOld(wvar.query);
27702760
} else {
27712761
ajax_inprogress_old = wvar.query;
2772-
console.log(response);
27732762
update(response);
27742763
}
27752764
} else {
@@ -2782,14 +2771,11 @@ function refresh() {
27822771
error: function() {
27832772
$("#stText").text("error |");
27842773

2785-
if(!zoomed_in && offline.get('opt_offline')) {
2786-
var data = offline.get('positions');
2787-
update(data);
2788-
$("#stText").text("no connection |");
2789-
$("#stTimer").attr("data-timestamp", data.fetch_timestamp);
2790-
}
2791-
27922774
ajax_inprogress = false;
2775+
2776+
if (ajax_inprogress_old != wvar.query) {
2777+
document.getElementById("timeperiod").disabled = false;
2778+
}
27932779
},
27942780
complete: function(request, textStatus) {
27952781
if (ajax_inprogress_old != wvar.query) {
@@ -3072,72 +3058,6 @@ function habitat_payload_step(remove_current) {
30723058
});
30733059
}
30743060

3075-
function initHabitat() {
3076-
$("#stText").text("loading |");
3077-
3078-
habitat_payload_step_data = {
3079-
idx: 0,
3080-
payloads: [],
3081-
};
3082-
var habitat_docs = [];
3083-
3084-
wvar.query.split(";").forEach(function(v) {
3085-
v = v.trim();
3086-
if(/^[a-z0-9]{32}$/ig.exec(v)) habitat_docs.push(v);
3087-
})
3088-
3089-
habitat_doc_step(habitat_docs);
3090-
}
3091-
3092-
3093-
function habitat_doc_step(hab_docs) {
3094-
var docid = hab_docs.shift();
3095-
3096-
ajax_positions = $.ajax({
3097-
type: "GET",
3098-
url: habitat_url + docid,
3099-
data: "",
3100-
dataType: "json",
3101-
success: function(response, textStatus) {
3102-
if(response.type == "flight") {
3103-
if(response.payloads.length > 0) {
3104-
ts_start = convert_time(response.start) / 1000;
3105-
ts_end = convert_time(response.end) / 1000;
3106-
3107-
3108-
response.payloads.forEach( function(payload_id) {
3109-
var url = habitat_url_payload_telemetry.replace(/\{ID\}/g, payload_id);
3110-
url = url.replace("{START}", ts_start).replace("{END}", ts_end);
3111-
3112-
habitat_payload_step_data.payloads.push({
3113-
prefix: response._id.substr(-4) + "/",
3114-
url: url,
3115-
skip: 0,
3116-
});
3117-
});
3118-
}
3119-
}
3120-
else {
3121-
if(hab_docs.length === 0) update(null);
3122-
console.error("tracker: docid", docid, " is not a flight_doc");
3123-
}
3124-
3125-
if(hab_docs.length === 0) {
3126-
habitat_payload_step();
3127-
} else {
3128-
habitat_doc_step(hab_docs);
3129-
}
3130-
},
3131-
error: function() {
3132-
if(hab_docs.length === 0) update(null);
3133-
console.error("tracker: error trying to load docid", docid);
3134-
},
3135-
complete: function(request, textStatus) {
3136-
}
3137-
});
3138-
}
3139-
3140-
31413061
var periodical, periodical_focus, periodical_receivers, periodical_recoveries;
31423062
var periodical_predictions = null;
31433063
var timer_seconds = 5;

0 commit comments

Comments
 (0)