<commit_before>/*
*	This document contains the calls to the Trello API
*	Created by : 	<NAME>
*	Created on : 	24/02/2015
*	Modified by :	*Append your name here*
*	Last modified: 	24/02/2015
*/
var $dictTotal = {};
var $dictStates = {};
var $dictBoards = {};
var $dictCards = {};
var $counter = true;
$(document).ready(function(){
	
updateLoggedIn;

var onAuthorize = function() {
    updateLoggedIn();
    $("#output").empty();
    
    Trello.members.get("me", function(member){
        $("#fullName").text(member.fullName);
	});
			
		var $dict = {};
		var $dictName = {};
		
		//Output a list of all status
		//Get all the boards the current user has access to
		$.when(Trello.get("members/me/boards", function(boards) {
			$.each(boards, function(ix, board) {
				if(board.name != "Welcome Board"){
					$dictBoards[board.name] = board.name;
					//Get all the lists the user has access to
					Trello.boards.get(board.id, {lists:"open"}, function(states){
						$dict = {}
						$.each(states.lists, function(ic, list){
							//Throw away the lists that are in "Done" state
							if(list.name.indexOf("Done")== -1){
								$dictStates[list.name] = list.name;
							}
						});
						write();
					}); 
				}
			});
		}));
};

function write(){
	$("#boards").empty();
	$("#state").empty();
	//Show the menu with the Board Name
	for (board in $dictBoards){
		$board = $("<li>")
		.attr({id:board, onclick:"loadBoard('"+board+"')"})
        .appendTo("#boards");
		$board = $("<a>")
		.attr({href:"#"})
        .text(board)
		.appendTo(document.getElementById(board));
	}
	//Show the menu with the List Name aka State
	for (state in $dictStates){
		$state = $("<li>")
		.attr({id:state, onclick:"loadState('"+state+"')"})
        .appendTo("#state");
		$state = $("<a>")
		.attr({href:"#"})
        .text(state)
		.appendTo(document.getElementById(state));
	}
	
}

var updateLoggedIn = function() {
    var isLoggedIn = Trello.authorized();
    $(".loggedout").toggle(!isLoggedIn);
    $(".loggedin").toggle(isLoggedIn);        
};
    
var logout = function() {
    Trello.deauthorize();
    updateLoggedIn();
};
                          
Trello.authorize({
    interactive:false,
    success: onAuthorize
});

$("#connectLink").click(function(){
    Trello.authorize({
        type: "popup",
		name: "SuperMetaBoard",
        success: onAuthorize
    })
});
    
$("#disconnect").click(logout);

});

function loadBoard(id){
	$("#content").empty();
	//Show the title of which board we load
	$board = $("<div>").attr({class:"boardTitle"}).text(id).appendTo("#content");
	//Get all the list in the current board
	for(list in $dictTotal[id]){
		//Get all the card in the current list
		//Write a list
		$list = $("<div>").attr({id:list, class:"list"}).appendTo("#content");
		$state = $("<div>").attr({id:list+"State", class:"state"}).text(list).appendTo($list);
		for(card in $dictTotal[id][list]){
			//Writes a card
			$card = $("<div>").attr({id:card, class:"card"}).appendTo($list);
			
			$title = $("<div>").attr({id:card+"Title", class:"title", onclick:"show('"+card.replace(/ /g,'')+"')"}).text(card).appendTo($card);
			//If the card has a content
			//NEED TO UPDATE THIS PART TO SUPPORT THE USER
			if($dictTotal[id][list][card] != ""){
				
				for(desc in $dictTotal[id][list][card]){
					console.log(desc);
				}
				
				var $plus = $("<span>").attr({id:card.replace(/ /g,'')+"plus"}).text(" +").appendTo($title);
				$content = $("<div>").attr({id:card.replace(/ /g,'')+"Content", class:"cardContent"}).text($dictTotal[id][list][card]).appendTo($card);
				//END OF UPDATE
			}
		}
	}
}

function loadState(id){
	$("#content").empty();
	//Show the title of which state we load
	$state = $("<div>").attr({class:"stateTitle"}).text(id).appendTo("#content");
	//Get all the boards in the dictionary
	for(board in $dictTotal){
		//Get all the list in the current board
		//Write a board
		$board = $("<div>").attr({id:board, class:"board"}).appendTo("#content");
		$boardName = $("<div>").attr({id:board+"Board", class:"state"}).text(board).appendTo($board);
		for(list in $dictTotal[board]){
			//If the list is the one we are looking for we do something, else we do nothing
			if(list == id){
				for(card in $dictTotal[board][list]){
					//Writes a card
					$card = $("<div>").attr({id:card, class:"card"}).appendTo($board);
					
					$title = $("<div>").attr({id:card+"Title", class:"title", onclick:"show('"+card.replace(/ /g,'')+"')"}).text(card).appendTo($card);
					//If the card has a content
					//UPDATE START
					if($dictTotal[board][list][card] != ""){
						var $plus = $("<span>").attr({id:card.replace(/ /g,'')+"plus"}).text(" +").appendTo($title);
						$content = $("<div>").attr({id:card.replace(/ /g,'')+"Content", class:"cardContent"}).text($dictTotal[board][list][card]).appendTo($card);
					}
					//UPDATE END
				}
			}
		}
	}
}

