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

  angular
    .module('brewKeeper')
    .controller('RecipeDetailController', RecipeDetailController);

  RecipeDetailController.$inject =
    ['$http', '$location', '$routeParams', '$rootScope'];

  function RecipeDetailController($http, $location, $routeParams, $rootScope) {
    $rootScope.cloneRecipe = cloneRecipe;
    $rootScope.makePublic = makePublic;

    var vm = this;
    vm.addBrewNote = addBrewNote;
    vm.addStep = addStep;
    vm.brewnotesUrl = '';
    vm.decreaseStep = decreaseStep;
    vm.deleteNote = deleteNote;
    vm.deleteRecipe = deleteRecipe;
    vm.deleteStep = deleteStep;
    vm.detail = {};
    vm.editNote = editNote;
    vm.editRecipe = editRecipe;
    vm.editStep = editStep;
    vm.hideEditStep = hideEditStep;
    vm.increaseStep = increaseStep;
    vm.notes = [];
    vm.rateRecipe = rateRecipe;
    vm.ratings = [{max: 5}];
    vm.recipeUrl = '';
    vm.recipesUrl = '';
    vm.showAddBrewNote = showAddBrewNote;
    vm.showAddSteps = showAddSteps;
    vm.showCloneModal = showCloneModal;
    vm.showEditNote = showEditNote;
    vm.showEditStep = showEditStep;
    vm.showMakePublic = showMakePublic;
    vm.showNoteIcons = showNoteIcons;
    vm.step = {};
    vm.steps = [];

    activate();

    ////////////////////////////////////////////////////////////////////////////
    // FUNCTIONS //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////

    /**
     * Prepare the page.
     */
    function activate() {
      $(document).scrollTop(0);

      vm.recipesUrl = $rootScope.baseUrl + '/api/users/' + $rootScope.username + '/recipes/';
      vm.recipeUrl = vm.recipesUrl + $routeParams.id + '/';
      vm.brewnotesUrl = vm.recipeUrl + 'brewnotes/';

      $http.get(vm.recipeUrl)
        .then(function(response) {
          vm.detail = response.data;
          vm.steps = response.data.steps;
          vm.notes = response.data.brewnotes;
          var currentRating = vm.detail.rating;
          vm.ratings = [{
              current: currentRating,
              max: 5
          }];
        });

      // Show the edit form if user clicks edit
      $('.edit-button').on('click', function() {
        $('.edit-recipe').removeClass("hidden");
        $('.recipe-view').addClass("hidden");
        $('.input-focus').focus();
      });

      // Hide the edit form if user cancels
      $('.cancel-recipe-edit').on('click', function() {
        $('.recipe-view').removeClass("hidden");
        $('.edit-recipe').addClass("hidden");
      });

      // Handle click on Add Steps
      $(".no-steps").click(vm.showAddSteps);

      // Handle confirmation of clone creation
      // $("button.confirm-clone-fail").on("click", vm.cloneRecipe);

      // Close the clone modal if the user cancels
      $("button.cancel-clone-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-clone-modal").addClass("inactive");
        return;
      });

      // Close no-steps error modal (when attempting to make public)
      $("button.steps-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.steps-modal").addClass("inactive");
      });

      // Close modal after cancelling make public confirmation
      $("button.cancel-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-modal").addClass("inactive");
        return;
      });

      // Trigger makePublic when user confirms
      // $("button.confirm-fail").on("click", vm.makePublic);

      // Close the made public success modal
      $("button.sharing-not-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.sharing-modal").addClass("inactive");
      });
    }

    /**
     * Add a brew note to this recipe with the filled-out info.
     */
    function addBrewNote() {
      $http.post(vm.brewnotesUrl, vm.brewnote)
        .success(function (data) {
          $(".brew-form").toggleClass("hidden");
          $http.get(vm.recipeUrl)
            .then(function(response){
              vm.notes = response.data.brewnotes;
            });
        });

      // Reset the brew note form data
      vm.brewnote = {};
    }

    /**
     * Add a new step to the recipe.
     */
    function addStep() {
      vm.step.step_number = vm.steps.length + 1;
      $('.input-focus').focus();
      $http.post(vm.recipeUrl + 'steps/', vm.step)
        .then(function(){
          $http.get(vm.recipeUrl)
            .then(function(response){
              // Show the Brew It button, hide the Add Steps button
              $(".brew-it-button").removeClass("hidden");
              $(".no-steps").addClass("hidden");
              vm.steps = response.data.steps;
            });
        });
      vm.step = {};
    }

    /**
     * Move the selected step further up the order.
     */
    function decreaseStep(step) {
      if (step.step_number <= 1) {
        return;
      }
      // Swap the steps
      // var currentStep = step.step_number - 1
      // var prevStep = step.step_number - 2
      var swapStep = vm.steps[step.step_number - 1];
      vm.steps[step.step_number - 1] = vm.steps[step.step_number - 2];
      vm.steps[step.step_number - 2] = swapStep;

      step.step_number--;
      $http.patch(vm.recipeUrl + 'steps/' + step.id + '/', step)
        .then(function() {
          $http.get(vm.recipeUrl)
            .then(function(response){
              vm.steps = response.data.steps;
            });
        });
    }

    /**
     * Delete the selected brew note.
     */
    function deleteNote(noteId) {
        $http.delete(vm.brewnotesUrl + noteId + '/')
          .then(function() {
            $http.get(vm.recipeUrl)
              .then(function(response) {
                vm.notes = response.data.brewnotes;
              });
          });
    }

    /**
     * Delete this recipe.
     */
    function deleteRecipe() {
      // Show modal to confirm action
      $(".wrapper").addClass("openerror");
      $("section.confirm-eliminate-modal").removeClass("inactive");
      // Hide modal if action cancelled
      $("button.cancel-clone-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-eliminate-modal").addClass("inactive");
        return;
      });
      // Hide modal, delete recipe, and return to recipe list upon confirmation
      $("button.confirm-eliminate-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-eliminate-modal").addClass("inactive");
        $http.delete(vm.recipeUrl)
          .then(function() {
            $location.path('/'+ $rootScope.username);
          });
      });
    }

    /**
     * Delete the selected step.
     */
    function deleteStep(stepNumber, stepId) {
      // Show modal to confirm action
      $(".wrapper").addClass("openerror");
      $("section.confirm-delete-modal").removeClass("inactive");
      // Hide modal if action cancelled
      $("button.cancel-delete-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-delete-modal").addClass("inactive");
        return;
      });
      // Hide modal and delete step upon confirmation
      $("button.confirm-delete-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-delete-modal").addClass("inactive");
        $http.delete(vm.recipeUrl + 'steps/' + stepId + '/')
          .then(function() {
            $http.get(vm.recipeUrl)
              .then(function(response){
                vm.steps = response.data.steps;
                if (response.data.steps.length === 0) {
                  $(".brew-it-button").addClass("hidden");
                  $(".no-steps").removeClass("hidden");
                }
              });
          });
      });
    }

    /**
     * Submit brew note update to API.
     */
    function editNote(note) {
      var noteView = "div.note-view" + note.id.toString();
      var editNoteSelector = "article.edit-note" + note.id.toString();
      $http.put(vm.brewnotesUrl + note.id + '/', note)
        .then(function () {
          $(editNoteSelector).addClass("hidden");
          $(noteView).removeClass("hidden");
        });
    }

    /**
     * Submit the edited recipe to the API for saving.
     */
    function editRecipe() {
      $http.patch(vm.recipeUrl, vm.detail)
        .then(function () {
          $('.edit-recipe').addClass("hidden");
          $('.recipe-view').removeClass("hidden");
        });
    }

    /**
     * Submit to the API changes made to this step.
     */
    function editStep(step) {
      $http.patch(vm.recipeUrl + 'steps/' + step.id + '/', step);
    }

    /**
     * Hide the step-editing UI elements.
     */
    function hideEditStep(stepId) {
      stepId = stepId.toString();
      $("div." + stepId).toggleClass("hidden");
    }

    /**
     * Move the selected step further down the step order.
     */
    function increaseStep(step) {<commit_msg>Fix type in comment<commit_after>;(function() {  // IFEE
  'use strict';

  angular
    .module('brewKeeper')
    .controller('RecipeDetailController', RecipeDetailController);

  RecipeDetailController.$inject =
    ['$http', '$location', '$routeParams', '$rootScope'];

  function RecipeDetailController($http, $location, $routeParams, $rootScope) {
    $rootScope.cloneRecipe = cloneRecipe;
    $rootScope.makePublic = makePublic;

    var vm = this;
    vm.addBrewNote = addBrewNote;
    vm.addStep = addStep;
    vm.brewnotesUrl = '';
    vm.decreaseStep = decreaseStep;
    vm.deleteNote = deleteNote;
    vm.deleteRecipe = deleteRecipe;
    vm.deleteStep = deleteStep;
    vm.detail = {};
    vm.editNote = editNote;
    vm.editRecipe = editRecipe;
    vm.editStep = editStep;
    vm.hideEditStep = hideEditStep;
    vm.increaseStep = increaseStep;
    vm.notes = [];
    vm.rateRecipe = rateRecipe;
    vm.ratings = [{max: 5}];
    vm.recipeUrl = '';
    vm.recipesUrl = '';
    vm.showAddBrewNote = showAddBrewNote;
    vm.showAddSteps = showAddSteps;
    vm.showCloneModal = showCloneModal;
    vm.showEditNote = showEditNote;
    vm.showEditStep = showEditStep;
    vm.showMakePublic = showMakePublic;
    vm.showNoteIcons = showNoteIcons;
    vm.step = {};
    vm.steps = [];

    activate();

    ////////////////////////////////////////////////////////////////////////////
    // FUNCTIONS //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////

    /**
     * Prepare the page.
     */
    function activate() {
      $(document).scrollTop(0);

      vm.recipesUrl = $rootScope.baseUrl + '/api/users/' + $rootScope.username + '/recipes/';
      vm.recipeUrl = vm.recipesUrl + $routeParams.id + '/';
      vm.brewnotesUrl = vm.recipeUrl + 'brewnotes/';

      $http.get(vm.recipeUrl)
        .then(function(response) {
          vm.detail = response.data;
          vm.steps = response.data.steps;
          vm.notes = response.data.brewnotes;
          var currentRating = vm.detail.rating;
          vm.ratings = [{
              current: currentRating,
              max: 5
          }];
        });

      // Show the edit form if user clicks edit
      $('.edit-button').on('click', function() {
        $('.edit-recipe').removeClass("hidden");
        $('.recipe-view').addClass("hidden");
        $('.input-focus').focus();
      });

      // Hide the edit form if user cancels
      $('.cancel-recipe-edit').on('click', function() {
        $('.recipe-view').removeClass("hidden");
        $('.edit-recipe').addClass("hidden");
      });

      // Handle click on Add Steps
      $(".no-steps").click(vm.showAddSteps);

      // Handle confirmation of clone creation
      // $("button.confirm-clone-fail").on("click", vm.cloneRecipe);

      // Close the clone modal if the user cancels
      $("button.cancel-clone-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-clone-modal").addClass("inactive");
        return;
      });

      // Close no-steps error modal (when attempting to make public)
      $("button.steps-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.steps-modal").addClass("inactive");
      });

      // Close modal after cancelling make public confirmation
      $("button.cancel-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-modal").addClass("inactive");
        return;
      });

      // Trigger makePublic when user confirms
      // $("button.confirm-fail").on("click", vm.makePublic);

      // Close the made public success modal
      $("button.sharing-not-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.sharing-modal").addClass("inactive");
      });
    }

    /**
     * Add a brew note to this recipe with the filled-out info.
     */
    function addBrewNote() {
      $http.post(vm.brewnotesUrl, vm.brewnote)
        .success(function (data) {
          $(".brew-form").toggleClass("hidden");
          $http.get(vm.recipeUrl)
            .then(function(response){
              vm.notes = response.data.brewnotes;
            });
        });

      // Reset the brew note form data
      vm.brewnote = {};
    }

    /**
     * Add a new step to the recipe.
     */
    function addStep() {
      vm.step.step_number = vm.steps.length + 1;
      $('.input-focus').focus();
      $http.post(vm.recipeUrl + 'steps/', vm.step)
        .then(function(){
          $http.get(vm.recipeUrl)
            .then(function(response){
              // Show the Brew It button, hide the Add Steps button
              $(".brew-it-button").removeClass("hidden");
              $(".no-steps").addClass("hidden");
              vm.steps = response.data.steps;
            });
        });
      vm.step = {};
    }

    /**
     * Move the selected step further up the order.
     */
    function decreaseStep(step) {
      if (step.step_number <= 1) {
        return;
      }
      // Swap the steps
      // var currentStep = step.step_number - 1
      // var prevStep = step.step_number - 2
      var swapStep = vm.steps[step.step_number - 1];
      vm.steps[step.step_number - 1] = vm.steps[step.step_number - 2];
      vm.steps[step.step_number - 2] = swapStep;

      step.step_number--;
      $http.patch(vm.recipeUrl + 'steps/' + step.id + '/', step)
        .then(function() {
          $http.get(vm.recipeUrl)
            .then(function(response){
              vm.steps = response.data.steps;
            });
        });
    }

    /**
     * Delete the selected brew note.
     */
    function deleteNote(noteId) {
        $http.delete(vm.brewnotesUrl + noteId + '/')
          .then(function() {
            $http.get(vm.recipeUrl)
              .then(function(response) {
                vm.notes = response.data.brewnotes;
              });
          });
    }

    /**
     * Delete this recipe.
     */
    function deleteRecipe() {
      // Show modal to confirm action
      $(".wrapper").addClass("openerror");
      $("section.confirm-eliminate-modal").removeClass("inactive");
      // Hide modal if action cancelled
      $("button.cancel-clone-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-eliminate-modal").addClass("inactive");
        return;
      });
      // Hide modal, delete recipe, and return to recipe list upon confirmation
      $("button.confirm-eliminate-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-eliminate-modal").addClass("inactive");
        $http.delete(vm.recipeUrl)
          .then(function() {
            $location.path('/'+ $rootScope.username);
          });
      });
    }

    /**
     * Delete the selected step.
     */
    function deleteStep(stepNumber, stepId) {
      // Show modal to confirm action
      $(".wrapper").addClass("openerror");
      $("section.confirm-delete-modal").removeClass("inactive");
      // Hide modal if action cancelled
      $("button.cancel-delete-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-delete-modal").addClass("inactive");
        return;
      });
      // Hide modal and delete step upon confirmation
      $("button.confirm-delete-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.confirm-delete-modal").addClass("inactive");
        $http.delete(vm.recipeUrl + 'steps/' + stepId + '/')
          .then(function() {
            $http.get(vm.recipeUrl)
              .then(function(response){
                vm.steps = response.data.steps;
                if (response.data.steps.length === 0) {
                  $(".brew-it-button").addClass("hidden");
                  $(".no-steps").removeClass("hidden");
                }
              });
          });
      });
    }

    /**
     * Submit brew note update to API.
     */
    function editNote(note) {
      var noteView = "div.note-view" + note.id.toString();
      var editNoteSelector = "article.edit-note" + note.id.toString();
      $http.put(vm.brewnotesUrl + note.id + '/', note)
        .then(function () {
          $(editNoteSelector).addClass("hidden");
          $(noteView).removeClass("hidden");
        });
    }

    /**
     * Submit the edited recipe to the API for saving.
     */
    function editRecipe() {
      $http.patch(vm.recipeUrl, vm.detail)
        .then(function () {
          $('.edit-recipe').addClass("hidden");
          $('.recipe-view').removeClass("hidden");
        });
    }

    /**
     * Submit the API changes made to this step.
     */
    function editStep(step) {
      $http.patch(vm.recipeUrl + 'steps/' + step.id + '/', step);
    }

    /**
     * Hide the step-editing UI elements.
     */
    function hideEditStep(stepId) {
      stepId = stepId.toString();
      $("div." + stepId).toggleClass("hidden");
    }

    /**
     * Move the selected step further down the step order.
     */
    function increaseStep(step) {
{'fraction_non_alphanumeric': 0.18478555549530987, 'fraction_numerical': 0.0013013067288402103, 'mean_word_length': 1.944914577678429, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2356658', 'n_tokens_mistral': 5393, 'n_tokens_neox': 5288, 'n_words': 976}