<commit_before>/**
 * Created by marti on 2017-03-26.
 */

app.factory('Model', function ($resource) {

  var useCardStats = true;
  var loggedIn = false;
  var boardsLoaded = false;
  var boards;
  var loadingCounter = 0;

  //Authorize to the trello api
  this.authorize = function(cb) {
    Trello.authorize({
      type: 'popup',
      name: 'Getting Started Application',
      scope: {
        read: 'true',
        write: 'true' },
      expiration: 'never',
      success: function() {
        console.log('Successful authentication');
        loggedIn = true;
        cb();
      },
      error: function() { console.log('Failed authentication'); }
    });
  };

  // Initialize Firebase
  var config = {
    apiKey: "AIzaSyAnGNc08nedi09D3T-vSW-kLN_lFFEjcDA",
    authDomain: "storylines-784ba.firebaseapp.com",
    databaseURL: "https://storylines-784ba.firebaseio.com",
    projectId: "storylines-784ba",
    storageBucket: "storylines-784ba.appspot.com",
    messagingSenderId: "631528991893"
  };
  firebase.initializeApp(config);

  //TODO: Assign "boards" variable by callback function
  var loadBoards = function (cb) {
    // Get all of the information about the boards you have access to
    var success = function(data) {
      boards = data;
      // console.log(boards);
      //cb(boards);
      boardsLoaded = true;
      for(var i = 0; i < boards.length; i++){
        loadCards(i, cb);
      }
      //loadAllCards(cb);
      //loadCards(cd);
      //console.log(data);
    };
    var error = function(errorMsg) {
      console.log(errorMsg);
    };
    Trello.get('/member/me/boards', success, error);
  };

  var loadCards = function (boardIndex, cb) {
    // Get all of the information about the boards you have access to
    var boardId = boards[boardIndex].id;

    var success = function(data) {
      boards[boardIndex].cards = data;
      //TODO: Uncomment this when function is implemented
      //boards[boardIndex].myCards = getUsersCards(boardIndex);

      //Calculate the statistics of the cards for this board
      //cardStats(boardIndex);
      //Call the callback when all the boards has got their cards
      if(++loadingCounter >= boards.length){
        if(useCardStats){
          cardStats(cb);
        }
        else{
          cb();
        }
      }
    };
    var error = function(errorMsg) {
      console.log(errorMsg);
    };
    Trello.get('/boards/' + boardId + '/cards', success, error);

  }
  //TODO: Return all the cards that is assigned to the logged in user
  var getUsersCards = function(boardIndex){

  }

  //TODO: Implement this
  var cardStats = function (cb) {

    for(var i = 0; i < boards.length; i++){
      //Create array for holding the stats
      boards[i].cardStats = {
        mediumPriority : 0,
        lowPriority : 0,
        highPriority : 0
      };
      //Loop through all the cards and add statistics for each
      for(var j = 0; j < boards[i].cards.length; j++){
        var card = boards[i].cards[j];
        //Check the label of the card
        var labels = card.labels;
        if(labels.length == 0){
          //Give "unlabeled" cards low priority
          boards[i].cardStats.lowPriority++;
        }
        for(var k = 0; k < labels.length; k++){
          if(labels[k].name.toLowerCase() == "high priority"){
            boards[i].cardStats.highPriority++;
            break;
          }
          else if(labels[k].name.toLowerCase() == "medium priority"){
            boards[i].cardStats.mediumPriority++;
            break;
          }
          else if(labels[k].name.toLowerCase() == "low priority"){
            boards[i].cardStats.lowPriority++;
            break;
          }
          else if(k == labels.length-1){
            //If it is the last label and it is none of the above then give it low priority
            boards[i].cardStats.lowPriority++;
            break;
          }
        }
      }
    }
    cb();
  };

  this.loadData = function (cb) {
    loadBoards(cb);
  }

  this.getBoards = function () {
    //Check if boards are not loaded
    if(!boardsLoaded){
      //console.error("Boards not loaded");
    }else{
      return boards;
    }
  };

  // Get board with specific id from the ones loaded.
  this.getBoard = function(id) {
    for(var i = 0; i < boards.length; i++) {
      if(boards[i].id == id)
        return boards[i];
    }
  }

  // Give the board with the id a new name
  this.changeBoardName = function(id, newName) {
    Trello.put('boards/'+id+'/name?value='+newName);
  }

  // Create a new board and post it to Trello
  this.createNewBoard = function() {
    Trello.post('/boards?name=New Project');
  }

  this.isLoggedIn = function () {
    return loggedIn;
  };

  this.boardsLoaded = function () {
    return boardsLoaded;
  };

  return this;

});
<commit_msg>Added the lists to the boards variable.<commit_after>/**
 * Created by marti on 2017-03-26.
 */

