-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
273 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class InventoryFood < ApplicationRecord | ||
belongs_to :inventory | ||
belongs_to :food | ||
belongs_to :Inventory, class_name: 'Inventory', foreign_key: 'inventory_id' | ||
belongs_to :Food, class_name: 'Food', foreign_key: 'food_id' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
class Recipe < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :User, class_name: 'User', foreign_key: 'user_id' | ||
has_many :recipe_foods, dependent: :destroy | ||
has_many :foods, through: :recipe_foods | ||
|
||
validates :name, presence: true, length: { minimum: 3, maximum: 50 } | ||
validates :description, presence: true, length: { minimum: 3, maximum: 500 } | ||
validates :preparation_time, presence: true, numericality: { only_integer: true, greater_than: 0 } | ||
validates :cooking_time, presence: true, numericality: { only_integer: true, greater_than: 0 } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class RecipeFood < ApplicationRecord | ||
belongs_to :recipe | ||
belongs_to :food | ||
belongs_to :recipe, class_name: 'Recipe', foreign_key: 'recipe_id' | ||
belongs_to :food, class_name: 'Food', foreign_key: 'food_id' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<%= form_with(model: @recipe, url: recipes_path, local: true) do |form| %> | ||
<div class = "mt-4 p-2"> | ||
<%= select_tag(:public, options_for_select([['Select Status', 'Status'], ['Public', 'Public'], ['Private', 'Private']], 'Status'), | ||
class: 'form-select') | ||
%> | ||
<% if @recipe.errors.any? %> | ||
<p class="text-danger mb-0"> | ||
<%= @recipe.errors[:status].first %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<div class = "mt-2 p-2"> | ||
<%= form.text_field :name, | ||
autofocus: true, | ||
autocomplete: 'name', | ||
placeholder: 'New inventory name', | ||
class: 'form-control' | ||
%> | ||
<% if @recipe.errors.any? %> | ||
<p class="text-danger mb-0"> | ||
<%= @recipe.errors[:name].first %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<div class = "mt-2 p-2"> | ||
<%= form.number_field :preparation_time, | ||
autofocus: true, | ||
autocomplete: 'preparation_time', | ||
placeholder: 'Preparation time in minutes', | ||
class: 'form-control' | ||
%> | ||
<% if @recipe.errors.any? %> | ||
<p class="text-danger mb-0"> | ||
<%= @recipe.errors[:preparation_time].first %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<div class = "mt-2 p-2"> | ||
<%= form.number_field :cooking_time, | ||
autofocus: true, | ||
autocomplete: 'cooking_time', | ||
placeholder: 'Cooking time in minutes', | ||
class: 'form-control' | ||
%> | ||
<% if @recipe.errors.any? %> | ||
<p class="text-danger mb-0"> | ||
<%= @recipe.errors[:cooking_time].first %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<div class = "mt-2 p-2"> | ||
<%= form.text_area :description, rows: "5", | ||
autofocus: true, | ||
autocomplete: 'description', | ||
placeholder: 'Description of the inventory', | ||
class: 'form-control' | ||
%> | ||
<% if @recipe.errors.any? %> | ||
<p class="text-danger mb-0"> | ||
<%= @recipe.errors[:description].first %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<div class="actions text-center"> | ||
<%= form.submit class: 'btn btn-outline-dark btn-sm mt-4' %> | ||
</div> | ||
<% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,39 @@ | ||
<h1> List of all recipes </h1> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
|
||
<ul> | ||
<% @recipes.each do |recipe| %> | ||
<div class ="recipe-wrapper"> | ||
<div class = "recipe-list"> | ||
<li class = "recipe-title"> | ||
<a href="/recipes/<%= recipe.id %>"><%=recipe.name%></a> | ||
</li> | ||
<%= button_to 'Remove', recipe_path(recipe), class: "remove-cmt-btn", method: :delete %> | ||
</div> | ||
<li class = "recipe-description"><%=recipe.description%></li> | ||
</div> | ||
<% end %> | ||
</ul> | ||
<div class="d-flex justify-content-end mt-2 mb-2 p-2"> | ||
<%= link_to 'New Recipe', new_recipe_path, class: "btn btn-primary text-right" %> | ||
</div> | ||
|
||
<% if notice %> | ||
<p class="alert alert-success"><%= notice %></p> | ||
<% end %> | ||
<% if alert %> | ||
<p class="alert alert-danger"> | ||
<%= alert %> | ||
</p> | ||
<% elsif @recipes.empty? %> | ||
<p class="alert alert-info"> | ||
No recipes added yet. Please add new recipe. | ||
</p> | ||
<% else %> | ||
<h1 class="text-center">Recipes List</h1> | ||
<% @recipes.each do |recipe| %> | ||
<div class="row border mb-4"> | ||
<div class="col-4 p-2 text-start"> | ||
<%= link_to recipe.name, recipe_path(recipe), class: 'nav-link mb-3 fs-4 link-dark'%> | ||
<% if can? :destroy, recipe %> | ||
<%= button_to "Remove", recipe_path(recipe), method: :delete, data: { confirm: "Are you sure you want to delete this inventory?" }, class: 'btn btn-danger mx-3 fs-5 p-1 custom-button-width' %> | ||
<% end %> | ||
</div> | ||
<div class="col p-2 text-start"> | ||
<p><%= recipe.description %></p> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<h1>Add New Recipe</h1> | ||
|
||
<%=render 'shared/recipe_form', recipe: @recipe %> | ||
<div class="container"> | ||
<div class="row d-flex justify-content-center"> | ||
<div class="col-md-6 mt-4 p-2"> | ||
<h1 class="text-center">New Recipe</h1> | ||
<%= render 'form' %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,68 @@ | ||
<h1> Here is a list of specific recipe </h1> | ||
<h2><%=@recipe.name%></h2> | ||
<ul class ="recipe-container"> | ||
<div class ="spec-recipe-wrapper"> | ||
<div class = "recipe-duration"> | ||
<li>Peparation Time: <%=@recipe.preparation_time%></li> | ||
<div class="container"> | ||
<div class="row d-flex justify-content-center"> | ||
<div class="col-md-6 mt-4 p-2"> | ||
<h1 class="text-center"> | ||
<%= @recipe.name %> | ||
</h1> | ||
|
||
<div class="d-flex justify-content-between align-items-center mb-3"> | ||
<span>Preparation Time: <%= @recipe.preparation_time %></span> | ||
<div class="form-check form-switch form-check-reverse"> | ||
<input class="form-check-input" type="checkbox" id="flexSwitchCheckReverse"> | ||
<label class="form-check-label" for="flexSwitchCheckReverse">Public</label> | ||
</div> | ||
</div> | ||
|
||
<li>Cooking Time: <%=@recipe.cooking_time%></li> | ||
|
||
</div> | ||
<div class="label-container"> | ||
<label class="switch"> | ||
<div > | ||
<p class ="public">Public:</p> | ||
</div> | ||
<div> | ||
<%= form_for @recipe, url: recipe_path(@recipe), method: :patch do |f| %> | ||
<%= f.check_box :public, {}, true, false %> | ||
<span class="slider"></span> | ||
<% end %> | ||
</div> | ||
</label> | ||
</div> | ||
</div> | ||
<p>Steps goes here...</p> | ||
<div class = "row-4"> | ||
<%= button_to 'Generate shopping list', recipe_path(@recipe), class: "remove-cmt-btn", remote: true %> | ||
<%= button_to 'Add ingredient', recipe_path(@recipe), class: "remove-cmt-btn", remote: false %> | ||
</div> | ||
</ul> | ||
<span class="d-block mb-3">Cooking Time: <%= @recipe.cooking_time %></span> | ||
<span class="steps">Steps goes here...</span> | ||
|
||
<div class="d-flex justify-content-between align-items-center mt-3"> | ||
<div class="add-btn"> | ||
<button type="button" data-bs-toggle="modal" data-bs-target="#exampleModal" class="btn btn-secondary"> | ||
Generate shopping list | ||
</button> | ||
</div> | ||
|
||
<div class="add-btn"> | ||
<%= link_to 'Add ingredient', new_recipe_recipe_food_path(recipe_id: @recipe.id), class: 'btn btn-primary' %> | ||
</div> | ||
</div> | ||
<hr/> | ||
|
||
<% if @recipe.recipe_foods.empty? %> | ||
<p class="no-record text-center"> | ||
No food ingredient added to this recipe yet. | ||
</p> | ||
<% else %> | ||
<table class="table table-striped table-bordered"> | ||
<% if @recipe.recipe_foods.any? %> | ||
<thead> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">Food</th> | ||
<th scope="col">Quantity</th> | ||
<th scope="col">Value</th> | ||
<th scope="col" class="food-action">Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @recipe.recipe_foods.each_with_index do |food_recipe, index| %> | ||
<tr> | ||
<td><%= index + 1 %></td> | ||
<td><%=food_recipe.food.name %></td> | ||
<td><%=food_recipe.quantity %></td> | ||
<td><%=food_recipe.quantity * food_recipe.food.price %></td> | ||
<td class="d-flex"> | ||
<%= link_to 'Modify', edit_recipe_recipe_food_path(@recipe, food_recipe), class: 'btn btn-danger btn-sm' %> | ||
<%= form_with(url: recipe_recipe_food_path(@recipe, food_recipe), method: :delete, data: { confirm: 'Are you sure?' }) do |f| %> | ||
<%= f.submit 'Remove', class: 'btn btn-danger btn-sm' %> | ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
</div> | ||
</div> |
Oops, something went wrong.