Skip to content

Commit

Permalink
merged files
Browse files Browse the repository at this point in the history
  • Loading branch information
zluo16 committed Jun 21, 2017
2 parents 6aba2df + e8549ad commit fc9793d
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 79 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ gem 'pg'
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/saver_recipe.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/saver_recipe.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the SaverRecipe controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
22 changes: 14 additions & 8 deletions app/controllers/recipe_ingredients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ def new
@recipe_ingredient = RecipeIngredient.new(recipe_id: params[:recipe_id])
end

def edit
@recipe_ingredient = RecipeIngredient.find(params[:id])
end

def show
@recipe_ingredient = RecipeIngredient.find(params[:id])
end

def create
@recipe_ingredient = RecipeIngredient.new(recipe_ingredient_params)
if @recipe_ingredient.save
Expand All @@ -25,6 +17,16 @@ def create
end
end


def edit
@recipe_ingredient = RecipeIngredient.find(params[:id])
end

def show
@recipe_ingredient = RecipeIngredient.find(params[:id])
end


def update
@recipe_ingredient = RecipeIngredient.find(params[:id])
if @recipe_ingredient.update(recipe_ingredient_params)
Expand All @@ -35,6 +37,10 @@ def update
end

def destroy
@recipe_ingredient = RecipeIngredient.find(params[:id])
@recipe = @recipe_ingredient.recipe
@recipe_ingredient.destroy
redirect_to recipe_path(@recipe)
end

private
Expand Down
22 changes: 22 additions & 0 deletions app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,40 @@ def index
def show
@recipe = Recipe.find(params[:id])
@author = User.find(@recipe.author_id)
@recipe_ingredient = RecipeIngredient.new
end

def new
@recipe = Recipe.new
end


def create
@recipe = Recipe.new(recipe_params)
return render :new unless @recipe.save
redirect_to recipe_path(@recipe)
end

def edit
@recipe = Recipe.find(params[:id])
if @recipe.author == current_user
else
redirect_to recipe_path(@recipe)
flash[:notice] = "You do not have access to edit #{@recipe.author.name}'s recipe for #{@recipe.name}"
end
end


def update
@recipe = Recipe.find(params[:id])
if @recipe.update(recipe_params)
redirect_to recipe_path(@recipe)
else
render :edit
end
end


private

def recipe_params
Expand Down
20 changes: 20 additions & 0 deletions app/controllers/saver_recipes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class SaverRecipesController < ApplicationController

# def new
# @recipe_ingredient = RecipeIngredient.new(params)
# @recipe_ingredient.save
# end
#

# def create
# @saver_recipe = SaverRecipe.new(saver_recipe_params)
# end



private
def sacver_recipe_params
params.require(:recipe).permit(:saver_id, :saved_recipe_id)
end

end
2 changes: 2 additions & 0 deletions app/helpers/saver_recipe_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SaverRecipeHelper
end
4 changes: 1 addition & 3 deletions app/models/saver_recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ class SaverRecipe < ApplicationRecord
belongs_to :saved_recipe, :class_name => "Recipe", :foreign_key => :saved_recipe_id
belongs_to :saver, :class_name => "User", :foreign_key => :saver_id

def user_id
self.saver_id
end


end
79 changes: 52 additions & 27 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,70 @@
<html>
<head>
<title>RecipeSharing</title>
<!-- Latest compiled and minified CSS -->
<%= csrf_meta_tags %>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css" />

</head>

<body>
<!-- navbar -->
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<!-- <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button> -->
<a class="navbar-brand" href="<%= root_url %>"/>Home</a>
<%if logged_in?%>
<a class="navbar-brand" href="<%= user_path(current_user) %>"/>Hi, <%= current_user.name%></a>
<%= link_to "Log Out", signout_path, method: :post, class: "navbar-brand"%>

<%= link_to "All Users", users_path, method: :get, class: "navbar-brand"%>
<% else %>
<a class="navbar-brand" href="<%= new_user_path %>"/>Sign Up</a>
<a class="navbar-brand" href="<%= signin_path %>"/>Sign In</a>
<%end%>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js">

</script>
<script>$(document).ready(function() {
$('select').material_select();
$('.modal').modal();
});</script>


