Skip to content

Commit

Permalink
Merge pull request #1507 from yeti-switch/1363-cdrs-visible-columns-4…
Browse files Browse the repository at this point in the history
…01-1

bug fix: for cdrs page, failed request when submit visible columns
  • Loading branch information
dmitry-sinina authored Jul 19, 2024
2 parents 5f55dae + e63511f commit 35bb80b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/admin/cdr/cdrs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
9 changes: 3 additions & 6 deletions app/assets/javascripts/index_as_table_visible_columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
},
Expand All @@ -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();
});
});

}
});
});
31 changes: 31 additions & 0 deletions spec/features/cdr/cdr_history/cdrs_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 35bb80b

Please sign in to comment.