<commit_before>/*
eslint no-shadow: ["error", { "allow": ["$scope"] }]
*/
/*
eslint no-underscore-dangle: ["error", { "allow": ["_id",] }]
*/

const shuffle = require('./app/components/ideas/shuffle');

const ideaControl = function ideaControl($scope, $rootScope, $mdDialog, $mdToast, db) {
  $scope.isShown = true;
  $scope.current = undefined;

  $scope.remove = (idea) => {
    db.removeIdea(idea, (err) => {
      if (!err) {
        $mdToast.show(
          $mdToast.simple()
          .textContent('Idea deleted.')
          .position('bottom start')
          .hideDelay(1000)
        );
      }
    });
  };

  function EditDialogController($scope, idea) {
    $scope.idea = idea;
    $scope.cancel = function cancel() {
      $mdDialog.cancel();
    };
    $scope.update = function update(newIdea) {
      if (newIdea) {
        $mdDialog.hide(newIdea);
      }
    };
  }
  $scope.edit = (ev, cur) => {
    $mdDialog.show({
      controller: EditDialogController,
      locals: {
        idea: cur.idea,
      },
      templateUrl: 'app/components/ideas/templates/editIdeaDialog.html',
      parent: angular.element(document.body),
      targetEvent: ev,
      clickOutsideToClose: true,
    })
    .then((idea) => {
      db.editIdea(cur._id, idea, (err) => {
        if (!err) {
          db.findIdeas((ideas) => {
            $scope.ideas = ideas;
            $scope.$apply();
          });
          $mdToast.show(
            $mdToast.simple()
            .textContent('Idea edited.')
            .position('bottom start')
            .hideDelay(1000)
          );
        }
      });
    });
  };

  function SplitDialogController($scope, cur) {
    $scope.cur = cur;
    $scope.tasks = [];
    $scope.numOfTasks = 1;
    $scope.cancel = function cancel() {
      $mdDialog.cancel();
    };
    $scope.split = function update(splittedTasks, numOfTasks) {
      if (splittedTasks.length === numOfTasks) {
        $mdDialog.hide(splittedTasks);
      }
    };
  }
  $scope.split = (ev, cur) => {
    $mdDialog.show({
      controller: SplitDialogController,
      templateUrl: 'app/components/ideas/templates/splitIdeaDialog.html',
      locals: {
        cur: $scope.current,
      },
      parent: angular.element(document.body),
      targetEvent: ev,
      clickOutsideToClose: true,
    })
    .then((tasks) => {
      let hasErr = false;
      tasks.forEach((task) => {
        db.insert(task, (err) => {
          if (err) {
            hasErr = true;
          }
        });
      });
      if (!hasErr) {
        db.removeIdea(cur._id, (err) => {
          if (!err) {
            $rootScope.$broadcast('Update tasks');
            $rootScope.$broadcast('Update ideas');
            $mdToast.show(
              $mdToast.simple()
              .textContent('Idea splitted into tasks.')
              .position('bottom start')<commit_msg>Resolve an issue in deleting idea<commit_after>/*
eslint no-shadow: ["error", { "allow": ["$scope"] }]
*/
/*
eslint no-underscore-dangle: ["error", { "allow": ["_id",] }]
*/

const shuffle = require('./app/components/ideas/shuffle');

const ideaControl = function ideaControl($scope, $rootScope, $mdDialog, $mdToast, db) {
  $scope.isShown = true;
  $scope.current = undefined;

  $scope.remove = (idea) => {
    db.removeIdea(idea, (err) => {
      if (!err) {
        db.findIdeas((ideas) => {
          $scope.ideas = ideas;
          $scope.$apply();
        });
        $mdToast.show(
          $mdToast.simple()
          .textContent('Idea deleted.')
          .position('bottom start')
          .hideDelay(1000)
        );
      }
    });
  };

  function EditDialogController($scope, idea) {
    $scope.idea = idea;
    $scope.cancel = function cancel() {
      $mdDialog.cancel();
    };
    $scope.update = function update(newIdea) {
      if (newIdea) {
        $mdDialog.hide(newIdea);
      }
    };
  }
  $scope.edit = (ev, cur) => {
    $mdDialog.show({
      controller: EditDialogController,
      locals: {
        idea: cur.idea,
      },
      templateUrl: 'app/components/ideas/templates/editIdeaDialog.html',
      parent: angular.element(document.body),
      targetEvent: ev,
      clickOutsideToClose: true,
    })
    .then((idea) => {
      db.editIdea(cur._id, idea, (err) => {
        if (!err) {
          db.findIdeas((ideas) => {
            $scope.ideas = ideas;
            $scope.$apply();
          });
          $mdToast.show(
            $mdToast.simple()
            .textContent('Idea edited.')
            .position('bottom start')
            .hideDelay(1000)
          );
        }
      });
    });
  };

  function SplitDialogController($scope, cur) {
    $scope.cur = cur;
    $scope.tasks = [];
    $scope.numOfTasks = 1;
    $scope.cancel = function cancel() {
      $mdDialog.cancel();
    };
    $scope.split = function update(splittedTasks, numOfTasks) {
      if (splittedTasks.length === numOfTasks) {
        $mdDialog.hide(splittedTasks);
      }
    };
  }
  $scope.split = (ev, cur) => {
    $mdDialog.show({
      controller: SplitDialogController,
      templateUrl: 'app/components/ideas/templates/splitIdeaDialog.html',
      locals: {
        cur: $scope.current,
      },
      parent: angular.element(document.body),
      targetEvent: ev,
      clickOutsideToClose: true,
    })
    .then((tasks) => {
      let hasErr = false;
      tasks.forEach((task) => {
        db.insert(task, (err) => {
          if (err) {
            hasErr = true;
          }
        });
      });
      if (!hasErr) {
        db.removeIdea(cur._id, (err) => {
          if (!err) {
            $rootScope.$broadcast('Update tasks');
            db.findIdeas((ideas) => {
              $scope.ideas = ideas;
              $scope.$apply();
            });
            $mdToast.show(
              $mdToast.simple()
              .textContent('Idea splitted into tasks.')
              .position('bottom start')
{'fraction_non_alphanumeric': 0.16365173288250212, 'fraction_numerical': 0.003043110735418428, 'mean_word_length': 1.9243697478991597, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 27, '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': '2551898', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1878, 'n_words': 318}