angular.module('editor.views.recipes.recipe', ['ui.router',
  'editor.data.ingredients', 'editor.data.recipes', 'editor.data.styles',
  'editor.data.equipments', 'editor.data.settings', 'editor.services.calculator',
  'editor.views.recipes', 'editor.directives.range', 'editor.filters.recipe'])
  .config(['$stateProvider', function($stateProvider) {
    $stateProvider.state('recipes.recipe', {
      url: '/:id',
      views: {
        '': {
          templateUrl: 'editor/views/recipes.recipe/layout.html',
          controller: 'RecipesRecipeController'
        },
        'content@recipes.recipe': {
          templateUrl: 'editor/views/recipes.recipe/recipe.html'
        },
        'header@recipes.recipe': {
          templateUrl: 'editor/views/recipes.recipe/header.html'
        },
        'info@recipes.recipe': {
          templateUrl: 'editor/views/recipes.recipe/profile.html'
        }
      }
    });
  }])
  .controller('RecipesRecipeController', function($scope, $state, $stateParams,
    $filter, styles, equipments, recipes, ingredients, calculator, settings) {

    $scope.styles = styles;
    $scope.equipments = equipments;
    $scope.settings = settings;
    $scope.calc = calculator;

    var recipeId = $stateParams.id;
    $scope.recipeId = $stateParams.id;

    recipes.get(recipeId).then(function(recipe) {
      $scope.recipe = recipe;
      $scope.headerEdit = !recipe.name;
      
      // Go to last recipe if current recipe disappear
      $scope.recipes = recipes;
      $scope.$watch('(recipes.items | filter:{id:recipe.id}).length',
        function(len) {
          if( len > 0 ) { return; }
          $state.go('recipes.last');
        }
      );

    });

    // Update equipment
    $scope.$watch('recipe.equipment', function(id) {
      var found = equipments.items.find(function(item) {
        return item.id == id;
      });
      $scope.equipment = found || settings.defaults.equipment;
    });

    // Watch for volume scaling
    $scope.$watch('recipe.finalVolume', function(newVolume, oldVolume) {
      if( !newVolume || !oldVolume ) { return; }
      if( settings.global.recipeAutoscale ) {
        calculator.recipeScaleVolume($scope.recipe, $scope.equipment, oldVolume, newVolume);
      }
    });

    // Watch for equipment scaling
    $scope.$watch('equipment', function(newEquipment, oldEquipment) {
      if( !newEquipment || !oldEquipment ) { return; }
      if( settings.global.recipeAutoscale ) {
        calculator.recipeScaleEquipment($scope.recipe, oldEquipment, newEquipment);
      }
    });

    $scope.copy = angular.copy;
    $scope.remove = function(array, item) {
      var index = array.indexOf(item);
      array.splice(index, 1);
    };

    // Ingredients
    $scope.ingredients = ingredients;

    $scope.numberOfIngredients = function(recipe) {
      if( !recipe ) { return 0; }
      return recipe.fermentables.length + recipe.hops.length
             + recipe.yeast.length + recipe.others.length;
    };

    $scope.addFermentable = function(recipe, fermentable) {
      var item = angular.copy(fermentable);
      item.weight = 0;
      recipe.fermentables.push(item);
    };

    $scope.addHop = function(recipe, hop) {
      var item = angular.copy(hop);
      item.weight = 0;
      item.time = 0;
      item.format = 'pellet';
      item.moment = 'boil';
      recipe.hops.push(item);
    };

    $scope.addOther = function(recipe, ingredient) {
      var item = angular.copy(ingredient);
      item.weight = 0;
      item.time = 0;
      item.moment = 'boil';
      recipe.others.push(item);
    };

  });


@@ -1776,17 +1776,24 @@
     
-var found
+$scope.equipment
  = e
@@ -1874,71 +1874,8 @@
 %7D);%0A
-      $scope.equipment = found %7C%7C settings.defaults.equipment;%0A
     

Fix default equipment