Skip to content

Commit

Permalink
Issue #78: Add look ahead and look behind filters in quizzes in progr…
Browse files Browse the repository at this point in the history
…ess dashboard
  • Loading branch information
guillogo committed Mar 12, 2021
1 parent 8edbfe7 commit 45ffbb9
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 7 deletions.
2 changes: 1 addition & 1 deletion amd/build/dashboard_quiz_inprogress.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/dashboard_quiz_inprogress.min.js.map

Large diffs are not rendered by default.

50 changes: 49 additions & 1 deletion amd/src/dashboard_quiz_inprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function($, Ajax, Templates, Fragment, ZoomModal, Str, Notification) {
var refreshPeriod = 60;
var counterid;
var tablesort = 'name_asc';
var hoursAhead = 1;
var hoursBehind = 1;

const cards = [
{cardId: 'local-assessfreq-quiz-summary-upcomming-graph', call: 'upcomming_quizzes', aspect: true},
Expand Down Expand Up @@ -299,7 +301,10 @@ function($, Ajax, Templates, Fragment, ZoomModal, Str, Notification) {
let sorton = sortarray[0];
let direction = sortarray[1];

let params = {'data': JSON.stringify({'search': search, 'page': page, 'sorton': sorton, 'direction': direction})};
let params = {'data': JSON.stringify(
{'search': search, 'page': page, 'sorton': sorton, 'direction': direction,
'hoursahead': hoursAhead, 'hoursbehind': hoursBehind}
)};

spinner.classList.remove('hide'); // Show sinner if not already shown.

Expand Down Expand Up @@ -408,6 +413,42 @@ function($, Ajax, Templates, Fragment, ZoomModal, Str, Notification) {
ZoomModal.zoomGraph(event, params, method);
};

/**
* Process the hours ahead event from the in progress quizzes table.
*/
const quizzesAheadSet = function(event) {
event.preventDefault();
if (event.target.tagName.toLowerCase() === 'a') {
let hours = event.target.dataset.metric;
setUserPreference('local_assessfreq_quizzes_inprogress_table_hoursahead_preference', hours)
.then(() => {
hoursAhead = hours;
processDashboard(); // Reload the table.
})
.fail(() => {
Notification.exception(new Error('Failed to update user preference: hours ahead'));
});
}
};

/**
* Process the hours behind event from the in progress quizzes table.
*/
const quizzesBehindSet = function(event) {
event.preventDefault();
if (event.target.tagName.toLowerCase() === 'a') {
let hours = event.target.dataset.metric;
setUserPreference('local_assessfreq_quizzes_inprogress_table_hoursbehind_preference', hours)
.then(() => {
hoursBehind = hours;
processDashboard(); // Reload the table.
})
.fail(() => {
Notification.exception(new Error('Failed to update user preference: hours behind'));
});
}
};

/**
* Initialise method for quizzes in progress dashboard rendering.
*/
Expand Down Expand Up @@ -442,6 +483,13 @@ function($, Ajax, Templates, Fragment, ZoomModal, Str, Notification) {
let upcommingZoom = document.getElementById('local-assessfreq-quiz-summary-upcomming-graph-zoom');
upcommingZoom.addEventListener('click', triggerZoomGraph);

// Set up behind and ahead quizzes event listeners.
let quizzesAheadElement = document.getElementById('local-assessfreq-quiz-student-table-hoursahead');
quizzesAheadElement.addEventListener('click', quizzesAheadSet);

let quizzesBehindElement = document.getElementById('local-assessfreq-quiz-student-table-hoursbehind');
quizzesBehindElement.addEventListener('click', quizzesBehindSet);

processDashboard();

};
Expand Down
Loading

0 comments on commit 45ffbb9

Please sign in to comment.