Skip to content

Commit 1a7d991

Browse files
committed
Fix sorting and filtering reset pagination
1 parent b1b5e06 commit 1a7d991

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/checker/admin.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,9 +1324,11 @@ try {
13241324
var selectedSegment = segments.find(segment => String(segment.id) === document.getElementById("filter-segment-input").value);
13251325
if (selectedSegment) filteredQuestions = filteredQuestions.filter(q => JSON.parse(selectedSegment.question_ids).find(qId => String(qId.id) === String(q.id)));
13261326
}
1327+
if (this && (this.id === 'filter-segment-input')) pagination.questions.page = 0;
13271328
pagination.questions.total = filteredQuestions.length;
13281329
if (document.querySelector('.questions #current-page')) document.querySelector('.questions #current-page').innerText = `Page ${pagination.questions.page + 1} of ${Math.ceil(pagination.questions.total / pagination.questions.perPage)}`;
13291330
var currentPageQuestions = filteredQuestions.slice(pagination.questions.page * pagination.questions.perPage, (pagination.questions.page + 1) * pagination.questions.perPage);
1331+
syncPagination();
13301332
renderedEditors = {};
13311333
if (active) {
13321334
Array.from(document.querySelector('.questions .section').children).forEach(rq => {
@@ -1915,10 +1917,15 @@ try {
19151917
if (!a.flagged && b.flagged) return 1;
19161918
return b.id - a.id;
19171919
});
1920+
if (this && ((this.id === 'course-period-input') || (this.id === 'filter-segment-input') || (this.id === 'sort-question-input') || (this.id === 'sort-seat-input'))) {
1921+
pagination.awaitingResponses.page = 0;
1922+
pagination.responses.page = 0;
1923+
}
19181924
pagination.awaitingResponses.total = responses1.filter(r => ((r.status === 'Invalid Format') || (r.status === 'Unknown, Recorded')) && document.querySelector('.awaitingResponses .section')).length;
19191925
pagination.responses.total = responses1.filter(r => !((r.status === 'Invalid Format') || (r.status === 'Unknown, Recorded')) && document.querySelector('.responses .section')).length;
19201926
if (document.querySelector('.awaitingResponses #current-page')) document.querySelector('.awaitingResponses #current-page').innerText = `Page ${pagination.awaitingResponses.page + 1} of ${Math.ceil(pagination.awaitingResponses.total / pagination.awaitingResponses.perPage)}`;
19211927
if (document.querySelector('.responses #current-page')) document.querySelector('.responses #current-page').innerText = `Page ${pagination.responses.page + 1} of ${Math.ceil(pagination.responses.total / pagination.responses.perPage)}`;
1928+
syncPagination();
19221929
const awaitingSection = document.querySelector('.awaitingResponses .section');
19231930
const responsesSection = document.querySelector('.responses .section');
19241931
const awaitingResponses = responses1.filter(r => (r.status === 'Invalid Format' || r.status === 'Unknown, Recorded'));
@@ -5450,7 +5457,6 @@ try {
54505457
}
54515458

54525459
function viewRoster() {
5453-
console.log(rosters)
54545460
if (!this || !this.parentElement || !this.parentElement.querySelector('input').id) return;
54555461
const roster = rosters.find(roster => String(roster.period) === this.parentElement.querySelector('input').id.split('period-')[1]);
54565462
var rosterDataString = '';
@@ -5815,7 +5821,7 @@ try {
58155821
const questionTitle = this.parentElement.parentElement.querySelector('#question-text-input')?.value;
58165822
const questionDescription = renderedEditors[Number(questionId)].getText().replaceAll('\\n', ' ').replaceAll(' ', ' ').trim() || null;
58175823
const questionImages = [...new Set(JSON.parse(questions.find(q => String(q.id) === questionId).images))];
5818-
console.log(questionTitle, questionDescription, questionImages);
5824+
// console.log(questionTitle, questionDescription, questionImages);
58195825
ui.setUnsavedChanges(true);
58205826
if (questionImages.length || questionDescription) {
58215827
ui.startLoader();
@@ -5975,6 +5981,18 @@ try {
59755981
paginationSection.parentElement.querySelector('#next-page-button').disabled = (pagination[group].page + 1 >= Math.ceil(pagination[group].total / pagination[group].perPage)) ? true : false;
59765982
paginationSection.parentElement.querySelector('#previous-page-button').disabled = false;
59775983
}
5984+
5985+
function syncPagination() {
5986+
Object.keys(pagination).forEach(group => {
5987+
if (document.querySelector(`.${group} .pagination`)) {
5988+
document.querySelectorAll(`.${group} .pagination`).forEach(paginationSection => {
5989+
paginationSection.parentElement.querySelector('#current-page').innerText = `Page ${pagination[group].page + 1} of ${Math.ceil(pagination[group].total / pagination[group].perPage)}`;
5990+
paginationSection.parentElement.querySelector('#next-page-button').disabled = (pagination[group].page + 1 >= Math.ceil(pagination[group].total / pagination[group].perPage)) ? true : false;
5991+
paginationSection.parentElement.querySelector('#previous-page-button').disabled = (pagination[group].page - 1 < 0) ? true : false;
5992+
});
5993+
}
5994+
});
5995+
}
59785996
} catch (error) {
59795997
if (storage.get("developer")) {
59805998
alert(`Error @ admin.js: ${error.message}`);

src/checker/ta.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,15 @@ try {
284284
if (!a.flagged && b.flagged) return 1;
285285
return b.id - a.id;
286286
});
287+
if (this && ((this.id === 'course-period-input') || (this.id === 'filter-segment-input') || (this.id === 'sort-question-input') || (this.id === 'sort-seat-input'))) {
288+
pagination.awaitingResponses.page = 0;
289+
pagination.responses.page = 0;
290+
}
287291
pagination.awaitingResponses.total = responses1.filter(r => ((r.status === 'Invalid Format') || (r.status === 'Unknown, Recorded')) && document.querySelector('.awaitingResponses .section')).length;
288292
pagination.responses.total = responses1.filter(r => !((r.status === 'Invalid Format') || (r.status === 'Unknown, Recorded')) && document.querySelector('.responses .section')).length;
289293
if (document.querySelector('.awaitingResponses #current-page')) document.querySelector('.awaitingResponses #current-page').innerText = `Page ${pagination.awaitingResponses.page + 1} of ${Math.ceil(pagination.awaitingResponses.total / pagination.awaitingResponses.perPage)}`;
290294
if (document.querySelector('.responses #current-page')) document.querySelector('.responses #current-page').innerText = `Page ${pagination.responses.page + 1} of ${Math.ceil(pagination.responses.total / pagination.responses.perPage)}`;
295+
syncPagination();
291296
const awaitingSection = document.querySelector('.awaitingResponses .section');
292297
const responsesSection = document.querySelector('.responses .section');
293298
const awaitingResponses = responses1.filter(r => (r.status === 'Invalid Format' || r.status === 'Unknown, Recorded'));
@@ -790,6 +795,18 @@ try {
790795
paginationSection.parentElement.querySelector('#next-page-button').disabled = (pagination[group].page + 1 >= Math.ceil(pagination[group].total / pagination[group].perPage)) ? true : false;
791796
paginationSection.parentElement.querySelector('#previous-page-button').disabled = false;
792797
}
798+
799+
function syncPagination() {
800+
Object.keys(pagination).forEach(group => {
801+
if (document.querySelector(`.${group} .pagination`)) {
802+
document.querySelectorAll(`.${group} .pagination`).forEach(paginationSection => {
803+
paginationSection.parentElement.querySelector('#current-page').innerText = `Page ${pagination[group].page + 1} of ${Math.ceil(pagination[group].total / pagination[group].perPage)}`;
804+
paginationSection.parentElement.querySelector('#next-page-button').disabled = (pagination[group].page + 1 >= Math.ceil(pagination[group].total / pagination[group].perPage)) ? true : false;
805+
paginationSection.parentElement.querySelector('#previous-page-button').disabled = (pagination[group].page - 1 < 0) ? true : false;
806+
});
807+
}
808+
});
809+
}
793810
} catch (error) {
794811
if (storage.get("developer")) {
795812
alert(`Error @ ta.js: ${error.message}`);

0 commit comments

Comments
 (0)