function show(id){
	doc = document.getElementById(id+"Content").style;
	plus = document.getElementById(id+"plus");
	if(doc.display == "none" || doc.display == ""){
		doc.display="block";
		plus.innerHTML = " -"
	}else{
		doc.display="none";
		plus.innerHTML = " +"
	}
}<commit_msg>The board menu is now working, the calls to the API are done every time we want to load a board.<commit_after>/*
*	This document contains the calls to the Trello API
*	Created by : 	<NAME>
*	Created on : 	24/02/2015
*	Modified by :	*Append your name here*
*	Last modified: 	24/02/2015
*/
var $dictTotal = {};
var $dictStates = {};
var $dictBoards = {};
var $dictCards = {};
var $counter = true;
$(document).ready(function(){
	
updateLoggedIn;

var onAuthorize = function() {
    updateLoggedIn();
    $("#output").empty();
    
    Trello.members.get("me", function(member){
        $("#fullName").text(member.fullName);
	});
			
		var $dict = {};
		var $dictName = {};
		
		//Output a list of all status
		//Get all the boards the current user has access to
		$.when(Trello.get("members/me/boards", function(boards) {
			$.each(boards, function(ix, board) {
				if(board.name != "Welcome Board"){
					$dictBoards[board.name] = board.id;
					//Get all the lists the user has access to
					Trello.boards.get(board.id, {lists:"open"}, function(states){
						$dict = {}
						$.each(states.lists, function(ic, list){
							//Throw away the lists that are in "Done" state
							if(list.name.indexOf("Done")== -1){
								$dictStates[list.name] = list.id;
							}
						});
						write();
					}); 
				}
			});
		}));
};

function write(){
	$("#boards").empty();
	$("#state").empty();
	//Show the menu with the Board Name
	for (board in $dictBoards){
		$board = $("<li>")
		.attr({id:board, onclick:"loadBoard('"+board+"')"})
        .appendTo("#boards");
		$board = $("<a>")
		.attr({href:"#"})
        .text(board)
		.appendTo(document.getElementById(board));
	}
	//Show the menu with the List Name aka State
	for (state in $dictStates){
		$state = $("<li>")
		.attr({id:state, onclick:"loadState('"+state+"')"})
        .appendTo("#state");
		$state = $("<a>")
		.attr({href:"#"})
        .text(state)
		.appendTo(document.getElementById(state));
	}
	
}

var updateLoggedIn = function() {
    var isLoggedIn = Trello.authorized();
    $(".loggedout").toggle(!isLoggedIn);
    $(".loggedin").toggle(isLoggedIn);        
};
    
var logout = function() {
    Trello.deauthorize();
    updateLoggedIn();
};
                          
Trello.authorize({
    interactive:false,
    success: onAuthorize
});

$("#connectLink").click(function(){
    Trello.authorize({
        type: "popup",
		name: "SuperMetaBoard",
        success: onAuthorize
    })
});
    
$("#disconnect").click(logout);

});