app.factory('Model', function ($resource) {

  var useCardStats = true;
  var loggedIn = false;
  var boardsLoaded = false;
  var boards;
  var loadingCounter = 0;

  //Authorize to the trello api
  this.authorize = function(cb) {
    Trello.authorize({
      type: 'popup',
      name: 'Getting Started Application',
      scope: {
        read: 'true',
        write: 'true' },
      expiration: 'never',
      success: function() {
        console.log('Successful authentication');
        loggedIn = true;
        cb();
      },
      error: function() { console.log('Failed authentication'); }
    });
  };

  // Initialize Firebase
  var config = {
    apiKey: "AIzaSyAnGNc08nedi09D3T-vSW-kLN_lFFEjcDA",
    authDomain: "storylines-784ba.firebaseapp.com",
    databaseURL: "https://storylines-784ba.firebaseio.com",
    projectId: "storylines-784ba",
    storageBucket: "storylines-784ba.appspot.com",
    messagingSenderId: "631528991893"
  };
  firebase.initializeApp(config);

  //TODO: Assign "boards" variable by callback function
  var loadBoards = function (cb) {
    // Get all of the information about the boards you have access to
    var success = function(data) {
      boards = data;
      for(var i = 0; i < boards.length; i++){
        loadLists(i, cb);
        //loadCards(i, cb);
      }
    };
    var error = function(errorMsg) {
      console.log(errorMsg);
    };
    Trello.get('/member/me/boards', success, error);
  };

  var loadLists = function (boardIndex, cb) {

    var boardId = boards[boardIndex].id;

    var success = function (data) {
      boards[boardIndex].lists = data;
      loadCards(boardIndex, cb);
    };
    var error = function(errorMsg) {
      console.log(errorMsg);
    };
    Trello.get('/boards/' + boardId + '/lists', success, error);

  }
  
  var loadCards = function (boardIndex, cb) {
    // Get all of the information about the boards you have access to
    var boardId = boards[boardIndex].id;

    var success = function(data) {
      boards[boardIndex].cards = data;
      //TODO: Uncomment this when function is implemented
      //boards[boardIndex].myCards = getUsersCards(boardIndex);

      //Calculate the statistics of the cards for this board
      //cardStats(boardIndex);
      //Call the callback when all the boards has got their cards
      if(++loadingCounter >= boards.length){
        if(useCardStats){
          cardStats(cb);
        }
        else{
          cb();
        }
      }
    };
    var error = function(errorMsg) {
      console.log(errorMsg);
    };
    Trello.get('/boards/' + boardId + '/cards', success, error);

  }
  //TODO: Return all the cards that is assigned to the logged in user
  var getUsersCards = function(boardIndex){

  }

  var cardStats = function (cb) {

    for(var i = 0; i < boards.length; i++){
      //Create array for holding the stats
      boards[i].cardStats = {
        mediumPriority : 0,
        lowPriority : 0,
        highPriority : 0
      };
      //Loop through all the cards and add statistics for each
      for(var j = 0; j < boards[i].cards.length; j++){
        var card = boards[i].cards[j];
        //Check the label of the card
        var labels = card.labels;
        if(labels.length == 0){
          //Give "unlabeled" cards low priority
          boards[i].cardStats.lowPriority++;
        }
        for(var k = 0; k < labels.length; k++){
          //Remove the "done cards"
          if(labels[k].name.toLowerCase() == "done") {
            break;
          }
          if(labels[k].name.toLowerCase() == "high priority"){
            boards[i].cardStats.highPriority++;
            break;
          }
          else if(labels[k].name.toLowerCase() == "medium priority"){
            boards[i].cardStats.mediumPriority++;
            break;
          }
          else if(labels[k].name.toLowerCase() == "low priority"){
            boards[i].cardStats.lowPriority++;
            break;
          }
          else if(k == labels.length-1){
            //If it is the last label and it is none of the above then give it low priority
            boards[i].cardStats.lowPriority++;
            break;
          }
        }
      }
    }
    boardsLoaded = true;
    cb();
  };

  this.loadData = function (cb) {
    loadBoards(cb);
  }

  this.getBoards = function () {
    //Check if boards are not loaded
    if(!boardsLoaded){
      //console.error("Boards not loaded");
    }else{
      return boards;
    }
  };

  // Get board with specific id from the ones loaded.
  this.getBoard = function(id) {
    for(var i = 0; i < boards.length; i++) {
      if(boards[i].id == id)
        return boards[i];
    }
  }

  // Give the board with the id a new name
  this.changeBoardName = function(id, newName) {
    Trello.put('boards/'+id+'/name?value='+newName);
  }

  // Create a new board and post it to Trello
  this.createNewBoard = function() {
    Trello.post('/boards?name=New Project');
  }

  this.isLoggedIn = function () {
    return loggedIn;
  };

  this.boardsLoaded = function () {
    return boardsLoaded;
  };

  return this;

});

{'fraction_non_alphanumeric': 0.13100829419406415, 'fraction_numerical': 0.009593284700709503, 'mean_word_length': 2.201535508637236, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '6229026', 'n_tokens_mistral': 3144, 'n_tokens_neox': 3039, 'n_words': 818}