<commit_before>//Could've used the same controller for add and edit, but figured it would be cleaner to keep them separate even though there is redundancy.

'use strict';

angular.module('brewApp.controllers')
    .controller('EditRecipeCtrl', ['$modalInstance', 'BrewMaster', 'notifications', 'logger', 'UserStore', '$modalParams', editRecipeController]);

function editRecipeController($modalInstance, BrewMaster, notifications, logger, UserStore, $modalParams) {
    /* jshint validthis: true */
    var self = this;

    UserStore.getCurrentUserRecipeById($modalParams.id).then(function(recipe) {
        self.recipe = angular.copy(recipe);
    });

    BrewMaster.getDefinitions().then(function(definitions) {
        self.units = definitions.units.volume.map(function(def) { return def.name; });

        if (BrewMaster.hasIngredient(definitions, 'yeast'))
            self.yeastTypes = definitions.ingredient.yeast.map(function(def) { return def.name; });
    });

    self.update = function(isValid) {
        if (isValid) {
            //Need a spinner on this?
            UserStore.updateRecipe(self.recipe).then(function() {<commit_msg>Getting recipe ingredients in edit recipe controller.<commit_after>//Could've used the same controller for add and edit, but figured it would be cleaner to keep them separate even though there is redundancy.

'use strict';

angular.module('brewApp.controllers')
    .controller('EditRecipeCtrl', ['$modalInstance', 'BrewMaster', 'notifications', 'logger', 'UserStore', '$modalParams', editRecipeController]);

function editRecipeController($modalInstance, BrewMaster, notifications, logger, UserStore, $modalParams) {
    /* jshint validthis: true */
    var self = this;

    UserStore.getCurrentUserRecipeById($modalParams.id).then(function(recipe) {
        self.recipe = angular.copy(recipe);

        UserStore.getRecipeIngredientsByRecipeId($modalParams.id).then(function(recipeIngredients) {
            //Todo: map ingredients to separate arrays for the UI.
        });
    });

    BrewMaster.getDefinitions().then(function(definitions) {
        self.units = definitions.units.volume.map(function(def) { return def.name; });

        if (BrewMaster.hasIngredient(definitions, 'yeast'))
            self.yeastTypes = definitions.ingredient.yeast.map(function(def) { return def.name; });
    });

    self.update = function(isValid) {
        if (isValid) {
            //Need a spinner on this?
            UserStore.updateRecipe(self.recipe).then(function() {
{'fraction_non_alphanumeric': 0.12554628526023043, 'fraction_numerical': 0.0, 'mean_word_length': 3.8893203883495144, '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': '928522', 'n_tokens_mistral': 723, 'n_tokens_neox': 708, 'n_words': 162}