-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor notes list and course list #395
Comments
mostly the same: var dataTable = $('#data_table_list').dataTable({
'bAutoWidth': false,
'bLengthChange': false,
// specify the number of rows in a page
'iDisplayLength': 20,
// or
'displayLength': 20,
// Position the filter bar at the top
'sDom': dataTable_sDom,
// or
'dom': '<"top">rt<"bottom"p><"clear">',
// Initial sorting
'aaSorting': [[1,'desc']]
// or
'aaSorting': [[2,'desc']],
});
// only notes check for table length
if (dataTable.length > 0) {
// searching.
// courses is handled here, search notes exists but is handled via FORM submit
// rather than JS filtering as done here for courses
$('#search-courses').keyup(function() {
dataTable.fnFilter($(this).val());
});
// sorting.
$('select.note-sort').change(function() {
dataTable.fnSort([[$(this).val(), 'desc']]);
});
// vs
$('#sort-by').change(function() {
var sortCol = $(this).val();
dataTable.fnSort([[sortCol, 'desc']]);
});
// filtering.
$('select.note-category').change(function() {
var category = $(this).val();
if (category === 'ALL') {
dataTable.fnFilter('');
} else {
dataTable.fnFilter(category);
}
});
// vs
$('#school-filter').change(function() {
var schoolName = $(this).val();
if (schoolName === 'ALL') {
dataTable.fnFilter('');
} else {
dataTable.fnFilter(schoolName);
}
});
// updating on reload.
// only found in notes-list
dataTable.fnSort([[$('select.note-sort').val(), 'desc']]);
// only found in courses-list
$('#school-filter').trigger('change');
} Here's a bunch of stuff that course-list does with var dataTable = $('#data_table_list').dataTable({
// ...
'paging': true,
'columns': [
{ 'name': 'course', 'orderable': false, 'searchable': true, 'visible': true,
'class': 'small-12 columns data-table-entry-wrapper' },
{ 'name': 'date', 'orderable': true, 'searchable': false, 'visible': false },
{ 'name': 'note_count', 'orderable': true, 'searchable': false, 'visible': false },
{ 'name': 'popularity', 'orderable': true, 'searchable': false, 'visible': false }
],
'createdRow': function(row, data, index) {
$(row).addClass('table-row');
},
// Use server-side processing
'processing': true,
'serverSide': true,
'ajax': function(data, callback, settings) {
$.get(course_list_ajax_url, data, function(dataWrapper, textStatus, jqXHR) {
for (i = 0; i < dataWrapper.data.length; i++) {
dataWrapper.data[i][0] = tableRow(dataWrapper.data[i][0]);
}
callback(dataWrapper);
});
}
// ...
}); |
Both of the templates define the
Searching on the notes list (course-detail) is done with a FORM, while course-list does it using JS (and so there are only some DOM placeholders in the template):
It shouldn't be too hard to convert notes searching to AJAX. |
Here's where the course-list ajax handling is defined. karmaworld/karmaworld/apps/courses/views.py Lines 262 to 323 in a1b255c
It looks like that was written out by hand with loving care, but we already have AJAX select to simplify a lot of that kind of work. See for example: karmaworld/karmaworld/apps/courses/models.py Lines 104 to 114 in 57c0252
Although that example only supports filtering as written, it should be a bit cleaner to rewrite |
The course-list AJAX code supports ordering, but that ordering is overridden by the javascript ordering performed by dataTable. That chunk of order code is probably not needed. |
These two files have a lot of code in common and serve the same basic function, but differ based on whether notes or courses are being displayed. It seems that they should be refactored into unified code as much as possible.
karmaworld/karmaworld/assets/js/note-list.js
Lines 3 to 33 in 5dae386
karmaworld/karmaworld/assets/js/course-list.js
Lines 18 to 81 in 96a0464
There are a number of differences between them. Comparing and contrasting will be a good practice before refactoring.
The text was updated successfully, but these errors were encountered: