Skip to content

Commit

Permalink
Adds Amount as sort option and adds secondary sort options
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Jul 31, 2019
1 parent 7d452a6 commit 084e57e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/listSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ $(document).on('turbolinks:load', function(){
{ name: 'bill_description', attr: 'data-sort-bill_description' },
{ name: 'item_title', attr: 'data-sort-item_title' },
{ name: 'payment_date', attr: 'data-sort-payment_date' },
{ name: 'bill_amount', attr: 'data-sort-bill_amount'},
],
};

Expand Down
17 changes: 17 additions & 0 deletions app/models/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ def to_partial_path
'fines/payment'
end

# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
def sort_key(key)
sort_key = case key
when :payment_date
[payment_date.strftime('%FT%T'), item_title, bill_description]
when :item_title
[item_title, payment_date, bill_description]
when :bill_amount
[bill_amount, payment_date, item_title, bill_description]
when :bill_description
[bill_description, payment_date.strftime('%FT%T'), item_title]
end

sort_key.join('---')
end
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength

private

def fee_pay_info
Expand Down
8 changes: 4 additions & 4 deletions app/views/fines/_payment.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<li class="list-group-item">
<div class="row d-flex flex-wrap position-relative">
<div class="d-flex flex-row flex-grow-1 justify-content-start w-100 row col-md-12 col-lg-6">
<div class="col-4 col-md-4 order-md-first bill_description" data-sort-bill_description="<%= payment.bill_description %>" >
<div class="col-4 col-md-4 order-md-first bill_description" data-sort-bill_description="<%= h payment.sort_key(:bill_description) %>" >
<%= payment.bill_description %>
</div>

<div class="col-3 col-md-4 order-first order-sm-first">
<div class="col-3 col-md-4 order-first order-sm-first bill_amount" data-sort-bill_amount="<%= h payment.sort_key(:bill_amount) %>">
<%= number_to_currency(payment.bill_amount) %>
</div>

<div class="col-5 col-md-4 text-right text-md-left payment_date" data-date="<%= payment.payment_date.strftime('%FT%T') %>" data-sort-payment_date="<%= payment.payment_date %>" >
<div class="col-5 col-md-4 text-right text-md-left payment_date" data-date="<%= h payment.sort_key(:payment_date) %>" data-sort-payment_date="<%= payment.payment_date %>" >
<%= l(payment.payment_date, format: :short) %>
</div>
</div>
<div class="d-flex flex-grow-1 flex-column flex-md-row w-75 row col-md-12 col-lg-6 item_title" data-sort-item_title="<%= payment.item_title %>">
<div class="d-flex flex-grow-1 flex-column flex-md-row w-75 row col-md-12 col-lg-6 item_title" data-sort-item_title="<%= h payment.sort_key(:item_title) %>">
<h3 class="col-md-10 clamp-3 record-title list-item-title"><%= payment.item_title %></h3>
</div>
<div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/fines/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@
<li class="dropdown-item" data-sort="bill_description">Reason</li>
<li class="dropdown-item active" data-sort="payment_date">Date paid</li>
<li class="dropdown-item" data-sort="item_title">Title</li>
<li class="dropdown-item" data-sort="bill_amount">Amount</li>
</ul>
</div>
</div>

<div class="d-none d-md-flex row font-weight-bold list-header">
<div class="row col-md-12 col-lg-6">
<div class="col-md-4" data-sort="bill_description">Reason</div>
<div class="col-md-4">Amount</div>
<div class="col-md-4" data-sort="bill_amount">Amount</div>
<div class="col-md-4 active" data-sort="payment_date">Paid on</div>
</div>
<div class="row col-md-12 col-lg-6">
Expand Down

0 comments on commit 084e57e

Please sign in to comment.