-
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.
Merge pull request #13 from kudojp/topic-food-items
MealPostのサブ項目としてFoodItemを追加する
- Loading branch information
Showing
39 changed files
with
406 additions
and
33 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
Empty file.
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,5 @@ | ||
module AjaxHelper | ||
def ajax_redirect_to(redirect_uri) | ||
{ js: "window.location.replace('#{redirect_uri}')" } | ||
end | ||
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
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,2 +1,12 @@ | ||
module MealPostsHelper | ||
def total_calories_of(meal_post) | ||
return '- kcal' if meal_post.food_items_with_calories_count.zero? | ||
return "#{meal_post.total_calories}kcal+" if meal_post.food_items_count != meal_post.food_items_with_calories_count | ||
|
||
"#{meal_post.total_calories}kcal" | ||
end | ||
|
||
def total_count_and_calories_of(meal_post) | ||
"#{meal_post.food_items_count}品 #{total_calories_of(meal_post)}" | ||
end | ||
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
File renamed without changes.
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,5 @@ | ||
.nested-fields { | ||
.fi_field { | ||
width: 30%; | ||
} | ||
} |
File renamed without changes.
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,19 @@ | ||
class FoodItem < ApplicationRecord | ||
belongs_to :meal_post | ||
counter_culture :meal_post | ||
counter_culture :meal_post, column_name: proc { |model| model.calory.nil? ? nil : 'food_items_with_calories_count' }, | ||
column_names: { ['food_items.calory IS NOT NULL'] => 'food_items_with_calories_count' } | ||
counter_culture :meal_post, column_name: 'total_calories', delta_column: 'calory' | ||
|
||
before_validation :strip_whitespaces | ||
validates :name, presence: true, length: { maximum: 30 } | ||
validates :amount, length: { maximum: 30 }, allow_blank: true | ||
validates :calory, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true | ||
|
||
private | ||
|
||
def strip_whitespaces | ||
name&.strip! | ||
amount&.strip! | ||
end | ||
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
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,18 +1,19 @@ | ||
<h1 class='row mb-5'><%= "Welcome back, #{@user.name}!" %></h1> | ||
<div class='row'> | ||
<div class='col-4'> | ||
<div class='col-2'> | ||
<p><%= link_to 'My Profile', user_path(@user) %></p> | ||
<p><%= link_to 'Followings', followings_user_path(@user) %></p> | ||
<p><%= link_to 'Followers', followers_user_path(@user) %></p> | ||
<p><%= link_to 'Your Upvotes', upvotes_user_path(@user) %></p> | ||
<p><%= link_to 'Your Downvotes', downvotes_user_path(@user) %></p> | ||
</div> | ||
|
||
<div class='col-4'> | ||
<div class='col-5'> | ||
<%= render template: 'meal_posts/index', locals: {title: 'Your Timeline', meal_posts: meal_posts} %> | ||
</div> | ||
|
||
<div class='col-4'> | ||
<%= render partial: 'meal_posts/new'%> | ||
<div class='col-5 mealpost-new'> | ||
<h3>食べたものを記録</h3> | ||
<%= render partial: 'meal_posts/new', locals: {new_meal_post: @new_meal_post} %> | ||
</div> | ||
</div> |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
<div class='edit_meal_post'> | ||
<% if meal_post.errors.any? %> | ||
<div class="meal_post_errors"> | ||
<% meal_post.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</div><br> | ||
<% end %> | ||
|
||
<%= form_for(meal_post, html: { method: :patch }, remote: true) do |f| %> | ||
<div class="field"> | ||
<%= f.text_field :content, placeholder: 'メニュー名' %> | ||
</div><br> | ||
|
||
<div class="fields"> | ||
<%= f.fields_for :food_items do |fi_field| %> | ||
<%= render partial: 'meal_posts/food_item_fields', locals: {f: fi_field} %> | ||
<% end %> | ||
<div class='links'> | ||
<%= link_to_add_association '', f, :food_items, partial: 'meal_posts/food_item_fields', class: "fas fa-plus-circle" %> | ||
</div> | ||
</div><br> | ||
|
||
<div class="field"> | ||
<%= f.text_field :time, class: 'datetimepicker', placeholder: '食べた日時を選択' %> | ||
</div> | ||
|
||
<!-- TODO: 画像もアップロードできるようにする --> | ||
|
||
<%= f.submit "投稿する" %> | ||
<% end %> | ||
</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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class='nested-fields'> | ||
<%= f.text_field :name, placeholder: '品目', class: 'fi_field' %> | ||
<%= f.text_field :amount , placeholder: '分量', class: 'fi_field' %> | ||
<%= f.number_field :calory, placeholder: 'カロリー', class: 'fi_field' %> | ||
<%= link_to_remove_association '', f, class: "fas fa-times-circle" %> | ||
</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
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,17 +1,22 @@ | ||
<!-- partial for posting new meal --> | ||
|
||
<%= form_for @new_meal_post, remote: true do |f| %> | ||
<%= form_for new_meal_post, remote: true do |f| %> | ||
<div class="field"> | ||
<%= f.label :content %><br /> | ||
<%= f.text_field :content %> | ||
</div> | ||
<%= f.text_field :content, placeholder: 'メニュー名' %> | ||
</div><br> | ||
|
||
<div class="fields"> | ||
<%= f.fields_for :food_items do |fi_field| %> | ||
<%= render partial: 'meal_posts/food_item_fields', locals: {f: fi_field} %> | ||
<% end %> | ||
<div class='links'> | ||
<%= link_to_add_association '', f, :food_items, partial: 'meal_posts/food_item_fields', class: "fas fa-plus-circle" %> | ||
</div> | ||
</div><br> | ||
|
||
<div class="field"> | ||
<%= f.label :time %> | ||
<%= f.text_field :time, class: 'datetimepicker' %> | ||
<%= f.text_field :time, class: 'datetimepicker', placeholder: '食べた日時を選択' %> | ||
</div> | ||
|
||
<!-- TODO: 画像もアップロードできるようにする --> | ||
|
||
<%= f.submit "Submit" %> | ||
<%= f.submit "投稿する" %> | ||
<% 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class='total_calories'> | ||
<h4> | ||
総カロリー | ||
</h4> | ||
<h1> | ||
<%= total_calories_of(meal_post) %> | ||
<h1> | ||
</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,10 @@ | ||
console.log("post successfully created"); | ||
// TODO: prependではなくtimeの順番にしたがってしかるべきところに挿入する | ||
<%# TODO: prependではなくtimeの順番にしたがってしかるべきところに挿入する %> | ||
$(".meal-posts").find(".card").first().prepend("<%= escape_javascript(render(partial: 'meal_posts/meal_post', locals: {meal_post: @new_meal_post})) %>"); | ||
$(".new_meal_post").replaceWith('<%= escape_javascript(render(partial: 'meal_posts/new', locals: {new_meal_post: @next_meal_post})) %>'); | ||
flatpickr(".datetimepicker", { | ||
altInput: true, | ||
enableTime: true, | ||
dateFormat: "Y-m-d H:i", | ||
inline: true | ||
}); |
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,5 @@ | ||
console.log('You could not create your meal post.'); | ||
$(".meal_post_errors").remove(); | ||
errorMessages = '<div class="meal_post_errors"><% @new_meal_post.errors.full_messages.each do |message| %><li><%= message %></li><% end %></div><br>'; | ||
$(".new_meal_post").prepend(errorMessages); | ||
|
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
Oops, something went wrong.