-
Notifications
You must be signed in to change notification settings - Fork 70
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
Admins hear success/error sounds when adding items to a pickup for a reservation #1827
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
79bf4be
WIP
crismali 6082a52
WIP
crismali d4e1ca1
Remove autoplaying audio tag
crismali ebbf2ba
Added custom turbo stream action to play sounds when building a reser…
crismali b342580
Added call to fastSeek if it is implemented in the browser
crismali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module Admin | ||
module Reservations | ||
class ReservationLoansController < BaseController | ||
include Sounds | ||
before_action :set_reservation_loan, only: :destroy | ||
|
||
def index | ||
|
@@ -11,6 +12,7 @@ def index | |
# that we're creating a ReservationLoan for an ItemPool without uniquely numbered items. | ||
# Otherwise, we're creating a ReservationLoan for an individual ReservableItem. | ||
def create | ||
@sound_type = success_sound_path | ||
if (reservation_hold_id = reservation_loan_params[:reservation_hold_id]) | ||
@reservation_hold = @reservation.reservation_holds.find(reservation_hold_id) | ||
|
||
|
@@ -36,6 +38,7 @@ def create | |
created_by: current_user | ||
) | ||
if pending_item.save | ||
@sound_type = neutral_sound_path | ||
respond_to do |format| | ||
format.turbo_stream | ||
end | ||
|
@@ -56,6 +59,7 @@ def create | |
format.turbo_stream | ||
end | ||
else | ||
@sound_type = failure_sound_path | ||
render_form | ||
end | ||
end | ||
|
@@ -65,6 +69,8 @@ def destroy | |
|
||
@reservation_hold = @reservation_loan.reservation_hold | ||
|
||
@sound_type = removed_sound_path | ||
|
||
respond_to do |format| | ||
format.turbo_stream do | ||
render :create | ||
|
@@ -75,13 +81,14 @@ def destroy | |
private | ||
|
||
def render_form_with_error(message) | ||
@sound_type = failure_sound_path | ||
@reservation_loan = ReservationLoan.new | ||
@reservation_loan.errors.add(:reservable_item_number, message) | ||
render_form | ||
end | ||
|
||
def render_form | ||
render partial: "admin/reservations/reservation_loans/form", locals: {reservation: @reservation, reservation_loan: @reservation_loan}, status: :unprocessable_entity | ||
render_turbo_response :create_error, status: :unprocessable_entity | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
end | ||
|
||
def set_reservation_loan | ||
|
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Sounds | ||
extend self | ||
|
||
ALL = [ | ||
SUCCESS = "success", | ||
NEUTRAL = "neutral", | ||
FAILURE = "failure", | ||
REMOVED = "removed" | ||
] | ||
|
||
ALL.each do |sound| | ||
define_method(:"#{sound}_sound_path") do | ||
"/sounds/#{sound}.wav" | ||
end | ||
end | ||
|
||
def all_sound_paths | ||
ALL.map { |sound| "/sounds/#{sound}.wav" } | ||
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
5 changes: 5 additions & 0 deletions
5
app/views/admin/reservations/pending_reservation_items/update.turbo_stream.erb
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 @@ | ||
<%= turbo_stream.action(:redirect, admin_reservation_loans_path(@pending_reservation_item.reservation)) %> | ||
|
||
<% if @sound_type %> | ||
<turbo-stream action="playSound" sound_type="<%= @sound_type %>"></turbo-stream> | ||
<% 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
9 changes: 9 additions & 0 deletions
9
app/views/admin/reservations/reservation_loans/create_error.turbo_stream.erb
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,9 @@ | ||
<turbo-stream action="replace" target="reservation-loan-form"> | ||
<template> | ||
<%= render partial: "admin/reservations/reservation_loans/form", formats: [:html], locals: {reservation: @reservation, reservation_loan: @reservation_loan} %> | ||
</template> | ||
</turbo-stream> | ||
|
||
<% if @sound_type %> | ||
<turbo-stream action="playSound" sound_type="<%= @sound_type %>"></turbo-stream> | ||
<% 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a file seemed like the easiest way to send down multiple turbo streams.