<commit_before>/* -*-mode:js; js-indent-level: 2 -*- */

angular.module('todoServices', ['ngResource']).
  factory('TodoLists', function($resource) {
    return $resource('/api/lists', {}, {
      query: { method: 'GET', isArray: true }
    });
  }).
  factory('TodoLabels', function($resource) {
    return $resource('/api/labels', {}, {
      query: { method: 'GET', isArray: true }
    });
  }).
  factory('TodoListItems', function($resource) {
    return $resource('/api/lists/:listId/items/', {listId:'@listId'}, {
      query: { method: 'GET', isArray: true },
      add: { method:'POST' },
    });
  }).
  factory('TodoListItem', function($resource) {
    return $resource('/api/items/:itemId/', {itemId:'@itemId'}, {
      save: { method:'POST', params: {request_method: 'PUT' } }
    });
  });

  
angular.module('trueDoList', ['ngRoute', 'ngAnimate', 'todoServices']);
/*
.
  config(['$routeProvider', function($routeProvider) {
    $routeProvider.
      when('/lists/:listId', { templateUrl: 'list-detail.html', controller: ListController}).
      otherwise({redirectTo: '/'});
  }]);
*/

function TodoListController($scope, TodoLists, TodoLabels, TodoListItems, TodoListItem) {
  $scope.lists = TodoLists.query();
  $scope.labels = TodoLabels.query();

  $scope.addItem = function() {
    if ($scope.itemEditInput === "" || $scope.listId === undefined) {
      return false;
    }
    var newItem = new TodoListItems();
    newItem.listId = $scope.listId;
    newItem.title = $scope.itemEditInput;
    newItem.$add(function() {
      $scope.selectList($scope.listId);
    });
  };

  $scope.saveItem = function() {
    if ($scope.itemEditInput === "" || $scope.editItemId === undefined) {
      return false;
    }
    var itemToSave = new TodoListItem();
    itemToSave.itemId = $scope.editItemId;
    itemToSave.title = $scope.itemEditInput;
    itemToSave.$save(function() {
      $scope.selectList($scope.listId, $scope.listTitle);
    });

  };
  
  $scope.selectList = function(listId, listTitle) {
    // TODO: Just take list as parameter
    $scope.listId = listId;
    $scope.listTitle = listTitle;
    $scope.listItems = TodoListItems.query({listId: listId});
  };

  $scope.beginEdit = function(itemId, title) {
    $scope.editItemId = itemId;
    $scope.itemEditInput = title;
  };

  $scope.cancelAction = function() {
    $scope.editItemId = null;
    $scope.itemEditInput = '';
  };
}<commit_msg>AngularJS rewrite: Renamed TodoListItem to TodoItem<commit_after>/* -*-mode:js; js-indent-level: 2 -*- */

angular.module('todoServices', ['ngResource']).
  factory('TodoLists', function($resource) {
    return $resource('/api/lists', {}, {
      query: { method: 'GET', isArray: true }
    });
  }).
  factory('TodoLabels', function($resource) {
    return $resource('/api/labels', {}, {
      query: { method: 'GET', isArray: true }
    });
  }).
  factory('TodoListItems', function($resource) {
    return $resource('/api/lists/:listId/items/', {listId:'@listId'}, {
      query: { method: 'GET', isArray: true },
      add: { method:'POST' },
    });
  }).
  factory('TodoItem', function($resource) {
    return $resource('/api/items/:itemId/', {itemId:'@itemId'}, {
      save: { method:'POST', params: {request_method: 'PUT' } }
    });
  });

  
angular.module('trueDoList', ['ngRoute', 'ngAnimate', 'todoServices']);
/*
.
  config(['$routeProvider', function($routeProvider) {
    $routeProvider.
      when('/lists/:listId', { templateUrl: 'list-detail.html', controller: ListController}).
      otherwise({redirectTo: '/'});
  }]);
*/

function TodoListController($scope, TodoLists, TodoLabels, TodoListItems, TodoItem) {
  $scope.lists = TodoLists.query();
  $scope.labels = TodoLabels.query();

  $scope.addItem = function() {
    if ($scope.itemEditInput === "" || $scope.listId === undefined) {
      return false;
    }
    var newItem = new TodoListItems();
    newItem.listId = $scope.listId;
    newItem.title = $scope.itemEditInput;
    newItem.$add(function() {
      $scope.selectList($scope.listId);
    });
  };

  $scope.saveItem = function() {
    if ($scope.itemEditInput === "" || $scope.editItemId === undefined) {
      return false;
    }
    var itemToSave = new TodoItem();
    itemToSave.itemId = $scope.editItemId;
    itemToSave.title = $scope.itemEditInput;
    itemToSave.$save(function() {
      $scope.selectList($scope.listId, $scope.listTitle);
    });

  };
  
  $scope.selectList = function(listId, listTitle) {
    // TODO: Just take list as parameter
    $scope.listId = listId;
    $scope.listTitle = listTitle;
    $scope.listItems = TodoListItems.query({listId: listId});
  };

  $scope.beginEdit = function(itemId, title) {
    $scope.editItemId = itemId;
    $scope.itemEditInput = title;
  };

  $scope.cancelAction = function() {
    $scope.editItemId = null;
    $scope.itemEditInput = '';
  };
}
{'fraction_non_alphanumeric': 0.1886288998357964, 'fraction_numerical': 0.00041050903119868636, 'mean_word_length': 3.454296160877514, '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': '5154128', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1602, 'n_words': 273}