Skip to content

Commit 49c774e

Browse files
committed
Fix bug advanced search
1 parent 6ec411f commit 49c774e

8 files changed

Lines changed: 28 additions & 26 deletions

File tree

app/assets/javascripts/kaui/multi_functions_bar_utils.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function searchParseOperatorText(text) {
2929
// Function to parse URL parameters
3030
function getUrlParams() {
3131
var params = {};
32-
var queryString = window.location.search.substring(1);
33-
queryString = queryString.replace(/ac_id/g, 'account_id');
32+
var advanceSearchQuery = new URLSearchParams(window.location.search).get('advance_search_query');
33+
var queryString = advanceSearchQuery !== null ? advanceSearchQuery : window.location.search.substring(1).replace(/ac_id/g, 'account_id');
3434
var regex = /([^&=]+)=([^&]*)/g;
3535
var m;
3636
while (m = regex.exec(queryString)) {
@@ -226,6 +226,10 @@ $(document).on('click', '.filter-close-icon', function() {
226226
}
227227
});
228228
var searchParams = searchQuery();
229+
// searchQuery() returns an already percent-encoded field[op]=value fragment; decode it
230+
// back to raw text so it can be sent as the (single-encoded) value of the dedicated
231+
// advance_search_query param instead of as top-level bracketed keys.
232+
var rawSearchParams = searchParams ? decodeURIComponent(searchParams) : searchParams;
229233
// Reapply search without the removed filter
230234
var tableSelectors = ['#invoices-table', '#accounts-table', '#payments-table', '#subscriptions-table'];
231235
var table = null;
@@ -240,15 +244,14 @@ $(document).on('click', '.filter-close-icon', function() {
240244

241245
if (table && table.ajax) {
242246
table.on('preXhr.dt', function(e, settings, data) {
243-
data.search.value = searchParams;
247+
data.advance_search_query = rawSearchParams;
244248
});
245249
table.ajax.reload(null, false);
246250
}
247251

248252
// Update URL
249-
if (searchParams) {
250-
var pushParams = (searchParams || '').replace(/account_id/g, 'ac_id');
251-
var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + pushParams;
253+
if (rawSearchParams) {
254+
var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?advance_search_query=' + encodeURIComponent(rawSearchParams);
252255
window.history.pushState({ path: newUrl }, '', newUrl);
253256
} else {
254257
var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname;

app/models/kaui/invoice.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Invoice < KillBillClient::Model::Invoice
66
# Columns shown by default on the Invoices list screen (demo-friendly defaults); the rest remain
77
# available but hidden until the user opts in via "Edit Columns".
88
DEFAULT_VISIBLE_COLUMNS = %w[invoice_number invoice_id status invoice_date target_date currency account_id].freeze
9-
ADVANCED_SEARCH_COLUMNS = %w[id account_id invoice_date target_date currency status balance].freeze
9+
ADVANCED_SEARCH_COLUMNS = %w[invoice_id account_id invoice_date target_date currency status balance].freeze
1010
ADVANCED_SEARCH_NAME_CHANGES = [%w[ac_id account_id]].freeze
1111

1212
def self.build_from_raw_invoice(raw_invoice)

app/models/kaui/payment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Payment < KillBillClient::Model::Payment
1717
'credited_amount' => 'credit',
1818
'refunded_amount' => 'refund'
1919
}.freeze
20-
ADVANCED_SEARCH_COLUMNS = %w[id account_id payment_method_id external_key].freeze
20+
ADVANCED_SEARCH_COLUMNS = %w[payment_id account_id payment_method_id payment_external_key].freeze
2121
ADVANCED_SEARCH_NAME_CHANGES = [%w[ac_id account_id]].freeze
2222

2323
def self.build_from_raw_payment(raw_payment)

app/views/kaui/accounts/index.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,10 @@ $(document).ready(function() {
132132
// If the page loaded with advanced search params in the URL (e.g. restored from
133133
// localStorage) but @advance_search_query was not set server-side, re-fire the
134134
// DataTable request with the correct filters.
135-
if (window.location.search.includes('_q=1') && '<%= j(@advance_search_query.to_s.strip) %>' === '') {
136-
var urlSearch = window.location.search.substring(1).replace(/ac_id/g, 'account_id');
135+
if (window.location.search.includes('advance_search_query=') && '<%= j(@advance_search_query.to_s.strip) %>' === '') {
136+
var urlSearch = new URLSearchParams(window.location.search).get('advance_search_query') || '';
137137
var ajaxUrl = "<%= accounts_pagination_path(:ordering => @ordering, :format => :json) %>";
138138
table.on('preXhr.dt.filter', function(e, settings, data) {
139-
data.search.value = urlSearch;
140139
data.advance_search_query = urlSearch;
141140
});
142141
table.ajax.url(ajaxUrl).load();

app/views/kaui/invoices/index.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ $(document).ready(function() {
106106
// If the page loaded with advanced search params in the URL (e.g. restored from
107107
// localStorage) but @advance_search_query was not set server-side, re-fire the
108108
// DataTable request with the correct filters.
109-
if (window.location.search.includes('_q=1') && '<%= j(@advance_search_query.to_s.strip) %>' === '' && !window.location.pathname.includes('/accounts/')) {
110-
var urlSearch = window.location.search.substring(1).replace(/ac_id/g, 'account_id');
111-
var ajaxUrl = "<%= invoices_pagination_path(:ordering => @ordering, :format => :json) %>" + '?' + urlSearch;
109+
if (window.location.search.includes('advance_search_query=') && '<%= j(@advance_search_query.to_s.strip) %>' === '' && !window.location.pathname.includes('/accounts/')) {
110+
var urlSearch = new URLSearchParams(window.location.search).get('advance_search_query') || '';
111+
var ajaxUrl = "<%= invoices_pagination_path(:ordering => @ordering, :format => :json) %>" + '?advance_search_query=' + encodeURIComponent(urlSearch);
112112
table.on('preXhr.dt.filter', function(e, settings, data) {
113-
data.search.value = urlSearch;
113+
data.advance_search_query = urlSearch;
114114
});
115115
table.ajax.url(ajaxUrl).load();
116116
}

app/views/kaui/payments/index.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ $(document).ready(function() {
121121
// If the page loaded with advanced search params in the URL (e.g. restored from
122122
// localStorage) but @advance_search_query was not set server-side, re-fire the
123123
// DataTable request with the correct filters.
124-
if (window.location.search.includes('_q=1') && '<%= j(@advance_search_query.to_s.strip) %>' === '' && !window.location.pathname.includes('/accounts/')) {
125-
var urlSearch = window.location.search.substring(1).replace(/ac_id/g, 'account_id');
126-
var ajaxUrl = "<%= payments_pagination_path(:ordering => @ordering, :format => :json) %>" + '?' + urlSearch;
124+
if (window.location.search.includes('advance_search_query=') && '<%= j(@advance_search_query.to_s.strip) %>' === '' && !window.location.pathname.includes('/accounts/')) {
125+
var urlSearch = new URLSearchParams(window.location.search).get('advance_search_query') || '';
126+
var ajaxUrl = "<%= payments_pagination_path(:ordering => @ordering, :format => :json) %>" + '?advance_search_query=' + encodeURIComponent(urlSearch);
127127
table.on('preXhr.dt.filter', function(e, settings, data) {
128-
data.search.value = urlSearch;
128+
data.advance_search_query = urlSearch;
129129
});
130130
table.ajax.url(ajaxUrl).load();
131131
}

app/views/kaui/shared/_advanced_search_filterbar.html.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,19 @@ $(document).ready(function() {
191191
var table = $('<%= table_selector %>').DataTable();
192192
table.off('preXhr.dt.filter');
193193
table.on('preXhr.dt.filter', function(e, settings, data) {
194-
data.search.value = searchQuery('<%= j search_query.to_s %>');
194+
data.advance_search_query = decodeURIComponent(searchQuery('<%= j search_query.to_s %>'));
195195
});
196196

197197
var searchParams = searchQuery('<%= j search_query.to_s %>');
198+
var rawSearchParams = searchParams ? decodeURIComponent(searchParams) : searchParams;
198199
var ajaxUrl = "<%= pagination_path %>";
199-
if (searchParams) {
200-
ajaxUrl += (ajaxUrl.includes('?') ? '&' : '?') + searchParams;
200+
if (rawSearchParams) {
201+
ajaxUrl += (ajaxUrl.includes('?') ? '&' : '?') + 'advance_search_query=' + encodeURIComponent(rawSearchParams);
201202
}
202203
table.ajax.url(ajaxUrl).load();
203204

204-
if (searchParams) {
205-
searchParams = searchParams.replace(/account_id/g, 'ac_id');
206-
var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + searchParams;
205+
if (rawSearchParams) {
206+
var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?advance_search_query=' + encodeURIComponent(rawSearchParams);
207207
window.history.pushState({ path: newUrl }, '', newUrl);
208208
}
209209

app/views/kaui/subscriptions/record_usage.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<% else %>
3838
This subscription's plan is billed via a standard (XML) catalog: usage is recorded against a <strong>unit type</strong>.
3939
<% end %>
40-
<a href="#" data-toggle="tooltip" class="kb-tooltip" title="Kaui automatically detects the catalog type for this subscription's account and submits usage through the matching Kill Bill API: the Record Usage API (unit type) for standard catalogs, or the Aviate Submit Usage Events API (billing meter code) for Aviate catalogs.">(?)</a>
40+
<a href="#" data-toggle="tooltip" class="kb-tooltip" title="Kaui automatically detects the catalog type for this subscription's account and submits usage through the matching Kill Bill API: the Record Usage API (unit type) for standard catalogs, or the Aviate Submit Usage Events API (billing meter code) for Aviate catalogs."></a>
4141
</small>
4242
</div>
4343
</div>

0 commit comments

Comments
 (0)