From cbb7a14621243f39185bc2bd01b2f63bb6ac4134 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 23 Apr 2018 14:17:56 +0630 Subject: [PATCH 1/6] update action cable for cloud --- app/controllers/origami/addorders_controller.rb | 4 ++-- app/controllers/origami/second_display_controller.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index e3122ded..499c20a7 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -184,11 +184,11 @@ puts items_arr.to_json @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) # for second display - if ENV["SERVER_MODE"] != 'cloud' + # if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale" - end + # end result = {:status=> @status, :data => @sale } render :json => result.to_json end diff --git a/app/controllers/origami/second_display_controller.rb b/app/controllers/origami/second_display_controller.rb index 4f2c06f8..611b49a9 100644 --- a/app/controllers/origami/second_display_controller.rb +++ b/app/controllers/origami/second_display_controller.rb @@ -13,9 +13,9 @@ class Origami::SecondDisplayController < BaseOrigamiController else tax_profiles = nil end - if ENV["SERVER_MODE"] != 'cloud' + if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status] - end + end end #Shop Name in Navbor helper_method :shop_detail From b92889fb237e3b7867c2b6f38580274cde593410 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 23 Apr 2018 14:41:07 +0630 Subject: [PATCH 2/6] change base url settings --- README.md | 3 +++ app/controllers/concerns/token_verification.rb | 3 ++- app/models/order_reservation.rb | 14 +++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fcc35040..712d61a9 100755 --- a/README.md +++ b/README.md @@ -184,6 +184,9 @@ For MoveTablePdf in print settings Add Kitchen Role of Employee => 1) settings/lookups => { type:employee_roles, name: Kitchen, value:kitchen } +Add Base URL for DOEMAL + 1) settings/lookups => { type:order_reservation, name: BaseURL, value:'{doemal url}' } + * ToDo list 1. Migration diff --git a/app/controllers/concerns/token_verification.rb b/app/controllers/concerns/token_verification.rb index b49ef597..85c9b858 100755 --- a/app/controllers/concerns/token_verification.rb +++ b/app/controllers/concerns/token_verification.rb @@ -24,7 +24,8 @@ module TokenVerification end end - @user = Employee.authenticate_by_token(token) + @user = Employee. + (token) if @user return true #Maybe log - login? diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 2fa99cf4..2d931d36 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -219,7 +219,19 @@ class OrderReservation < ApplicationRecord end def self.send_status_to_ordering(url,ref_no,status) - base_url = "http://192.168.1.186:3002" + base_url = 'https://api.doemal.com' + order_reservation = Lookup.collection_of("order_reservation") + if !order_reservation.empty? + order_reservation.each do |order_reserve| + if order_reserve[0] == 'BaseURL' + base_url = order_reserve[1] + end + end + else + Rails.logger.debug "Add order reservation BaseURL " + response = {status: false} + end + Rails.logger.debug "Doemal URL" + base_url post_url = base_url + url begin From 5ea950f5aa75108223d3abc53345983c772dc8a8 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 23 Apr 2018 14:43:27 +0630 Subject: [PATCH 3/6] update addore cable for second display closed --- app/controllers/origami/addorders_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 499c20a7..2eab460a 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -184,11 +184,11 @@ puts items_arr.to_json @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) # for second display - # if ENV["SERVER_MODE"] != 'cloud' + if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale" - # end + end result = {:status=> @status, :data => @sale } render :json => result.to_json end From 2255fcd2d473d2ac694285bd5ed121de0db0a748 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 23 Apr 2018 15:09:04 +0630 Subject: [PATCH 4/6] add token in lookups --- README.md | 1 + app/models/order_reservation.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 712d61a9..43a2091e 100755 --- a/README.md +++ b/README.md @@ -186,6 +186,7 @@ Add Kitchen Role of Employee Add Base URL for DOEMAL 1) settings/lookups => { type:order_reservation, name: BaseURL, value:'{doemal url}' } + 2) settings/lookups => { type:order_reservation, name: Token, value:'{doemal token}' } * ToDo list diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 2d931d36..5aab27ba 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -220,11 +220,14 @@ class OrderReservation < ApplicationRecord def self.send_status_to_ordering(url,ref_no,status) base_url = 'https://api.doemal.com' + token = '3T-tnlYtFJ-5Z1vY6XQqxQ' order_reservation = Lookup.collection_of("order_reservation") if !order_reservation.empty? order_reservation.each do |order_reserve| if order_reserve[0] == 'BaseURL' base_url = order_reserve[1] + elsif order_reserve[0] == 'Token' + token = order_reserve[1] end end else @@ -234,11 +237,12 @@ class OrderReservation < ApplicationRecord Rails.logger.debug "Doemal URL" + base_url post_url = base_url + url + begin response = HTTParty.post(post_url, :body => { id: ref_no, status: status}.to_json, :headers => { - 'Authorization' => 'Token token=3T-tnlYtFJ-5Z1vY6XQqxQ', + 'Authorization' => 'Token token='+token, 'Content-Type' => 'application/json', 'Accept' => 'application/json; version=3' }, :timeout => 10 From 6e3a5300a69733b36548725719d407bd8cfb1341 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 23 Apr 2018 15:39:56 +0630 Subject: [PATCH 5/6] close cable in cloud mode --- app/controllers/api/bill_controller.rb | 4 +++- app/controllers/api/call_waiters_controller.rb | 5 +++-- .../order_reserve/order_reservation_controller.rb | 5 +++-- .../origami/request_bills_controller.rb | 4 +++- app/controllers/origami/split_bill_controller.rb | 6 +++--- app/models/dining_facility.rb | 8 ++++++-- app/models/order.rb | 14 +++++++++++--- app/models/sale_payment.rb | 4 +++- 8 files changed, 35 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 994f6fe4..a4c8b383 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -47,7 +47,9 @@ class Api::BillController < Api::ApiController Promotion.promo_activate(@sale) #BillBroadcastJob.perform_later(table) - ActionCable.server.broadcast "bill_channel",table: table + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "bill_channel",table: table + end else @status = false @error_message = "No Current Open Shift" diff --git a/app/controllers/api/call_waiters_controller.rb b/app/controllers/api/call_waiters_controller.rb index b695dc33..d0a0e3df 100644 --- a/app/controllers/api/call_waiters_controller.rb +++ b/app/controllers/api/call_waiters_controller.rb @@ -6,8 +6,9 @@ class Api::CallWaitersController < ActionController::API @time = params[:time] @table = DiningFacility.find(@table_id) # CallWaiterJob.perform_later(@table,@time) - ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time - + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time + end # get printer info @shop = Shop.first unique_code = "CallWaiterPdf" diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 42768d58..486e0c9e 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -59,8 +59,9 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation_id, flag = OrderReservation.addOrderReservationInfo(params) order_reservation = OrderReservation.find(order_reservation_id) - ActionCable.server.broadcast "order_reservation_channel",data: order_reservation - + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "order_reservation_channel",data: order_reservation + end if flag render :json => { :status => true, :order_reservation_id => order_reservation_id, :message => "Order reservation is successfully created!" } else diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 05dbdce4..8c1d3a43 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -39,7 +39,9 @@ class Origami::RequestBillsController < ApplicationController # Promotion Activation Promotion.promo_activate(@sale) #bill channel - ActionCable.server.broadcast "bill_channel",table: table + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "bill_channel",table: table + end if order.source == "quick_service" result = {:status=> @status, :data => @sale.sale_id } render :json => result.to_json diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index 8cd68d9c..547a8a7e 100755 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -335,9 +335,9 @@ class Origami::SplitBillController < BaseOrigamiController end Promotion.promo_activate(sale) - - ActionCable.server.broadcast "bill_channel",table: table - + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "bill_channel",table: table + end render :json => { status: status } else render :json => { status: false, error_message: 'No Current Open Shift!'} diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 50fc6a52..793ba287 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -156,13 +156,17 @@ class DiningFacility < ApplicationRecord table = DiningFacility.find(table_id) #Send to background job for processing # CheckInBookingJob.perform_later(table) - ActionCable.server.broadcast "check_in_booking_channel",table: table + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "check_in_booking_channel",table: table + end end def self.checkin_time table = DiningFacility.get_checkin_booking if table.length > 0 - ActionCable.server.broadcast "checkin_channel",table: table + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "checkin_channel",table: table + end end end diff --git a/app/models/order.rb b/app/models/order.rb index e4ab883b..a4f27778 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -321,7 +321,9 @@ class Order < ApplicationRecord end else msg = ' Print Error ! Please contact to service' - ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' + end if !sidekiq.nil? OrderQueueProcessorJob.perform_later(self.id, self.table_id) else @@ -335,7 +337,9 @@ class Order < ApplicationRecord end end assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) - ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + end end end @@ -372,7 +376,9 @@ class Order < ApplicationRecord type = 'order' #Send to background job for processing # OrderBroadcastJob.perform_later(table,type) + if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "order_channel",table: table,type:type + end end end @@ -526,7 +532,9 @@ class Order < ApplicationRecord end end end - ActionCable.server.broadcast "second_display_channel",data: @data_array,status:@status + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "second_display_channel",data: @data_array,status:@status + end end private diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 29d755d7..098b5733 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -607,7 +607,9 @@ class SalePayment < ApplicationRecord type = 'payment' #Send to background job for processing # OrderBroadcastJob.perform_later(table,type) - ActionCable.server.broadcast "order_channel",table: table,type:type + if ENV["SERVER_MODE"] != 'cloud' + ActionCable.server.broadcast "order_channel",table: table,type:type + end end end end From 3d39e398df07dd0028a0bddc86258841ef69246e Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 23 Apr 2018 16:16:41 +0630 Subject: [PATCH 6/6] remove actioncable --- .../api/order_reserve/order_reservation_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 486e0c9e..c3c9f39b 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -59,9 +59,9 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation_id, flag = OrderReservation.addOrderReservationInfo(params) order_reservation = OrderReservation.find(order_reservation_id) - if ENV["SERVER_MODE"] != 'cloud' - ActionCable.server.broadcast "order_reservation_channel",data: order_reservation - end + # if ENV["SERVER_MODE"] != 'cloud' + # ActionCable.server.broadcast "order_reservation_channel",data: order_reservation + # end if flag render :json => { :status => true, :order_reservation_id => order_reservation_id, :message => "Order reservation is successfully created!" } else