styles
This commit is contained in:
parent
2e862b25cf
commit
3cc62b0149
@ -237,7 +237,7 @@
|
|||||||
|
|
||||||
var lines = data.replace("\r", "").split("\n");
|
var lines = data.replace("\r", "").split("\n");
|
||||||
|
|
||||||
var regex = /^(?:([\d\/.]+)\s+)?(?:([\w-]+)(?:\s+of)?\s+)?(\w[\w ,\-\(\)\/]*)$/i;
|
var regex = /^(?:([\d\/.]+(?:\s+[\d\/]+)?)\s+)?(?:([\w-]+)(?:\s+of)?\s+)?(\w[\w ,\-\(\)\/]*)$/i;
|
||||||
|
|
||||||
var magicFunc = function(str) {
|
var magicFunc = function(str) {
|
||||||
if (str == "-") {
|
if (str == "-") {
|
||||||
|
@ -49,3 +49,13 @@ div.step-editor {
|
|||||||
div#ingredient-list, div#step-list {
|
div#ingredient-list, div#step-list {
|
||||||
padding-bottom: 15px;
|
padding-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.recipe-view {
|
||||||
|
.ingredients div {
|
||||||
|
padding-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.steps div {
|
||||||
|
padding-bottom: 15px;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
class RecipesController < ApplicationController
|
class RecipesController < ApplicationController
|
||||||
before_action :set_recipe, only: [:show, :edit, :update, :destroy]
|
before_action :set_recipe, only: [:show, :edit, :update, :destroy, :scale]
|
||||||
|
|
||||||
# GET /recipes
|
# GET /recipes
|
||||||
# GET /recipes.json
|
# GET /recipes.json
|
||||||
def index
|
def index
|
||||||
@recipes = Recipe.all
|
@recipes = Recipe.active
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /recipes/1
|
# GET /recipes/1
|
||||||
@ -12,6 +12,13 @@ class RecipesController < ApplicationController
|
|||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /recipes/1
|
||||||
|
def scale
|
||||||
|
@scale = params[:factor]
|
||||||
|
@recipe.scale(@scale)
|
||||||
|
render :show
|
||||||
|
end
|
||||||
|
|
||||||
# GET /recipes/new
|
# GET /recipes/new
|
||||||
def new
|
def new
|
||||||
@recipe = Recipe.new
|
@recipe = Recipe.new
|
||||||
@ -54,10 +61,16 @@ class RecipesController < ApplicationController
|
|||||||
# DELETE /recipes/1
|
# DELETE /recipes/1
|
||||||
# DELETE /recipes/1.json
|
# DELETE /recipes/1.json
|
||||||
def destroy
|
def destroy
|
||||||
@recipe.destroy
|
@recipe.deleted = true
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to recipes_url, notice: 'Recipe was successfully destroyed.' }
|
if @recipe.save
|
||||||
format.json { head :no_content }
|
format.html { redirect_to recipes_url, notice: 'Recipe was successfully destroyed.' }
|
||||||
|
format.json { head :no_content }
|
||||||
|
else
|
||||||
|
format.html { redirect_to recipes_url, error: 'Recipe could not be destroyed.' }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ class Recipe < ActiveRecord::Base
|
|||||||
has_many :recipe_ingredients, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
|
has_many :recipe_ingredients, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
|
||||||
has_many :recipe_steps, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
|
has_many :recipe_steps, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
|
||||||
|
|
||||||
|
scope :active, -> { where('deleted <> ? OR deleted IS NULL', true) }
|
||||||
|
|
||||||
accepts_nested_attributes_for :recipe_ingredients, allow_destroy: true
|
accepts_nested_attributes_for :recipe_ingredients, allow_destroy: true
|
||||||
accepts_nested_attributes_for :recipe_steps, allow_destroy: true
|
accepts_nested_attributes_for :recipe_steps, allow_destroy: true
|
||||||
|
|
||||||
@ -11,5 +13,11 @@ class Recipe < ActiveRecord::Base
|
|||||||
validates :total_time, numericality: true, allow_blank: true
|
validates :total_time, numericality: true, allow_blank: true
|
||||||
validates :active_time, numericality: true, allow_blank: true
|
validates :active_time, numericality: true, allow_blank: true
|
||||||
|
|
||||||
|
def scale(factor)
|
||||||
|
recipe_ingredients.each do |ri|
|
||||||
|
ri.scale(factor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -22,4 +22,10 @@ class RecipeIngredient < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def scale(factor)
|
||||||
|
if factor.present? && self.quantity.present? && factor != '1'
|
||||||
|
self.quantity = UnitConversion.convert(self.quantity, factor, nil, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,34 +2,50 @@
|
|||||||
<div class="recipe-view">
|
<div class="recipe-view">
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-10">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>
|
<h1>
|
||||||
<%= @recipe.name %>
|
<%= @recipe.name %>
|
||||||
<small>
|
<% if @scale %>
|
||||||
<%= @recipe.description %>
|
<span class="label label-default"><%= @scale %> X</span>
|
||||||
</small>
|
<% end %>
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
<p class="lead">
|
||||||
|
<%= @recipe.description %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-2">
|
||||||
|
<div class="dropdown">
|
||||||
|
<button id="scaleLabel" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
Scale
|
||||||
|
<span class="caret"></span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="scaleLabel">
|
||||||
|
<% ['1/4', '1/3', '1/2', '2/3', '3/4', '1', '1 1/2', '2', '3', '4'].each do |scale| %>
|
||||||
|
<li><%= link_to scale, scale_recipe_path(@recipe, scale) %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<% if @recipe.total_time.present? || @recipe.active_time.present? %>
|
<% if @recipe.total_time.present? || @recipe.active_time.present? %>
|
||||||
<div class="col-xs-4">
|
<div class="col-xs-3">
|
||||||
<span><%= recipe_time(@recipe) %></span>
|
<p><%= recipe_time(@recipe) %></p>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @recipe.yields.present? %>
|
<% if @recipe.yields.present? %>
|
||||||
<div class="col-xs-4">
|
<div class="col-xs-3">
|
||||||
<span>Yields</span><span><%= @recipe.yields %></span>
|
<p>Yields</p><p><%= @recipe.yields %></p>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @recipe.source.present? %>
|
<% if @recipe.source.present? %>
|
||||||
<div class="col-xs-4">
|
<div class="col-xs-6">
|
||||||
<span>Source</span><span><%= @recipe.source %></span>
|
<p>Source</p><p><%= @recipe.source %></p>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
@ -37,21 +53,34 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-4">
|
<div class="col-xs-12 col-sm-4">
|
||||||
<h4>Ingredients</h4>
|
<div class="panel panel-default">
|
||||||
<ul>
|
<div class="panel-heading">
|
||||||
<% @recipe.recipe_ingredients.each do |i| %>
|
<h3 class="panel-title">Ingredients</h3>
|
||||||
<li><%= "#{i.quantity} #{i.units} of #{i.custom_name}" %></li>
|
</div>
|
||||||
<% end %>
|
<div class="panel-body">
|
||||||
</ul>
|
<ul class="ingredients">
|
||||||
|
<% @recipe.recipe_ingredients.each do |i| %>
|
||||||
|
<li><div><%= "#{i.quantity} #{i.units} of #{i.custom_name}" %></div></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xs-12 col-sm-8">
|
<div class="col-xs-12 col-sm-8">
|
||||||
<h4>Directions</h4>
|
<div class="panel panel-default">
|
||||||
<ol>
|
<div class="panel-heading">
|
||||||
<% @recipe.recipe_steps.each do |s| %>
|
<h3 class="panel-title">Directions</h3>
|
||||||
<li> <%= "#{s.step}" %></li>
|
</div>
|
||||||
<% end %>
|
<div class="panel-body">
|
||||||
</ol>
|
<ol class="steps">
|
||||||
|
<% @recipe.recipe_steps.each do |s| %>
|
||||||
|
<li><div><%= "#{s.step}" %></div></li>
|
||||||
|
<% end %>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :recipes
|
resources :recipes do
|
||||||
|
member do
|
||||||
|
get 'scale/:factor', action: :scale, as: :scale
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
resources :ingredients, except: [:show] do
|
resources :ingredients, except: [:show] do
|
||||||
collection do
|
collection do
|
||||||
|
5
db/migrate/20160119012704_add_deleted_to_recipes.rb
Normal file
5
db/migrate/20160119012704_add_deleted_to_recipes.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class AddDeletedToRecipes < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :recipes, :deleted, :boolean
|
||||||
|
end
|
||||||
|
end
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160113002615) do
|
ActiveRecord::Schema.define(version: 20160119012704) do
|
||||||
|
|
||||||
create_table "ingredients", force: :cascade do |t|
|
create_table "ingredients", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20160113002615) do
|
|||||||
t.integer "active_time"
|
t.integer "active_time"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.boolean "deleted"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user