Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sorting issue #443

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
RAILS_ENV: test
jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
include:
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ ruby '>= 3.1.0'
gemspec

gem 'rails', '~> 7.0.1'

# This fix is temporary until the next release of the gem
# See https://stackoverflow.com/questions/79360526/uninitialized-constant-activesupportloggerthreadsafelevellogger-nameerror
gem 'concurrent-ruby', '1.3.4'

group :development do
gem 'gem-release'
gem 'json'
Expand Down
1 change: 1 addition & 0 deletions app/controllers/kaui/engine_controller_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def paginate(searcher, data_extractor, formatter, table_default_columns = [])
# Until we support server-side sorting
ordering = (params[:order] || {})[:'0'] || {}
ordering_column = (ordering[:column] || 0).to_i
ordering_column = params[:colum_order][ordering_column].to_i if params[:colum_order].present?
ordering_dir = ordering[:dir] || 'asc'
unless search_key.nil?
pages.sort! do |a, b|
Expand Down
8 changes: 1 addition & 7 deletions app/controllers/kaui/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ def pagination
end
else
lambda do |invoice, column|
[
invoice.invoice_number.to_i,
invoice.invoice_date,
invoice.amount,
invoice.balance,
invoice.status
][column]
Kaui.account_invoices_columns.call(invoice, view_context)[2][column]
end
end

Expand Down
10 changes: 1 addition & 9 deletions app/controllers/kaui/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,7 @@ def pagination
end

data_extractor = lambda do |payment, column|
[
payment.payment_number.to_i,
payment.payment_date,
payment.total_authed_amount_to_money,
payment.paid_amount_to_money,
payment.returned_amount_to_money,
payment.transactions.empty? ? nil : payment.transactions[-1].status,
payment.payment_external_key
][column]
Kaui.account_payments_columns.call(account, payment, view_context)[2][column]
end

formatter = lambda do |payment|
Expand Down
3 changes: 3 additions & 0 deletions app/views/kaui/invoices/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ $(document).ready(function() {
"search": {"search": "<%= @search_query %>"},
"ajax": {
url: "<%= invoices_pagination_path(:ordering => @ordering, :format => :json) %>",
data: function(d) {
d.colum_order = $('#invoices-table').DataTable().colReorder.order();
},
dataSrc: function(json) {
var colOrder = table.colReorder.order();
var reorderedData = json.data.map(function(row) {
Expand Down
3 changes: 3 additions & 0 deletions app/views/kaui/payments/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ $(document).ready(function() {
"paging": false,
"ajax": {
url: "<%= payments_pagination_path(:format => :json) %>",
data: function(d) {
d.colum_order = $('#payments-table').DataTable().colReorder.order();
},
dataSrc: function(json) {
var colOrder = $('#payments-table').DataTable().colReorder.order();
var reorderedData = json.data.map(function(row) {
Expand Down
17 changes: 14 additions & 3 deletions lib/kaui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ module Kaui
invoice&.send(attr.downcase)
end
end
# Add additional values if needed
[headers, values]

raw_data = fields.map { |attr| invoice&.send(attr.downcase) }

[headers, values, raw_data]
end

self.account_payments_columns = lambda do |account = nil, payment = nil, view_context = nil|
Expand Down Expand Up @@ -177,8 +179,17 @@ module Kaui
end
end

raw_data = fields.map do |attr|
case attr
when 'status'
payment.transactions.empty? ? nil : view_context.colored_transaction_status(payment.transactions[-1].status)
else
payment&.send(attr.downcase)
end
end

# Add additional values if needed
[headers, values]
[headers, values, raw_data]
end

self.account_audit_logs_columns = lambda do
Expand Down
5 changes: 3 additions & 2 deletions script/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ ARGV = [SANDBOX_ROOT_PATH, '--skip-bundle'].freeze
Rails::Generators::AppGenerator.start

puts 'Setting up Kaui'
ARGV = [SANDBOX_ROOT_PATH, "--path=#{KAUI_ROOT_PATH}", '--skip-bundle'].freeze
KauiCmd::Installer.start
installer_args = [SANDBOX_ROOT_PATH, "--path=#{KAUI_ROOT_PATH}", '--skip-bundle'].freeze
KauiCmd::Installer.start(installer_args)

FileUtils.rm_f "#{SANDBOX_ROOT_PATH}/public/index.html"

puts 'Running migrations'
Expand Down