Class: SolidusAdmin::UsersController

Inherits:
BaseController
  • Object
show all
Includes:
ControllerHelpers::Search, Spree::Core::ControllerHelpers::StrongParameters
Defined in:
app/controllers/solidus_admin/users_controller.rb

Instance Method Summary collapse

Methods included from ComponentsHelper

#component

Instance Method Details

#addressesObject



29
30
31
32
33
34
# File 'app/controllers/solidus_admin/users_controller.rb', line 29

def addresses
  respond_to do |format|
    format.turbo_stream { render turbo_stream: '<turbo-stream action="refresh" />' }
    format.html { render component('users/addresses').new(user: @user) }
  end
end

#destroyObject



75
76
77
78
79
80
81
82
# File 'app/controllers/solidus_admin/users_controller.rb', line 75

def destroy
  @users = Spree.user_class.where(id: params[:id])

  Spree.user_class.transaction { @users.destroy_all }

  flash[:notice] = t('.success')
  redirect_back_or_to users_path, status: :see_other
end

#editObject



69
70
71
72
73
# File 'app/controllers/solidus_admin/users_controller.rb', line 69

def edit
  respond_to do |format|
    format.html { render component('users/edit').new(user: @user) }
  end
end

#indexObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/solidus_admin/users_controller.rb', line 16

def index
  users = apply_search_to(
    Spree.user_class.order(created_at: :desc, id: :desc),
    param: :q,
  )

  set_page_and_extract_portion_from(users)

  respond_to do |format|
    format.html { render component('users/index').new(page: @page) }
  end
end

#itemsObject



61
62
63
64
65
66
67
# File 'app/controllers/solidus_admin/users_controller.rb', line 61

def items
  set_items

  respond_to do |format|
    format.html { render component('users/items').new(user: @user, items: @items) }
  end
end

#ordersObject



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

def orders
  set_orders

  respond_to do |format|
    format.html { render component('users/orders').new(user: @user, orders: @orders) }
  end
end

#store_creditsObject



84
85
86
87
88
89
90
# File 'app/controllers/solidus_admin/users_controller.rb', line 84

def store_credits
  @store_credits = Spree::StoreCredit.where(user_id: @user.id).order(id: :desc)

  respond_to do |format|
    format.html { render component("users/store_credits/index").new(user: @user, store_credits: @store_credits) }
  end
end

#update_addressesObject



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

def update_addresses
  set_address_from_params

  if @address.valid? && @user.update(user_params)
    flash[:success] = t(".#{@type}.success")

    respond_to do |format|
      format.turbo_stream { render turbo_stream: '<turbo-stream action="refresh" />' }
      format.html { render component('users/addresses').new(user: @user) }
    end
  else
    respond_to do |format|
      format.html { render component('users/addresses').new(user: @user, address: @address, type: @type), status: :unprocessable_entity }
    end
  end
end