<commit_before>/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function(){
    // Sets up click behavior on all button elements with the alert class
    // that exist in the DOM when the instruction was executed
	$.dynatableSetup({
		features: {
		  paginate: true,
		  sort: true,
		  pushState: true,
		  search: false,
		  recordCount: true,
		  perPageSelect: false
		},
		params: {
			records: "_root"
		}
	});
	
    $("#loc_type_input").on( "change", function(event) {updateLocationList(event)});
	
    $("#query-submit").on( "click", function(event) {
		event.preventDefault();
		event.stopPropagation();
		updateTable();
    });
	
	/* Kick off the fancy selects */
	$('.selectpicker').selectpicker();
	
	initSelectMap();
});

var dynamicTable = null;

function updateTable() {
	var url = buildDataUrl();
	console.log( "Submitting the AJAX Request as: " + url);
	
	$("table.hidden").show();
	
	$.ajax({
		dataType: "json",
		url: url,
		success: tableDataReady
	});

	
}

var tableDataReady = function(data) {
	
	var records = data.items;
	
	for (i=0; i<data.items.length; i++) {
		var item = data.items[i];
		var link = item['link']['url'];
		item['url'] = link;
		
		var resource = item['browseCategories'][0];
		item['resource'] = resource;
		
		var contacts = item['contacts'];
		for (j=0; j<contacts.length; j++) {
			var contact = contacts[j];
			var type = contact['contactType'];
			
			if (type == null) type = contact['type'];
			
			if ("Point of Contact" == type) {
				item['contact'] = contact['name'] + " (Point of Contact)";
				break;
			} else if ("Author" == type) {
				item['contact'] = contact['name'] + " (Author)";
				break;
			} else if ("Project Chief" == type) {
				item['contact'] = contact['name'] + " (Project Chief)";
				break;
			} else {
				item['contact'] = "???"
			}
			
		}
	}
	
	if (dynamicTable == null) {
		$("#query-results-table").dynatable({
			dataset: {
				records: records
			},
			writers: {
				_cellWriter: writeCell
			}
		});
		
		dynamicTable = $("#query-results-table").data('dynatable');
	} else {
		dynamicTable.processingIndicator.show();
		dynamicTable.records.updateFromJson(records);
		dynamicTable.dom.update();
		dynamicTable.processingIndicator.hide();

	}
	
};

function writeCell(column, record) {
    var html = glriAttributeWriter(column, record);
    var td = '<td';

    if (column.hidden || column.textAlign) {
      td += ' style="';

      // keep cells for hidden column headers hidden
      if (column.hidden) {
        td += 'display: none;';
      }

      // keep cells aligned as their column headers are aligned
      if (column.textAlign) {
        td += 'text-align: ' + column.textAlign + ';';
      }

      td += '"';
    }
	
    html = td + '>' + html + '</td>';
	
	return html;
 };
 
 function glriAttributeWriter(column, record) {

	var text;
	var id = column['id'];
	var val = record[id];
	
	if (id == "url") {
		text = "<a href=\"" + val + "\" target=\"_blank\">link</a>";
	} else if (id == "title") {
		
		var type = record['resource'];
		
		
		text = "<a class=\"resource-type\" title=\"" + type + ": Click to go directly to this record in ScienceBase\" href=\"" + record["url"] + "\" target=\"_blank\">";
		
		text += "<img src=\"style/image/";
		
		if ("Data" == type) {
			text += "data.svg";
		} else if ("Project" == type) {
			text += "project.svg";
		} else if ("Publication" == type) {
			text += "publication.svg";
		} else {
			text += "unknown_type.svg";
		}
		
		text += "\"/>";
		
		text += "</a>";
		
		text += "<h5>" + val + "</h5>";
	} else {
		text = record[id];
	}
    return text;
 };

function buildDataUrl() {
	var url = $("#sb-query-form").attr("action");
	url += "?" + $("#sb-query-form").serialize();
	return url;
}

function updateLocationList(event) {
	
	//location type just selected by the user
	var typeSelection = event.currentTarget.options[event.currentTarget.selectedIndex].value;
	
	$("#loc_name_input optgroup").each(function() {
		if (this.label.indexOf(typeSelection + "s") == 0) {
			$(this).removeAttr("disabled");
		} else {
			$(this).attr("disabled", "disabled");
		}
	});
	
	//No location selection made prior to this is valid, so clear out.
	$("#loc_name_input").val("");
}


