Sort orders by last names

This commit is contained in:
James Wu
2023-03-24 00:33:55 +09:00
committed by David Cook
parent 15058299d8
commit 546e90b286
4 changed files with 56 additions and 24 deletions

View File

@@ -11,5 +11,6 @@ angular.module("admin.indexUtils").factory 'SortOptions', ->
sortingExpr
toggle: (predicate) ->
@reverse = (@predicate == predicate) && !@reverse
# predicate is a string or an array of strings
@reverse = (JSON.stringify(@predicate) == JSON.stringify(predicate)) && !@reverse
@predicate = predicate

View File

@@ -3,8 +3,8 @@
module Api
module Admin
class OrderSerializer < ActiveModel::Serializer
attributes :id, :number, :user_id, :full_name, :email, :phone, :completed_at,
:completed_at_utc_iso8601, :display_total,
attributes :id, :number, :user_id, :full_name, :first_name, :last_name, :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,
:distributor_name, :special_instructions, :display_outstanding_balance,
@@ -17,6 +17,14 @@ module Api
object.billing_address.nil? ? "" : ( object.billing_address.full_name || "" )
end
def first_name
object.billing_address.nil? ? "" : ( object.billing_address.first_name || "" )
end
def last_name
object.billing_address.nil? ? "" : ( object.billing_address.last_name || "" )
end
def distributor_name
object.distributor&.name
end

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.full_name')" }
%a{ :href => '', 'ng-click' => "sorting.toggle(['order.last_name', 'order.first_name'])" }
= 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.full_name }}
%td.full_name{ 'ng-show' => 'columns.full_name.visible' } {{ line_item.order.last_name + ', ' + line_item.order.first_name }}
%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 }}

View File

@@ -228,7 +228,7 @@ describe '
it "displays a column for user's full name" do
expect(page).to have_selector "th.full_name", text: "NAME"
expect(page).to have_selector "td.full_name", text: o1.bill_address.full_name
expect(page).to have_selector "td.full_name", text: "#{o1.bill_address.last_name}, #{o1.bill_address.first_name}"
expect(page).to have_selector "td.full_name", text: ""
end
@@ -266,46 +266,69 @@ describe '
end
describe "sorting of line items" do
let!(:o1) {
create(:order_with_distributor, state: 'complete', shipment_state: 'ready',
completed_at: Time.zone.now)
}
let!(:o2) {
create(:order_with_distributor, state: 'complete', shipment_state: 'ready',
completed_at: Time.zone.now)
}
let!(:o1) do
create(
:order_with_distributor,
bill_address: create(:address, first_name: 'Bob', last_name: 'Taylor'),
state: 'complete',
shipment_state: 'ready',
completed_at: Time.zone.now
)
end
let!(:o2) do
create(
:order_with_distributor,
bill_address: create(:address, first_name: 'Mary', last_name: 'Smith'),
state: 'complete',
shipment_state: 'ready',
completed_at: Time.zone.now
)
end
let!(:o3) do
create(
:order_with_distributor,
bill_address: create(:address, first_name: 'Bill', last_name: 'Taylor'),
state: 'complete',
shipment_state: 'ready',
completed_at: Time.zone.now
)
end
let!(:li1) { create(:line_item_with_shipment, order: o1) }
let!(:li2) { create(:line_item_with_shipment, order: o2) }
let!(:li3) { create(:line_item_with_shipment, order: o3) }
before :each do
visit_bulk_order_management
end
it "sorts by customer name when the customer name header is clicked" do
customer_names = [o1.name, o2.name].sort
it "sorts by customer last name when the customer name header is clicked" do
within "#listing_orders thead" do
click_on "Name"
end
expect(page).to have_selector("#listing_orders .line_item:nth-child(1) .full_name",
text: customer_names[0])
text: "Smith, Mary")
expect(page).to have_selector("#listing_orders .line_item:nth-child(2) .full_name",
text: customer_names[1])
text: "Taylor, Bill")
expect(page).to have_selector("#listing_orders .line_item:nth-child(3) .full_name",
text: "Taylor, Bob")
end
it "sorts by customer name in reverse when the customer name header is clicked twice" do
customer_names = [o1.name, o2.name].sort.reverse
it "sorts by customer last name in reverse when the customer name header is clicked twice" do
within "#listing_orders thead" do
click_on "Name"
click_on "Name"
end
expect(page).to have_selector("#listing_orders .line_item:nth-child(1) .full_name",
text: customer_names[1])
text: "Taylor, Bob")
expect(page).to have_selector("#listing_orders .line_item:nth-child(2) .full_name",
text: customer_names[0])
text: "Taylor, Bill")
expect(page).to have_selector("#listing_orders .line_item:nth-child(3) .full_name",
text: "Smith, Mary")
end
end
end