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

  // Tags controller
  angular
    .module('tags')
    .controller('PollsTagController', PollsTagController);

  PollsTagController.$inject = [
    '$scope',
    '$translate',
    'tagResolve',
    'Action',
    'TagsApi',
    'ngDialog'
  ];

  function PollsTagController(
    $scope,
    $translate,
    tag,
    Action,
    TagsApi,
    dialog
  ) {
    var vm = this;
    vm.tag = tag;

    $scope.busy = false;
    vm.polls = [];
    vm.language = $translate.use();
    vm.page = 1;
    vm.sort = '-created';

    handleLoadPolls();
    vm.handleLoadPolls = handleLoadPolls;
    function handleLoadPolls() {
      if ($scope.stopped || $scope.busy) return;
      $scope.busy = true;
      TagsApi.getPollsByTagId(vm.tag._id, vm.page, vm.language, vm.sort)
        .then(res => {
          if (!res.data.length || res.data.length === 0) {
            $scope.stopped = true;
            $scope.busy = false;
            return;
          }
          var promises = [];
          res.data.forEach(poll => {
            promises.push(prepareShowingData(poll));
          });
          return Promise.all(promises);
        })
        .then(results => {
          // Gán data vào list hiện tại
          results = results || [];
          vm.polls = _.union(vm.polls, results);
          vm.page += 1;
          $scope.busy = false;
          if (results.length < 10) { $scope.stopped = true; }
          if (!$scope.$$phase) $scope.$digest();
        })
        .catch(err => {
          $scope.busy = false;
          $scope.handleShowMessage('MS_CM_LOAD_ERROR', true);
        });
    }
    function prepareShowingData(poll) {
      return new Promise((resolve, reject) => {
        poll = Action.prepareShowingData(poll);
        return resolve(poll);
      });
    }
    vm.handleChangeSortType = () => {
      vm.page = 1;
      $scope.busy = $scope.stopped = false;
      vm.polls = [];
      handleLoadPolls();
    }

    $scope.poll_filter = poll => {
      if (poll.isPublic) {
        return true;
      } else {
        return poll.isCurrentUserOwner;
      }
    };
    $scope.handleDeletePoll = (poll) => {
      if (!poll.isCurrentUserOwner) {
        $scope.handleShowMessage('MS_CM_AUTH_ERROR', true);
        return;
      }
      // Gọi function show dialog từ scope cha
      $scope.handleShowConfirm({
        content: 'LB_POLLS_CONFIRM_DELETE',<commit_msg>Commited from HaNhatLenh at Mon, Oct 09, 2017  5:35:09 PM<commit_after>(function () {
  'use strict';

  // Tags controller
  angular
    .module('tags')
    .controller('PollsTagController', PollsTagController);

  PollsTagController.$inject = [
    '$scope',
    '$translate',
    'tagResolve',
    'Action',
    'TagsApi',
    'ngDialog'
  ];

  function PollsTagController(
    $scope,
    $translate,
    tag,
    Action,
    TagsApi,
    dialog
  ) {
    var vm = this;
    vm.tag = tag;

    $scope.busy = false;
    vm.polls = [];
    vm.language = $translate.use();
    vm.page = 1;
    vm.sort = '-created';

    handleLoadPolls();
    vm.handleLoadPolls = handleLoadPolls;
    function handleLoadPolls() {
      if ($scope.stopped || $scope.busy) return;
      $scope.busy = true;
      TagsApi.getPollsByTagId(vm.tag._id, vm.page, vm.language, vm.sort)
        .then(res => {
          if (!res.data.length || res.data.length === 0) {
            $scope.stopped = true;
            $scope.busy = false;
            return;
          }
          var promises = [];
          res.data.forEach(poll => {
            promises.push(prepareShowingData(poll));
          });
          return Promise.all(promises);
        })
        .then(results => {
          // Gán data vào list hiện tại
          results = results || [];
          vm.polls = _.union(vm.polls, results);
          vm.page += 1;
          $scope.busy = false;
          if (results.length < 10) { $scope.stopped = true; }
          if (!$scope.$$phase) $scope.$digest();
        })
        .catch(err => {
          $scope.busy = false;
          $scope.handleShowMessage('MS_CM_LOAD_ERROR', true);
        });
    }
    function prepareShowingData(poll) {
      return new Promise((resolve, reject) => {
        poll = Action.prepareShowingData(poll);
        return resolve(poll);
      });
    }
    vm.handleChangeSortType = () => {
      vm.page = 1;
      $scope.busy = $scope.stopped = false;
      vm.polls = [];
      handleLoadPolls();
    };

    $scope.poll_filter = poll => {
      if (poll.isPublic) {
        return true;
      } else {
        return poll.isCurrentUserOwner;
      }
    };
    $scope.handleDeletePoll = (poll) => {
      if (!poll.isCurrentUserOwner) {
        $scope.handleShowMessage('MS_CM_AUTH_ERROR', true);
        return;
      }
      // Gọi function show dialog từ scope cha
      $scope.handleShowConfirm({
        content: 'LB_POLLS_CONFIRM_DELETE',
{'fraction_non_alphanumeric': 0.14355727996732692, 'fraction_numerical': 0.004696753114151521, 'mean_word_length': 1.9172126265634306, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '4626047', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1583, 'n_words': 292}