<commit_before>//////////////////////////////////////
//                                  //
//      Calendar functionality      //
//                                  //
//////////////////////////////////////
// Todo:
// NOTE: syncEvents() has FAKE length

"use strict";

$(document).ready(function() {
	// var gCalURL = 'https://www.google.com/calendar/feeds/nk1n38oqstjhj5c'+
	//				 'm87f28ljpog%40group.calendar.google.com/public/basic';
	var gCalURL = '';

	// initialize the draggable events
	$('#external-events div.external-event').each(function() {
	
		var eventObject = {};
		
		// store the Event Object in the DOM element so we can get to it later
		$(this).data('eventObject', eventObject);
		
		// make the event draggable using jQuery UI
		$(this).draggable({
			zIndex: 999,
			revert: true,      // will cause the event to go back to its
			revertDuration: 0  //  original position after the drag
		});
		
	});

	// initialize the calendar
	$('#calendar').fullCalendar({
		header: {
			left: 'prev,next today',
			center: 'title',
			right: 'month,agendaWeek'
		},
		allDaySlot : false,
		events: {
			url: gCalURL,
			backgroundColor : "#bbb",
			textColor : "#666"
			},
		editable: true,
		droppable: true, 
		drop: function(date, allDay) { 
			BNB.calendar.dropEventHandler(date, allDay, this);
		}
	});

	// Set right click event handler for context menu
	document.body.onmousedown = (function(){

		return function(e){ 

			var rightClick,
				e = e || window.event;

			// Make sure it's a right click
			if (e.which) rightClick = (e.which == 3);
			else if (e.button) rightClick = (e.button == 2);
			
			// User right clicked -- open menu
			if(rightClick) {
				BNB.calendar.rightClickMenu(e); 
				return false;
			}
		}
	})(window.event);

});
$("footer").remove();
var BNB = BNB || {};

