<commit_before>(function () {
  'use strict';

  angular
    .module('ddayApp')
    .controller('ProjectController', ProjectController);

  /** @ngInject */
  function ProjectController (Auth, FirebaseRef, $firebaseObject, Project, toastr) {
    var vm = this;

    vm.inProgress = true;

    vm.raw = {
      uid: null,
      title: '',
      description: '',
      todos: [],
      team: []
    };

    vm.addOrUpdateMode = true;
    vm.model = null;

    Auth.getLoggedIn().then(function (loggedIn) {
      vm.loggedIn = loggedIn;
      $firebaseObject(FirebaseRef.userById(vm.loggedIn.uid)).$loaded(function (user) {
        vm.user = user;
        if (vm.user.projectId) {
          Project.findById(vm.user.projectId).$loaded(function (project) {
            vm.model = project;
            vm.addOrUpdateMode = false;
          }, handleError).finally(function () {
            vm.inProgress = false;
          });
        } else {
          vm.raw.team.push({
            email: vm.loggedIn.password.email
          });
          vm.model = angular.extend({}, vm.raw);
          vm.model.uid = vm.loggedIn.uid;
          vm.inProgress = false;
        }
      }, handleError).finally(function () {
        vm.inProgress = false;
      });
    });

    vm.addOrUpdateInProgress = false;
    vm.updateMode = updateMode;
    vm.addOrUpdateProject = addOrUpdateProject;
    vm.removeProject = removeProject;

    vm.todo = {
      name: ''
    };

    vm.createTodo = createTodo;
    vm.removeTodo = removeTodo;
    vm.toggleTodo = toggleTodo;

    vm.person = {
      email: ''
    };

    vm.createPerson = createPerson;
    vm.removePerson = removePerson;

    function updateMode () {
      vm.addOrUpdateMode = true;
    }

    function addOrUpdateProject () {
      var title = vm.model.title.trim();
      if (!title) {
        toastr.warning('You need to type a title!');
        return;
      }

      var description = vm.model.description.trim();
      if (!description) {
        toastr.warning('Your need to type a description!');
        return;
      }

      vm.addOrUpdateInProgress = true;

      if (angular.isFunction(vm.model.$save)) {
        vm.model.$save().then(function () {
          vm.addOrUpdateMode = false;
          toastr.success('Your project was successfully updated!');
        }, handleError).finally(function () {
          vm.addOrUpdateInProgress = false;
        });
        return;
      }

      Project.create(vm.model).then(function (id) {
        vm.user.projectId = id;
        vm.user.$save().then(null, handleError);
        Project.findById(vm.user.projectId).$loaded(function (data) {
          vm.model = data;
          vm.addOrUpdateMode = false;
        }, handleError).finally(function () {
          vm.addOrUpdateInProgress = false;
          toastr.success('Your project was successfully created!');
        });
      }, handleError).finally(function () {
        vm.addOrUpdateInProgress = false;
      });
    }

    function removeProject () {
      vm.inProgress = true;
      vm.model.$remove().then(function () {
        vm.addOrUpdateMode = true;
        vm.model = angular.extend({}, vm.raw);
        vm.user.projectId = null;
        vm.user.$save().then(null, handleError);
        toastr.success('Your project has been removed!');
      }, handleError).finally(function () {
        vm.inProgress = false;
      });
    }

    function createTodo () {
      var name = vm.todo.name.trim();
      if (!name) {
        return;
      }

      vm.model.todos.push({
        name: name,
        done: false
      });
      if (angular.isFunction(vm.model.$save)) {
        vm.model.$save().then(null, handleError);
      }
      vm.todo.name = '';
    }

    function removeTodo ($index) {
      vm.model.todos.splice($index, 1);
      if (angular.isFunction(vm.model.$save)) {
        vm.model.$save().then(null, handleError);
      }
    }

    function toggleTodo () {
      if (angular.isFunction(vm.model.$save)) {
        vm.model.$save().then(null, handleError);
      }
    }

    function createPerson () {
      var email = vm.person.email.trim();
      if (!email) {
        return;
      }

      vm.model.team.push({
        email: email
      });<commit_msg>Fix for adding TODOs later<commit_after>(function () {
  'use strict';

  angular
    .module('ddayApp')
    .controller('ProjectController', ProjectController);

  /** @ngInject */
  function ProjectController (Auth, FirebaseRef, $firebaseObject, Project, toastr) {
    var vm = this;

    vm.inProgress = true;

    vm.raw = {
      uid: null,
      title: '',
      description: '',
      todos: [],
      team: []
    };

    vm.addOrUpdateMode = true;
    vm.model = null;

    Auth.getLoggedIn().then(function (loggedIn) {
      vm.loggedIn = loggedIn;
      $firebaseObject(FirebaseRef.userById(vm.loggedIn.uid)).$loaded(function (user) {
        vm.user = user;
        if (vm.user.projectId) {
          Project.findById(vm.user.projectId).$loaded(function (project) {
            vm.model = project;
            vm.addOrUpdateMode = false;
          }, handleError).finally(function () {
            vm.inProgress = false;
          });
        } else {
          vm.raw.team.push({
            email: vm.loggedIn.password.email
          });
          vm.model = angular.extend({}, vm.raw);
          vm.model.uid = vm.loggedIn.uid;
          vm.inProgress = false;
        }
      }, handleError).finally(function () {
        vm.inProgress = false;
      });
    });

    vm.addOrUpdateInProgress = false;
    vm.updateMode = updateMode;
    vm.addOrUpdateProject = addOrUpdateProject;
    vm.removeProject = removeProject;

    vm.todo = {
      name: ''
    };

    vm.createTodo = createTodo;
    vm.removeTodo = removeTodo;
    vm.toggleTodo = toggleTodo;

    vm.person = {
      email: ''
    };

    vm.createPerson = createPerson;
    vm.removePerson = removePerson;

    function updateMode () {
      vm.addOrUpdateMode = true;
    }

    function addOrUpdateProject () {
      var title = vm.model.title.trim();
      if (!title) {
        toastr.warning('You need to type a title!');
        return;
      }

      var description = vm.model.description.trim();
      if (!description) {
        toastr.warning('Your need to type a description!');
        return;
      }

      vm.addOrUpdateInProgress = true;

      if (angular.isFunction(vm.model.$save)) {
        vm.model.$save().then(function () {
          vm.addOrUpdateMode = false;
          toastr.success('Your project was successfully updated!');
        }, handleError).finally(function () {
          vm.addOrUpdateInProgress = false;
        });
        return;
      }

      Project.create(vm.model).then(function (id) {
        vm.user.projectId = id;
        vm.user.$save().then(null, handleError);
        Project.findById(vm.user.projectId).$loaded(function (data) {
          vm.model = data;
          vm.addOrUpdateMode = false;
        }, handleError).finally(function () {
          vm.addOrUpdateInProgress = false;
          toastr.success('Your project was successfully created!');
        });
      }, handleError).finally(function () {
        vm.addOrUpdateInProgress = false;
      });
    }

    function removeProject () {
      vm.inProgress = true;
      vm.model.$remove().then(function () {
        vm.addOrUpdateMode = true;
        vm.model = angular.extend({}, vm.raw);
        vm.user.projectId = null;
        vm.user.$save().then(null, handleError);
        toastr.success('Your project has been removed!');
      }, handleError).finally(function () {
        vm.inProgress = false;
      });
    }

    function createTodo () {
      var name = vm.todo.name.trim();
      if (!name) {
        return;
      }

      if (!vm.model.todos) {
        vm.model.todos = [];
      }

      vm.model.todos.push({
        name: name,
        done: false
      });
      if (angular.isFunction(vm.model.$save)) {
        vm.model.$save().then(null, handleError);
      }
      vm.todo.name = '';
    }

    function removeTodo ($index) {
      vm.model.todos.splice($index, 1);
      if (angular.isFunction(vm.model.$save)) {
        vm.model.$save().then(null, handleError);
      }
    }

    function toggleTodo () {
      if (angular.isFunction(vm.model.$save)) {
        vm.model.$save().then(null, handleError);
      }
    }

    function createPerson () {
      var email = vm.person.email.trim();
      if (!email) {
        return;
      }

      if (!vm.model.team) {
        vm.model.team = [];
      }

      vm.model.team.push({
        email: email
      });
{'fraction_non_alphanumeric': 0.14254258894425773, 'fraction_numerical': 0.00023177656738903696, 'mean_word_length': 1.9768885822697482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2122566', 'n_tokens_mistral': 2668, 'n_tokens_neox': 2627, 'n_words': 452}