function loadBoard(id){
	$("#content").empty();
	//Show the title of which board we load
	$board = $("<div>").attr({class:"boardTitle"}).text(id).appendTo("#content");
	//Get the current board Id
	boardId = $dictBoards[id];
	//Get all the list of lists the board currently has
	Trello.boards.get(boardId, {lists:"open"}, function(states){
		$.each(states.lists, function(ic, list){
			//Throw away the lists that are in "Done" state
			if(list.name.indexOf("Done")== -1){
				$list = $("<div>").attr({id:list.id, class:"list"}).appendTo("#content");
				$state = $("<div>").attr({id:list+"State", class:"state"}).text(list.name).appendTo($list);
				//Get the list of the current cards in the list
				Trello.lists.get(list.id, {cards:"open"},function (list){
					//Add all the cards in a dictionary
					$counter = 0;
					$.each(list.cards, function(iy, card){
						$card = $("<div>").attr({id:card.id, class:"card"}).appendTo(document.getElementById(list.id));
						$title = $("<div>").attr({id:card.id+"Title", class:"title", onclick:"show('"+card.id+"')"}).text(card.name).appendTo($card);
						if(card.desc != ""){
							$plus = $("<span>").attr({id:card.id+"plus"}).text(" +").appendTo($title);
							$content = $("<div>").attr({id:card.id+"Content", class:"cardContent"}).text(card.desc).appendTo($card);
						}
						if(card.idMembers != ""){
							//Get the list of all members of the current card
							Trello.members.get(card.idMembers, function(member){
								$member = $("<div>").attr({id:member.id, class:"member"}).text(member.fullName).appendTo(document.getElementById(card.id));
								if(member.avatarHash == "" || member.avatarHash == null){
									//Member doesn't have an avatar, we add his initials
									$avatar = $("<div>").attr({id:member.id+"Avatar", class:"initials"}).text(member.initials).appendTo($member);
								}else{
									//Member have an avatar, we show it
									$avatar = $("<img>").attr({id:member.id+"Avatar", class:"avatar", alt:member.username,src:"https://trello-avatars.s3.amazonaws.com/"+member.avatarHash+"/30.png"}).appendTo($member);
								}
							});
							
						}
						/*for(pos in card.idMembers){
							//Get all the member in the current card
							Trello.members.get(card.idMembers[pos], {fields:"all"}, function(member){
								if(member.avatarHash == ""){
									//Prepare the member full name + initials
									$dictUser[member.fullName] = member.initials;
								}else{
									//Prepare the member full name + image
									$dictUser[member.fullName] = member.avatarHash
								}
							});
						}
						$dictDesc[card.desc] = $dictUser;
						$dictCard[card.name] = card.desc;*/
					});
				});
			}
		});
	}); 
	//Get all the list in the current board
	/*for(list in $dictTotal[id]){
		//Get all the card in the current list
		//Write a list
		
		
		for(card in $dictTotal[id][list]){
			//Writes a card
			
			
			
			//If the card has a content
			//NEED TO UPDATE THIS PART TO SUPPORT THE USER
			if($dictTotal[id][list][card] != ""){
				
				for(desc in $dictTotal[id][list][card]){
					console.log(desc);
				}
				
				
				//END OF UPDATE
			}
		}
	}*/
}

function loadState(id){
	$("#content").empty();
	//Show the title of which state we load
	$state = $("<div>").attr({class:"stateTitle"}).text(id).appendTo("#content");
	//Get all the boards in the dictionary
	for(board in $dictTotal){
		//Get all the list in the current board
		//Write a board
		$board = $("<div>").attr({id:board, class:"board"}).appendTo("#content");
		$boardName = $("<div>").attr({id:board+"Board", class:"state"}).text(board).appendTo($board);
		for(list in $dictTotal[board]){
			//If the list is the one we are looking for we do something, else we do nothing
			if(list == id){
				for(card in $dictTotal[board][list]){
					//Writes a card
					$card = $("<div>").attr({id:card, class:"card"}).appendTo($board);
					
					$title = $("<div>").attr({id:card+"Title", class:"title", onclick:"show('"+card.replace(/ /g,'')+"')"}).text(card).appendTo($card);
					//If the card has a content
					//UPDATE START
					if($dictTotal[board][list][card] != ""){
						var $plus = $("<span>").attr({id:card.replace(/ /g,'')+"plus"}).text(" +").appendTo($title);
						$content = $("<div>").attr({id:card.replace(/ /g,'')+"Content", class:"cardContent"}).text($dictTotal[board][list][card]).appendTo($card);
					}
					//UPDATE END
				}
			}
		}
	}
}

function show(id){
	doc = document.getElementById(id+"Content").style;
	plus = document.getElementById(id+"plus");
	if(doc.display == "none" || doc.display == ""){
		doc.display="block";
		plus.innerHTML = " -"
	}else{
		doc.display="none";
		plus.innerHTML = " +"
	}
}

/*
								//Get all the cards in the current list
								Trello.lists.get(list.id, {cards:"open"},function (list){
									//Add all the cards in a dictionary
									$counter = 0;
									$.each(list.cards, function(iy, card){
										for(pos in card.idMembers){
											//Get all the member in the current card
											Trello.members.get(card.idMembers[pos], {fields:"all"}, function(member){
												
												if(member.avatarHash == ""){
													//Prepare the member full name + initials
													$dictUser[member.fullName] = member.initials;
												}else{
													//Prepare the member full name + image
													$dictUser[member.fullName] = member.avatarHash
												}
											});
										}
										$dictDesc[card.desc] = $dictUser;
										$dictCard[card.name] = card.desc;
									});
								});
								//Then we change the dictionary, and make sure we added the state in the state dictionary
								$dictName[list.name] = list.name;
								$dict[list.name] = $dictCard;


*/
{'fraction_non_alphanumeric': 0.20660356264440635, 'fraction_numerical': 0.002981292390251174, 'mean_word_length': 3.1248078696587767, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 1, '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': '1295935', 'n_tokens_mistral': 5389, 'n_tokens_neox': 4411, 'n_words': 988}