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

  // CaseList directive controller
  function casePeopleController($scope, crmApi) {
    // The ts() and hs() functions help load strings for this module.
    var ts = $scope.ts = CRM.ts('civicase'),
      item = $scope.item,
      clientIds = _.map(item.client, 'contact_id'),
      clients = _.indexBy(item.client, 'contact_id'),
      relTypes = CRM.civicase.relationshipTypes,
      relTypesByName = _.indexBy(relTypes, 'name_b_a');

    $scope.CRM = CRM;
    $scope.allowMultipleCaseClients = CRM.civicase.allowMultipleCaseClients;
    $scope.roles = [];
    $scope.rolesFilter = '';
    $scope.rolesPage = 1;
    $scope.rolesAlphaFilter = '';
    $scope.rolesSelectionMode = '';
    $scope.rolesSelectedTask = '';
    $scope.relations = [];
    $scope.relationsPage = 1;
    $scope.relationsAlphaFilter = '';
    $scope.relationsSelectionMode = '';
    $scope.relationsSelectedTask = '';
    $scope.letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
    $scope.contactTasks = CRM.civicase.contactTasks;

    function formatRole (role) {
      var relType = relTypesByName[role.name];
      role.role = relType.label_b_a;
      role.contact_type = relType.contact_type_b;
      role.contact_sub_type = relType.contact_sub_type_b;
      role.description = (role.manager ? (ts('Case Manager.') + ' ') : '') + (relType.description || '');
      role.relationship_type_id = relType.id;
    }
    $scope.allRoles = _.each(_.cloneDeep(item.definition.caseRoles), formatRole);

    var getSelectedContacts = $scope.getSelectedContacts = function(tab, onlyChecked) {
      var idField = (tab === 'roles' ? 'contact_id' : 'id');
      if (onlyChecked || $scope[tab + 'SelectionMode'] === 'checked') {
        return _.collect(_.filter($scope[tab], {checked: true}), idField);
      }
      else if ($scope[tab + 'SelectionMode'] === 'all') {
        return _.collect($scope[tab], idField);
      }
      return [];
    };

    var getCaseRoles = $scope.getCaseRoles = function() {
      var caseRoles = $scope.rolesAlphaFilter ? [] : _.cloneDeep($scope.allRoles),
        allRoles = _.cloneDeep($scope.allRoles),
        selected = getSelectedContacts('roles', true);
      if ($scope.rolesFilter) {
        caseRoles = $scope.rolesFilter === 'client' ? [] : [_.findWhere(caseRoles, {name: $scope.rolesFilter})];
      }
      _.each(item.contacts, function (contact) {
        var role = contact.relationship_type_id ? _.findWhere(caseRoles, {relationship_type_id: contact.relationship_type_id}) : null;
        if ((!role || role.contact_id) && contact.relationship_type_id) {<commit_msg>ViewPeople - Fix crash<commit_after>(function(angular, $, _) {

  // CaseList directive controller
  function casePeopleController($scope, crmApi) {
    // The ts() and hs() functions help load strings for this module.
    var ts = $scope.ts = CRM.ts('civicase'),
      item = $scope.item,
      clientIds = _.map(item.client, 'contact_id'),
      clients = _.indexBy(item.client, 'contact_id'),
      relTypes = CRM.civicase.relationshipTypes,
      relTypesByName = _.indexBy(relTypes, 'name_b_a');

    $scope.CRM = CRM;
    $scope.allowMultipleCaseClients = CRM.civicase.allowMultipleCaseClients;
    $scope.roles = [];
    $scope.rolesFilter = '';
    $scope.rolesPage = 1;
    $scope.rolesAlphaFilter = '';
    $scope.rolesSelectionMode = '';
    $scope.rolesSelectedTask = '';
    $scope.relations = [];
    $scope.relationsPage = 1;
    $scope.relationsAlphaFilter = '';
    $scope.relationsSelectionMode = '';
    $scope.relationsSelectedTask = '';
    $scope.letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
    $scope.contactTasks = CRM.civicase.contactTasks;

    function formatRole (role) {
      var relType = relTypesByName[role.name];
      role.role = relType.label_b_a;
      role.contact_type = relType.contact_type_b;
      role.contact_sub_type = relType.contact_sub_type_b;
      role.description = (role.manager ? (ts('Case Manager.') + ' ') : '') + (relType.description || '');
      role.relationship_type_id = relType.id;
    }
    $scope.allRoles = [];

    var getSelectedContacts = $scope.getSelectedContacts = function(tab, onlyChecked) {
      var idField = (tab === 'roles' ? 'contact_id' : 'id');
      if (onlyChecked || $scope[tab + 'SelectionMode'] === 'checked') {
        return _.collect(_.filter($scope[tab], {checked: true}), idField);
      }
      else if ($scope[tab + 'SelectionMode'] === 'all') {
        return _.collect($scope[tab], idField);
      }
      return [];
    };

    var getCaseRoles = $scope.getCaseRoles = function() {
      if ($scope.item && $scope.item.definition && $scope.item.definition.caseRoles) {
        $scope.allRoles = _.each(_.cloneDeep($scope.item.definition.caseRoles), formatRole);
      }
      var caseRoles = $scope.rolesAlphaFilter ? [] : _.cloneDeep($scope.allRoles),
        allRoles = _.cloneDeep($scope.allRoles),
        selected = getSelectedContacts('roles', true);
      if ($scope.rolesFilter) {
        caseRoles = $scope.rolesFilter === 'client' ? [] : [_.findWhere(caseRoles, {name: $scope.rolesFilter})];
      }
      _.each(item.contacts, function (contact) {
        var role = contact.relationship_type_id ? _.findWhere(caseRoles, {relationship_type_id: contact.relationship_type_id}) : null;
        if ((!role || role.contact_id) && contact.relationship_type_id) {
{'fraction_non_alphanumeric': 0.15378914211599037, 'fraction_numerical': 0.0007411524921252547, 'mean_word_length': 3.374392220421394, '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': '209576', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1716, 'n_words': 293}