From 79bf4beb6b295014a600418c6351d76323333f0a Mon Sep 17 00:00:00 2001 From: Michael Crismali Date: Tue, 28 Jan 2025 18:53:19 -0600 Subject: [PATCH 1/5] WIP --- .../reservation_loans_controller.rb | 8 ++++++++ app/javascript/controllers/index.js | 6 ++++++ .../reservation_pickup_sounds_controller.js | 19 +++++++++++++++++++ .../reservation_loans/create.turbo_stream.erb | 2 +- .../reservation_loans/index.html.erb | 5 ++++- 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 app/javascript/controllers/reservation_pickup_sounds_controller.js diff --git a/app/controllers/admin/reservations/reservation_loans_controller.rb b/app/controllers/admin/reservations/reservation_loans_controller.rb index bae360dc9..1e06b285b 100644 --- a/app/controllers/admin/reservations/reservation_loans_controller.rb +++ b/app/controllers/admin/reservations/reservation_loans_controller.rb @@ -1,6 +1,10 @@ module Admin module Reservations class ReservationLoansController < BaseController + COMPLETE_SUCCESS = 'complete-success' + PARTIAL_SUCCESS = 'partial-success' + ERROR = 'error' + before_action :set_reservation_loan, only: :destroy def index @@ -11,6 +15,8 @@ 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 = ERROR + if (reservation_hold_id = reservation_loan_params[:reservation_hold_id]) @reservation_hold = @reservation.reservation_holds.find(reservation_hold_id) @@ -36,6 +42,7 @@ def create created_by: current_user ) if pending_item.save + @sound_type = COMPLETE_SUCCESS respond_to do |format| format.turbo_stream end @@ -52,6 +59,7 @@ def create end if @reservation_loan.save + @sound_type = COMPLETE_SUCCESS respond_to do |format| format.turbo_stream end diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index 7508bd4e0..29da51cd4 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -34,6 +34,8 @@ import NotesController from './notes_controller' import ReservationDatesController from './reservation_dates_controller' +import ReservationPickupSoundsController from './reservation_pickup_sounds_controller' + import SidebarController from './sidebar_controller' import TagEditorController from './tag_editor_controller' @@ -56,6 +58,10 @@ application.register('modal', ModalController) application.register('multi-select', MultiSelectController) application.register('notes', NotesController) application.register('reservation-dates', ReservationDatesController) +application.register( + 'reservation-pickup-sounds', + ReservationPickupSoundsController +) application.register('sidebar', SidebarController) application.register('tag-editor', TagEditorController) application.register('toggle', ToggleController) diff --git a/app/javascript/controllers/reservation_pickup_sounds_controller.js b/app/javascript/controllers/reservation_pickup_sounds_controller.js new file mode 100644 index 000000000..c9f812c4b --- /dev/null +++ b/app/javascript/controllers/reservation_pickup_sounds_controller.js @@ -0,0 +1,19 @@ +import { Controller } from '@hotwired/stimulus' + +const COMPLETE_SUCCESS = 'complete-success' +const PARTIAL_SUCCESS = 'partial-success' +const ERROR = 'error' + +export default class extends Controller { + playSound(event) { + const { newStream } = event.detail + + if (newStream.target === 'reservation-loan-form') { + const soundType = newStream.querySelector('template').dataset.soundType + + console.log({soundType}) + } + + + } +} diff --git a/app/views/admin/reservations/reservation_loans/create.turbo_stream.erb b/app/views/admin/reservations/reservation_loans/create.turbo_stream.erb index d1e1f9dd0..03689a221 100644 --- a/app/views/admin/reservations/reservation_loans/create.turbo_stream.erb +++ b/app/views/admin/reservations/reservation_loans/create.turbo_stream.erb @@ -1,5 +1,5 @@ - + +<% if @sound_type %> + +<% end %> diff --git a/app/views/admin/reservations/pending_reservation_items/update.turbo_stream.erb b/app/views/admin/reservations/pending_reservation_items/update.turbo_stream.erb new file mode 100644 index 000000000..6d6b9158f --- /dev/null +++ b/app/views/admin/reservations/pending_reservation_items/update.turbo_stream.erb @@ -0,0 +1,5 @@ +<%= turbo_stream.action(:redirect, admin_reservation_loans_path(@pending_reservation_item.reservation)) %> + +<% if @sound_type %> + +<% end %> diff --git a/app/views/admin/reservations/reservation_loans/create.turbo_stream.erb b/app/views/admin/reservations/reservation_loans/create.turbo_stream.erb index d1e1f9dd0..7d6d5e352 100644 --- a/app/views/admin/reservations/reservation_loans/create.turbo_stream.erb +++ b/app/views/admin/reservations/reservation_loans/create.turbo_stream.erb @@ -12,6 +12,10 @@ <% end %> +<% if @sound_type %> + +<% end %> +