add cable but not complete
This commit is contained in:
4
Gemfile
4
Gemfile
@@ -11,6 +11,10 @@ gem 'rails', '~> 5.1.0'
|
|||||||
# Use mysql as the database for Active Record
|
# Use mysql as the database for Active Record
|
||||||
gem 'mysql2', '>= 0.3.18', '< 0.5'
|
gem 'mysql2', '>= 0.3.18', '< 0.5'
|
||||||
#gem 'pg'
|
#gem 'pg'
|
||||||
|
|
||||||
|
# redis server for cable
|
||||||
|
gem 'redis', '~> 3.0'
|
||||||
|
|
||||||
# Use Puma as the app server
|
# Use Puma as the app server
|
||||||
gem 'puma', '~> 3.0'
|
gem 'puma', '~> 3.0'
|
||||||
# Use SCSS for stylesheets
|
# Use SCSS for stylesheets
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ GEM
|
|||||||
sass (>= 3.4.19)
|
sass (>= 3.4.19)
|
||||||
builder (3.2.3)
|
builder (3.2.3)
|
||||||
byebug (9.0.6)
|
byebug (9.0.6)
|
||||||
coffee-rails (4.2.1)
|
coffee-rails (4.2.2)
|
||||||
coffee-script (>= 2.2.0)
|
coffee-script (>= 2.2.0)
|
||||||
railties (>= 4.0.0, < 5.2.x)
|
railties (>= 4.0.0)
|
||||||
coffee-script (2.4.1)
|
coffee-script (2.4.1)
|
||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
@@ -97,7 +97,7 @@ GEM
|
|||||||
minitest (5.10.2)
|
minitest (5.10.2)
|
||||||
multi_json (1.12.1)
|
multi_json (1.12.1)
|
||||||
mysql2 (0.4.6)
|
mysql2 (0.4.6)
|
||||||
nio4r (2.0.0)
|
nio4r (2.1.0)
|
||||||
nokogiri (1.7.2)
|
nokogiri (1.7.2)
|
||||||
mini_portile2 (~> 2.1.0)
|
mini_portile2 (~> 2.1.0)
|
||||||
pdf-core (0.7.0)
|
pdf-core (0.7.0)
|
||||||
@@ -238,6 +238,7 @@ DEPENDENCIES
|
|||||||
puma (~> 3.0)
|
puma (~> 3.0)
|
||||||
rack-cors
|
rack-cors
|
||||||
rails (~> 5.1.0)
|
rails (~> 5.1.0)
|
||||||
|
redis (~> 3.0)
|
||||||
rspec-rails (~> 3.5)
|
rspec-rails (~> 3.5)
|
||||||
sass-rails (~> 5.0)
|
sass-rails (~> 5.0)
|
||||||
schema_to_scaffold
|
schema_to_scaffold
|
||||||
@@ -255,4 +256,4 @@ DEPENDENCIES
|
|||||||
web-console (>= 3.3.0)
|
web-console (>= 3.3.0)
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.14.6
|
1.15.0
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Action Cable provides the framework to deal with WebSockets in Rails.
|
// 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 action_cable
|
||||||
//= require_self
|
//= 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
|
module ApplicationCable
|
||||||
class Channel < ActionCable::Channel::Base
|
class Channel < ActionCable::Channel::Base
|
||||||
end
|
end
|
||||||
|
# Order Queue Station Channel
|
||||||
|
class OrderChannel < ActionCable::Channel::Base
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# Order Queue Station Channel
|
||||||
|
class OQSChannel < ActionCable::Channel::Base
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
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
|
||||||
@@ -5,6 +5,7 @@ class OrderQueueProcessorJob < ApplicationJob
|
|||||||
# Do something later
|
# Do something later
|
||||||
#Order ID
|
#Order ID
|
||||||
order = Order.find(order_id)
|
order = Order.find(order_id)
|
||||||
|
|
||||||
#Loop through the order stations and process the items
|
#Loop through the order stations and process the items
|
||||||
#Execute orders and send to order stations
|
#Execute orders and send to order stations
|
||||||
if order
|
if order
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ class Order < ApplicationRecord
|
|||||||
#internal references attributes for business logic control
|
#internal references attributes for business logic control
|
||||||
attr_accessor :items, :guest, :table_id, :new_booking, :booking_type, :employee_name, :booking_id
|
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
|
#Main Controller method to create new order - validate all inputs and generate new order
|
||||||
# order_item : {
|
# order_item : {
|
||||||
# order_item_code : "",
|
# order_item_code : "",
|
||||||
@@ -43,6 +42,9 @@ class Order < ApplicationRecord
|
|||||||
#Send order to queue one it done!
|
#Send order to queue one it done!
|
||||||
process_order_queue
|
process_order_queue
|
||||||
|
|
||||||
|
#send order to broadcast job
|
||||||
|
send_order_broadcast
|
||||||
|
|
||||||
return true, booking
|
return true, booking
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -201,4 +203,10 @@ class Order < ApplicationRecord
|
|||||||
#Send to background job for processing
|
#Send to background job for processing
|
||||||
OrderQueueProcessorJob.perform_later(self.id)
|
OrderQueueProcessorJob.perform_later(self.id)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -51,4 +51,7 @@ Rails.application.configure do
|
|||||||
# Use an evented file watcher to asynchronously detect changes in source code,
|
# Use an evented file watcher to asynchronously detect changes in source code,
|
||||||
# routes, locales, etc. This feature depends on the listen gem.
|
# routes, locales, etc. This feature depends on the listen gem.
|
||||||
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
||||||
|
|
||||||
|
# Set Cable URL
|
||||||
|
config.action_cable.url = "ws://192.168.1.140:3002/cable"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ Rails.application.routes.draw do
|
|||||||
root 'home#index'
|
root 'home#index'
|
||||||
mount Sidekiq::Web => '/kiq'
|
mount Sidekiq::Web => '/kiq'
|
||||||
|
|
||||||
|
# Action Cable Creation
|
||||||
|
mount ActionCable.server => "/cable"
|
||||||
|
|
||||||
#--------- SmartSales Installation ------------#
|
#--------- SmartSales Installation ------------#
|
||||||
get 'install' => 'install#index'
|
get 'install' => 'install#index'
|
||||||
post 'install' => 'install#create'
|
post 'install' => 'install#create'
|
||||||
|
|||||||
5
spec/jobs/order_broadcast_job_spec.rb
Normal file
5
spec/jobs/order_broadcast_job_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe OrderBroadcastJob, type: :job do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user