Class: Admin::BranchesController

Inherits:
BaseController show all
Defined in:
app/controllers/admin/branches_controller.rb

Overview

typed: ignore frozen_string_literal: true

Constant Summary

Constants inherited from BaseController

Admin::BaseController::INTERNAL_SERVER_ERROR_MESSAGE

Instance Method Summary collapse

Methods inherited from BaseController

#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from AdminHelper

#dynamic_pricings_formatter, #link_to_admin_reservations_path_by_id, #link_to_admin_restaurants_path_by_id, #link_to_log, #optional_locales, #optional_locales_with_labels, #staff_signed_in?

Methods included from UpdateLocaleConcern

#setup_locale

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

#createObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/admin/branches_controller.rb', line 20

def create
  branch_params = params.require(:branch).permit(:name, :logo)
  @branch = Branch.new branch_params

  if @branch.valid? && @branch.save
    redirect_to [:admin, @branch], notice: 'Branch created successfully'
  else
    render :new, alert: @branch.errors.full_messages.to_sentence
  end
end

#destroyObject



53
54
55
56
57
58
59
# File 'app/controllers/admin/branches_controller.rb', line 53

def destroy
  if params.key?(:restaurant_id)
    destroy_restaurant
  else
    destroy_branch
  end
end

#editObject



35
# File 'app/controllers/admin/branches_controller.rb', line 35

def edit; end

#indexObject



7
8
9
10
11
12
13
14
# File 'app/controllers/admin/branches_controller.rb', line 7

def index
  set_meta_tags title: 'Restaurant Branches Overview'
  @grid = ::Admin::BranchesGrid.new(params[:admin_branches_grid]) do |scope|
    scope.page(params[:page]).per(50)
  end
  etag = CityHash.hash32([self.class.to_s, @grid.assets.cache_key, params])
  return unless stale?(etag: etag)
end

#newObject



16
17
18
# File 'app/controllers/admin/branches_controller.rb', line 16

def new
  @branch = Branch.new
end

#showObject



31
32
33
# File 'app/controllers/admin/branches_controller.rb', line 31

def show
  set_meta_tags title: "#{@branch.name} Branch"
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/admin/branches_controller.rb', line 37

def update
  branch_param = params.require(:branch).permit(:name, :restaurants, :logo)
  if branch_param.key?(:restaurants)
    restaurant = Restaurant.find(branch_param.require(:restaurants))
    if restaurant.update branch_id: @branch.id
      redirect_back fallback_location: back_fallback_location, notice: "#{restaurant.name} restaurant added successfully"
    else
      redirect_back fallback_location: back_fallback_location, alert: "#{restaurant.name} restaurant could not be added. #{restaurant.errors.full_messages.to_sentence}"
    end
  elsif @branch.update branch_param
    redirect_to [:admin, @branch], notice: 'Branch successfully updated'
  else
    render :edit
  end
end