From 035d0851eeb428b4ba8d616cd5e099ba32efe534 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 14 Dec 2017 17:10:05 +0630 Subject: [PATCH] update checking booking --- .../javascripts/channels/check_in_booking.js | 14 ++++++++++++++ app/channels/check_in_booking_channel.rb | 10 ++++++++++ app/controllers/api/check_in_process_controller.rb | 4 ++++ app/jobs/check_in_booking_job.rb | 9 +++++++++ app/models/dining_facility.rb | 7 +++++++ spec/jobs/check_in_booking_job_spec.rb | 5 +++++ 6 files changed, 49 insertions(+) create mode 100644 app/assets/javascripts/channels/check_in_booking.js create mode 100644 app/channels/check_in_booking_channel.rb create mode 100644 app/jobs/check_in_booking_job.rb create mode 100644 spec/jobs/check_in_booking_job_spec.rb diff --git a/app/assets/javascripts/channels/check_in_booking.js b/app/assets/javascripts/channels/check_in_booking.js new file mode 100644 index 00000000..6cd42863 --- /dev/null +++ b/app/assets/javascripts/channels/check_in_booking.js @@ -0,0 +1,14 @@ +App.checkin = App.cable.subscriptions.create('CheckInBookingChannel', { +// App.messages = App.cable.subscriptions.create('MessagesChannel', { + + connected: function() {}, + + disconnected: function() {}, + + received: function(data) { + $('.table_'+data.table.id).removeClass('green'); + $('.table_'+data.table.id).addClass('orange'); + $('.new_text_'+data.table.id).removeClass('hide') + } +}); + diff --git a/app/channels/check_in_booking_channel.rb b/app/channels/check_in_booking_channel.rb new file mode 100644 index 00000000..f9df89ba --- /dev/null +++ b/app/channels/check_in_booking_channel.rb @@ -0,0 +1,10 @@ +class CheckInBookingChannel < ApplicationCable::Channel + def subscribed + stream_from "check_in_booking_channel" + end + + def unsubscribed + stop_all_streams + # Any cleanup needed when channel is unsubscribed + end +end diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb index cfce827f..30f9a732 100644 --- a/app/controllers/api/check_in_process_controller.rb +++ b/app/controllers/api/check_in_process_controller.rb @@ -5,8 +5,12 @@ class Api::CheckInProcessController < Api::ApiController dining_facility = DiningFacility.find(params[:dining_id]) booking = dining_facility.get_current_checkout_booking if !booking.nil? + + DiningFacility.check_in_booking(params[:dining_id]) + check_in_time = booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") check_out_time = booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") + render :json => { :status => true, :check_in_time => check_in_time, :check_out_time => check_out_time } else render :json => { :status => false, :error_message => "No current booking!" } diff --git a/app/jobs/check_in_booking_job.rb b/app/jobs/check_in_booking_job.rb new file mode 100644 index 00000000..7f8d39d3 --- /dev/null +++ b/app/jobs/check_in_booking_job.rb @@ -0,0 +1,9 @@ +class CheckInBookingJob < ApplicationJob + queue_as :default + + def perform(table) + ActionCable.server.broadcast "check_in_booking_channel",table: table + end +end + + diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 595f0e0f..2e6c8616 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -122,4 +122,11 @@ class DiningFacility < ApplicationRecord end return arr_booking end + + #send order items and send to order queue + def self.check_in_booking(table_id) + table = DiningFacility.find(table_id) + #Send to background job for processing + CheckInBookingJob.perform_later(table) + end end diff --git a/spec/jobs/check_in_booking_job_spec.rb b/spec/jobs/check_in_booking_job_spec.rb new file mode 100644 index 00000000..04d03684 --- /dev/null +++ b/spec/jobs/check_in_booking_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CheckInBookingJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end