<commit_before>/* global angular:false */

/**
 * This file defines filters that attach to bindings in 
 * partial view templates and return a custom transformation
 * of their input.
 * 
 * @author lambert8
 * @see https://opensource.ncsa.illinois.edu/confluence/display/~lambert8/Filters
 */
angular.module('ndslabs-filters', [ 'ndslabs-services' ])

/**
 * Make lodash available for injection into filters
 */ 
.constant('_', window._)

/**
 * Given a string, capitalize it
 */ 
.filter('capitalize', [ '_', function(_) {
  return function(input) {
    return _.capitalize(input);
  };
}])

/**
 * Return the external IP of the API / GUI server 
 * appended with the port if one is provided.
 */ 
.filter('externalHostPort', [ 'ApiHost', 'ApiPort', '_', function(ApiHost, ApiPort, _) {
  return function(endpt) {
    // TODO: How do we know if this can be navigated to?
    var protocol = endpt.protocol;
    
    // Hard-coding HTTP for now, since specs specify TCP instead of HTTP
    return protocol + '://' + ApiHost + (endpt.nodePort ? ':' + endpt.nodePort : '');
  };
}])

/**
 * Trust the given snippet as valid HTML.
 */ 
.filter('unsafe', [ '$sce', function($sce) {
  return function(input) {
    return $sce.trustAsHtml(input);
  };
}])


/**
 * Given a string, encode it so that it can be safely put into a URL
 */
.filter('urlEncode', [ '_', function(_) {
  return function(input) {
    if(input) {
      return window.encodeURIComponent(_.replace(input, '\s', '+')); 
    }
    return "";
  }
}])
/**
 * Given a string, decode it safely from URL form
 */
.filter('urlDecode', [ function() {
  return function(input) {
    if(input) {
      return window.decodeURIComponent(input); 
    }
    return "";
  }
}])
/**
 * Given an array of specs, return only those which can be added to your namespace.
 */
.filter('isStack', [ '_', function(_) {
  return function(input, showStandalones) {
    if (!showStandalones) {
      return _.filter(input, ['isStack', true]);
    }
    
    return _.filter(input, { 'isStandalone': true });
  }
}])
/**
 * Given a stack, return a list of ALL of its services' endpoints
 */
.filter('allEndpoints', ['_', function(_) {
  return function(stack) {
    var endpoints = [];
    angular.forEach(stack.services, function(svc) {
      endpoints = _.concat(endpoints, svc.endpoints);
    });
    return endpoints;
  };
}])
/**<commit_msg>'isStack','isStandalone' -> display<commit_after>/* global angular:false */

/**
 * This file defines filters that attach to bindings in 
 * partial view templates and return a custom transformation
 * of their input.
 * 
 * @author lambert8
 * @see https://opensource.ncsa.illinois.edu/confluence/display/~lambert8/Filters
 */
angular.module('ndslabs-filters', [ 'ndslabs-services' ])

/**
 * Make lodash available for injection into filters
 */ 
.constant('_', window._)

/**
 * Given a string, capitalize it
 */ 
.filter('capitalize', [ '_', function(_) {
  return function(input) {
    return _.capitalize(input);
  };
}])

/**
 * Return the external IP of the API / GUI server 
 * appended with the port if one is provided.
 */ 
.filter('externalHostPort', [ 'ApiHost', 'ApiPort', '_', function(ApiHost, ApiPort, _) {
  return function(endpt) {
    // TODO: How do we know if this can be navigated to?
    var protocol = endpt.protocol;
    
    // Hard-coding HTTP for now, since specs specify TCP instead of HTTP
    return protocol + '://' + ApiHost + (endpt.nodePort ? ':' + endpt.nodePort : '');
  };
}])

/**
 * Trust the given snippet as valid HTML.
 */ 
.filter('unsafe', [ '$sce', function($sce) {
  return function(input) {
    return $sce.trustAsHtml(input);
  };
}])


/**
 * Given a string, encode it so that it can be safely put into a URL
 */
.filter('urlEncode', [ '_', function(_) {
  return function(input) {
    if(input) {
      return window.encodeURIComponent(_.replace(input, '\s', '+')); 
    }
    return "";
  }
}])
/**
 * Given a string, decode it safely from URL form
 */
.filter('urlDecode', [ function() {
  return function(input) {
    if(input) {
      return window.decodeURIComponent(input); 
    }
    return "";
  }
}])
/**
 * Given an array of specs, return only those which can be added to your namespace.
 */
.filter('isStack', [ '_', function(_) {
  return function(input, showStandalones) {
    if (!showStandalones) {
      return _.filter(input, ['display', 'stack']);
    }

    // Return stacks and standalones
    return _.filter(input, function(o) {
      return o.display;
    }); 
  }
}])
/**
 * Given a stack, return a list of ALL of its services' endpoints
 */
.filter('allEndpoints', ['_', function(_) {
  return function(stack) {
    var endpoints = [];
    angular.forEach(stack.services, function(svc) {
      endpoints = _.concat(endpoints, svc.endpoints);
    });
    return endpoints;
  };
}])
/**
{'fraction_non_alphanumeric': 0.15943824865757952, 'fraction_numerical': 0.0008261049153242462, 'mean_word_length': 3.1967071057192373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '6618092', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1522, 'n_words': 432}