<commit_before>'use strict';

define(['angular'], function(angular) {


  var app = angular.module('portal.misc.services', []);

  app.factory('PortalGroupService', function($http, miscService, SERVICE_LOC){

    var getGroups = function(){
      var groupPromise = $http.get(SERVICE_LOC.groupURL, {cache : true}).then (
                                    function(result){
                                      return result.data.groups;
                                    },function(reason){
                                      miscService.redirectUser(reason.status, 'group json feed call');
                                    });
      return groupPromise;
    }

    var groupsServiceEnabled = function() {
      if(SERVICE_LOC.groupURL) {
        return true;
      } else {
        return false;
      }
    }

    return {
      getGroups : getGroups,
      groupsServiceEnabled : groupsServiceEnabled
    }
  });

  app.factory('PortalAddToHomeService', function($http, filterFilter, NAMES, MISC_URLS){

    var canAddToHome = function(){
      if (MISC_URLS.addToHomeURLS && MISC_URLS.addToHomeURLS.addToHomeActionURL) {
            return true;
      } else {
        return false;
      }
    };

    var inHome = function(fname){
      return $http.get(MISC_URLS.addToHomeURLS.layoutURL).then(function(result){
        var layout = result.data.layout;
        if(layout) {
          var theFname = (fname ? fname : NAMES.fname);
          var filteredLayout = filterFilter(layout, {fname : theFname});
          return filteredLayout && filteredLayout.length > 0;
        } else {
          return false;
        }
      }, function(){
        //failed
        console.warn('could not reach portal server to get layout, portal down?');
        return true; //returning it is in the layout by default since portal is down
      });
    };

    var addToHome = function(fname){
      return $http.post(MISC_URLS.addToHomeURLS.addToHomeActionURL + (fname ? fname : NAMES.fname));
    };

    return {
      canAddToHome : canAddToHome,
      inHome : inHome,
      addToHome : addToHome
    };
  });

  app.factory('miscService', function($analytics, $http, $window, $location, MISC_URLS) {

    /**
     Used to redirect users to login screen iff result code is 0 (yay shib) or 302

     Setup MISC_URLS.loginURL in js/app-config.js to have redirects happen
    **/
    var redirectUser = function(status, caller) {
      if(status === 0 || status === 302) {
        console.log("redirect happening due to " + status);
        if(MISC_URLS.loginURL) {
          window.location.replace(MISC_URLS.loginURL);
        } else {
          console.warn("MISC_URLS.loginURL was not set, cannot redirect");
        }
      } else {
        console.warn("Strange behavior from " + caller +". Returned status code : " + status);
      }
    };

    /**
     Google Analytics page view
     - searchTerm : Optional parameter to say "this is a search page".
                    This is the actual search term used.
     @depricated
    **/
    var pushPageview = function (searchTerm) {
      var path = $location.path();
      if(searchTerm) {
        path += "?q=" + searchTerm;
      }
      console.warn('this method is deprecated in favor of automatic page views in angulartics. Will be removed in 3.0.0');
      console.log('ga pageview logged ' + path);
      $analytics.pageTrack(path);
    };

    /**
     Google Analytics event push
     - category : e.g.: beta header
     - action   : e.g.: beta buttons
     - label    : e.g.: back to classic<commit_msg>spelling is hard<commit_after>'use strict';

define(['angular'], function(angular) {


  var app = angular.module('portal.misc.services', []);

  app.factory('PortalGroupService', function($http, miscService, SERVICE_LOC){

    var getGroups = function(){
      var groupPromise = $http.get(SERVICE_LOC.groupURL, {cache : true}).then (
                                    function(result){
                                      return result.data.groups;
                                    },function(reason){
                                      miscService.redirectUser(reason.status, 'group json feed call');
                                    });
      return groupPromise;
    }

    var groupsServiceEnabled = function() {
      if(SERVICE_LOC.groupURL) {
        return true;
      } else {
        return false;
      }
    }

    return {
      getGroups : getGroups,
      groupsServiceEnabled : groupsServiceEnabled
    }
  });

  app.factory('PortalAddToHomeService', function($http, filterFilter, NAMES, MISC_URLS){

    var canAddToHome = function(){
      if (MISC_URLS.addToHomeURLS && MISC_URLS.addToHomeURLS.addToHomeActionURL) {
            return true;
      } else {
        return false;
      }
    };

    var inHome = function(fname){
      return $http.get(MISC_URLS.addToHomeURLS.layoutURL).then(function(result){
        var layout = result.data.layout;
        if(layout) {
          var theFname = (fname ? fname : NAMES.fname);
          var filteredLayout = filterFilter(layout, {fname : theFname});
          return filteredLayout && filteredLayout.length > 0;
        } else {
          return false;
        }
      }, function(){
        //failed
        console.warn('could not reach portal server to get layout, portal down?');
        return true; //returning it is in the layout by default since portal is down
      });
    };

    var addToHome = function(fname){
      return $http.post(MISC_URLS.addToHomeURLS.addToHomeActionURL + (fname ? fname : NAMES.fname));
    };

    return {
      canAddToHome : canAddToHome,
      inHome : inHome,
      addToHome : addToHome
    };
  });

  app.factory('miscService', function($analytics, $http, $window, $location, MISC_URLS) {

    /**
     Used to redirect users to login screen iff result code is 0 (yay shib) or 302

     Setup MISC_URLS.loginURL in js/app-config.js to have redirects happen
    **/
    var redirectUser = function(status, caller) {
      if(status === 0 || status === 302) {
        console.log("redirect happening due to " + status);
        if(MISC_URLS.loginURL) {
          window.location.replace(MISC_URLS.loginURL);
        } else {
          console.warn("MISC_URLS.loginURL was not set, cannot redirect");
        }
      } else {
        console.warn("Strange behavior from " + caller +". Returned status code : " + status);
      }
    };

    /**
     Google Analytics page view
     - searchTerm : Optional parameter to say "this is a search page".
                    This is the actual search term used.
     @deprecated : will drop in 3.0.0
    **/
    var pushPageview = function (searchTerm) {
      var path = $location.path();
      if(searchTerm) {
        path += "?q=" + searchTerm;
      }
      console.warn('this method is deprecated in favor of automatic page views in angulartics. Will be removed in 3.0.0');
      console.log('ga pageview logged ' + path);
      $analytics.pageTrack(path);
    };

    /**
     Google Analytics event push
     - category : e.g.: beta header
     - action   : e.g.: beta buttons
     - label    : e.g.: back to classic
{'fraction_non_alphanumeric': 0.11090959821428571, 'fraction_numerical': 0.0037667410714285715, 'mean_word_length': 2.0715509854327334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1074233', 'n_tokens_mistral': 2120, 'n_tokens_neox': 2019, 'n_words': 527}