Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def new

def show
@order = current_order
@restaurants = @order.items.map(&:restaurant).uniq
#@restaurants = @order.items.map(&:restaurant).uniq

@grouped_order_items = @order.order_items.group_by{|oi| oi.restaurant}
end

def checkout_one_restaurant
Expand Down Expand Up @@ -50,9 +52,8 @@ def checkout
end

def place_order
current_order.update_status("completed")
current_order.place
flash.notice = "Your order is successfull"
UserMailer.order_email(current_user, current_user.orders.last).deliver
create_order
redirect_to user_path(current_user)
end
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/restaurants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def index
end

def new
@restaurant = Restaurant.new
@restaurant = current_user.restaurants.new
@restaurant_detail = RestaurantDetail.new
@hours = Hours.new
end
Expand Down Expand Up @@ -54,7 +54,8 @@ def edit
def update
if params[:restaurant][:status]
@status = params[:restaurant][:status]
@restaurant = Restaurant.find(params[:id])
#@restaurant = Restaurant.find(params[:id])
@restaurant = current_user.restaurants.find(params[:id])
@restaurant.status = @status
restaurant_admin = @restaurant.restaurant_employees.first
@user = restaurant_admin.user
Expand Down
21 changes: 21 additions & 0 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,25 @@ def generate_unique_url
def order_username(customer_id)
User.find(customer_id).username
end

def place
update_status("completed")
notifier.order_placed(customer, self)
end

def notifier
USER_NOTIFIER.new
end
end

class UserNotifierEmail
def order_placed(customer, self)
UserMailer.order_email(customer, self).deliver
end
end

class UserNotifierFake
def order_placed(customer, self)
true
end
end
3 changes: 2 additions & 1 deletion app/views/items/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
<li class="category"><%= category.name %></li>
<% end %>
</ul>
<% end %>
<% if @order %>
<%= button_to "Add to Order", add_item_path(@item.id), {class: "btn btn-success"} %>
<% else %>
<%= link_to "Add to Order", new_order_path(:item_id => @item.id), {:class => "btn btn-success"} %>
<% end %>
<% end %>

5 changes: 2 additions & 3 deletions app/views/orders/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="current-order">
<h1>Current Orders</h1>

<% @restaurants.each do |restaurant| %>
<% @grouped_order_item.each do |restaurant, order_items| %>

<h3 class="restaurant-<%= restaurant.id %>">
<%= link_to restaurant.name, restaurant_path(restaurant)%>
Expand All @@ -18,8 +18,7 @@
</tr>
</thead>
<tbody>
<% @order_items = @order.find_order_items_by_restaurant_id(@order, restaurant.id) %>
<% @order_items.each do |order_item| %>
<% order_items.each do |order_item| %>
<% item = order_item.item %>
<tr id="item_<%= item.id %>">
<td class="item-title"><%= link_to item.title, item_path(item.id) %></td>
Expand Down
6 changes: 6 additions & 0 deletions app/views/restaurants/_restaurant.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h3 class="restaurant-<%= restaurant.id %>">
<%= link_to restaurant.name, restaurant_path(restaurant)%>
</h3>
<% if restaurant.restaurant_employees.any? %>
<p> There is an employee <p>
<% end %>
18 changes: 2 additions & 16 deletions app/views/restaurants/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
<h1> Active Restaurants </h1>
<div class="active-restaurants">
<% @restaurants.each do |restaurant| %>
<h3 class="restaurant-<%= restaurant.id %>">
<%= link_to restaurant.name, restaurant_path(restaurant)%>
</h3>
<% if restaurant.restaurant_employees.any? %>
<p> There is an employee <p>
<% end %>
<% end %>
<%= render :partial => 'restaurant', :collection => @restaurants %>
</div>

<div class="pending-restaurants">
<h1> Pending Restaurants </h1>
<% @pending_restaurants.each do |restaurant| %>
<h3 class="restaurant-<%= restaurant.id %>">
<%= link_to restaurant.name, restaurant_path(restaurant)%>
</h3>
<% if restaurant.restaurant_employees.any? %>
<p> There is an employee <p>
<% end %>
<% end %>
<%= render :partial => 'restaurant', :collection => @pending_restaurants %>
</div>
5 changes: 5 additions & 0 deletions config/initializers/user_notifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if Rails.env.development? || Rails.env.test?
USER_NOTIFIER = UserNotifierFake
else
USER_NOTIFIER = UserNotifierEmail
end