Merge pull request #2972 from AndrewKvalheim/ajax-datatables-rails-1_part-2

Update datatables for ajax-datatables-rails 1
This commit is contained in:
Henne Vogelsang 2022-03-29 15:15:10 +02:00 committed by GitHub
commit d471d9eb23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 22 deletions

View file

@ -20,7 +20,7 @@ module Admin
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
render json: RegistrationDatatable.new({}, conference: @conference, view_context: view_context) render json: RegistrationDatatable.new(params, conference: @conference, view_context: view_context)
end end
format.pdf { render 'index', layout: false } format.pdf { render 'index', layout: false }
format.xlsx do format.xlsx do

View file

@ -23,7 +23,7 @@ module Admin
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
render json: UserDatatable.new({}, view_context: view_context) render json: UserDatatable.new(params, view_context: view_context)
end end
end end
end end

View file

@ -14,7 +14,6 @@ class RegistrationDatatable < AjaxDatatablesRails::ActiveRecord
@view_columns ||= { @view_columns ||= {
id: { source: 'Registration.id', cond: :eq }, id: { source: 'Registration.id', cond: :eq },
name: { source: 'User.name' }, name: { source: 'User.name' },
roles: { source: 'Role.name' },
email: { source: 'User.email' }, email: { source: 'User.email' },
accepted_code_of_conduct: { source: 'Registration.accepted_code_of_conduct', searchable: false }, accepted_code_of_conduct: { source: 'Registration.accepted_code_of_conduct', searchable: false },
actions: { source: 'Registration.id', searchable: false, orderable: false } actions: { source: 'Registration.id', searchable: false, orderable: false }
@ -41,7 +40,6 @@ class RegistrationDatatable < AjaxDatatablesRails::ActiveRecord
roles: conference_role_titles(record.user), roles: conference_role_titles(record.user),
email: record.email, email: record.email,
accepted_code_of_conduct: !!record.accepted_code_of_conduct, # rubocop:disable Style/DoubleNegation accepted_code_of_conduct: !!record.accepted_code_of_conduct, # rubocop:disable Style/DoubleNegation
questions: {},
edit_url: edit_admin_conference_registration_path(conference, record), edit_url: edit_admin_conference_registration_path(conference, record),
DT_RowId: record.id DT_RowId: record.id
} }
@ -53,7 +51,7 @@ class RegistrationDatatable < AjaxDatatablesRails::ActiveRecord
end end
# override upstream santitation, which converts everything to strings # override upstream santitation, which converts everything to strings
def sanitize(records) def sanitize_data(records)
records records
end end
end end

View file

@ -22,8 +22,7 @@ class UserDatatable < AjaxDatatablesRails::ActiveRecord
name: { source: 'User.name' }, name: { source: 'User.name' },
attended: { source: 'attended_count', searchable: false }, attended: { source: 'attended_count', searchable: false },
roles: { source: 'Role.name' }, roles: { source: 'Role.name' },
view_url: { source: 'User.id', searchable: false, orderable: false }, actions: { source: 'User.id', searchable: false, orderable: false }
edit_url: { source: 'User.id', searchable: false, orderable: false }
} }
end end

View file

@ -26,7 +26,6 @@
%tr %tr
%th{ width: '0' } ID# %th{ width: '0' } ID#
%th{ width: '25%' } Name %th{ width: '25%' } Name
%th{ width: '0' } Roles
%th{ width: '0' } E-Mail %th{ width: '0' } E-Mail
%th{ width: '0' } %th{ width: '0' }
%abbr{ title: 'Code of Conduct' } CoC %abbr{ title: 'Code of Conduct' } CoC
@ -63,14 +62,6 @@
return content; return content;
} }
}, },
{
"name": "roles",
"data": "roles",
"className": "truncate",
"render": function(data, type, row) {
return data.join(', ');
}
},
{ {
"data": "email" "data": "email"
}, },
@ -80,13 +71,13 @@
"searchable": false "searchable": false
}, },
{ {
"data": null, "data": "actions",
"className": "actions", "className": "actions",
"searchable": false, "searchable": false,
"sortable": false, "sortable": false,
"render": function (data, type, row, meta) { "render": function (data, type, row, meta) {
return '<div class="btn-group">'+ return '<div class="btn-group">'+
'<a class="btn-primary" href="'+data.edit_url+'">Edit</a>'+ '<a class="btn-primary" href="'+row.edit_url+'">Edit</a>'+
'</div>'; '</div>';
} }
} }
@ -94,5 +85,4 @@
}); });
registrationsDataTable.columns(3).visible(codeOfConductPresent); registrationsDataTable.columns(3).visible(codeOfConductPresent);
registrationsDataTable.columns(2).visible(false);
}); });

View file

@ -61,13 +61,13 @@
} }
}, },
{ {
"data": null, "data": "actions",
"className": "actions", "className": "actions",
"sortable": false, "sortable": false,
"render": function (data, type, row, meta) { "render": function (data, type, row, meta) {
return '<div class="btn-group">'+ return '<div class="btn-group">'+
'<a class="btn-info" href="'+data.view_url+'">View</a>'+ '<a class="btn-info" href="'+row.view_url+'">View</a>'+
'<a class="btn-primary" href="'+data.edit_url+'">Edit</a>'+ '<a class="btn-primary" href="'+row.edit_url+'">Edit</a>'+
'</div>'; '</div>';
} }
} }