<commit_before>var socket = io();

function removeDuplicates(arr) {
	var seen = {};
	var out = [];
	var len = arr.length;
	var j = 0;
	for (var i = 0; i < len; i++) {
		var item = arr[i];
		if (seen[item] !== 1) {
			seen[item] = 1;
			out[j++] = item;
		}
	 }
	return out;
}
function debounce(fn, threshold) {
	var timeout;
	return function debounced() {
		if (timeout) {
			clearTimeout(timeout);
		}

		function delayed() {
			fn();
			timeout = null;
		}
		timeout = setTimeout(delayed, threshold || 100);
	}
}
function hideLeftbar(time, button) {
	$(".leftbar").velocity({
		left: "-260px"
	}, time);
	$(".documents_list").velocity({
		left: "40px"
	}, time);
	$(button).removeClass("glyphicon-chevron-left").addClass("glyphicon-chevron-right");
	$(button).velocity({
		left: "10px"
	}, time);
	setTimeout(function() {
		$(".documents_list").css("width", "calc(100vw - 60px)")
		$grid.isotope();
	}, time)
}
function showLeftbar(time, button) {
	$(".leftbar").velocity({
		left: "0px"
	}, time);
	$(".documents_list").velocity({
		left: "300px"
	}, time);
	$(button).removeClass("glyphicon-chevron-right").addClass("glyphicon-chevron-left");
	$(button).velocity({
		left: "220px"
	}, time);
	setTimeout(function() {
		$(".documents_list").css("width", "calc(100vw - 320px)")
		$grid.isotope();
	}, time);
}
jQuery.fn.flash = function(color, duration) {
	var current = this.css('backgroundColor');
	this.animate({
		backgroundColor: color
	}, duration / 2).animate({
		backgroundColor: current
	}, duration / 2);
}
function showDropHere() {
	$("#add_file_sign").removeClass("glyphicon-plus")
	$("#add_file_sign").html("Drop Here");
	$(".add_file").css("background-color", "#f5f5f5");
	$("#add_file_sign").css("font-size", "40px");
}
function hideDropHere() {
	$("#add_file_sign").addClass("glyphicon-plus")
	$("#add_file_sign").html("");
	$(".add_file").css("background-color", "#e9e9e9")
	$("#add_file_sign").css("font-size", "60px");
}
function loadTeamFolders() {
	sendAjax("GET", "/folders/team", function(folders) {
		for (var i = 0; i < folders.length; i++) {
			var li = document.createElement("li");
			$(li).attr("data-folderid", folders[i]._id);
			$(li).addClass("drive_name");
			$(li).append('<span id="make_drive" class="glyphicon glyphicon-folder-open"></span>'+folders[i].name);
			$(".folders_list").append($(li));
		}
		setTimeout(function() { //finde better way
			$(".folders_list").children().first().next().next().trigger("click")
		},100)
	});
}
function newTeamFolderModal(title) {
	var new_modal = new jBox('Modal', {
		width: 350,
		height: 373,
		title: title,
		onClose: function() {
			setTimeout(function() {
				team_folder_modal.destroy();  //keyword "this" does not work. make sure to name the modal "team_folder_modal".
			}, 100)
		}
	});
	var span = document.createElement("span");
	var folder_name = '<input type="text" id="folder_name" class="name_input" placeholder="Group Name" />';
	var user_search = '<input type="text" placeholder="Search Names..." class="members_search" id="folder_members_search">';
	var potential_members = document.createElement("div");
	$(potential_members).attr("id", "potential_folder_members");
	$(potential_members).addClass("potential_members");
	$(potential_members).addClass("medium-tall");
	var make_team_folder = '<input type="button" id="make_team_folder" class="button done_button" value="Done">'
	sendAjax("GET", "/subdivisions/joined", function(subdivisions) {
		for (var i = 0; i < subdivisions.length; i++) {
			var subdivision = document.createElement("p");
			$(subdivision).addClass("potential_subdivision");
			$(subdivision).attr("data-subdivisionid", subdivisions[i]._id);
			$(subdivision).html(subdivisions[i].name);
			$(potential_members).append(subdivision);
		}
	}, { async: false }); // TODO: should this really be synchronous?

	sendAjax("GET", "/teams/current/users", function(users) {
		for (var i = 0; i < users.length; i++) {
			var user = document.createElement("p");
			$(user).addClass("potential_member");
			$(user).attr("data-userid", users[i]._id);
			$(user).html(users[i].firstname + " " + users[i].lastname);
			$(potential_members).append(user);
			if (users[i]._id == localStorage._id) {
				$(user).addClass("clicked");
				$(user).addClass("hidden");
			}
		}
		$(span).append($(folder_name));
		$(span).append($(user_search));
		$(span).append("<br/>");
		$(span).append($(potential_members));
		$(span).append("<br/>");
		$(span).append($(make_team_folder));
		new_modal.setContent($(span));
		new_modal.open();
	})
	return new_modal;
}
function addFileModal(title) {
	var new_modal = new jBox('Modal', {
		width: 300,
		height: 230,
		title: 'Upload a File',
		onOpen: function() {
			$("#chosen_file").html("No File Selected");
			$("#file").val("");
			$(".file_name")[0].value = "";
			document.getElementById("file").onchange = function() {
				uploads = this.files;
				if (this.files.length == 1) {
					document.getElementById("chosen_file").innerHTML = this.files[0].name;
					setTimeout(function() {
						$("#chosen_file").flash("#0099ff", 1000);
					}, 300);
				} else {
					document.getElementById("chosen_file").innerHTML = "Multiple Selected";
					setTimeout(function() {
						$("#chosen_file").flash("#0099ff", 1000);
					}, 300);
				}
			};

		},
		onClose: function() {
			setTimeout(function() {
				add_file_modal.destroy(); //keyword "this" does not work. make sure to name the modal "add_file_modal".
			}, 100)
		}
	});
	new_modal.setContent("<form enctype='multipart/form-data' action='/files' method='post' id='upload_form'><input type='file' id='file' class='hidden' name='uploadedFile'></input><input type='button' class='button file_choose' value='Choose File'></input><p id='chosen_file'>No File Selected</p><input type='text' class='file_name' name='fileName' placeholder='File Name'></input><input type='submit' class='button upload_button' value='Upload'></input></form>");
	new_modal.open();
	return new_modal;
}
function bytesToSize(bytes) {
	if (bytes < 1000) {
		return +bytes.toFixed(2) + " Bytes";
	} else if (bytes < 1000000) {
		return +(bytes/1000).toFixed(2)+ " KB"<commit_msg>Fix path to upload file in drive<commit_after>var socket = io();

function removeDuplicates(arr) {
	var seen = {};
	var out = [];
	var len = arr.length;
	var j = 0;
	for (var i = 0; i < len; i++) {
		var item = arr[i];
		if (seen[item] !== 1) {
			seen[item] = 1;
			out[j++] = item;
		}
	 }
	return out;
}
function debounce(fn, threshold) {
	var timeout;
	return function debounced() {
		if (timeout) {
			clearTimeout(timeout);
		}

		function delayed() {
			fn();
			timeout = null;
		}
		timeout = setTimeout(delayed, threshold || 100);
	}
}
function hideLeftbar(time, button) {
	$(".leftbar").velocity({
		left: "-260px"
	}, time);
	$(".documents_list").velocity({
		left: "40px"
	}, time);
	$(button).removeClass("glyphicon-chevron-left").addClass("glyphicon-chevron-right");
	$(button).velocity({
		left: "10px"
	}, time);
	setTimeout(function() {
		$(".documents_list").css("width", "calc(100vw - 60px)")
		$grid.isotope();
	}, time)
}
function showLeftbar(time, button) {
	$(".leftbar").velocity({
		left: "0px"
	}, time);
	$(".documents_list").velocity({
		left: "300px"
	}, time);
	$(button).removeClass("glyphicon-chevron-right").addClass("glyphicon-chevron-left");
	$(button).velocity({
		left: "220px"
	}, time);
	setTimeout(function() {
		$(".documents_list").css("width", "calc(100vw - 320px)")
		$grid.isotope();
	}, time);
}
jQuery.fn.flash = function(color, duration) {
	var current = this.css('backgroundColor');
	this.animate({
		backgroundColor: color
	}, duration / 2).animate({
		backgroundColor: current
	}, duration / 2);
}
function showDropHere() {
	$("#add_file_sign").removeClass("glyphicon-plus")
	$("#add_file_sign").html("Drop Here");
	$(".add_file").css("background-color", "#f5f5f5");
	$("#add_file_sign").css("font-size", "40px");
}
function hideDropHere() {
	$("#add_file_sign").addClass("glyphicon-plus")
	$("#add_file_sign").html("");
	$(".add_file").css("background-color", "#e9e9e9")
	$("#add_file_sign").css("font-size", "60px");
}
function loadTeamFolders() {
	sendAjax("GET", "/folders/team", function(folders) {
		for (var i = 0; i < folders.length; i++) {
			var li = document.createElement("li");
			$(li).attr("data-folderid", folders[i]._id);
			$(li).addClass("drive_name");
			$(li).append('<span id="make_drive" class="glyphicon glyphicon-folder-open"></span>'+folders[i].name);
			$(".folders_list").append($(li));
		}
		setTimeout(function() { //finde better way
			$(".folders_list").children().first().next().next().trigger("click")
		},100)
	});
}
function newTeamFolderModal(title) {
	var new_modal = new jBox('Modal', {
		width: 350,
		height: 373,
		title: title,
		onClose: function() {
			setTimeout(function() {
				team_folder_modal.destroy();  //keyword "this" does not work. make sure to name the modal "team_folder_modal".
			}, 100)
		}
	});
	var span = document.createElement("span");
	var folder_name = '<input type="text" id="folder_name" class="name_input" placeholder="Group Name" />';
	var user_search = '<input type="text" placeholder="Search Names..." class="members_search" id="folder_members_search">';
	var potential_members = document.createElement("div");
	$(potential_members).attr("id", "potential_folder_members");
	$(potential_members).addClass("potential_members");
	$(potential_members).addClass("medium-tall");
	var make_team_folder = '<input type="button" id="make_team_folder" class="button done_button" value="Done">'
	sendAjax("GET", "/subdivisions/joined", function(subdivisions) {
		for (var i = 0; i < subdivisions.length; i++) {
			var subdivision = document.createElement("p");
			$(subdivision).addClass("potential_subdivision");
			$(subdivision).attr("data-subdivisionid", subdivisions[i]._id);
			$(subdivision).html(subdivisions[i].name);
			$(potential_members).append(subdivision);
		}
	}, { async: false }); // TODO: should this really be synchronous?

	sendAjax("GET", "/teams/current/users", function(users) {
		for (var i = 0; i < users.length; i++) {
			var user = document.createElement("p");
			$(user).addClass("potential_member");
			$(user).attr("data-userid", users[i]._id);
			$(user).html(users[i].firstname + " " + users[i].lastname);
			$(potential_members).append(user);
			if (users[i]._id == localStorage._id) {
				$(user).addClass("clicked");
				$(user).addClass("hidden");
			}
		}
		$(span).append($(folder_name));
		$(span).append($(user_search));
		$(span).append("<br/>");
		$(span).append($(potential_members));
		$(span).append("<br/>");
		$(span).append($(make_team_folder));
		new_modal.setContent($(span));
		new_modal.open();
	})
	return new_modal;
}
function addFileModal(title) {
	var new_modal = new jBox('Modal', {
		width: 300,
		height: 230,
		title: 'Upload a File',
		onOpen: function() {
			$("#chosen_file").html("No File Selected");
			$("#file").val("");
			$(".file_name")[0].value = "";
			document.getElementById("file").onchange = function() {
				uploads = this.files;
				if (this.files.length == 1) {
					document.getElementById("chosen_file").innerHTML = this.files[0].name;
					setTimeout(function() {
						$("#chosen_file").flash("#0099ff", 1000);
					}, 300);
				} else {
					document.getElementById("chosen_file").innerHTML = "Multiple Selected";
					setTimeout(function() {
						$("#chosen_file").flash("#0099ff", 1000);
					}, 300);
				}
			};

		},
		onClose: function() {
			setTimeout(function() {
				add_file_modal.destroy(); //keyword "this" does not work. make sure to name the modal "add_file_modal".
			}, 100)
		}
	});
	new_modal.setContent("<form enctype='multipart/form-data' action='/files/upload' method='post' id='upload_form'><input type='file' id='file' class='hidden' name='uploadedFile'></input><input type='button' class='button file_choose' value='Choose File'></input><p id='chosen_file'>No File Selected</p><input type='text' class='file_name' name='fileName' placeholder='File Name'></input><input type='submit' class='button upload_button' value='Upload'></input></form>");
	new_modal.open();
	return new_modal;
}
function bytesToSize(bytes) {
	if (bytes < 1000) {
		return +bytes.toFixed(2) + " Bytes";
	} else if (bytes < 1000000) {
		return +(bytes/1000).toFixed(2)+ " KB"
{'fraction_non_alphanumeric': 0.20972718415069827, 'fraction_numerical': 0.017862942513803184, 'mean_word_length': 4.915946205571566, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 41, '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': '3597021', 'n_tokens_mistral': 4775, 'n_tokens_neox': 4174, 'n_words': 775}