<commit_before>(function(angular, $, _, CRM) {

  function getStatusType(status_id) {
    var statusType;
    _.each(CRM.civicase.activityStatusTypes, function(statuses, type) {
      if (statuses.indexOf(parseInt(status_id)) >= 0) {
        statusType = type;
      }
    });
    return statusType;
  }

  angular.module('civicase').directive('civicaseSortheader', function() {
    return {
      restrict: 'A',
      link: function(scope, element, attrs) {

        function change() {
          element.toggleClass('sorting', attrs.civicaseSortheader === scope.sortField);
          element.find('i.cc-sort-icon').remove();
          if (attrs.civicaseSortheader === scope.sortField) {
            element.append('<i class="cc-sort-icon fa fa-arrow-circle-' + (scope.sortDir === 'ASC' ? 'up' : 'down') + '"></i>');
          }
        }

        scope.changeSortDir = function() {
          scope.sortDir = (scope.sortDir === 'ASC' ? 'DESC' : 'ASC');
        };

        element
          .addClass('civicase-sortable')
          .on('click', function(e) {
            if ($(e.target).is('th, .cc-sort-icon')) {
              if (scope.sortField === attrs.civicaseSortheader) {
                scope.changeSortDir();
              } else {
                scope.sortField = attrs.civicaseSortheader;
                scope.sortDir = 'ASC';
              }
              scope.$digest();
            }
          });

        scope.$watch('sortField', change);
        scope.$watch('sortDir', change);
      }
    };
  });

  angular.module('civicase').factory('formatActivity', function() {
    var activityTypes = CRM.civicase.activityTypes;
    var activityStatuses = CRM.civicase.activityStatuses;
    return function (act) {
      act.category = (activityTypes[act.activity_type_id].grouping ? activityTypes[act.activity_type_id].grouping.split(',') : []);
      act.icon = activityTypes[act.activity_type_id].icon;
      act.type = activityTypes[act.activity_type_id].label;
      act.status = activityStatuses[act.status_id].label;
      act.status_type = getStatusType(act.status_id);
      act.is_completed = act.status_type !== 'incomplete'; // FIXME doesn't distinguish cancelled from completed
      act.is_overdue = act.is_overdue === '1';
      act.color = activityStatuses[act.status_id].color || '#42afcb';
      if (act.category.indexOf('alert') > -1) {
        act.color = ''; // controlled by css
      }
    };
  });

  angular.module('civicase').factory('getActivityFeedUrl', function($route, $location) {
    return function(caseId, category, status, id) {
      var af = {};
      if (category) {
        af["activity_type_id.grouping"] = category;
      }
      if (status) {
        af.status_id = status;
      }
      var p = angular.extend({}, $route.current.params, {
        caseId: caseId,
        tab: 'activities',
        aid: id || 0,
        focus: 1,
        sx: 0,
        ai: '{"myActivities":false,"delegated":false}',
        af: JSON.stringify(af)
      });
      return $location.path() + '?' + $.param(p);
    };
  });

  // Export a set of civicase-related utility functions.
  // <div civicase-util="myhelper" />
  angular.module('civicase').directive('civicaseUtil', function(){
    return {
      restrict: 'EA',
      scope: {
        civicaseUtil: '='
      },
      controller: function ($scope, formatActivity) {
        var util = this;
        util.formatActivity = function(a) {formatActivity(a);return a;};
        util.formatActivities = function(rows) {_.each(rows, formatActivity);return rows;};
        util.isSameDate = function(d1, d2) {
          return d1 && d2 && (d1.slice(0, 10) === d2.slice(0, 10));
        };<commit_msg>Fix status type in activity links<commit_after>(function(angular, $, _, CRM) {

  function getStatusType(status_id) {
    var statusType;
    _.each(CRM.civicase.activityStatusTypes, function(statuses, type) {
      if (statuses.indexOf(parseInt(status_id)) >= 0) {
        statusType = type;
      }
    });
    return statusType;
  }

  angular.module('civicase').directive('civicaseSortheader', function() {
    return {
      restrict: 'A',
      link: function(scope, element, attrs) {

        function change() {
          element.toggleClass('sorting', attrs.civicaseSortheader === scope.sortField);
          element.find('i.cc-sort-icon').remove();
          if (attrs.civicaseSortheader === scope.sortField) {
            element.append('<i class="cc-sort-icon fa fa-arrow-circle-' + (scope.sortDir === 'ASC' ? 'up' : 'down') + '"></i>');
          }
        }

        scope.changeSortDir = function() {
          scope.sortDir = (scope.sortDir === 'ASC' ? 'DESC' : 'ASC');
        };

        element
          .addClass('civicase-sortable')
          .on('click', function(e) {
            if ($(e.target).is('th, .cc-sort-icon')) {
              if (scope.sortField === attrs.civicaseSortheader) {
                scope.changeSortDir();
              } else {
                scope.sortField = attrs.civicaseSortheader;
                scope.sortDir = 'ASC';
              }
              scope.$digest();
            }
          });

        scope.$watch('sortField', change);
        scope.$watch('sortDir', change);
      }
    };
  });

  angular.module('civicase').factory('formatActivity', function() {
    var activityTypes = CRM.civicase.activityTypes;
    var activityStatuses = CRM.civicase.activityStatuses;
    return function (act) {
      act.category = (activityTypes[act.activity_type_id].grouping ? activityTypes[act.activity_type_id].grouping.split(',') : []);
      act.icon = activityTypes[act.activity_type_id].icon;
      act.type = activityTypes[act.activity_type_id].label;
      act.status = activityStatuses[act.status_id].label;
      act.status_type = getStatusType(act.status_id);
      act.is_completed = act.status_type !== 'incomplete'; // FIXME doesn't distinguish cancelled from completed
      act.is_overdue = act.is_overdue === '1';
      act.color = activityStatuses[act.status_id].color || '#42afcb';
      if (act.category.indexOf('alert') > -1) {
        act.color = ''; // controlled by css
      }
    };
  });

  angular.module('civicase').factory('getActivityFeedUrl', function($route, $location) {
    return function(caseId, category, status, id) {
      var af = {};
      if (category) {
        af["activity_type_id.grouping"] = category;
      }
      if (status) {
        af.status_id = CRM.civicase.activityStatusTypes[status];
      }
      var p = angular.extend({}, $route.current.params, {
        caseId: caseId,
        tab: 'activities',
        aid: id || 0,
        focus: 1,
        sx: 0,
        ai: '{"myActivities":false,"delegated":false}',
        af: JSON.stringify(af)
      });
      return $location.path() + '?' + $.param(p);
    };
  });

  // Export a set of civicase-related utility functions.
  // <div civicase-util="myhelper" />
  angular.module('civicase').directive('civicaseUtil', function(){
    return {
      restrict: 'EA',
      scope: {
        civicaseUtil: '='
      },
      controller: function ($scope, formatActivity) {
        var util = this;
        util.formatActivity = function(a) {formatActivity(a);return a;};
        util.formatActivities = function(rows) {_.each(rows, formatActivity);return rows;};
        util.isSameDate = function(d1, d2) {
          return d1 && d2 && (d1.slice(0, 10) === d2.slice(0, 10));
        };
{'fraction_non_alphanumeric': 0.15792305622814098, 'fraction_numerical': 0.0053806833467850415, 'mean_word_length': 2.429428044280443, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 13, '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': '770622', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2296, 'n_words': 399}