Skip to content

Commit

Permalink
Merge pull request #2972 from AndrewKvalheim/ajax-datatables-rails-1_…
Browse files Browse the repository at this point in the history
…part-2

Update datatables for ajax-datatables-rails 1
  • Loading branch information
hennevogel authored Mar 29, 2022
2 parents c3dfd76 + 2a93d09 commit d471d9e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def index
respond_to do |format|
format.html
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
format.pdf { render 'index', layout: false }
format.xlsx do
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def index
respond_to do |format|
format.html
format.json do
render json: UserDatatable.new({}, view_context: view_context)
render json: UserDatatable.new(params, view_context: view_context)
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/datatables/registration_datatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def view_columns
@view_columns ||= {
id: { source: 'Registration.id', cond: :eq },
name: { source: 'User.name' },
roles: { source: 'Role.name' },
email: { source: 'User.email' },
accepted_code_of_conduct: { source: 'Registration.accepted_code_of_conduct', searchable: false },
actions: { source: 'Registration.id', searchable: false, orderable: false }
Expand All @@ -41,7 +40,6 @@ def data
roles: conference_role_titles(record.user),
email: record.email,
accepted_code_of_conduct: !!record.accepted_code_of_conduct, # rubocop:disable Style/DoubleNegation
questions: {},
edit_url: edit_admin_conference_registration_path(conference, record),
DT_RowId: record.id
}
Expand All @@ -53,7 +51,7 @@ def get_raw_records # rubocop:disable Naming/AccessorMethodName
end

# override upstream santitation, which converts everything to strings
def sanitize(records)
def sanitize_data(records)
records
end
end
3 changes: 1 addition & 2 deletions app/datatables/user_datatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def view_columns
name: { source: 'User.name' },
attended: { source: 'attended_count', searchable: false },
roles: { source: 'Role.name' },
view_url: { source: 'User.id', searchable: false, orderable: false },
edit_url: { source: 'User.id', searchable: false, orderable: false }
actions: { source: 'User.id', searchable: false, orderable: false }
}
end

Expand Down
14 changes: 2 additions & 12 deletions app/views/admin/registrations/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
%tr
%th{ width: '0' } ID#
%th{ width: '25%' } Name
%th{ width: '0' } Roles
%th{ width: '0' } E-Mail
%th{ width: '0' }
%abbr{ title: 'Code of Conduct' } CoC
Expand Down Expand Up @@ -63,14 +62,6 @@
return content;
}
},
{
"name": "roles",
"data": "roles",
"className": "truncate",
"render": function(data, type, row) {
return data.join(', ');
}
},
{
"data": "email"
},
Expand All @@ -80,19 +71,18 @@
"searchable": false
},
{
"data": null,
"data": "actions",
"className": "actions",
"searchable": false,
"sortable": false,
"render": function (data, type, row, meta) {
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>';
}
}
]
});

registrationsDataTable.columns(3).visible(codeOfConductPresent);
registrationsDataTable.columns(2).visible(false);
});
6 changes: 3 additions & 3 deletions app/views/admin/users/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
}
},
{
"data": null,
"data": "actions",
"className": "actions",
"sortable": false,
"render": function (data, type, row, meta) {
return '<div class="btn-group">'+
'<a class="btn-info" href="'+data.view_url+'">View</a>'+
'<a class="btn-primary" href="'+data.edit_url+'">Edit</a>'+
'<a class="btn-info" href="'+row.view_url+'">View</a>'+
'<a class="btn-primary" href="'+row.edit_url+'">Edit</a>'+
'</div>';
}
}
Expand Down

0 comments on commit d471d9e

Please sign in to comment.