<!-- Dropdown Structure -->
<ul id="dropdown1" class="dropdown-content">
<%if logged_in?%>
<li><a href="<%= user_path(current_user) %>">My Profile</a></li>
<li><%= link_to "Sign Out", signout_path, method: :post%></li>
<% else %>
<li class="show-on-small"><a href="<%= new_user_path %>">Sign Up</a></li>
<li class="show-on-small"><a href="<%= signin_path %>">Sign In</a></li>
<%end%>
<li class="divider"></li>
<li class="hide-on-large-only"><a href="<%= users_path %>">All Users</a></li>
<li class="hide-on-large-only"><a href="<%= recipes_path %>">All Recipes</a></li>
</ul>
<nav>
<div class="nav-wrapper">
<a href="<%= root_url %>" class="brand-logo left">RecipeSharingApp</a>
<ul class="right">
<li class="hide-on-small-only"><a href="<%= users_path %>">All Users</a></li>
<li class="hide-on-small-only"><a href="<%= recipes_path %>">All Recipes</a></li>

<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<!-- nav here -->
</ul>
</div><!--/.nav-collapse -->
<%if logged_in?%>
<!-- Dropdown Trigger -->
<li><a class="dropdown-button" href="#!" data-activates="dropdown1">Hi, <%= current_user.name%><i class="material-icons right">arrow_drop_down</i></a></li>
<% else %>
<li class="hide-on-med-and-up"><a class="dropdown-button" href="#!" data-activates="dropdown1">Menu<i class="material-icons right">arrow_drop_down</i></a></li>

<li class="hide-on-small-only"><a href="<%= new_user_path %>">Sign Up</a></li>
<li class="hide-on-small-only"><a href="<%= signin_path %>">Sign In</a></li>
<%end%>
</ul>
</div>
</nav>
<div class="container">
<% if flash[:notice] %>
<div><script>Materialize.toast('<%= flash[:notice] %>', 4000)</script></div>
<% end %>
<%= yield %>

</div>

<%= yield %>
</body>
</html>
10 changes: 10 additions & 0 deletions app/views/recipe_ingredients/_recipe_ingredient_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= form_for(@recipe_ingredient) do |t| %>
<%= t.hidden_field :recipe_id, :value => params[:recipe_id] %><br>
<%= t.collection_select :ingredient_id, Ingredient.all, :id, :name, { prompt: "Choose an ingredient" }%><br>


<%= t.number_field :quantity, placeholder: 'Quantity' %>
<%= t.select :units, ['Cup(s)', 'Gram(s)', 'Kilogram(s)', 'Liter(s)', 'Mililiter(s)', 'Pound(s)', 'Ounce(s)', 'Pint(s)', 'Teaspoon(s)', 'Tablespoon(s)'], { prompt: "Choose a unit of measure" }%><br><br>

<%= t.submit "Add Ingredient to Recipe " %>
<% end %>
10 changes: 1 addition & 9 deletions app/views/recipe_ingredients/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<h1> New Recipe Ingredient </h1>

<%= form_for(@recipe_ingredient) do |t| %>


<%= t.hidden_field :recipe_id, :value => params[:recipe_id] %><br>
<%= t.collection_select :ingredient_id, Ingredient.order(:name), :id, :name, include_blank: false%><br>
<%= t.number_field :quantity, placeholder: 'Quantity' %>

<%= t.submit "Create Recipe-Ingredient" %>
<% end %>
<%= render "recipe_ingredient_form" %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<%= f.hidden_field :author_id, :value => current_user.id %>
<%= f.label :image, 'Add image of recipe' %><br>
<%= f.file_field :image %>
<%= f.file_field :image %><br><br>
<%= f.label :name, 'Name Your Recipe: ' %>
<%= f.text_field :name %><br><br>
<%= f.label :prep_time, 'Minutes to prep your recipe: ' %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/recipes/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Edit <%@recipe.name%></h1>

<%= render 'recipe_form' %>
82 changes: 62 additions & 20 deletions app/views/recipes/show.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,63 @@
<h1><%= @recipe.name %></h1>
<h3>made by <%= @author.name %></h3>

<p>prep time: <%= @recipe.prep_time %> minutes</p><br>
<p>cook time: <%= @recipe.cook_time %> minutes</p><br>
<p><strong>Total Time: <%= "#{@recipe.prep_time + @recipe.cook_time}" %></strong></p><br>

