Implement full_name_for_sorting

This commit is contained in:
James Wu
2023-04-08 23:15:44 +09:00
committed by David Cook
parent 546e90b286
commit a75f16e23c
3 changed files with 11 additions and 5 deletions

View File

@@ -4,4 +4,8 @@ module AddressDisplay
def full_name_reverse
[lastname, firstname].reject(&:blank?).join(" ")
end
def full_name_for_sorting
[last_name, first_name].reject(&:blank?).join(", ")
end
end

View File

@@ -3,7 +3,9 @@
module Api
module Admin
class OrderSerializer < ActiveModel::Serializer
attributes :id, :number, :user_id, :full_name, :first_name, :last_name, :email, :phone,
include AddressDisplay
attributes :id, :number, :user_id, :full_name, :full_name_for_sorting, :email, :phone,
:completed_at, :completed_at_utc_iso8601, :display_total,
:edit_path, :state, :payment_state, :shipment_state,
:payments_path, :ready_to_ship, :ready_to_capture, :created_at,
@@ -18,11 +20,11 @@ module Api
end
def first_name
object.billing_address.nil? ? "" : ( object.billing_address.first_name || "" )
object.billing_address&.first_name || ""
end
def last_name
object.billing_address.nil? ? "" : ( object.billing_address.last_name || "" )
object.billing_address&.last_name || ""
end
def distributor_name

View File

@@ -133,7 +133,7 @@
%a{ :href => '', 'ng-click' => "sorting.toggle('order.number')" }
= t("admin.orders.bulk_management.order_no")
%th.full_name{ 'ng-show' => 'columns.full_name.visible' }
%a{ :href => '', 'ng-click' => "sorting.toggle(['order.last_name', 'order.first_name'])" }
%a{ :href => '', 'ng-click' => "sorting.toggle('order.full_name_for_sorting')" }
= t("admin.name")
%th.email{ 'ng-show' => 'columns.email.visible' }
%a{ :href => '', 'ng-click' => "sorting.toggle('order.email')" }
@@ -170,7 +170,7 @@
%td.bulk
%input{ :type => "checkbox", :name => 'bulk', 'ng-model' => 'line_item.checked', 'ignore-dirty' => true }
%td.order_no{ 'ng-show' => 'columns.order_no.visible' } {{ line_item.order.number }}
%td.full_name{ 'ng-show' => 'columns.full_name.visible' } {{ line_item.order.last_name + ', ' + line_item.order.first_name }}
%td.full_name{ 'ng-show' => 'columns.full_name.visible' } {{ line_item.order.full_name_for_sorting }}
%td.email{ 'ng-show' => 'columns.email.visible' } {{ line_item.order.email }}
%td.phone{ 'ng-show' => 'columns.phone.visible' } {{ line_item.order.phone }}
%td.date{ 'ng-show' => 'columns.order_date.visible' } {{ line_item.order.completed_at }}