Skip to content

Commit

Permalink
bug fix: for cdrs page, failed request when submit visible columns
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ivanov-Anton committed Jul 18, 2024
1 parent 3a9fcd1 commit bf8ac6a
Show file tree
Hide file tree
Showing 3 changed files with 34 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
10 changes: 4 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,8 @@ $(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() {
debugger;
window.location.reload();
});
},
Expand All @@ -27,10 +25,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();
});
});

}
});
});
29 changes: 29 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,33 @@
expect(page).to have_table_cell(column: 'ID', exact_text: cdr.id)
end
end

describe 'Visible columns feature' do
context 'when click to "Visible columns" link' do
before do
visit cdrs_path
click_link 'Visible columns'
end

it 'should display "Visible columns" popup', js: true do
expect(page).to have_selector '.ui-widget'
expect(page).to have_selector '.ui-dialog-title', exact_text: 'Visible table columns'
within '.ui-dialog' do
expect(page).to have_button :Show
expect(page).to have_button :Cancel
end
end
end

context 'when click to "Reset" link' do
let!(:admin_user) { create :admin_user, visible_columns: { cdrs: %w[id] } }

before { visit cdrs_path }

it 'should click to "Reset" link', js: true do
click_link :Reset
expect(admin_user.reload).to have_attributes(visible_columns: { 'cdrs' => '' })
end
end
end
end

0 comments on commit bf8ac6a

Please sign in to comment.