BNB.calendar = (function(){

	var dragContainer = document.getElementById('external-events'),
		experiments = {}, 
		protocolList = {};

	getEvents(dragContainer.getAttribute('data-calendar'));

	// Sync external event Objects with the current calendar
	// Arg: URL string
	function getEvents(url){
		$.getJSON(url)
		.done(function(data){syncEvents(data);})
		.fail(function(){console.log("Failed to get a list of events.")})
	}

	// Get JSON objects from another file, done in getEvents(), and 
	// add the data to the list of draggable events
	// Arg: JSON object
	function syncEvents(p){

		var placedExperiments = [];

		// Make experiment structure from action id strings
		for(var a = 0;  a < p.events.length; a++){

			// Id string: bnb-orgId-expId-protocolId-stepId-actionId
			var expId = p.events[a].id.split("-")[2],
				protocolId = p.events[a].id.split("-")[3],
				stepId = p.events[a].id.split("-")[4],
				exp,
				protocol,
				step;

			// Create an exp object for this action if one doesn't exist with its ID
			if(!experiments[expId]){
				experiments[expId] = { 
					id: expId,
					title: p.events[a].experiment, 
					protocols: [] 
				};
			}
			exp = experiments[expId];

			// Create a Protocol object for this action if one doesn't exist with its ID
			if( !getObjInArr(exp.protocols, 'id', protocolId) ){
				exp.protocols.push({ 
					id: protocolId,
					title: p.events[a].protocol, 
					steps: [] 
				});
			}
			protocol = exp.protocols[exp.protocols.length - 1];

			// Create a step object if it doesn't exist for this step ID
			if( !getObjInArr(protocol.steps, 'id', stepId) ){
				protocol.steps.push({
					id: stepId,
					stepNumber: protocol.steps.length,
					actions: []
				});
				
			}
			var step = getObjInArr(protocol.steps, 'id', stepId);

			// + extra properties
			if(p.meta.descriptions) exp.description = p.meta.descriptions[expId];	// exp descrip
			if(!p.events[a].id) p.events[a].id = p.events[a].objectid;				// action id
			p.events[a].stepNumber = step.actions.length + 1;			       		// stepnumber

			// Add the action to its place in the structure
			step.actions.push(p.events[a]);
		}

		// Show a draggable item for each protocol the user has access to
		for(var e in experiments)
			
			var thisExp = experiments[e];

			// Create draggable node
			var eventNode = document.createElement('div');
			eventNode.className = 'custom-event';
			eventNode.innerHTML = thisExp.title;
			eventNode.setAttribute("data-id", thisExp.id);

			// Check for already placed experiments (.start != 0)
			if(thisExp.protocols[0].steps[0].actions[0].start !== 0){
				placedExperiments.push(thisExp.id);
			}

			// Protocols in experiment
			for(var b = 0, pLen = thisExp.protocols.length; b < pLen; b++){
				var thisProtocol = thisExp.protocols[b],
					pId = thisExp.protocols[b].id;

			   // Steps in protocol
			   for(var c = 0; c < thisProtocol.steps.length; c++){
			   		var thisStep = thisProtocol.steps[c],
			   			sId = thisProtocol.steps[c].id;

			   		// Actions in step
			   		for(var d = 0; d < thisStep.actions.length; d++){

				   		var thisAction = thisStep.actions[d],
				   			idArr = thisStep.actions[d].id.split("-");
				   		var eId = idArr[2],  // Experiment
				   			pId = idArr[3],  // Protocol
				   			sId = idArr[4],  // Step
				   			aId = idArr[5];  // Action
				   		var domId = 'data-'+ eId +'-'+ pId +'-'+ sId +'-'+ aId + '-';

				   		eventNode.setAttribute(domId + "title", thisAction.title);
				   		eventNode.setAttribute(domId + "verb", thisAction.verb);
				   		eventNode.setAttribute(domId + "step-number", thisAction.stepNumber);
				   		eventNode.setAttribute(domId + "active", thisAction.active);
						eventNode.setAttribute(domId + "notes", thisAction.notes);
						eventNode.setAttribute(domId + "length", /*thisAction.duration*/ 6000);
						eventNode.setAttribute(domId + "event-id", thisAction.id);
						eventNode.setAttribute(domId + "eid", eId);
						eventNode.setAttribute(domId + "pid", pId);
						eventNode.setAttribute(domId + "sid", sId);
						eventNode.setAttribute(domId + "aid", aId);
			   }
			}
<commit_msg>Removed testing stuff<commit_after>//////////////////////////////////////
//                                  //
//      Calendar functionality      //
//                                  //
//////////////////////////////////////
// Todo:
// NOTE: syncEvents() has FAKE length

"use strict";

$(document).ready(function() {
	// var gCalURL = 'https://www.google.com/calendar/feeds/nk1n38oqstjhj5c'+
	//				 'm87f28ljpog%40group.calendar.google.com/public/basic';
	var gCalURL = '';

	// initialize the draggable events
	$('#external-events div.external-event').each(function() {
	
		var eventObject = {};
		
		// store the Event Object in the DOM element so we can get to it later
		$(this).data('eventObject', eventObject);
		
		// make the event draggable using jQuery UI
		$(this).draggable({
			zIndex: 999,
			revert: true,      // will cause the event to go back to its
			revertDuration: 0  //  original position after the drag
		});
		
	});

	// initialize the calendar
	$('#calendar').fullCalendar({
		header: {
			left: 'prev,next today',
			center: 'title',
			right: 'month,agendaWeek'
		},
		allDaySlot : false,
		events: {
			url: gCalURL,
			backgroundColor : "#bbb",
			textColor : "#666"
			},
		editable: true,
		droppable: true, 
		drop: function(date, allDay) { 
			BNB.calendar.dropEventHandler(date, allDay, this);
		}
	});

	// Set right click event handler for context menu
	document.body.onmousedown = (function(){

		return function(e){ 

			var rightClick,
				e = e || window.event;

			// Make sure it's a right click
			if (e.which) rightClick = (e.which == 3);
			else if (e.button) rightClick = (e.button == 2);
			
			// User right clicked -- open menu
			if(rightClick) {
				BNB.calendar.rightClickMenu(e); 
				return false;
			}
		}
	})(window.event);

});

var BNB = BNB || {};

BNB.calendar = (function(){

	var dragContainer = document.getElementById('external-events'),
		experiments = {}, 
		protocolList = {};

	getEvents(dragContainer.getAttribute('data-calendar'));

	// Sync external event Objects with the current calendar
	// Arg: URL string
	function getEvents(url){
		$.getJSON(url)
		.done(function(data){syncEvents(data);})
		.fail(function(){console.log("Failed to get a list of events.")})
	}

	// Get JSON objects from another file, done in getEvents(), and 
	// add the data to the list of draggable events
	// Arg: JSON object
	function syncEvents(p){

		var placedExperiments = [];

		// Make experiment structure from action id strings
		for(var a = 0;  a < p.events.length; a++){

			// Id string: bnb-orgId-expId-protocolId-stepId-actionId
			var expId = p.events[a].id.split("-")[2],
				protocolId = p.events[a].id.split("-")[3],
				stepId = p.events[a].id.split("-")[4],
				exp,
				protocol,
				step;

			// Create an exp object for this action if one doesn't exist with its ID
			if(!experiments[expId]){
				experiments[expId] = { 
					id: expId,
					title: p.events[a].experiment, 
					protocols: [] 
				};
			}
			exp = experiments[expId];

			// Create a Protocol object for this action if one doesn't exist with its ID
			if( !getObjInArr(exp.protocols, 'id', protocolId) ){
				exp.protocols.push({ 
					id: protocolId,
					title: p.events[a].protocol, 
					steps: [] 
				});
			}
			protocol = exp.protocols[exp.protocols.length - 1];

			// Create a step object if it doesn't exist for this step ID
			if( !getObjInArr(protocol.steps, 'id', stepId) ){
				protocol.steps.push({
					id: stepId,
					stepNumber: protocol.steps.length,
					actions: []
				});
				
			}
			var step = getObjInArr(protocol.steps, 'id', stepId);

			// + extra properties
			if(p.meta.descriptions) exp.description = p.meta.descriptions[expId];	// exp descrip
			if(!p.events[a].id) p.events[a].id = p.events[a].objectid;				// action id
			p.events[a].stepNumber = step.actions.length + 1;			       		// stepnumber

			// Add the action to its place in the structure
			step.actions.push(p.events[a]);
		}

		// Show a draggable item for each protocol the user has access to
		for(var e in experiments)
			
			var thisExp = experiments[e];

			// Create draggable node
			var eventNode = document.createElement('div');
			eventNode.className = 'custom-event';
			eventNode.innerHTML = thisExp.title;
			eventNode.setAttribute("data-id", thisExp.id);

			// Check for already placed experiments (.start != 0)
			if(thisExp.protocols[0].steps[0].actions[0].start !== 0){
				placedExperiments.push(thisExp.id);
			}

			// Protocols in experiment
			for(var b = 0, pLen = thisExp.protocols.length; b < pLen; b++){
				var thisProtocol = thisExp.protocols[b],
					pId = thisExp.protocols[b].id;

			   // Steps in protocol
			   for(var c = 0; c < thisProtocol.steps.length; c++){
			   		var thisStep = thisProtocol.steps[c],
			   			sId = thisProtocol.steps[c].id;

			   		// Actions in step
			   		for(var d = 0; d < thisStep.actions.length; d++){

				   		var thisAction = thisStep.actions[d],
				   			idArr = thisStep.actions[d].id.split("-");
				   		var eId = idArr[2],  // Experiment
				   			pId = idArr[3],  // Protocol
				   			sId = idArr[4],  // Step
				   			aId = idArr[5];  // Action
				   		var domId = 'data-'+ eId +'-'+ pId +'-'+ sId +'-'+ aId + '-';

				   		eventNode.setAttribute(domId + "title", thisAction.title);
				   		eventNode.setAttribute(domId + "verb", thisAction.verb);
				   		eventNode.setAttribute(domId + "step-number", thisAction.stepNumber);
				   		eventNode.setAttribute(domId + "active", thisAction.active);
						eventNode.setAttribute(domId + "notes", thisAction.notes);
						eventNode.setAttribute(domId + "length", thisAction.duration);
						eventNode.setAttribute(domId + "event-id", thisAction.id);
						eventNode.setAttribute(domId + "eid", eId);
						eventNode.setAttribute(domId + "pid", pId);
						eventNode.setAttribute(domId + "sid", sId);
						eventNode.setAttribute(domId + "aid", aId);
			   }
			}

{'fraction_non_alphanumeric': 0.15949941206114565, 'fraction_numerical': 0.006551318662859062, 'mean_word_length': 2.5810526315789475, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4544128', 'n_tokens_mistral': 4655, 'n_tokens_neox': 3855, 'n_words': 948}