From e63511fdd8dcd0bcf3db30d758efc5c5803fda2d Mon Sep 17 00:00:00 2001 From: Anton-Ivanov Date: Thu, 18 Jul 2024 22:06:27 +0300 Subject: [PATCH] bug fix: for cdrs page, failed request when submit visible columns The $.getJSON calls in index_as_table_visible_columns.js have been shortened and simplified for better readability. The "index" function within cdrs.rb was also modified to include download_links in CSV and JSON formats. --- app/admin/cdr/cdrs.rb | 2 +- .../index_as_table_visible_columns.js | 9 ++---- .../cdr/cdr_history/cdrs_index_spec.rb | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/admin/cdr/cdrs.rb b/app/admin/cdr/cdrs.rb index af436511d..356e44cf1 100644 --- a/app/admin/cdr/cdrs.rb +++ b/app/admin/cdr/cdrs.rb @@ -607,7 +607,7 @@ def scoped_collection end end - index do + index download_links: %i[csv json] do column :id do |cdr| if cdr.has_dump? if cdr.has_recording? diff --git a/app/assets/javascripts/index_as_table_visible_columns.js b/app/assets/javascripts/index_as_table_visible_columns.js index 3245e0fc9..910b327ab 100644 --- a/app/assets/javascripts/index_as_table_visible_columns.js +++ b/app/assets/javascripts/index_as_table_visible_columns.js @@ -9,10 +9,7 @@ $(document).ready(function(){ var $select = $(this).closest('#block_available_columns').find('select'), selected_fields = $select.val(); $(this).parent().find('.ui-dialog-buttonset').text('Loading...'); - $.getJSON( - this.href, - {index_table_visible_columns: selected_fields} - ).success(function(){ + $.getJSON(this.href, {index_table_visible_columns: selected_fields}, function() { window.location.reload(); }); }, @@ -27,10 +24,10 @@ $(document).ready(function(){ }); $('#reset_visible_columns').click(function(){ - $.getJSON(this.href, {index_table_visible_columns: ''}).success(function(){ + $.getJSON(this.href, {index_table_visible_columns: ''}, function () { window.location.reload(); }); }); } -}); \ No newline at end of file +}); diff --git a/spec/features/cdr/cdr_history/cdrs_index_spec.rb b/spec/features/cdr/cdr_history/cdrs_index_spec.rb index 7b01fdf45..2e6964cff 100644 --- a/spec/features/cdr/cdr_history/cdrs_index_spec.rb +++ b/spec/features/cdr/cdr_history/cdrs_index_spec.rb @@ -98,4 +98,35 @@ expect(page).to have_table_cell(column: 'ID', exact_text: cdr.id) end end + + describe 'Visible columns feature' do + context 'when click to "Reset" link' do + subject { click_link :Reset } + + let!(:admin_user) { create :admin_user, visible_columns: { cdrs: %w[id] } } + + before { visit cdrs_path } + + it 'should click to "Reset" link', js: true do + expect { subject }.to change { admin_user.reload.visible_columns['cdrs'] }.from(%w[id]).to('') + end + end + + context 'when select the several columns and submit form' do + subject { click_button 'Show' } + + let!(:admin_user) { create :admin_user, visible_columns: { cdrs: %w[id] } } + + before do + visit cdrs_path + click_link 'Visible columns' + select 'time_start', from: 'select_available_columns' + select 'time_end', from: 'select_available_columns' + end + + it 'should reload index page and then render only selected columns', js: true do + expect { subject }.to change { admin_user.reload.visible_columns }.from({ 'cdrs' => %w[id] }).to({ 'cdrs' => %w[id time_start time_end] }) + end + end + end end