Skip to content

Commit

Permalink
simple items controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Dec 3, 2024
1 parent 25dc378 commit 42f6eb7
Show file tree
Hide file tree
Showing 28 changed files with 54 additions and 47 deletions.
31 changes: 31 additions & 0 deletions app/controllers/trade/admin/desk/items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Trade::Admin
class Desk::ItemsController < ItemsController
before_action :set_desk

def index
q_params = {
status: ['init', 'checked', 'ordered']
}
q_params.merge! default_params
q_params.merge! params.permit(:cart_id, :order_id, :good_type, :good_id, :desk_id, :aim, :address_id, :status)

@items = Item.includes(:user, :item_promotes, :order).default_where(q_params).order(order_id: :desc).page(params[:page]).per(params[:per])
end

def history
q_params = {
status: ['deliverable', 'done']
}
q_params.merge! default_params
q_params.merge! params.permit(:cart_id, :order_id, :good_type, :good_id, :desk_id, :aim, :address_id, :status)

@items = Item.includes(:user, :item_promotes, :order).default_where(q_params).order(order_id: :desc).page(params[:page]).per(params[:per])
end

private
def set_desk
@desk = Space::Desk.default_where(default_params).find params[:desk_id]
end

end
end
22 changes: 0 additions & 22 deletions app/controllers/trade/admin/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,6 @@ def produce
@items = Item.includes(:user, :item_promotes, :purchase_items, :order, :good).where.not(order_id: nil).default_where(q_params).order(id: :desc).page(params[:page]).per(params[:per])
end

def desk
q_params = {
status: ['init', 'checked', 'ordered']
}
q_params.merge! default_params
q_params.merge! params.permit(:cart_id, :order_id, :good_type, :good_id, :desk_id, :aim, :address_id, :status)

@desk = Space::Desk.default_where(default_params).find params[:desk_id]
@items = Item.includes(:user, :item_promotes, :order).default_where(q_params).order(order_id: :desc).page(params[:page]).per(params[:per])
end

def desk_history
q_params = {
status: ['deliverable', 'done']
}
q_params.merge! default_params
q_params.merge! params.permit(:cart_id, :order_id, :good_type, :good_id, :desk_id, :aim, :address_id, :status)

@desk = Space::Desk.default_where(default_params).find params[:desk_id]
@items = Item.includes(:user, :item_promotes, :order).default_where(q_params).order(order_id: :desc).page(params[:page]).per(params[:per])
end

def carts
@carts = @item.carts.includes(:user, :member)
end
Expand Down
10 changes: 10 additions & 0 deletions app/views/trade/admin/desk/items/_base/_desk_bar.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="tabs is-centered mb-3">
<ul>
<li class="<%= active_helper(action: 'index', active: 'is-active') %>">
<%= link_to t('.index.title'), { action: 'index' } %>
</li>
<li class="<%= active_helper(action: 'history', active: 'is-active') %>">
<%= link_to t('.history.title'), { action: 'history' } %>
</li>
</ul>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
<%= button_to({ action: 'destroy', id: model.id }, method: :delete, aria: { label: t('.destroy.title') }, form: { data: { turbo_confirm: t('.destroy.confirm') } }, class: 'button is-small is-rounded is-light') do %>
<i class="fa-solid fa-trash text-danger"></i>
<% end %>
<%= button_to({ action: 'update', id: model.id }, method: :patch, params: { 'item[desk_id]': nil }, aria: { label: t('.destroy.title') }, form: { data: { turbo_confirm: t('.destroy.confirm') } }, class: 'button is-small is-rounded is-light') do %>
<i class="fa-solid fa-trash text-danger"></i>
<% end if false %>
</div>
<div data-show-target="item" class="visibility-hidden">
<%= link_to({ action: 'carts', id: model.id }, class: 'button is-small is-rounded is-light') do %>
<i class="fa-solid fa-cart-shopping text-info"></i>
<span class="ml-1"><%= t('.items.carts.title') %></span>
<% end %>
</div>
</td>
</tr>
File renamed without changes.
10 changes: 0 additions & 10 deletions app/views/trade/admin/items/_base/_desk_bar.html.erb

This file was deleted.

10 changes: 6 additions & 4 deletions config/locales/zh.controller.admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ zh:
items:
index:
title: 售出产品
desk:
title: 点单详情
desk_history:
title: 订单历史
carts:
title: 所在购物车
compute:
Expand Down Expand Up @@ -222,3 +218,9 @@ zh:
rent_charges:
index:
title: 租金规则
desk:
items:
index:
title: 点单详情
history:
title: 订单历史
9 changes: 7 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@
collection do
get :purchase
get :produce
get 'desk/:desk_id' => :desk
get 'desk_history/:desk_id' => :desk_history
post :trial
post :batch_purchase
end
Expand All @@ -170,6 +168,13 @@
patch :deny
end
end
resources :desks, only: [] do
resources :items, controller: 'desk/items' do
collection do
get :history
end
end
end
end

namespace :trade, defaults: { business: 'trade' } do
Expand Down

0 comments on commit 42f6eb7

Please sign in to comment.