From 00e1a6f8094996f17675175a30def5e9bbf3e76a Mon Sep 17 00:00:00 2001 From: Kyle Le Date: Fri, 19 Jul 2024 00:06:58 +0700 Subject: [PATCH] [technical-support-137] New feature to modify columns --- app/controllers/kaui/accounts_controller.rb | 9 +- app/views/kaui/accounts/_edit_columns.erb | 144 ++++++++++++++++++++ app/views/kaui/accounts/index.html.erb | 13 +- lib/kaui.rb | 17 ++- 4 files changed, 161 insertions(+), 22 deletions(-) create mode 100644 app/views/kaui/accounts/_edit_columns.erb diff --git a/app/controllers/kaui/accounts_controller.rb b/app/controllers/kaui/accounts_controller.rb index 87f9d39d..efd0b470 100644 --- a/app/controllers/kaui/accounts_controller.rb +++ b/app/controllers/kaui/accounts_controller.rb @@ -39,14 +39,7 @@ def pagination end formatter = lambda do |account| - child_label = '' - unless account.parent_account_id.nil? - child_label = account.parent_account_id.nil? ? '' : view_context.content_tag(:span, 'Child', class: %w[label label-info account-child-label]) - end - - row = [child_label, view_context.link_to(account.account_id, view_context.url_for(action: :show, account_id: account.account_id))] - row += Kaui.account_search_columns.call(account, view_context)[1] - row + Kaui.account_search_columns.call(account, view_context)[1] end paginate searcher, data_extractor, formatter diff --git a/app/views/kaui/accounts/_edit_columns.erb b/app/views/kaui/accounts/_edit_columns.erb new file mode 100644 index 00000000..cef9c9e5 --- /dev/null +++ b/app/views/kaui/accounts/_edit_columns.erb @@ -0,0 +1,144 @@ + + + + +<%= javascript_tag do %> +$(document).ready(function() { + updateDropdownOrder(); + + function loadState() { + var state = JSON.parse(localStorage.getItem('DataTables_accounts-table_' + window.location.pathname)); + return state || { columns: [], columnOrder: [] }; + } + + function updateDropdownOrder() { + var state = loadState(); + var columnOrder = state.ColReorder; + var $list = $('#column-visibility'); + var thElements = document.querySelectorAll('#accounts-table th'); + var $columnTitles = Array.from(thElements).map(function(th) { + return th.textContent.trim(); + }); + if (columnOrder !== undefined) { + $list.empty(); + columnOrder.forEach(function(colIdx, index) { + var $item = $('
  • ', { class: "list-group-item-manual", "data-id": index }); + var column = state.columns[colIdx]; + var col_name = $columnTitles[colIdx]; + var $label = $('