From 9f24c56e610e8bd5262f149bdb04b8fa97e830e5 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 1 Jun 2018 17:38:59 +0630 Subject: [PATCH] add audio for order reservation --- .gitignore | 1 + app/assets/javascripts/channels/order_reservation.js | 3 ++- app/assets/javascripts/custom.js | 6 +++--- .../api/order_reserve/order_reservation_controller.rb | 9 +++++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 66f5a09c..239ae203 100755 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ capybara-*.html /public/uploads/* /public/swf/* /public/receipts/ +/public/*.mp3 /coverage/ /spec/tmp/* *.orig diff --git a/app/assets/javascripts/channels/order_reservation.js b/app/assets/javascripts/channels/order_reservation.js index 00d8e2cf..d257e2b0 100644 --- a/app/assets/javascripts/channels/order_reservation.js +++ b/app/assets/javascripts/channels/order_reservation.js @@ -8,6 +8,7 @@ App.order_reservation = App.cable.subscriptions.create('OrderReservationChannel' if(data.from == "" || hostname == data.from){ var shop_code = data.shop_code; var order = data.data; + var audio = data.audio; if(order.length > 0){ $('.custom-table.'+shop_code+'_order_reserve_cable tbody').html(""); $("."+shop_code+" > .nav-item.red > a > p.num").text(order.length); @@ -16,7 +17,7 @@ App.order_reservation = App.cable.subscriptions.create('OrderReservationChannel' if(key==0){ active_class = "tr-active"; if (typeof audioPlayBackground !== 'undefined' && $.isFunction(audioPlayBackground)) { - audioPlayBackground(shop_code); + audioPlayBackground(shop_code,audio); } if (typeof showNewOrderAlert !== 'undefined' && $.isFunction(showNewOrderAlert)) { showNewOrderAlert(order[key],shop_code); diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 7477ffd3..e14cc205 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -159,10 +159,10 @@ $(document).ready(function() { }); /* start order reservation function */ -function audioPlayBackground(shop_code){ - console.log(shop_code); +function audioPlayBackground(shop_code,audio){ + // console.log(shop_code); //audio play - var audio = new Audio('/'+shop_code+'-beep.mp3'); // define your audio + var audio = new Audio('/'+audio); // define your audio // setTimeout(function(){ // audio.loop = true; audio.play(); diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 3553c7e0..6d323f52 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -65,10 +65,15 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController if flag shop = Shop.find_by_id(1) - if !shop.shop_code.nil? + if !shop.nil? shop_code = shop.shop_code + order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio") + if !order_audio.nil? + audio = order_audio.image + end else shop_code = '' + audio = '' end result = { :status => true, :order_reservation_id => order_reservation_id, :message => "Order reservation is successfully created!" } @@ -78,7 +83,7 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController else from = "" end - ActionCable.server.broadcast "order_reservation_channel",data: order_reservation,shop_code: shop_code,from:from + ActionCable.server.broadcast "order_reservation_channel",data: order_reservation,shop_code: shop_code,from:from,audio:audio else result = { :status => true, :order_reservation_id => order_reservation_id, :message => "Order reservation is already existed!" } end