<commit_before>'use strict';

angular.module('dateaWebApp')
.controller('NavCtrl'
, [ '$scope'
  , 'User'
  , '$rootScope'
  , '$modal'
  , '$location'
  , 'localStorageService'
  , 'State'
  , '$timeout'
, function (
    $scope
  , User
  , $rootScope
  , $modal
  , $location
  , localStorageService
  , State
  , $timeout
) {
	// fn declarations
	var onSignIn
	  , updateUserDataFromApi
	  , userStatusOnInit = 1
	  ;

	$scope.nav  = {};
	$scope.user = {};
	$scope.state = State.state;

	$scope.nav.visible = User.isSignedIn();

	$scope.nav.isCollapsed = true;
	$scope.alerts = []

	updateUserDataFromApi = function () {
		console.log("UPDATE USER FROM API");
		var ls = localStorageService
		  , updatedData
		  , currentData = ls.get('user')
		  ;

		User.getData( { username: currentData.username} )
		.then( function ( response ) {
			updatedData = response;
			angular.extend(currentData, updatedData);
			ls.set( 'user', currentData );
			User.updateUserDataFromStorage();
			if ( User.data.status === 0 ) {
				$location.path( '/configuracion' );
				$rootScope.$broadcast("user:statusCheck", {status: 0, changed: false});
				//$scope.addAlert( { type : 'danger'
				//                 , msg  : 'Por favor indique su correo para terminar el registro'
				//                 } );
			} else if (User.data.status === 1 && userStatusOnInit === 0) {
				userStatusOnInit = null;
				$location.path( '/configuracion' );
				$rootScope.$broadcast("user:statusCheck", {status: 1, changed: true});
			} else {
				$location.path( '/');
			}
		}, function ( reason ) {
			console.log( reason );
		} );
	}

	onSignIn = function ( givens ) {
		var path = $location.path();
		User.updateUserDataFromStorage();
		$scope.nav.visible = User.isSignedIn();
		if ( path === '/signin'
		  || path === '/signup'
		  || path === '/crear-cuenta'
		  || path === '/registrate'
		  || path !== '/'
		) {
			$scope.nav.visible = true;
		}
		$scope.user = User.data;
	
		if ( !givens && User.data.status === 0) {
			userStatusOnInit = User.data.status;
			updateUserDataFromApi();
		}
	}

	$scope.closeAlert = function(index) {
		$scope.alerts.splice(index, 1);
	};

	$scope.addAlert = function ( givens ) {
		$scope.alerts = [];
		$scope.alerts.push( givens );
	}

	$rootScope.$on( 'user:signedIn', function ( event, error ) {
		onSignIn();
	} );

	$rootScope.$on( 'user:signedOut', function ( event, error ) {
		$scope.nav.visible = User.isSignedIn();
	} );

	$rootScope.$on( 'user:hasDateado', function ( event, error ) {
		updateUserDataFromApi();
	} );

	$scope.$on( '$locationChangeStart', function ( scope, next, current ){
		User.updateUserDataFromStorage();
		onSignIn({checkUserStatus: false});
	});

	$rootScope.$on( 'error:someError', function () {
		console.log( 'hubo un error http' );
	} )


	$scope.nav.signIn = function () {
		$location.path( '/signin' );
	}

	$scope.nav.signOut = function () {
		User.signOut();
	}

	$scope.nav.datear = function () {
		$modal.open( { templateUrl : 'views/datear.html'
		             , controller  : 'DatearCtrl'
		             , windowClass : 'datear-modal'
		             , resolve     : {
		                datearModalGivens : function () {
		                 	return {};
		                 }
		               }
		             } )
	}

	if ( User.isSignedIn()) {
		onSignIn();
	}

	// $scope.nav.datear();
<commit_msg>add scroll to top on location change success<commit_after>'use strict';

angular.module('dateaWebApp')
.controller('NavCtrl'
, [ '$scope'
  , 'User'
  , '$rootScope'
  , '$modal'
  , '$location'
  , 'localStorageService'
  , 'State'
  , '$timeout'
  , '$window'
, function (
    $scope
  , User
  , $rootScope
  , $modal
  , $location
  , localStorageService
  , State
  , $timeout
  , $window
) {
	// fn declarations
	var onSignIn
	  , updateUserDataFromApi
	  , userStatusOnInit = 1
	  ;

	$scope.nav  = {};
	$scope.user = {};
	$scope.state = State.state;

	$scope.nav.visible = User.isSignedIn();

	$scope.nav.isCollapsed = true;
	$scope.alerts = []

	updateUserDataFromApi = function () {
		console.log("UPDATE USER FROM API");
		var ls = localStorageService
		  , updatedData
		  , currentData = ls.get('user')
		  ;

		User.getData( { username: currentData.username} )
		.then( function ( response ) {
			updatedData = response;
			angular.extend(currentData, updatedData);
			ls.set( 'user', currentData );
			User.updateUserDataFromStorage();
			if ( User.data.status === 0 ) {
				$location.path( '/configuracion' );
				$rootScope.$broadcast("user:statusCheck", {status: 0, changed: false});
				//$scope.addAlert( { type : 'danger'
				//                 , msg  : 'Por favor indique su correo para terminar el registro'
				//                 } );
			} else if (User.data.status === 1 && userStatusOnInit === 0) {
				userStatusOnInit = null;
				$location.path( '/configuracion' );
				$rootScope.$broadcast("user:statusCheck", {status: 1, changed: true});
			} else {
				$location.path( '/');
			}
		}, function ( reason ) {
			console.log( reason );
		} );
	}

	onSignIn = function ( givens ) {
		var path = $location.path();
		User.updateUserDataFromStorage();
		$scope.nav.visible = User.isSignedIn();
		if ( path === '/signin'
		  || path === '/signup'
		  || path === '/crear-cuenta'
		  || path === '/registrate'
		  || path !== '/'
		) {
			$scope.nav.visible = true;
		}
		$scope.user = User.data;
	
		if ( !givens && User.data.status === 0) {
			userStatusOnInit = User.data.status;
			updateUserDataFromApi();
		}
	}

	$scope.closeAlert = function(index) {
		$scope.alerts.splice(index, 1);
	};

	$scope.addAlert = function ( givens ) {
		$scope.alerts = [];
		$scope.alerts.push( givens );
	}

	$rootScope.$on( 'user:signedIn', function ( event, error ) {
		onSignIn();
	} );

	$rootScope.$on( 'user:signedOut', function ( event, error ) {
		$scope.nav.visible = User.isSignedIn();
	} );

	$rootScope.$on( 'user:hasDateado', function ( event, error ) {
		updateUserDataFromApi();
	} );

	$scope.$on( '$locationChangeStart', function ( scope, next, current ){
		User.updateUserDataFromStorage();
		onSignIn({checkUserStatus: false});
	});

	$scope.$on( '$locationChangeSuccess', function () {
		$window.scrollTo( 0, 0 );
	} );

	$rootScope.$on( 'error:someError', function () {
		console.log( 'hubo un error http' );
	} )


	$scope.nav.signIn = function () {
		$location.path( '/signin' );
	}

	$scope.nav.signOut = function () {
		User.signOut();
	}

	$scope.nav.datear = function () {
		$modal.open( { templateUrl : 'views/datear.html'
		             , controller  : 'DatearCtrl'
		             , windowClass : 'datear-modal'
		             , resolve     : {
		                datearModalGivens : function () {
		                 	return {};
		                 }
		               }
		             } )
	}

	if ( User.isSignedIn()) {
		onSignIn();
	}

	// $scope.nav.datear();

{'fraction_non_alphanumeric': 0.17442030042292547, 'fraction_numerical': 0.002625054688639347, 'mean_word_length': 2.703023758099352, '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': '7294984', 'n_tokens_mistral': 2634, 'n_tokens_neox': 2335, 'n_words': 429}