add cable but not complete
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Action Cable provides the framework to deal with WebSockets in Rails.
|
||||
// You can generate new channels where WebSocket features live using the rails generate channel command.
|
||||
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
|
||||
//
|
||||
//= require action_cable
|
||||
//= require_self
|
||||
|
||||
24
app/assets/javascripts/channels/order_queue_station.js
Normal file
24
app/assets/javascripts/channels/order_queue_station.js
Normal file
@@ -0,0 +1,24 @@
|
||||
App.order_queue_station = App.cable.subscriptions.create("OrderQueueStationChannel", {
|
||||
connected: function() {},
|
||||
|
||||
disconnected: function() {},
|
||||
|
||||
received: function(message) {
|
||||
alert(message);
|
||||
},
|
||||
|
||||
order: function(message) {
|
||||
return this.perform('order', {
|
||||
message: message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// $(function(){
|
||||
// $("#submit_order").on('click', function(event) {
|
||||
// var orderData=$("#new_order").serializeObject();
|
||||
// App.order_station.order(orderData);
|
||||
// //orderData='';
|
||||
// return event.preventDefault();
|
||||
// });
|
||||
// });
|
||||
@@ -1,4 +1,14 @@
|
||||
module ApplicationCable
|
||||
class Channel < ActionCable::Channel::Base
|
||||
end
|
||||
class Channel < ActionCable::Channel::Base
|
||||
end
|
||||
# Order Queue Station Channel
|
||||
class OrderChannel < ActionCable::Channel::Base
|
||||
|
||||
end
|
||||
|
||||
# Order Queue Station Channel
|
||||
class OQSChannel < ActionCable::Channel::Base
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
13
app/channels/order_queue_station_channel.rb
Normal file
13
app/channels/order_queue_station_channel.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class OrderQueueStationChannel < ApplicationCable::Channel
|
||||
def subscribed
|
||||
stream_from "order_queue_station_channel"
|
||||
end
|
||||
|
||||
def unsubscribed
|
||||
# Any cleanup needed when channel is unsubscribed
|
||||
end
|
||||
|
||||
def order(message)
|
||||
# ToDo
|
||||
end
|
||||
end
|
||||
8
app/jobs/order_broadcast_job.rb
Normal file
8
app/jobs/order_broadcast_job.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class OrderBroadcastJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(message)
|
||||
order = Order.find(message) # message come as order_id
|
||||
ApplicationCable.server.broadcast "order_queue_station_channel", order: order
|
||||
end
|
||||
end
|
||||
@@ -3,8 +3,9 @@ class OrderQueueProcessorJob < ApplicationJob
|
||||
|
||||
def perform(order_id)
|
||||
# Do something later
|
||||
#Order ID
|
||||
#Order ID
|
||||
order = Order.find(order_id)
|
||||
|
||||
#Loop through the order stations and process the items
|
||||
#Execute orders and send to order stations
|
||||
if order
|
||||
|
||||
@@ -8,7 +8,6 @@ class Order < ApplicationRecord
|
||||
#internal references attributes for business logic control
|
||||
attr_accessor :items, :guest, :table_id, :new_booking, :booking_type, :employee_name, :booking_id
|
||||
|
||||
|
||||
#Main Controller method to create new order - validate all inputs and generate new order
|
||||
# order_item : {
|
||||
# order_item_code : "",
|
||||
@@ -43,6 +42,9 @@ class Order < ApplicationRecord
|
||||
#Send order to queue one it done!
|
||||
process_order_queue
|
||||
|
||||
#send order to broadcast job
|
||||
send_order_broadcast
|
||||
|
||||
return true, booking
|
||||
|
||||
end
|
||||
@@ -198,7 +200,13 @@ class Order < ApplicationRecord
|
||||
|
||||
#Process order items and send to order queue
|
||||
def process_order_queue
|
||||
#Send to background job for processing
|
||||
#Send to background job for processing
|
||||
OrderQueueProcessorJob.perform_later(self.id)
|
||||
end
|
||||
|
||||
#send order items and send to order queue
|
||||
def send_order_broadcast
|
||||
#Send to background job for processing
|
||||
OrderBroadcastJob.perform_later(self.id)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user