Skip to content

Commit

Permalink
refactor displaying ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
sgibson47 committed Nov 14, 2018
1 parent fa16155 commit c72cf93
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/ingredient.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class Ingredient{
this.serving_size_number = serving_size_number
this.serving_size_unit = serving_size_unit
}
}

createIngredientDivs(){
Ingredient.prototype.createIngredientDivs = function(){
return `<div class="name">
<a href="/ingredients/${this.id}">${this.name}</a>
</div><!--name-->
<div class="serving">
Serving Size: ${this.serving_size_number} ${this.serving_size_unit}
</div> <!--serving-->`
}
}

const displayIngredients = function(){
for(let i of INGREDIENTS.slice(start, end)){
Expand Down
27 changes: 16 additions & 11 deletions app/assets/javascripts/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ class Recipe{
}
}

class Making{
constructor(id, rating, notes, user_id, recipe_id){
this.id = id
this.rating = rating
this.notes = notes
this.user_id = user_id
this.recipe_id = recipe_id
}

createListItem(){
return `<li>Rating: ${this.rating} stars <br>Notes: ${this.notes}</li>`
}
}


const createIngredientListItems = function (amounts, ingredients){
var amountsArray =[]
Expand Down Expand Up @@ -82,14 +96,6 @@ const createIngredientDiv = function (amounts, ingredients){
createIngredientListItems(amounts, ingredients)
}

// const displayMakings = function (makings){
// console.log(makings)
// console.log(makings[0])
// let makingsToDisplayAfterSlice = makings.slice(0, (makings.length - 1))
// console.log(makingsToDisplayAfterSlice)
// let makingsHTML = createMakingListItems(makingsToDisplayAfterSlice);
// $('#recipe-makings ul').append(makingsHTML);
// }

const createShowHtml = function (recipe){
let header = recipe.createRecipeHeader();
Expand Down Expand Up @@ -121,8 +127,6 @@ const getRecipe = function(){

document.addEventListener("turbolinks:load", function(){

getRecipe();

$('body').on('submit','#new_making_of_recipe', function(e){
e.preventDefault();

Expand All @@ -134,7 +138,8 @@ document.addEventListener("turbolinks:load", function(){

making.done(function(data) {
newMaking = new Making(data.id, data.rating, data.notes, data.user_id, data.recipe_id)
$('#recipe-makings ul').append(newMaking.createListItem());
let newMakingHTML = newMaking.createListItem();
$('#recipe-makings ul').append(newMakingHTML);
that.reset();
});
});
Expand Down
8 changes: 4 additions & 4 deletions app/views/ingredients/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<div class="ingredients">

<div id="ingredients-index">

<script>
getIngredients();
</script>

</div>

</div>

<script>
getIngredients();
</script>

0 comments on commit c72cf93

Please sign in to comment.