<commit_before>(function() {
'use strict';

angular.module('NourritureControllers')
	.controller('IngredientsDashboardController', IngredientsDashboardController);

IngredientsDashboardController.$inject = ["$scope", "IngredientService", 'SearchService', 'toastr',"$log", "$mdDialog", "$document", "$state"];

function IngredientsDashboardController($scope, IngredientService, SearchService, toastr, $log, $mdDialog, $document, $state)
{
	var vm = this;

	$log.log("innit");

	//Table specs
	vm.table = {
		name : '',
		metadata : {
			"items": 10,
			"page" : 1,
			"total" : 4
		}
	};

	vm.IngredientsGetSuccess = function (data) {
		$log.log(data);
		vm.table.total = data.metadata.total;
		vm.ingredients = data.ingredients;
	};

	vm.IngredientsGetFailure = function (data) {
		$log.log(data.data);
		var errorMsg = "This is odd...";
		if(data.data.errmsg)
			if (data.data.errmsg.indexOf("name") > -1)
				errorMsg = "Seems like the ingredient already exists";
		if (data.data.message)
			errorMsg = "This ingredient doesn't exist";
		toastr.error(errorMsg, 'Woops...', {timeOut : 300});
	};

	vm.IngredientsDeleteSuccess = function (data) {
		$log.log(data);
		toastr.success("Ingredient Deleted Successfully", "Success", {timeOut : 300});
		vm.searchIngredientsByName();
	};

	vm.IngredientsDeleteFailure = function (data) {
		$log.log(data.data);
		var errorMsg = "This is odd...";
		if(data.data.errmsg)
			if (data.data.errmsg.indexOf("name") > -1)
				errorMsg = "Seems like the ingredient already exists";
		if (data.data.message)
			errorMsg = "This ingredient doesn't exist";
		toastr.error(errorMsg, 'Woops...', {timeOut : 300});
	};

	//Init data
	SearchService
		.ingredients
		.save(vm.table)
		.$promise
		.then(vm.IngredientsGetSuccess, vm.IngredientsGetFailure);

	vm.deleteIngredient = function(ingredient) {
		IngredientService
		.ingredient_id
		.delete({id : ingredient._id})
		.$promise
		.then(vm.IngredientsDeleteSuccess, vm.IngredientsDeleteFailure);
	}

	vm.searchIngredientsByName = function() {
		if (!$scope.search)
			IngredientService
			.ingredients
			.query()
			.$promise
			.then(vm.IngredientsGetSuccess, vm.IngredientsGetFailure);
		else
			IngredientService
				.ingredient_name
				.query({name : $scope.search})
				.$promise
				.then(vm.IngredientsGetSuccess, vm.IngredientsGetFailure);
	};

	//Table functions
	vm.tableOnOrderChange = function(order) {
		if (order[0] == '-')
		{
			vm.table.order.order = "desc";
			vm.table.order.field = vm.table.order.field.slice(1);
		}
		else
			vm.table.order.order = "asc";
		$log.log(vm.table);
		if (vm.table.order.order == "desc")
			vm.table.order.field = "-" + vm.table.order.field;
	};

	//Dialogs
	vm.infosIngredientDialog = function(event, ingredient) {
		$mdDialog.show({
		controller: vm.dialogController,
		controllerAs : "infosIngredient",
		templateUrl: 'app/templates/dialogTemplates/ingredientInfos.tmpl.html',
		parent: angular.element($document.body),
		locals : {ingredient : ingredient},
		bindToController : true,
		targetEvent: event,
		clickOutsideToClose:true
		})
	};

	vm.deleteIngredientDialog = function(event, ingredient) {
		var confirm = $mdDialog.confirm()
					.title('Are you sure you want to delete this ingredient ?')
					.ok('Delete ingredient')
					.cancel('Not really actually')
					.targetEvent(event);
<commit_msg>added sorting on name<commit_after>(function() {
'use strict';

angular.module('NourritureControllers')
	.controller('IngredientsDashboardController', IngredientsDashboardController);

IngredientsDashboardController.$inject = ["$scope", "IngredientService", 'SearchService', 'toastr',"$log", "$mdDialog", "$document", "$state"];

function IngredientsDashboardController($scope, IngredientService, SearchService, toastr, $log, $mdDialog, $document, $state)
{
	var vm = this;

	$log.log("innit");

	//Table specs
	vm.table = {
		name : '',
		metadata : {
			"items": 10,
			"page" : 1,
			"total" : 4
		}
	};

	vm.IngredientsGetSuccess = function (data) {
		$log.log(data);
		vm.table.total = data.metadata.total;
		vm.ingredients = data.ingredients;
		if (vm.table.order)
			if (vm.table.order.order == "desc")
				if (vm.table.order.field[0] != "-")
					vm.table.order.field = "-" + vm.table.order.field;
	};

	vm.IngredientsGetFailure = function (data) {
		$log.log(data.data);
		var errorMsg = "This is odd...";
		if(data.data.errmsg)
			if (data.data.errmsg.indexOf("name") > -1)
				errorMsg = "Seems like the ingredient already exists";
		if (data.data.message)
			errorMsg = "This ingredient doesn't exist";
		toastr.error(errorMsg, 'Woops...', {timeOut : 300});
	};

	vm.IngredientsDeleteSuccess = function (data) {
		$log.log(data);
		toastr.success("Ingredient Deleted Successfully", "Success", {timeOut : 300});
		vm.searchIngredientsByName();
	};

	vm.IngredientsDeleteFailure = function (data) {
		$log.log(data.data);
		var errorMsg = "This is odd...";
		if(data.data.errmsg)
			if (data.data.errmsg.indexOf("name") > -1)
				errorMsg = "Seems like the ingredient already exists";
		if (data.data.message)
			errorMsg = "This ingredient doesn't exist";
		toastr.error(errorMsg, 'Woops...', {timeOut : 300});
	};

	//Init data
	SearchService
		.ingredients
		.save(vm.table)
		.$promise
		.then(vm.IngredientsGetSuccess, vm.IngredientsGetFailure);

	vm.deleteIngredient = function(ingredient) {
		IngredientService
		.ingredient_id
		.delete({id : ingredient._id})
		.$promise
		.then(vm.IngredientsDeleteSuccess, vm.IngredientsDeleteFailure);
	}

	vm.searchIngredientsByName = function() {
		if (!$scope.search)
			IngredientService
			.ingredients
			.query()
			.$promise
			.then(vm.IngredientsGetSuccess, vm.IngredientsGetFailure);
		else
			IngredientService
				.ingredient_name
				.query({name : $scope.search})
				.$promise
				.then(vm.IngredientsGetSuccess, vm.IngredientsGetFailure);
	};

	//Table functions
	vm.tableOnOrderChange = function(order) {
		if (order[0] == '-')
		{
			vm.table.order.order = "desc";
			vm.table.order.field = vm.table.order.field.slice(1);
		}
		else
			vm.table.order.order = "asc";
		$log.log(vm.table);
		SearchService
			.ingredients
			.save(vm.table)
			.$promise
			.then(vm.IngredientsGetSuccess, vm.IngredientsGetFailure);
	};

	//Dialogs
	vm.infosIngredientDialog = function(event, ingredient) {
		$mdDialog.show({
		controller: vm.dialogController,
		controllerAs : "infosIngredient",
		templateUrl: 'app/templates/dialogTemplates/ingredientInfos.tmpl.html',
		parent: angular.element($document.body),
		locals : {ingredient : ingredient},
		bindToController : true,
		targetEvent: event,
		clickOutsideToClose:true
		})
	};

	vm.deleteIngredientDialog = function(event, ingredient) {
		var confirm = $mdDialog.confirm()
					.title('Are you sure you want to delete this ingredient ?')
					.ok('Delete ingredient')
					.cancel('Not really actually')
					.targetEvent(event);

{'fraction_non_alphanumeric': 0.1535335945436076, 'fraction_numerical': 0.005079088666376433, 'mean_word_length': 4.075110456553755, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, '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': '263055', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2402, 'n_words': 443}