-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Members deliveries, show when no next basket
This patch ensures that the deliveries page is still shown even when there is no next basket. Future deliveries could still be present when for example the next basket is marked as absent or empty. Showing it avoid confusion and allows the user to see the status of the next deliveries. It's also useful to still show past deliveries when there is no next basket.
- Loading branch information
Showing
5 changed files
with
78 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class Members::DeliveriesController < Members::BaseController | ||
before_action :ensure_baskets | ||
|
||
# GET /deliveries | ||
def index | ||
if @next_basket = current_member.next_basket | ||
membership_ids = [ @next_basket.membership_id ] | ||
if current_member.future_membership | ||
membership_ids << current_member.future_membership.id | ||
end | ||
@future_baskets = | ||
Basket | ||
.where(membership_id: membership_ids) | ||
.filled | ||
.coming | ||
.includes(:delivery, :basket_size, :depot, baskets_basket_complements: :basket_complement) | ||
@past_baskets = | ||
@next_basket | ||
.membership | ||
.baskets | ||
.filled | ||
.past | ||
.includes(:delivery, :basket_size, :depot, baskets_basket_complements: :basket_complement) | ||
else | ||
redirect_to members_login_path | ||
end | ||
@next_basket = current_member.next_basket | ||
@future_baskets = | ||
Basket | ||
.where(membership_id: current_member.memberships.current_or_future) | ||
.filled | ||
.coming | ||
.includes(:delivery, :basket_size, :depot, baskets_basket_complements: :basket_complement) | ||
@past_baskets = | ||
current_member | ||
.closest_membership | ||
.baskets | ||
.filled | ||
.past | ||
.includes(:delivery, :basket_size, :depot, baskets_basket_complements: :basket_complement) | ||
end | ||
|
||
private | ||
|
||
def ensure_baskets | ||
return if current_member.baskets.any? | ||
|
||
redirect_to members_login_path | ||
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
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