Class: Dashboard::V2::PackageMenusController
- Inherits:
-
MainController
- Object
- ActionController::Base
- ApplicationController
- MainController
- Dashboard::V2::PackageMenusController
- Defined in:
- app/controllers/dashboard/v2/package_menus_controller.rb
Direct Known Subclasses
Instance Method Summary collapse
Methods inherited from MainController
#default_fallback_location, #default_url_options, #kiosque_callback
Methods included from LogrageCustomLogger
Methods included from Stimulus::TagController
Methods included from OwnerLoginMode
#current_owner, #group_owner_type?, #request_path_contain_group?, #single_owner_type?
Methods included from OwnerDashboardsHelper
#events_ajax_previous_link, #show_source
Methods inherited from ApplicationController
#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=
Methods included from ControllerHelpers
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Instance Method Details
#activate_menu ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/dashboard/v2/package_menus_controller.rb', line 13 def = params.require(:package_menu).permit(:package_menu_id, :active) active = [:active].to_s == 'true' = HhPackage::RestaurantPackageMenu.find([:package_menu_id]) .active = active .save success = .errors.blank? = if success && active I18n.t('activate_success', menu: ..name) elsif success && !active I18n.t('inactivate_success', menu: ..name) else .errors..to_sentence end if @restaurant.present? package = ..section.package is_visible = package..joins(menus: :restaurant_package_menus) .where(hh_package_restaurant_package_menus: { active: true, restaurant_id: @restaurant.id }).count.positive? package.restaurant_packages.where(restaurant: @restaurant).update is_visible: is_visible end render json: { success: success, message: } end |
#index ⇒ Object
11 |
# File 'app/controllers/dashboard/v2/package_menus_controller.rb', line 11 def index; end |
#restaurant_menus ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/dashboard/v2/package_menus_controller.rb', line 44 def = [] packages = @restaurant.restaurant_packages.map(&:package) packages.select do |p| p. && p..to_s.include?('hh_menu') end.map do |package| package_data = { name: package.name, sections: sections_data(package), allow_to_edit: package.fetch_package_attr. } .push(package_data) end render json: { data: } end |
#show ⇒ Object
63 64 65 66 67 68 |
# File 'app/controllers/dashboard/v2/package_menus_controller.rb', line 63 def show = HhPackage::PackageMenu.find(params[:id]) render json: { data: } end |
#update ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/dashboard/v2/package_menus_controller.rb', line 70 def update = params[:id] = params.permit(:name_en, :name_th, :image).tap do |h| h.delete :image if h[:image] == 'null' || h[:image].blank? end active = params[:active].to_s == 'true' success = true = 'Menu successfully updated' = HhPackage::PackageMenu.find_by(id: ) unless .present? && .update_attributes() success = false = if .errors.present? .errors..to_sentence else 'Update failed, package menu not found' end end = HhPackage::RestaurantPackageMenu.find_by( restaurant_id: @restaurant.id, package_menu_id: ) if success && .present? .active = active .save success = .errors.blank? if .errors.present? success = false = .errors..to_sentence end end @restaurant.touch if success render json: { success: success, message: } end |