///////////
// Map Functions
///////////
function initSelectMap() {
	
	var lon = -85.47;
	var lat = 45.35;
	var zoom = 5.25;
	var map, wmsLayer, boxLayer;<commit_msg>Fixed.<commit_after>/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function(){
    // Sets up click behavior on all button elements with the alert class
    // that exist in the DOM when the instruction was executed
	$.dynatableSetup({
		features: {
		  paginate: true,
		  sort: true,
		  pushState: true,
		  search: false,
		  recordCount: true,
		  perPageSelect: false
		},
		params: {
			records: "_root"
		}
	});
	
    $("#loc_type_input").on( "change", function(event) {updateLocationList(event)});
	
    $("#query-submit").on( "click", function(event) {
		event.preventDefault();
		event.stopPropagation();
		updateTable();
    });
	
	/* Kick off the fancy selects */
	$('.selectpicker').selectpicker();
	
	initSelectMap();
});

var dynamicTable = null;

function updateTable() {
	var url = buildDataUrl();
	console.log( "Submitting the AJAX Request as: " + url);
	
	$("table.hidden").show();
	
	$.ajax({
		dataType: "json",
		url: url,
		success: tableDataReady
	});

	
}

var tableDataReady = function(data) {
	
	var records = data.items;
	
	for (i=0; i<data.items.length; i++) {
		var item = data.items[i];
		var link = item['link']['url'];
		item['url'] = link;
		
		var resource = item['browseCategories'][0];
		item['resource'] = resource;
		
		var contacts = item['contacts'];
		for (j=0; j<contacts.length; j++) {
			var contact = contacts[j];
			var type = contact['contactType'];
			
			if (type == null) type = contact['type'];
			
			if ("Point of Contact" == type) {
				item['contact'] = contact['name'] + " (Point of Contact)";
				break;
			} else if ("Author" == type) {
				item['contact'] = contact['name'] + " (Author)";
				break;
			} else if ("Project Chief" == type) {
				item['contact'] = contact['name'] + " (Project Chief)";
				break;
			} else {
				item['contact'] = "???"
			}
			
		}
	}
	
	if (dynamicTable == null) {
		$("#query-results-table").dynatable({
			dataset: {
				records: records
			},
			writers: {
				_cellWriter: writeCell
			}
		});
		
		dynamicTable = $("#query-results-table").data('dynatable');
	} else {
		dynamicTable.processingIndicator.show();
		dynamicTable.records.updateFromJson(records);
		dynamicTable.dom.update();
		dynamicTable.processingIndicator.hide();

	}
	
};

function writeCell(column, record) {
    var html = glriAttributeWriter(column, record);
    var td = '<td';

    if (column.hidden || column.textAlign) {
      td += ' style="';

      // keep cells for hidden column headers hidden
      if (column.hidden) {
        td += 'display: none;';
      }

      // keep cells aligned as their column headers are aligned
      if (column.textAlign) {
        td += 'text-align: ' + column.textAlign + ';';
      }

      td += '"';
    }
	
    html = td + '>' + html + '</td>';
	
	return html;
 };
 
 function glriAttributeWriter(column, record) {

	var text;
	var id = column['id'];
	var val = record[id];
	
	if (id == "url") {
		text = "<a href=\"" + val + "\" target=\"_blank\">link</a>";
	} else if (id == "title") {
		
		var type = record['resource'];
		
		
		text = "<a class=\"resource-type\" title=\"" + type + ": Click to go directly to this record in ScienceBase\" href=\"" + record["url"] + "\" target=\"_blank\">";
		
		text += "<img src=\"style/image/";
		
		if ("Data" == type) {
			text += "data.svg";
		} else if ("Project" == type) {
			text += "project.svg";
		} else if ("Publication" == type) {
			text += "publication.svg";
		} else {
			text += "unknown_type.svg";
		}
		
		text += "\"/>";
		
		text += "</a>";
		
		text += "<h5>" + val + "</h5>";
	} else {
		text = record[id];
	}
    return text;
 };

function buildDataUrl() {
	var url = $("#sb-query-form").attr("action");
	url += "?" + $("#sb-query-form").serialize();
	return url;
}

function updateLocationList(event) {
	
	//location type just selected by the user
	var typeSelection = event.currentTarget.options[event.currentTarget.selectedIndex].value;
	
	$("#loc_name_input optgroup").each(function() {
		if (this.label.indexOf(typeSelection + "s") == 0) {
			$(this).removeAttr("disabled");
		} else {
			$(this).attr("disabled", "disabled");
		}
	});
	
	//No location selection made prior to this is valid, so clear out.
	$("#loc_name_input").val("");
	$("#loc_name_input").selectpicker('refresh')
}


///////////
// Map Functions
///////////
function initSelectMap() {
	
	var lon = -85.47;
	var lat = 45.35;
	var zoom = 5.25;
	var map, wmsLayer, boxLayer;
{'fraction_non_alphanumeric': 0.19105010601495367, 'fraction_numerical': 0.0037942193951567907, 'mean_word_length': 2.9884290164664, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5928013', 'n_tokens_mistral': 3293, 'n_tokens_neox': 2876, 'n_words': 742}