Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom selection of columns in aircraft table #72

Merged
merged 12 commits into from
Jul 21, 2020
Prev Previous commit
Next Next commit
Toggle checkbox functionality with persistence
  • Loading branch information
erictran committed Jul 9, 2020
commit 67e018cb63a9bbc587490de76934e8d8f8c3c1a5
41 changes: 41 additions & 0 deletions public_html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ function initialize() {
toggleAllPlanes(true);
})

// Event handlers for to column checkboxes
var checkboxes = ['#icao_col_checkbox' , '#flag_col_checkbox','#ident_col_checkbox',
'#reg_col_checkbox', '#ac_col_checkbox', '#squawk_col_checkbox', '#alt_col_checkbox',
'#speed_col_checkbox', '#vrate_col_checkbox', '#distance_col_checkbox',
'#heading_col_checkbox', '#messages_col_checkbox', '#msg_age_col_checkbox',
'#rssi_col_checkbox', '#lat_col_checkbox', '#lon_col_checkbox', '#datasource_col_checkbox']

checkboxes.forEach(function (element){
$(element).on('click', function() {
console.log(element)
toggleColumn(element, true);
});
});

// Force map to redraw if sidebar container is resized - use a timer to debounce
var mapResizeTimeout;
$("#sidebar_container").on("resize", function() {
Expand All @@ -353,6 +367,10 @@ function initialize() {
toggleAllPlanes(false);
toggleGroupByDataType(false);

for (var i = 0; i < checkboxes.length; i++) {
toggleColumn(checkboxes[i], false);
}

// Get receiver metadata, reconfigure using it, then continue
// with initialization
$.ajax({ url: 'data/receiver.json',
Expand Down Expand Up @@ -1999,3 +2017,26 @@ function onSetRangeRings() {

createSiteCircleFeatures();
}

function toggleColumn(div, toggled) {
if (typeof localStorage[div] === 'undefined') {
localStorage.setItem(div, 'deselected');
}

var status = localStorage.getItem(div);
var infoTable = $("#tableinfo");

if (toggled === true) {
status = (status === 'deselected') ? 'selected' : 'deselected';
}

if (status === 'selected') {
$(div).addClass('settingsCheckboxChecked');
showColumn(infoTable, '#registration', true);
} else {
$(div).removeClass('settingsCheckboxChecked');
showColumn(infoTable, '#registration', false);
}

localStorage.setItem(div, status);
}