<commit_before>/**
 * Created by jiting on 15/5/11.
 */
angular.module('freeCoderApp')
  .controller('todoCtrl', ['$scope', '$log', '$filter', '$state', 'Member', 'Task', 'Pomodoro', 'messagesContext', 'fcDateUtils', 'userTasks', function ($scope, $log, $filter, $state, Member, Task, Pomodoro, messagesContext, fcDateUtils, userTasks) {
    $scope.uiText = {
      newTaskTitlePlaceholder: messagesContext.get('todo.new.placeholder'),
      displayCompletedTasks: messagesContext.get('todo.filter.display.completed.tasks'),
      delete: messagesContext.get('todo.button.delete'),
      pomodoro: messagesContext.get('todo.button.pomodoro')
    };
    $scope.alert = {};
    $scope.newTask = {};
    $scope.todayTasks = [];
    $scope.todayCompletedTasks = [];
    $scope.tasks = [];
    $scope.scopes = {}; // record scope information of tree-nodes.


    /**
     * Split today tasks and to-do tasks out.
     */
    var splitTasks = function (allTasks) {
      $scope.todayTasks = [];
      $scope.tasks = [];
      for (var i = 0; i < allTasks.length; i++) {
        var task = allTasks[i];
        if (fcDateUtils.isInToday(task.targetTime)) {
          $scope.todayTasks.push(angular.copy(task));
        } else {
          $scope.tasks.push(angular.copy(task));
        }
      }
    };

    var checkTasksCount = function () {
      if ($scope.tasks.length == 0) {
        $scope.uiText.noTasks = messagesContext.get('todo.list.no.tasks');
      } else if ($scope.uiText.noTasks) {
        delete $scope.uiText.noTasks;
      }
    };

    $scope.createTask = function () {
      Task.create($scope.newTask).$promise.then(function (value, responseHeaders) {
        $scope.newTask = {};
        $scope.tasks.unshift(value);
        checkTasksCount();
      }, function (errResp) {
        alertRequestError(errResp);
      });
    };

    $scope.getTasks = function () {
      Member.tasks({
        id: Member.getCurrentId(),
        filter: {order: 'order DESC'}
      }).$promise.then(function (value, respHeaders) {
          $scope.tasks = value;
          checkTasksCount();
        }, function (errResp) {
          alertRequestError(errResp);
        })
    };

    $scope.deleteTask = function (index) {
      var taskId = $scope.tasks[index].id;
      $log.debug('Deleting task. index, id:', index, taskId);
      Task.deleteById({id: taskId}).$promise.then(function (value, respHeader) {
        $scope.tasks.splice(index, 1);
      }, function (errResp) {
        alertRequestError(errResp);
      });
    };

    $scope.finishTask = function (task) {
      $log.debug('Changing task completion. id, isCompleted:', task.id, task.isCompleted);
      task.completionTime = task.isCompleted ? new Date().getTime() : 0;
      Task.update({where: {id: task.id}}, task).$promise.then(function (value, respHeader) {
        $log.debug('Updated task completion successful. id, isCompleted, completionTime:', value.id, value.isCompleted, value.completionTime);
      }, function (errResp) {
        alertRequestError(errResp);
      });
    };

    $scope.startPomodoro = function (task) {
      var now = new Date().getTime();
      Member.pomodoros({
        id: Member.getCurrentId(),
        filter: {where: {status: 'inProgress'}}
      }, function (value, respHeader) {
        var remainDuration;
        if (value.length > 0) {
          // if there is in progress pomodoro but time out, then finish it.
          var pomodoro = value[0];
          var pomodoroEndTime = Date.parse(pomodoro.startTime) + pomodoro.duration;
          remainDuration = pomodoroEndTime - new Date().getTime();
          if (remainDuration <= 0) {
            Pomodoro.finishPomodoro({id: pomodoro.id});
          }
        }

        if (value.length == 0 || remainDuration <= 0) {
          Pomodoro.create({startTime: now, taskId: task.id}).$promise.then(function (value, respHeaders) {<commit_msg>Provide required property 'type' to create Pomodoro.<commit_after>/**
 * Created by jiting on 15/5/11.
 */
angular.module('freeCoderApp')
  .controller('todoCtrl', ['$scope', '$log', '$filter', '$state', 'Member', 'Task', 'Pomodoro', 'messagesContext', 'fcDateUtils', 'userTasks', function ($scope, $log, $filter, $state, Member, Task, Pomodoro, messagesContext, fcDateUtils, userTasks) {
    $scope.uiText = {
      newTaskTitlePlaceholder: messagesContext.get('todo.new.placeholder'),
      displayCompletedTasks: messagesContext.get('todo.filter.display.completed.tasks'),
      delete: messagesContext.get('todo.button.delete'),
      pomodoro: messagesContext.get('todo.button.pomodoro')
    };
    $scope.alert = {};
    $scope.newTask = {};
    $scope.todayTasks = [];
    $scope.todayCompletedTasks = [];
    $scope.tasks = [];
    $scope.scopes = {}; // record scope information of tree-nodes.


    /**
     * Split today tasks and to-do tasks out.
     */
    var splitTasks = function (allTasks) {
      $scope.todayTasks = [];
      $scope.tasks = [];
      for (var i = 0; i < allTasks.length; i++) {
        var task = allTasks[i];
        if (fcDateUtils.isInToday(task.targetTime)) {
          $scope.todayTasks.push(angular.copy(task));
        } else {
          $scope.tasks.push(angular.copy(task));
        }
      }
    };

    var checkTasksCount = function () {
      if ($scope.tasks.length == 0) {
        $scope.uiText.noTasks = messagesContext.get('todo.list.no.tasks');
      } else if ($scope.uiText.noTasks) {
        delete $scope.uiText.noTasks;
      }
    };

    $scope.createTask = function () {
      Task.create($scope.newTask).$promise.then(function (value, responseHeaders) {
        $scope.newTask = {};
        $scope.tasks.unshift(value);
        checkTasksCount();
      }, function (errResp) {
        alertRequestError(errResp);
      });
    };

    $scope.getTasks = function () {
      Member.tasks({
        id: Member.getCurrentId(),
        filter: {order: 'order DESC'}
      }).$promise.then(function (value, respHeaders) {
          $scope.tasks = value;
          checkTasksCount();
        }, function (errResp) {
          alertRequestError(errResp);
        })
    };

    $scope.deleteTask = function (index) {
      var taskId = $scope.tasks[index].id;
      $log.debug('Deleting task. index, id:', index, taskId);
      Task.deleteById({id: taskId}).$promise.then(function (value, respHeader) {
        $scope.tasks.splice(index, 1);
      }, function (errResp) {
        alertRequestError(errResp);
      });
    };

    $scope.finishTask = function (task) {
      $log.debug('Changing task completion. id, isCompleted:', task.id, task.isCompleted);
      task.completionTime = task.isCompleted ? new Date().getTime() : 0;
      Task.update({where: {id: task.id}}, task).$promise.then(function (value, respHeader) {
        $log.debug('Updated task completion successful. id, isCompleted, completionTime:', value.id, value.isCompleted, value.completionTime);
      }, function (errResp) {
        alertRequestError(errResp);
      });
    };

    $scope.startPomodoro = function (task) {
      var now = new Date().getTime();
      Member.pomodoros({
        id: Member.getCurrentId(),
        filter: {where: {status: 'inProgress'}}
      }, function (value, respHeader) {
        var remainDuration;
        if (value.length > 0) {
          // if there is in progress pomodoro but time out, then finish it.
          var pomodoro = value[0];
          var pomodoroEndTime = Date.parse(pomodoro.startTime) + pomodoro.duration;
          remainDuration = pomodoroEndTime - new Date().getTime();
          if (remainDuration <= 0) {
            Pomodoro.finishPomodoro({id: pomodoro.id});
          }
        }

        if (value.length == 0 || remainDuration <= 0) {
          Pomodoro.create({startTime: now, taskId: task.id, type: 'work'}).$promise.then(function (value, respHeaders) {
{'fraction_non_alphanumeric': 0.15548198140837896, 'fraction_numerical': 0.0035655163631733095, 'mean_word_length': 2.6530232558139537, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '1644759', 'n_tokens_mistral': 2462, 'n_tokens_neox': 2376, 'n_words': 478}