<commit_before>/* Copyright 2013-2015 Extended Mind Technologies Oy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 'use strict';
 /*jshint -W008 */

 function listDirective($parse, $q, $rootScope, $timeout, UISessionService) {
  return {
    require: ['^listContainer', '?^swiperSlide'],
    restrict: 'A',
    scope: true,
    controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
      $scope.listInfos = {};
      $scope.listOptions = {};
      $scope.listAddState = {};
      if ($attrs.listOptions) {
        $scope.listOptions = $parse($attrs.listOptions)($scope);
      }

      var listArrayFn = $parse($attrs.list);
      $scope.getFullArray = function(){
        return listArrayFn($scope);
      };

      $scope.getVisibleArray = function(getFullArrayFn, limitTo) {
        var fullArray = getFullArrayFn();
        if (fullArray) {
          if (customFilterItemVisible) {
            $scope.listInfos.array = customFilterItemVisible(fullArray);  // Cache filtered full array
          } else if ($scope.listOptions.hideItemDefault) {
            // Return empty array.
            // NOTE:  This is intended to be working together with custom filter. While it is not visible,
            //        but will be later, use this to avoid Angular error "Controller 'list', required by
            //        directive 'listItem', can't be found!"
            $scope.listInfos.array = [];
          } else {
            $scope.listInfos.array = fullArray; // Cache filtered full array
          }
          return $scope.listInfos.array.slice(0, limitTo);
        }
      };

      $scope.getFilteredFullArrayLength = function() {
        if ($scope.listInfos.array)
          return $scope.listInfos.array.length;
      };

      this.notifyArrayVisible = function(/*array*/) {
        if (arrayVisibleCallbacks) {
          for (var id in arrayVisibleCallbacks) {
            if (arrayVisibleCallbacks.hasOwnProperty(id)) arrayVisibleCallbacks[id]();
          }
        }
        $scope.arrayVisible = true;
      };

      this.getSlideId = function() {
        return $scope.listOptions.id;
      };

      var arrayVisibleCallbacks = {};
      this.registerArrayVisibleCallback = function(callback, id) {
        arrayVisibleCallbacks[id] = callback;
      };
      $scope.registerArrayVisibleCallback = this.registerArrayVisibleCallback;

      this.unregisterArrayVisibleCallback = function(id) {
        if (arrayVisibleCallbacks[id])
          delete arrayVisibleCallbacks[id];
      };
      $scope.unregisterArrayVisibleCallback = this.unregisterArrayVisibleCallback;

      var listOpenOnAddFn;
      if ($attrs.listOpen){
        listOpenOnAddFn = $parse($attrs.listOpen).bind(undefined, $scope);
      }
      $scope.activateListAdd = function() {
        if (angular.isFunction($scope.isListAddDisabled) && $scope.isListAddDisabled()){
          // Add is disabled, exit
          return;
        }
        if (listOpenOnAddFn){
          // Execute open function
          listOpenOnAddFn();
        } else if ($scope.activateAddItem) {
          $scope.activateAddItem();
          if ($scope.notifyAddAction){
            $scope.notifyAddAction('activate', $scope.listAddState.featureInfo,
                                   $scope.listAddState.subfeature);
          }
        }
      };
      this.activateListAdd = $scope.activateListAdd;

      this.registerAddActiveCallback = function(callback){
        $scope.activateAddItem = callback;
      };

      this.notifyListItemAddActive = function(active) {
        $scope.listItemAddActive = active;
      };

      this.notifyListItemAdd = function(){
        if ($scope.notifyAddAction){
          return $scope.notifyAddAction('add', $scope.listAddState.featureInfo,
                                                   $scope.listAddState.subfeature);
        }
      };

      this.notifyListItemExitNoAdd = function(){
        if ($scope.notifyAddAction){
          return $scope.notifyAddAction('noAdd', $scope.listAddState.featureInfo,
                                                   $scope.listAddState.subfeature);
        }
      };

      this.notifyListItemBeginAdd = function(){
        if ($scope.notifyAddAction){
          return $scope.notifyAddAction('beginAdd', $scope.listAddState.featureInfo,
                                                   $scope.listAddState.subfeature);
        }
      };

      var customFilterItemVisible;
      this.setCustomFilterItemVisible = function(filter){
        customFilterItemVisible = filter;
      };
      $scope.isListItemVisible = function(item, param){
        if (customFilterItemVisible){
          return customFilterItemVisible(item, param);
        }
        return true;
      };

      this.registerIsNearListBottomCallback = function(callback) {
        $scope.isNearListBottomCallback = callback;
        if ($scope.listInfos && $scope.listInfos.array) {
          // Return initial status to caller.
          return $scope.currentListLimitTo < $scope.getFilteredFullArrayLength();
        }
      };

      this.toggleLeftCheckbox = function(item, toggleFn, checkingTimeout) {

        var checkboxCheckingReadyDeferred = $q.defer();
        var checked = toggleFn(item, checkboxCheckingReadyDeferred);

        if (checked) {
          checkingTimeout = $timeout(function() {
            UISessionService.allow('leaveAnimation', 200);
            checkboxCheckingReadyDeferred.resolve(item);
            if (!$scope.$$phase && !$rootScope.$$phase) $scope.$digest();
          }, $rootScope.CHECKBOX_CHECKING_ANIMATION_TIME);
        } else{
          if (checkingTimeout){
            $timeout.cancel(checkingTimeout);
            checkingTimeout = undefined;
          }
          checkboxCheckingReadyDeferred.resolve(item);
        }

        return checkingTimeout;
      };
    }],
    link: function(scope, element, attrs, controllers) {
      var listLockedCallback;
      if (attrs.listLocked) {
        listLockedCallback = $parse(attrs.listLocked).bind(undefined, scope);
      }

      controllers[0].registerGetFullArrayFn(scope.getFullArray);

      function notifyListAddFeature(featureInfo, subfeature){
        scope.listAddState.featureInfo = featureInfo;
        scope.listAddState.subfeature = subfeature;
      }

      function activateListAdd() {<commit_msg>Task complete leave animation triggers only after last completion when completing multiple tasks at once.<commit_after>/* Copyright 2013-2015 Extended Mind Technologies Oy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 'use strict';
 /*jshint -W008 */

 function listDirective($parse, $q, $rootScope, $timeout, UISessionService) {
  return {
    require: ['^listContainer', '?^swiperSlide'],
    restrict: 'A',
    scope: true,
    controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
      $scope.listInfos = {};
      $scope.listOptions = {};
      $scope.listAddState = {};
      if ($attrs.listOptions) {
        $scope.listOptions = $parse($attrs.listOptions)($scope);
      }

      var listArrayFn = $parse($attrs.list);
      $scope.getFullArray = function(){
        return listArrayFn($scope);
      };

      $scope.getVisibleArray = function(getFullArrayFn, limitTo) {
        var fullArray = getFullArrayFn();
        if (fullArray) {
          if (customFilterItemVisible) {
            $scope.listInfos.array = customFilterItemVisible(fullArray);  // Cache filtered full array
          } else if ($scope.listOptions.hideItemDefault) {
            // Return empty array.
            // NOTE:  This is intended to be working together with custom filter. While it is not visible,
            //        but will be later, use this to avoid Angular error "Controller 'list', required by
            //        directive 'listItem', can't be found!"
            $scope.listInfos.array = [];
          } else {
            $scope.listInfos.array = fullArray; // Cache filtered full array
          }
          return $scope.listInfos.array.slice(0, limitTo);
        }
      };

      $scope.getFilteredFullArrayLength = function() {
        if ($scope.listInfos.array)
          return $scope.listInfos.array.length;
      };

      this.notifyArrayVisible = function(/*array*/) {
        if (arrayVisibleCallbacks) {
          for (var id in arrayVisibleCallbacks) {
            if (arrayVisibleCallbacks.hasOwnProperty(id)) arrayVisibleCallbacks[id]();
          }
        }
        $scope.arrayVisible = true;
      };

      this.getSlideId = function() {
        return $scope.listOptions.id;
      };

      var arrayVisibleCallbacks = {};
      this.registerArrayVisibleCallback = function(callback, id) {
        arrayVisibleCallbacks[id] = callback;
      };
      $scope.registerArrayVisibleCallback = this.registerArrayVisibleCallback;

      this.unregisterArrayVisibleCallback = function(id) {
        if (arrayVisibleCallbacks[id])
          delete arrayVisibleCallbacks[id];
      };
      $scope.unregisterArrayVisibleCallback = this.unregisterArrayVisibleCallback;

      var listOpenOnAddFn;
      if ($attrs.listOpen){
        listOpenOnAddFn = $parse($attrs.listOpen).bind(undefined, $scope);
      }
      $scope.activateListAdd = function() {
        if (angular.isFunction($scope.isListAddDisabled) && $scope.isListAddDisabled()){
          // Add is disabled, exit
          return;
        }
        if (listOpenOnAddFn){
          // Execute open function
          listOpenOnAddFn();
        } else if ($scope.activateAddItem) {
          $scope.activateAddItem();
          if ($scope.notifyAddAction){
            $scope.notifyAddAction('activate', $scope.listAddState.featureInfo,
                                   $scope.listAddState.subfeature);
          }
        }
      };
      this.activateListAdd = $scope.activateListAdd;

      this.registerAddActiveCallback = function(callback){
        $scope.activateAddItem = callback;
      };

      this.notifyListItemAddActive = function(active) {
        $scope.listItemAddActive = active;
      };

      this.notifyListItemAdd = function(){
        if ($scope.notifyAddAction){
          return $scope.notifyAddAction('add', $scope.listAddState.featureInfo,
                                                   $scope.listAddState.subfeature);
        }
      };

      this.notifyListItemExitNoAdd = function(){
        if ($scope.notifyAddAction){
          return $scope.notifyAddAction('noAdd', $scope.listAddState.featureInfo,
                                                   $scope.listAddState.subfeature);
        }
      };

      this.notifyListItemBeginAdd = function(){
        if ($scope.notifyAddAction){
          return $scope.notifyAddAction('beginAdd', $scope.listAddState.featureInfo,
                                                   $scope.listAddState.subfeature);
        }
      };

      var customFilterItemVisible;
      this.setCustomFilterItemVisible = function(filter){
        customFilterItemVisible = filter;
      };
      $scope.isListItemVisible = function(item, param){
        if (customFilterItemVisible){
          return customFilterItemVisible(item, param);
        }
        return true;
      };

      this.registerIsNearListBottomCallback = function(callback) {
        $scope.isNearListBottomCallback = callback;
        if ($scope.listInfos && $scope.listInfos.array) {
          // Return initial status to caller.
          return $scope.currentListLimitTo < $scope.getFilteredFullArrayLength();
        }
      };

      var checkingItemsDeferred = [];
      function resolveAllDeferredCheckings(){
        UISessionService.allow('leaveAnimation', 200);
        for (var i=0; i<checkingItemsDeferred.length; i++){
          if (checkingItemsDeferred[i].deferred)
            checkingItemsDeferred[i].deferred.resolve(checkingItemsDeferred[i].item);
        }
        checkingItemsDeferred = [];
      }
      function resolveDeferredChekckingsIfItemLatest(item){
        return $timeout(function() {
            if (checkingItemsDeferred.length > 0 &&
                (checkingItemsDeferred[checkingItemsDeferred.length-1].item === item ||
                (checkingItemsDeferred.length>1 &&
                 checkingItemsDeferred[checkingItemsDeferred.length-1].deferred === undefined &&
                 checkingItemsDeferred[checkingItemsDeferred.length-2].item === item))){
              resolveAllDeferredCheckings();
              if (!$scope.$$phase && !$rootScope.$$phase) $scope.$digest();
            }
          }, $rootScope.CHECKBOX_CHECKING_ANIMATION_TIME);
      }

      this.toggleLeftCheckbox = function(item, toggleFn, checkingTimeout) {
        var checkboxCheckingReadyDeferred = $q.defer();
        var checked = toggleFn(item, checkboxCheckingReadyDeferred);
        if (checked) {
          checkingItemsDeferred.push({deferred: checkboxCheckingReadyDeferred, item: item});
          checkingTimeout = resolveDeferredChekckingsIfItemLatest(item);
        } else{
          checkingItemsDeferred.push({item: item});
          if (checkingTimeout){
            $timeout.cancel(checkingTimeout);
            checkingTimeout = undefined;
          }
          if (checkingItemsDeferred.length > 1){
            // See if this item is among the recently checked (not the last one, as that was just pushed)
            // and splice it from there
            for (var i=0; i<checkingItemsDeferred.length-1; i++){
              if (checkingItemsDeferred[i].item === item){
                checkingItemsDeferred.splice(i, 1);
                break;
              }
            }
          }
          checkboxCheckingReadyDeferred.resolve(item);
          resolveDeferredChekckingsIfItemLatest(item);
        }
        return checkingTimeout;
      };
    }],
    link: function(scope, element, attrs, controllers) {
      var listLockedCallback;
      if (attrs.listLocked) {
        listLockedCallback = $parse(attrs.listLocked).bind(undefined, scope);
      }

      controllers[0].registerGetFullArrayFn(scope.getFullArray);

      function notifyListAddFeature(featureInfo, subfeature){
        scope.listAddState.featureInfo = featureInfo;
        scope.listAddState.subfeature = subfeature;
      }

      function activateListAdd() {
{'fraction_non_alphanumeric': 0.10598056479488685, 'fraction_numerical': 0.0032609404552272877, 'mean_word_length': 2.353893263342082, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3514564', 'n_tokens_mistral': 4061, 'n_tokens_neox': 3957, 'n_words': 853}