<p>
<strong>Instructions: </strong>
<%= @recipe.instructions %>
</p>

<% if @recipe.ingredients.count > 0 %>
<ul>
<% @recipe.recipe_ingredients.each do |i| %>
<li><%= i.quantity %> - <%= i.ingredient.name %></li>
<% end %>
</ul>
<% end %>

<%= link_to 'Add Recipe-Ingredient', new_recipe_ingredient_path(:recipe_id => @recipe.id) %>
<h4>made by <%= @author.name %></h4>

<div>
<% if current_user == @recipe.author%>
<a class="btn" href="<%= edit_recipe_path(@recipe)%>">Edit</a>
<a class="btn" href="<%= edit_recipe_path(@recipe)%>">Delete Recipe</a>
<% else %>
<!-- THIS BUTTON IS NOT YET WORKING WORKING ON IT NOW -->
<%= link_to "Save Recipe", new_saver_recipe_path(saver_id: current_user.id, saved_recipe_id: @recipe.id) %>
<% end %>
</div><br><br>

<div>
<%= image_tag @recipe.image.url(:medium) if @recipe.image? %>
</div>

<div>
<h5>Overview </h5>
<p>Prep Time: <%= @recipe.prep_time %> minutes</p>
<p>Cook Time: <%= @recipe.cook_time %> minutes</p>
<p><strong>Total Time: <%= "#{@recipe.prep_time + @recipe.cook_time}" %> minutes</strong></p>
</div>


<div>
<h5>Ingredients: </h5>
<% if @recipe.ingredients.count > 0 %>
<ul>
<% @recipe.recipe_ingredients.each do |i| %>
<li><%= i.quantity %> <%= i.units%><%= i.ingredient.name %> <%= link_to "Delete", i, method: :delete %></li>
<% end %>
</ul>
<% end %>
<% if current_user == @recipe.author%>
<!-- Modal Trigger -->
<a class="modal-trigger waves-effect waves-light btn" href="#add_recipe_ingredient_modal">Add Ingredient</a>

<!-- Modal Structure -->
<div id="add_recipe_ingredient_modal" class="modal modal-fixed-footer">
<div class="modal-content">
<h4>Add Ingredient to <%=@recipe.name%></h4>
<%= form_for(@recipe_ingredient) do |t| %>
<%= t.hidden_field :recipe_id, value: @recipe.id %><br>
<%= t.collection_select :ingredient_id, Ingredient.all, :id, :name, { prompt: "Choose an ingredient" }%><br>

<%= t.number_field :quantity, placeholder: 'Quantity' %>
<%= t.select :units, ['Cup(s)', 'Gram(s)', 'Kilogram(s)', 'Liter(s)', 'Mililiter(s)', 'Pound(s)', 'Ounce(s)', 'Pint(s)', 'Teaspoon(s)', 'Tablespoon(s)'], { prompt: "Choose a unit of measure" }%><br><br>

<%= t.submit "Add Ingredient to Recipe " %>
<% end %>
</div>
</div>
<% end %>


</div>


<div>
<h5>Instructions: </h5>
<%= simple_format @recipe.instructions %>
</div><br>
32 changes: 21 additions & 11 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h5>USER PROFILE</h5>

<%= image_tag @user.image.url(:medium) if @user.image? %>
<div>
<%= image_tag @user.image.url(:medium) if @user.image? %>
</div>

<h1> <%= @user.name %></h1>
<% if @user == current_user %>
Expand All @@ -19,17 +21,25 @@
</li>
</ul>


<h3> Authored Recipes </h3>
<p>
This is where we will see the users' authored recipes
</p>

<div>
<h3> Authored Recipes </h3>
<% if @user.recipes.count > 0%>
<ul>
<% @user.recipes.each do |r|%>
<li>
<%= link_to r.name, recipe_path(r)%>
</li>
<% end %>
</ul>
<% else %>
<p>
<%= @user.name%> has not yet authored any recipes
</p>
<% end %>
</div>



<h3> Saved Recipes </h3>
<div>

<p>
This is where we will see the users' saved recipes
</p>
</div>
Loading

0 comments on commit fc9793d

Please sign in to comment.