<commit_before>/*global $:false */
'use strict';

angular.module('mean.listedecourse').controller('ListedecourseController', ['$scope', '$log', '$http', 'Global', 'Listedecourse','$modal','$sce', '$analytics', '$location',
  function($scope, $log, $http, Global, Listedecourse, $modal, $sce, $analytics, $location) {
    $scope.global = Global;
    $scope.package = {
      name: 'listedecourse'
    };


	  	$scope.open = function (size) {
            $analytics.pageTrack('openRecipe');
		    var modalInstance = $modal.open({
		      templateUrl: '/listedecourse/views/myModal.html',
		      controller: 'ModalInstanceCtrl',
		      size: size,
		      resolve: {
		        listedecourse: function () {
		          return $scope.listedecourse;
		        }
		      }
		    });

		    modalInstance.result.then(function (selectedItem) {
		      $scope.selected = selectedItem;
		    }, function () {
		      $log.info('Modal dismissed at: ' + new Date());
		    });
		};

    	$scope.results = [];
		$scope.NumberOfRecipe = 0;
		$scope.NumberOfIngredient = 0;
        $scope.search = function(){
            $analytics.pageTrack('search/'+this.query);
            $location.path('/search/'+this.query);
        	$log.info('Search for query : ' + this.query);
            // TODO Waiting screen
            $('body').addClass('loading');

        	$http.get('/marmitonsnippet/search/' + this.query).
    		  success(function(data, status, headers, config) {
    		  	$scope.results = data;
    		  	$log.info($scope.results);
                $('body').removeClass('loading');
    		  }).
    		  error(function(data, status, headers, config) {
                // TODO RETURN MESSAGE ERROR
    		    $scope.results = {};
                $('body').removeClass('loading');
    		 });
        };
        $scope.getRecipe = function(recipeUrl){
            $('body').addClass('loading');
            $analytics.pageTrack('recipe/' + recipeUrl);
            $location.path('/recipe/'+recipeUrl);
        	$log.info('Get Recipe : ' + recipeUrl);

        	$http.get('/marmitonsnippet/recette/' + encodeURIComponent(recipeUrl)).
    		  success(function(data, status, headers, config) {
                $log.info('recipe ' + $scope.recipe);
                if($scope.recipe && $scope.recipe.result && $scope.recipe.result.image){
                    $log.info('before ' + $scope.recipe.result.image);
                    $log.info('delete image');
                    delete $scope.recipe.result.image;    
                    $log.info('after ' + $scope.recipe.result.image);
                }
                $scope.recipe = data;
                $scope.recipe.result.descriptionSafe = $sce.trustAsHtml(data.result.description);
                delete $scope.recipe.result.description;
    		  	$log.info($scope.recipe);
                $scope.num = parseInt($scope.recipe.result.contenu.nbrPersons);
                $scope.oldNbrPersons = parseInt($scope.recipe.result.contenu.nbrPersons);
                $log.info('newNbrPersons : ' + $scope.recipe.result.contenu.nbrPersons);
                $('body').removeClass('loading');
    		  }).
    		  error(function(data, status, headers, config) {
    		    $('body').removeClass('loading');
    		 });
        };
        
        $scope.$watch('num', function(){
        	var nbrPersons = $scope.oldNbrPersons;
        	$log.info('NbrPersons : ' + nbrPersons + ' New : ' + $scope.num);
        	var inputNbrPersons = $scope.num;
        	if($scope.recipe){
	        	$scope.recipe.result.contenu.ingredients.forEach(function(element, index){
	        		var quantity = element.quantity / nbrPersons * inputNbrPersons;
	        		$log.info('new Final quantity for ' + element.product + ' = ' + quantity);
	        		element.quantity = quantity;
	        	});
	        	$scope.oldNbrPersons = inputNbrPersons;
	        }
        });<commit_msg>Fix bug of first add to list people number<commit_after>/*global $:false */
'use strict';

angular.module('mean.listedecourse').controller('ListedecourseController', ['$scope', '$log', '$http', 'Global', 'Listedecourse','$modal','$sce', '$analytics', '$location',
  function($scope, $log, $http, Global, Listedecourse, $modal, $sce, $analytics, $location) {
    $scope.global = Global;
    $scope.package = {
      name: 'listedecourse'
    };


	  	$scope.open = function (size) {
            $analytics.pageTrack('openRecipe');
		    var modalInstance = $modal.open({
		      templateUrl: '/listedecourse/views/myModal.html',
		      controller: 'ModalInstanceCtrl',
		      size: size,
		      resolve: {
		        listedecourse: function () {
		          return $scope.listedecourse;
		        }
		      }
		    });

		    modalInstance.result.then(function (selectedItem) {
		      $scope.selected = selectedItem;
		    }, function () {
		      $log.info('Modal dismissed at: ' + new Date());
		    });
		};

    	$scope.results = [];
		$scope.NumberOfRecipe = 0;
		$scope.NumberOfIngredient = 0;
        $scope.search = function(){
            $analytics.pageTrack('search/'+this.query);
            $location.path('/search/'+this.query);
        	$log.info('Search for query : ' + this.query);
            // TODO Waiting screen
            $('body').addClass('loading');

        	$http.get('/marmitonsnippet/search/' + this.query).
    		  success(function(data, status, headers, config) {
    		  	$scope.results = data;
    		  	$log.info($scope.results);
                $('body').removeClass('loading');
    		  }).
    		  error(function(data, status, headers, config) {
                // TODO RETURN MESSAGE ERROR
    		    $scope.results = {};
                $('body').removeClass('loading');
    		 });
        };
        $scope.getRecipe = function(recipeUrl){
            $('body').addClass('loading');
            $analytics.pageTrack('recipe/' + recipeUrl);
            $location.path('/recipe/'+recipeUrl);
        	$log.info('Get Recipe : ' + recipeUrl);

        	$http.get('/marmitonsnippet/recette/' + encodeURIComponent(recipeUrl)).
    		  success(function(data, status, headers, config) {
                $log.info('recipe ' + $scope.recipe);
                if($scope.recipe && $scope.recipe.result && $scope.recipe.result.image){
                    $log.info('before ' + $scope.recipe.result.image);
                    $log.info('delete image');
                    delete $scope.recipe.result.image;    
                    $log.info('after ' + $scope.recipe.result.image);
                }
                $scope.recipe = data;
                $scope.recipe.result.descriptionSafe = $sce.trustAsHtml(data.result.description);
                delete $scope.recipe.result.description;
    		  	$log.info($scope.recipe);
                $scope.num = parseInt($scope.recipe.result.contenu.nbrPersons);
                $scope.oldNbrPersons = parseInt($scope.recipe.result.contenu.nbrPersons);
                $log.info('newNbrPersons : ' + $scope.recipe.result.contenu.nbrPersons);
                $('body').removeClass('loading');
    		  }).
    		  error(function(data, status, headers, config) {
    		    $('body').removeClass('loading');
    		 });
        };
        
        $scope.$watch('num', function(){
        	var nbrPersons = $scope.oldNbrPersons;
        	$log.info('NbrPersons : ' + nbrPersons + ' New : ' + $scope.num);
        	var inputNbrPersons = $scope.num;
        	if($scope.recipe){
                $scope.recipe.result.contenu.nbrPersons = $scope.num;
	        	$scope.recipe.result.contenu.ingredients.forEach(function(element, index){
	        		var quantity = element.quantity / nbrPersons * inputNbrPersons;
	        		$log.info('new Final quantity for ' + element.product + ' = ' + quantity);
	        		element.quantity = quantity;
	        	});
	        	$scope.oldNbrPersons = inputNbrPersons;
	        }
        });
{'fraction_non_alphanumeric': 0.15792148392834457, 'fraction_numerical': 0.0005081946385465633, 'mean_word_length': 2.107777339123569, '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': '1889993', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2366, 'n_words': 346}