<commit_before>/**
 * Created by <NAME> <<EMAIL>>
 *     on Mon Mar 17 2014
 */

angular.module('GeoAngular').factory('Route', function ($rootScope, $location, Alias) {

  var init = true;

  // default route parameters. gets reset by AppCtrl.
  var params = {
    lat: '45',
    lng: '0',
    zoom: '4',
    layers: Alias.osm,
    stories: 'Route' //NH TODO take out, just for debugging...
  };

  function updateLocation() {
    var path = '/map@' + params.lat +
      ',' + params.lng +
      ',' + params.zoom +
      '(' + params.layers + ')';
    if (params.stories) path += '/stories/' + params.stories;
    if (params.landing) path += '/landing';

    $location.path(path);
  }

  /**
   * Simple object equality test. angular.equals is expensive.
   * @param obj1
   * @param obj2
   * @returns {boolean}
   */
  function equals(obj1, obj2) {
    if (Object.keys(obj1).length !== Object.keys(obj2).length)
      return false;
    for (var key in obj1) {
      if (obj1[key] !== obj2[key])
        return false;
    }
    return true;
  }


  return function(routeParams) {
    // only do this stuff if we have an arg in the fn call
    if (typeof routeParams !== 'undefined' && routeParams !== null) {
      if (init) {
        params = routeParams;
        $rootScope.$broadcast('route-init', params);
        console.log('route-init');
        console.log(JSON.stringify(params));
        init = false;
      } else {
        // Angular is trolling Route. We don't want to do 3 broadcasts of the same thing.
        if ( equals(params,routeParams) ) return params;
        angular.extend(params, routeParams);
        updateLocation();
        $rootScope.$broadcast('route-update', params);
        console.log('route-update');
        console.log(JSON.stringify(params));
      }
    }
    return params;
  };


});<commit_msg>clicking initial landing link now working. NH TODO: see why param equality test in Route.js is true thus preventing map refresh<commit_after>/**
 * Created by <NAME> <<EMAIL>>
 *     on Mon Mar 17 2014
 */

angular.module('GeoAngular').factory('Route', function ($rootScope, $location, Alias) {

  var init = true;

  // default route parameters. gets reset by AppCtrl.
  var params = {
    lat: '45',
    lng: '0',
    zoom: '4',
    layers: Alias.osm,
    stories: 'Route' //NH TODO take out, just for debugging...
  };

  function updateLocation() {
    var path = '/map@' + params.lat +
      ',' + params.lng +
      ',' + params.zoom +
      '(' + params.layers + ')';
    if (params.stories) path += '/stories/' + params.stories;
    if (params.landing) path += '/landing';

    $location.path(path);
  }

  /**
   * Simple object equality test. angular.equals is expensive.
   * @param obj1
   * @param obj2
   * @returns {boolean}
   */
  function equals(obj1, obj2) {
    if (Object.keys(obj1).length !== Object.keys(obj2).length)
      return false;
    for (var key in obj1) {
      if (obj1[key] !== obj2[key])
        return false;
    }
    return true;
  }


  return function(routeParams) {
    // only do this stuff if we have an arg in the fn call
    if (typeof routeParams !== 'undefined' && routeParams !== null) {
      if (init) {
        params = routeParams;
        $rootScope.$broadcast('route-init', params);
        console.log('route-init');
        console.log(JSON.stringify(params));
        init = false;
      } else {
        // Angular is trolling Route. We don't want to do 3 broadcasts of the same thing.
        //NH TODO: Figure out why this is true when initial landing link is clicked
//        if ( equals(params,routeParams) ) return params;
        angular.extend(params, routeParams);
        updateLocation();
        $rootScope.$broadcast('route-update', params);
        console.log('route-update');
        console.log(JSON.stringify(params));
      }
    }
    // NH good way to test if outsiders are messing with inside
//    return angular.extend({},params);
    return params;
  };


});
{'fraction_non_alphanumeric': 0.14540431943746862, 'fraction_numerical': 0.010045203415369162, 'mean_word_length': 2.4455017301038064, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '918580', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1207, 'n_words': 359}