Skip to content

Commit

Permalink
Merge pull request #427 from tungleduyxyz/technical-support-175
Browse files Browse the repository at this point in the history
Fix bug when displaying tables
  • Loading branch information
reshmabidikar authored Dec 19, 2024
2 parents 29335f0 + 58072c1 commit 9ab916e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 64 deletions.
2 changes: 1 addition & 1 deletion app/models/kaui/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Kaui
class Invoice < KillBillClient::Model::Invoice
TABLE_IGNORE_COLUMNS = %w[amount balance credit_adj refund_adj items is_parent_invoice parent_invoice_id parent_account_id audit_logs].freeze
TABLE_IGNORE_COLUMNS = %w[amount balance credit_adj refund_adj items is_parent_invoice parent_invoice_id parent_account_id audit_logs bundle_keys].freeze

def self.build_from_raw_invoice(raw_invoice)
result = Kaui::Invoice.new
Expand Down
80 changes: 36 additions & 44 deletions app/views/kaui/accounts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,43 @@

<%= javascript_tag do %>
$(document).ready(function() {
$.ajax({
url: "<%= accounts_pagination_path(:ordering => @ordering, :format => :json) %>",
type: "GET",
success: function(response) {
const visibleColumns = response.columns;

var table = $('#accounts-table').DataTable({
"colReorder": {
"enable": false
},
"stateSave": true,
"scrollX": true,
"dom": "<'row'r>t<'row'<'col-md-6'i><'col-md-6'p>>",
"pagingType": <% if @max_nb_records.nil? -%>"simple"<% else -%>"full_numbers"<% end -%>,
"language": {
<!-- See DefaultPaginationSqlDaoHelper.java -->
"info": <% if @max_nb_records.nil? -%>"Showing _START_ to _END_ of <%= number_with_delimiter(Kaui::EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD) -%>+ entries"<% else -%>"Showing _START_ to _END_ of _TOTAL_ entries"<% end -%>
},
"pageLength": <%= @limit %>,
"displayStart": <%= @offset %>,
<% if @search_query.blank? %>
"ordering": false,
<% elsif !@ordering.blank? %>
"order": [[ 1, "<%= @ordering %>" ]],
<% end %>
"processing": true,
"serverSide": true,
"search": {"search": "<%= @search_query %>"},
"ajax": {
url: "<%= accounts_pagination_path(:ordering => @ordering, :format => :json) %>",
dataSrc: function(json) {
var colOrder = $('#accounts-table').DataTable().colReorder.order();
var reorderedData = json.data.map(function(row) {
var newRow = [];
for (var i = 0; i < colOrder.length; i++) {
newRow.push(row[colOrder[i]]);
}
return newRow;
});
return reorderedData;
var table = $('#accounts-table').DataTable({
"colReorder": {
"enable": false
},
"stateSave": true,
"scrollX": true,
"dom": "<'row'r>t<'row'<'col-md-6'i><'col-md-6'p>>",
"pagingType": <% if @max_nb_records.nil? -%>"simple"<% else -%>"full_numbers"<% end -%>,
"language": {
<!-- See DefaultPaginationSqlDaoHelper.java -->
"info": <% if @max_nb_records.nil? -%>"Showing _START_ to _END_ of <%= number_with_delimiter(Kaui::EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD) -%>+ entries"<% else -%>"Showing _START_ to _END_ of _TOTAL_ entries"<% end -%>
},
"pageLength": <%= @limit %>,
"displayStart": <%= @offset %>,
<% if @search_query.blank? %>
"ordering": false,
<% elsif !@ordering.blank? %>
"order": [[ 1, "<%= @ordering %>" ]],
<% end %>
"processing": true,
"serverSide": true,
"search": {"search": "<%= @search_query %>"},
"ajax": {
url: "<%= accounts_pagination_path(:ordering => @ordering, :format => :json) %>",
dataSrc: function(json) {
var colOrder = table.colReorder.order();
var reorderedData = json.data.map(function(row) {
var newRow = [];
for (var i = 0; i < colOrder.length; i++) {
newRow.push(row[colOrder[i]]);
}
},
"columns": visibleColumns
});
}
return newRow;
});
return reorderedData;
}
},
"columns": <%= raw @visible_columns.to_json %>
});

<!-- When we don't know the total number of pages, we need to hide the legend and next button manually -->
Expand Down
7 changes: 1 addition & 6 deletions app/views/kaui/invoices/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $(document).ready(function() {
"ajax": {
url: "<%= invoices_pagination_path(:ordering => @ordering, :format => :json) %>",
dataSrc: function(json) {
var colOrder = $('#invoices-table').DataTable().colReorder.order();
var colOrder = table.colReorder.order();
var reorderedData = json.data.map(function(row) {
var newRow = [];
for (var i = 0; i < colOrder.length; i++) {
Expand All @@ -70,11 +70,6 @@ $(document).ready(function() {
}
});

var searchQuery = "<%= @search_query %>";
if (searchQuery) {
table.search(searchQuery).draw();
}

<!-- When we don't know the total number of pages, we need to hide the legend and next button manually -->
<% if @max_nb_records.nil? %>
$('#invoices-table').on('draw.dt', function() {
Expand Down
5 changes: 0 additions & 5 deletions app/views/kaui/payments/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ $(document).ready(function() {
"search": {"search": "<%= @search_query %>"},
});

var searchQuery = "<%= @search_query %>";
if (searchQuery) {
table.search(searchQuery).draw();
}

<!-- When we don't know the total number of pages, we need to hide the legend and next button manually -->
<% if @max_nb_records.nil? %>
$('#payments-table').on('draw.dt', function() {
Expand Down
10 changes: 2 additions & 8 deletions lib/kaui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ module Kaui
when 'balance'
view_context.humanized_money_with_symbol(invoice.balance_to_money)
when 'invoice_id'
view_context.link_to(invoice.invoice_number, view_context.url_for(controller: :invoices, action: :show, account_id: invoice.account_id, id: invoice.invoice_id))
view_context.link_to(invoice.invoice_id, view_context.url_for(controller: :invoices, action: :show, account_id: invoice.account_id, id: invoice.invoice_id))
when 'status'
default_label = 'label-info'
default_label = 'label-default' if invoice&.status == 'DRAFT'
Expand All @@ -140,7 +140,7 @@ module Kaui
self.account_payments_columns = lambda do |account = nil, payment = nil, view_context = nil|
fields = KillBillClient::Model::PaymentAttributes.instance_variable_get('@json_attributes')
# Change the order if needed
fields = %w[payment_date authed_amount paid_amount returned_amount] + fields
fields = %w[payment_date] + fields
fields -= %w[payment_number transactions audit_logs]
fields.unshift('status')
fields.unshift('payment_number')
Expand All @@ -154,12 +154,6 @@ module Kaui
view_context.link_to(payment.payment_number, view_context.url_for(controller: :payments, action: :show, account_id: payment.account_id, id: payment.payment_id))
when 'payment_date'
view_context.format_date(payment.payment_date, account&.time_zone)
when 'authed_amount'
view_context.humanized_money_with_symbol(payment.total_authed_amount_to_money)
when 'paid_amount'
view_context.humanized_money_with_symbol(payment.paid_amount_to_money)
when 'returned_amount'
view_context.humanized_money_with_symbol(payment.returned_amount_to_money)
when 'status'
payment.transactions.empty? ? nil : view_context.colored_transaction_status(payment.transactions[-1].status)
else
Expand Down

0 comments on commit 9ab916e

Please sign in to comment.