<commit_before>'use strict';

/* Controllers */

angular.module('myApp.controllers', ['LocalStorageModule']).
  controller('HomeCtrl', ['$scope', '$location', 'Utils', 'localStorageService', 'Api', function(scope, location, Utils, session, Api) {
    console.log('loaded homeCtrl');

  }])


  .controller('LoginCtrl', ['$scope', '$location', 'Utils', 'localStorageService', 'Api', function(scope, location, Utils, session, Api) {
  	console.log('loaded loginCtrl');

  }])

  /* Callback Controller */
  .controller('CallbackCtrl', ['$scope', '$timeout', '$location', 'localStorageService', 'Utils', 'Api', function(scope, timeout, location, session, Utils, Api) {
	console.log('callback loaded');  	
  	//set code  	
    if(! Utils.isEmpty(location.search().code) ) {
    	Api.setCode(location.search().code);
      //add code
    	// session.add("id", location.search().code);
    	//get session organization
    	var orgId = session.get('id');
    	var code = Api.getCode();
    	var creds = Api.getUserCredentials();

    	// console.log(creds.authResponse.userID);
/*    	Api.createGlobeAccessToken(code, creds.user.id).then(function(result) {
    		console.log(result);
    	}, function(result) {
    		console.log(result);
    	});
*/

    	timeout(function() {
    		delete location.search().code;
    		location.path('/organizations/detail/' + orgId);
    		//after successful redirect delete session orgId
    		session.remove("id");
    	}, 1000)
    }
  }])

  /* Organization Controller*/
  .controller('OrganizationCtrl', ['$scope', '$rootScope', '$sce', '$routeParams', '$location', 'localStorageService', 'Api', 'Utils', function(scope, rootScope, sce, routeParams, location, session, Api, Utils) {
    var creds = Api.getUserCredentials();
    var code = Api.getCode();

    scope.showBanner = true;
    scope.orgDetail = {};
    scope.params = routeParams;
    scope.hasGlobeAccessToken = (Utils.isEmpty(creds)) ? "" : creds.user.has_globe_access_token;
    scope.isLoggedIn = (Utils.isEmpty(creds)) ? false : true;
    scope.tarrif_rate = 0;
    console.log(scope.isLoggedIn);

    Api.getListOrganization().then(function(result) {
      console.log(result.data);
      scope.orgLists = result.data.result;
    }, function(result) {
      console.log(result.data);
    });

    scope.getDetail = function(orgID) {
      Api.getOrgDetail(orgID).then(function(result) {
        console.log(result.data);
        scope.orgDetail = result.data.result;
        scope.trustedHtml = sce.trustAsHtml(result.data.result.description);
        
        console.log(scope.hasGlobeAccessToken);
        if(!scope.isLoggedIn) return false;
        if(eval(scope.hasGlobeAccessToken) != 1) {
          console.log('if');
	        Api.createGlobeAccessToken(code, creds.user.id).then(function(result) {
            console.log('createGlobeAccessToken');
    				console.log(result);
    			}, function(result) {
            //redirect to login facebook
            // location.path('/login');
    				console.log(result);
    			});
        }else {
          console.log('else');
        	scope.globeAccessToken = creds.user.globe_access_token;<commit_msg>updates<commit_after>'use strict';

/* Controllers */

angular.module('myApp.controllers', ['LocalStorageModule']).
  controller('HomeCtrl', ['$scope', '$location', 'Utils', 'localStorageService', 'Api', function(scope, location, Utils, session, Api) {
    console.log('loaded homeCtrl');

  }])


  .controller('LoginCtrl', ['$scope', '$location', 'Utils', 'localStorageService', 'Api', function(scope, location, Utils, session, Api) {
  	console.log('loaded loginCtrl');

  }])

  /* Callback Controller */
  .controller('CallbackCtrl', ['$scope', '$timeout', '$location', 'localStorageService', 'Utils', 'Api', function(scope, timeout, location, session, Utils, Api) {
	console.log('callback loaded');  	
  	//set code  	
    if(! Utils.isEmpty(location.search().code) ) {
    	Api.setCode(location.search().code);
      //add code
    	// session.add("id", location.search().code);
    	//get session organization
    	var orgId = session.get('id');
    	var code = Api.getCode();
    	var creds = Api.getUserCredentials();

    	// console.log(creds.authResponse.userID);
/*    	Api.createGlobeAccessToken(code, creds.user.id).then(function(result) {
    		console.log(result);
    	}, function(result) {
    		console.log(result);
    	});
*/

    	timeout(function() {
    		delete location.search().code;
    		location.path('/organizations/detail/' + orgId);
    		//after successful redirect delete session orgId
    	}, 1000)
    }
  }])

  /* Organization Controller*/
  .controller('OrganizationCtrl', ['$scope', '$rootScope', '$sce', '$routeParams', '$location', 'localStorageService', 'Api', 'Utils', function(scope, rootScope, sce, routeParams, location, session, Api, Utils) {
    var creds = Api.getUserCredentials();
    var code = Api.getCode();

    scope.showBanner = true;
    scope.orgDetail = {};
    scope.params = routeParams;
    scope.hasGlobeAccessToken = (Utils.isEmpty(creds)) ? "" : creds.user.has_globe_access_token;
    scope.isLoggedIn = (Utils.isEmpty(creds)) ? false : true;
    scope.tarrif_rate = 0;
    console.log(scope.isLoggedIn);

    Api.getListOrganization().then(function(result) {
      console.log(result.data);
      scope.orgLists = result.data.result;
    }, function(result) {
      console.log(result.data);
    });

    scope.getDetail = function(orgID) {
      session.remove("id");
      Api.getOrgDetail(orgID).then(function(result) {
        console.log(result.data);
        scope.orgDetail = result.data.result;
        scope.trustedHtml = sce.trustAsHtml(result.data.result.description);
        
        console.log(scope.hasGlobeAccessToken);
        if(!scope.isLoggedIn) return false;
        if(eval(scope.hasGlobeAccessToken) != 1) {
          console.log('if');
	        Api.createGlobeAccessToken(code, creds.user.id).then(function(result) {
            console.log('createGlobeAccessToken');
    				console.log(result);
    			}, function(result) {
            //redirect to login facebook
            // location.path('/login');
    				console.log(result);
    			});
        }else {
          console.log('else');
        	scope.globeAccessToken = creds.user.globe_access_token;
{'fraction_non_alphanumeric': 0.164079822616408, 'fraction_numerical': 0.0019005384859043396, 'mean_word_length': 3.2525252525252526, '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': '2248867', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1974, 'n_words': 327}